← Back to PRs

#6108: Fix compaction producing empty summary when ctx.model is undefined (#6083)

by GangEunzzang open 2026-02-01 08:47 View on GitHub →
agents
## Summary When `createAgentSession()` is used, `extensionRunner.initialize()` is not called, leaving `ctx.model` undefined. This causes compaction to return only a fallback placeholder instead of a proper summary. ## Changes - Add `extractModelFromMessages()` to extract model info from assistant messages as fallback - Look up the full model object from `ctx.modelRegistry.getAvailable()` ## Test plan - [x] Build passes (`npm run build`) - [ ] Manual test with compaction when ctx.model is undefined Fixes #6083 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes a compaction edge case where `ctx.model` can be unset (e.g., sessions created via `createAgentSession()` without `extensionRunner.initialize()`), causing the safeguard to fall back to the placeholder summary. It adds a fallback that scans recent assistant messages for provider/model identifiers and then resolves the full model entry via `ctx.modelRegistry.getAvailable()` so staged summarization can still run. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge; it adds a narrow fallback path with limited surface area. - Changes are localized to compaction safeguard logic and preserve existing behavior when `ctx.model` is present. Main risk is assuming assistant messages consistently carry `provider`/`model` fields and that `modelRegistry.getAvailable()` contains a matching entry, but failures still degrade to the existing fallback summary. - src/agents/pi-extensions/compaction-safeguard.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs