#15239: fix(compact): add execution-time fallback + transient retry for /compact
size: M
Cluster:
Compaction Enhancements and Features
## Summary
- make `/compact` use execution-time model fallback (instead of only pre-resolving model)
- add one-time transient HTTP retry for compaction, aligned with chat resilience behavior
## Problem
`/compact` did not have the same resilience behavior as chat replies for model/provider instability.
Specifically:
- compaction execution could fail on transient provider errors and stop immediately
- fallback handling around compaction was not fully aligned with the execution path behavior used in chat
This is especially risky because compaction is a recovery operation when context pressure is high.
## Changes
1. Move compaction into execution-time fallback flow
- run `compactEmbeddedPiSession(...)` inside `runWithModelFallback(...)`
- fallback candidates are applied during actual compaction execution
2. Add one-time transient HTTP retry for `/compact`
- on transient HTTP errors (e.g. 5xx), retry the full fallback cycle once
- keep a bounded retry (single retry, 2.5s delay) to avoid loops
3. Add targeted tests for compact resilience
- execution-time fallback path is used
- primary failure falls back to next model successfully
- transient HTTP error triggers one full retry cycle
## Validation
### Targeted
- `pnpm -s test src/auto-reply/reply/commands-compact.test.ts` (pass)
### Baseline check (non-PR-related failures)
- Ran representative failing browser suite on both this branch and `upstream/main`:
- `src/browser/server.covers-additional-endpoint-branches.test.ts`
- both show the same `Unauthorized` / `401 vs 404` failure pattern
- conclusion: those failures are pre-existing baseline/environmental issues, not introduced by this change
## Risk & Rollback
- Scope is limited to `/compact` command path + dedicated tests (2 files)
- If needed, rollback is straightforward by reverting this PR commit set
## Tracking
Fixes #14543
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR routes `/compact` through the shared `runWithModelFallback` execution-time fallback mechanism and adds a one-time retry of the entire fallback cycle after a transient HTTP failure (2.5s delay). It also introduces new unit tests for the fallback and retry behavior by mocking the embedded PI compaction runner and fallback helper.
Key integration point is `handleCompactCommand` now defers provider/model selection to `runWithModelFallback` during compaction execution, aligning `/compact` resilience with the rest of the agent execution paths.
<h3>Confidence Score: 3/5</h3>
- This PR is moderately safe to merge once abort semantics and the new test’s session shape are corrected.
- Core change (running compaction inside runWithModelFallback + bounded transient retry) is localized and covered by targeted tests, but the current implementation swallows AbortError (changing cancellation behavior) and the new test constructs an impossible SessionEntry shape (`groupSpace` vs `space`), reducing confidence in coverage.
- src/auto-reply/reply/commands-compact.ts, src/auto-reply/reply/commands-compact.test.ts
<sub>Last reviewed commit: 23edd6e</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#11970: feat: add model.compact config for dedicated compaction model
by meaadore1221-afk · 2026-02-08
83.2%
#10505: feat(compaction): add timeout, model override, and diagnostic logging
by thebtf · 2026-02-06
80.6%
#20038: (fix): Compaction: preserve recent context and sync session memory ...
by rodrigouroz · 2026-02-18
78.9%
#15322: feat: post-compaction target token trimming + fallback strategy
by echoVic · 2026-02-13
78.7%
#12046: fix(compaction): add fallback for undefined ctx.model (#12016)
by anandsuraj · 2026-02-08
78.5%
#18663: feat: progressive compaction escalation and mechanical flush fallback
by Adamya05 · 2026-02-16
77.9%
#11089: feat(compaction): support customInstructions and model override for...
by p697 · 2026-02-07
77.8%
#17864: fix(compaction): pass model through runtime + reduce chunk ratio to...
by battman21 · 2026-02-16
77.5%
#14021: feat(compaction): optional memory flush before manual /compact
by phenomenoner · 2026-02-11
77.5%
#19878: fix: Handle compaction when fallback model has smaller context window
by gaurav10gg · 2026-02-18
77.1%