#12046: fix(compaction): add fallback for undefined ctx.model (#12016)
agents
stale
Cluster:
Compaction Safeguards and Summaries
## Problem
Compaction safeguard fails when `ctx.model` is undefined, causing exit code 1 and falling back to generic summary instead of generating AI-powered summary.
## Solution
- Changed `const model` to `let model` to allow reassignment
- Added fallback logic to retrieve model from `getCompactionSafeguardRuntime()`
- Added comprehensive diagnostic logging for debugging
## Benefits
- Prevents compaction failures when model context is missing
- Provides detailed error logs for troubleshooting
- Maintains backward compatibility with existing code
Fixes #12016
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change updates the compaction safeguard extension to be more resilient when `ctx.model` is missing. It introduces a fallback to read the model from the compaction safeguard runtime (via `getCompactionSafeguardRuntime(ctx.sessionManager)`), and adds additional warning/error logging to aid diagnosis. This keeps the existing behavior of returning a generic fallback summary when no model/API key is available, but avoids failing compaction purely due to an undefined model in the compaction context.
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge, with one logging/data-exposure concern to address.
- The functional change is small and contained (model fallback), and preserves the existing fallback-summary behavior when no model/API key is available. The main remaining risk is the new diagnostic logging potentially emitting sensitive internal context details into logs when `ctx.model` is absent.
- src/agents/pi-extensions/compaction-safeguard.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#6108: Fix compaction producing empty summary when ctx.model is undefined ...
by GangEunzzang · 2026-02-01
88.8%
#4223: fix: compaction safeguard falls through when ctx.model is unavailable
by hanxiao · 2026-01-29
87.5%
#17864: fix(compaction): pass model through runtime + reduce chunk ratio to...
by battman21 · 2026-02-16
83.3%
#10711: fix: cancel compaction instead of truncating history when summariza...
by DukeDeSouth · 2026-02-06
82.6%
#15927: feat: add compaction.model override config option
by Shuai-DaiDai · 2026-02-14
81.1%
#11089: feat(compaction): support customInstructions and model override for...
by p697 · 2026-02-07
81.0%
#11970: feat: add model.compact config for dedicated compaction model
by meaadore1221-afk · 2026-02-08
80.7%
#10505: feat(compaction): add timeout, model override, and diagnostic logging
by thebtf · 2026-02-06
80.0%
#15239: fix(compact): add execution-time fallback + transient retry for /co...
by VintLin · 2026-02-13
78.5%
#20038: (fix): Compaction: preserve recent context and sync session memory ...
by rodrigouroz · 2026-02-18
78.5%