Repository navigation
Description
Problem
With automatic compaction enabled, deterministic context reduction can exhaust its eligible content without triggering durable compaction. The runner then continues toward the ordinary provider request. Exhaustion currently records a warning rather than determining escalation.
This is a source-level behavior gap, not a claim that a provider hard limit was exceeded or that a runtime regression has been reproduced.
Current mechanism
At c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba:
context-reduction.ts:80-84,180-203defaults to a target of 0.8 of the usable window. Once the eligible reduction steps are exhausted, a request still above that target producesoutcome: "exhausted". Protected recent content stays protected.runner/llm.ts:290-305callscompactIfNeededbefore publishing the context report. It does not pass the exhausted outcome to that check. A false result leads to logging exhaustion and continuing toward the ordinary request.compaction.ts:233-243independently checks whether the estimated lowered request exceedscontext - max(output, buffer). With auto enabled, an exhausted reduction can therefore coexist with a skipped compaction.compaction.ts:179-222also returns false for no summarizable head, an oversized summary prompt, a failed summary stream, or an empty summary. The caller cannot distinguish these cases from a request that needed no compaction.
The reducer and compactor measure different serialized representations. A regression test must capture both estimates instead of assuming that one displayed counter proves the compaction condition.
Related history
#320 already recorded that the exhausted outcome only logs while the contract called for escalation. #341 aligned the documentation with separate, config-driven compaction; it did not implement exhausted-to-compaction behavior. This follow-up concerns behavior with automatic compaction enabled, not another label or documentation-only change. Explicit compaction.auto=false must remain respected.
Acceptance
- Through the real runner path, cover
auto=truewith protected or irreducible content above the reduction target but below the current independent compaction gate. Exhaustion should trigger a durable compaction attempt rather than only a warning. - Preserve
auto=false. Do not override disabled automatic compaction. - Preserve protected content and durable summary/continuation semantics. Do not solve this by dropping protected recent turns, raising a limit, weakening protection, or changing only UI text.
- Cover no summarizable head, summary prompt too large, provider failure, and empty summary. Make the decision or failure observable, avoid unbounded compaction loops, and do not report compaction as completed when no summary was saved.
- The existing runner test
escalates to compaction instead of reducing protected contentcrosses the higher compaction gate. Add coverage for the exhausted-only interval rather than treating that existing test as proof of this path.
Sources
- https://github.com/mdev34-lab/silvercode/blob/c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba/packages/core/src/session/runner/llm.ts
- https://github.com/mdev34-lab/silvercode/blob/c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba/packages/core/src/session/compaction.ts
- https://github.com/mdev34-lab/silvercode/blob/c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba/packages/core/src/session/context-reduction.ts
- Follow-ups from PR #317 Arena review (context reduction, background-tasks, webchat store) #320
- docs(session): exhausted outcome and compaction contract (#320) #341
Additional execution path: opencode v1 loop
The issue must cover the opencode session loop used by the current HTTP API and TUI, not only the core v2 runner. A core-only escalation change would not establish the behavior of this path.
Source at c54ff0e:
server/routes/instance/httpapi/handlers/session.ts:54,353-377resolvesSessionPrompt.Serviceand forwards normal/async prompts to it.session/context-reduction.ts:93-103maps v1 history into the core reduction model and returns its report and projected history. It does not perform compaction.session/prompt.ts:1794-1828reduces the current request, publishesSessionEvent.Context.Prepared, lowers the result and calls the processor. The reduction report's exhausted outcome does not schedule compaction or block dispatch here.session/prompt.ts:1633-1639checks overflow usinglastFinished.tokens, not the newly prepared reduction report.session/processor.ts:552-595receives provider usage at step-finish and setsneedsCompactionusing that usage.processor.ts:727-736also handles a provider context-overflow error, honoring disabled auto compaction. The result is handled byprompt.ts:1868-1882to schedule the next compaction task.session/overflow.ts:28-34uses the provider token total (or input+output+cache fields), respects auto=false and compares against its own usable-window calculation. That is a separate quantity and timing from the prepared-request estimate displayed by the TUI.tui/context/sync.tsx:391-395stores the prepared report, and the shared context-usage helper renders its tokens and utilization. The report is the most recent published preparation measurement, not a live provider tokenizer or proof of which compaction branch ran.
Consequences established by source:
- In this path a current reduction estimate above its reported usable window can still proceed while prior provider usage remains below the compaction check. The explanation is not limited to a gap between an 80% reduction target and a 100% compaction target.
- Disabled auto compaction, stale or different provider usage, model selection/limits and request representation are distinct conditions that regression coverage must discriminate.
- Existing v1 test
loop stops provider overflow instead of auto-compacting when disabledcovers auto=false and must remain valid. Add a v1 integration regression for auto=true, exhausted prepared context and dispatch/escalation order; a core v2 runner test alone is insufficient. - Verify whether a compaction task was never scheduled, scheduled but failed, or completed and then immediately re-exhausted. Do not infer this from a single rendered frame.
Sources:
https://github.com/mdev34-lab/silvercode/blob/c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba/packages/opencode/src/session/prompt.ts
https://github.com/mdev34-lab/silvercode/blob/c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba/packages/opencode/src/session/processor.ts
https://github.com/mdev34-lab/silvercode/blob/c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba/packages/opencode/src/session/context-reduction.ts
https://github.com/mdev34-lab/silvercode/blob/c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba/packages/opencode/src/session/overflow.ts
https://github.com/mdev34-lab/silvercode/blob/c54ff0ef5a1ba02f84bd96cd1e7c5454f4ef18ba/packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts
Activity
fix(session): bound core v2 exhausted compaction escalation per turn …