#22859: fix: guard against undefined fileOps properties in compaction safeguard
agents
size: XS
Cluster:
Memory Management Enhancements
## Summary
- Adds nullish coalescing (`?? []`) fallbacks for `fileOps.read`, `.edited`, and `.written` in `computeFileLists()` to prevent `TypeError: Cannot read properties of undefined (reading 'filter')` when any of these properties are undefined
Without this guard, compaction crashes and falls back to summarization instead of producing real summaries.
Fixes #7190
## Local Validation
- [x] Verified the fix handles all three properties (`read`, `edited`, `written`)
- [x] Spread + `?? []` pattern is safe for both arrays and undefined values
## Scope
XS — 1-line change (2 lines reformatted) in one file
## AI Assistance
Used Claude Code for issue investigation and fix implementation.
## Author
@miloudbelarebia
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds nullish coalescing guards (`?? []`) to prevent `TypeError` when `fileOps.read`, `fileOps.edited`, or `fileOps.written` are undefined. Without these guards, the spread operators would throw runtime errors, causing compaction to fail and fall back to basic truncation instead of generating proper summaries.
<h3>Confidence Score: 5/5</h3>
- Safe to merge - defensive guard that prevents runtime errors
- Minimal defensive fix that adds proper undefined handling without changing logic. Uses idiomatic TypeScript pattern and matches the PR description's stated intent.
- No files require special attention
<sub>Last reviewed commit: fa31e1f</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22901: fix: guard against NaN reserveTokens in compaction safeguard
by miloudbelarebia · 2026-02-21
79.3%
#22786: fix: guard against undefined file.path in system-prompt-report
by miloudbelarebia · 2026-02-21
77.7%
#18724: fix(compaction): add defensive guards for undefined session.messages
by mdlmarkham · 2026-02-17
77.5%
#22711: fix: post-compaction audit skips non-existent required files
by taw0002 · 2026-02-21
72.7%
#12046: fix(compaction): add fallback for undefined ctx.model (#12016)
by anandsuraj · 2026-02-08
71.9%
#20038: (fix): Compaction: preserve recent context and sync session memory ...
by rodrigouroz · 2026-02-18
71.8%
#20851: fix: harden resolveUserPath and compact against undefined workspaceDir
by davidrudduck · 2026-02-19
71.7%
#10711: fix: cancel compaction instead of truncating history when summariza...
by DukeDeSouth · 2026-02-06
71.7%
#17864: fix(compaction): pass model through runtime + reduce chunk ratio to...
by battman21 · 2026-02-16
71.6%
#20553: fix(completion): guard zsh compdef call for environments without co...
by mr-sk · 2026-02-19
69.9%