Repository navigation
fix(session): escalate exhausted context reduction to compaction - #835
agenteinstinct1-max wants to merge 10 commits into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
| .pipe(Effect.ignore) | ||
| // Reduction stops at protected content. When it exhausted its eligible steps the | ||
| // prepared request is still over target, so escalate to durable compaction before | ||
| // dispatching it. This is a threshold compaction and must follow compaction.auto. |
There was a problem hiding this comment.
WARNING: Possible non-progress loop when exhausted compaction is attempted but does not succeed
This branch escalates to compaction.create(...) and immediately return "continue" whenever reduction.report.outcome === "exhausted" and auto-compaction is enabled, but it does not check whether compaction actually completed or changed the request/history. If compaction is skipped/fails (e.g. no summarizable head, summary too large, provider failure) while the reduction remains exhausted, the loop may re-enter this same path repeatedly with the same prepared state.
Consider handling a non-successful compaction result explicitly (e.g. proceed with the reduced request, surface the failure, or add a guard to avoid retrying the same exhausted escalation indefinitely).
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (4 files)
Previous Review Summaries (5 snapshots, latest commit 0718d82)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 0718d82)Status: 1 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (4 files)
Fix these issues in Kilo Cloud Previous review (commit 4f50095)Status: 6 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (8 files)
Note: Three issues are in files ( Fix these issues in Kilo Cloud Previous review (commit cc8ebad)This review did not finish. The model reached its output limit before it Previous review (commit cc8ebad)Status: No Issues Found | Recommendation: Merge Overview
NotesThe previous WARNING finding ("Exhausted-reduction escalation can re-enter indefinitely if Files Reviewed (2 files)
Previous review (commit 5726716)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (6 files)
Reviewed by free · Input: 118.4K · Output: 26.1K · Cached: 247.2K |
| const summary = (yield* MessageV2.parts(processor.message.id).pipe( | ||
| Effect.provideService(Database.Service, database), | ||
| )) | ||
| .filter((part): part is SessionV1.TextPart => part.type === "text") |
There was a problem hiding this comment.
SUGGESTION: Summary extraction assumes text parts exist; non-text compaction skipped silently
The summary extraction (lines 556-563) filters for type === "text" parts. If compaction produces only tool calls or other non-text parts (e.g., a compaction that only runs tools), summary will be empty and the Compacted event is skipped with a warning. This may be intentional, but consider whether a compaction with only tool activity should still publish an event (perhaps with empty summary) for consistency.
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
| if (!(defect instanceof TurnTransitionError)) return yield* Effect.die(defect) | ||
| yield* Effect.yieldNow | ||
| if (defect.transition._tag === "ContinueAfterOverflowCompaction") | ||
| return yield* runAfterOverflowCompaction(sessionID, undefined, defect.transition.step) |
There was a problem hiding this comment.
WARNING: compactions once-per-turn bound is bypassed on overflow recovery
runAfterOverflowCompaction accepts a compactions counter (llm.ts:456) that gates compactIfNeeded to compactions === 0, enforcing "escalate at most once per turn". This call site omits compactions, so it defaults to 0: after an overflow compaction already ran via compactAfterOverflow (llm.ts:386), runTurnAttempt re-enters with compactions === 0 and compactIfNeeded can compact a second time in the same turn, over-summarizing history and contradicting the stated once-per-turn guarantee.
Propagate the counter here, e.g. pass compactions + 1 since an overflow compaction just occurred.
| return yield* runAfterOverflowCompaction(sessionID, undefined, defect.transition.step) | |
| return yield* runAfterOverflowCompaction(sessionID, undefined, defect.transition.step, compactions + 1) |
Issue for this PR
Closes #841. Refs #830, which remains open. #841 tracks the scoped exhausted escalation, bounded re-entry and automatic blank-summary history defects. It does not replace or shrink #830's broader acceptance.
Type of change
What does this PR do?
Pass the prepared exhausted reduction outcome to core compaction and schedule compaction before ordinary v1 dispatch when automatic compaction is enabled. Bound no-progress re-entry so it reaches dispatch or terminal failure. Publish completion only for a nonblank persisted summary and log reason-specific failures.
For a blank automatic summary, persist
summary: falsebefore continuation so a normally finished assistant message cannot hide original history throughfilterCompacted(). Use honest failure continuation text, including the distinction between media placeholders in a replay copy and original attachments that may remain in history. Preserve nonblank behavior and the existing error-result path.V4 reviewed candidate: d247e74, tree ef389d40696268675683e9ba55e2233ac34b7074, parent f90b548, integrating base 32c33f4. Candidate objects and all three V4 post-image blobs were independently checked against the unmodified author patch. Publication and exact-head checks are tracked separately; these local identity checks are not a CI result.
The same independent Arena reviewer reviewed all eight changed files and returned CLEAN for scoped V4, resolving the recursion, blank-summary and unfinished-test-fake blockers. The reviewer verified the attached patches, not the supplied commit bundle. Kilo's overflow-budget-reset warning remains bounded and nonblocking: a provider step can permit a threshold summary, an overflow summary and a post-overflow threshold summary. This is not a strict once-per-entire-prompt summary budget. Review: https://arena.ai/agent/01a1c817-7dc7-77ed-8953-3ac7fb8a614a .
No timeout, assertion, protection, workflow or CI gate is relaxed.
How did you verify your code works?
On the unmodified V4 candidate, full opencode compaction and context-reduction files: 62 pass, 1 existing disabled-v2-projector skip, 210 expectations. Related real-prompt subset: 3 pass. The shared fake now persists whitespace or summary text and a normal finish, so the overflow test checks actual completion eligibility and original user text/image retention.
Causal controls are separate from candidate results. Removing only
summary: falsefails first at the direct summary-flag assertion (line 995, true instead of false). A separately labelled diagnostic that also removes only that first assertion reaches the original user text/image retention failure at line 1011. Removing only the flag fix in the real prompt regression also loses protected original history. These controls do not count as passing candidate tests.Published exact head: d247e74, tree ef389d40696268675683e9ba55e2233ac34b7074, on base 32c33f4. Normal work-branch fast-forward only; no direct integration-branch push.
Current exact-head status checked November 11 at 05:16 BRT: typecheck and both standards jobs pass. Both Linux and Windows unit CI are RED. Linux failed in
packages/core/test/lib/effect.test.ts:57: the cancelled-effect test captured the abandoned-finalizer marker but did not findfinalizer boomin the captured stderr line. The preceding thrown-error/message assertions passed. Full core result: 1547 pass, 8 skip, 1 fail, 4403 expectations. The failure ended the Turbo run, so the full opencode prompt/TUI suites, generated-client check and HttpAPI gates are not qualified by that run. Linux job: https://github.com/mdev34-lab/silvercode/actions/runs/42980679036/job/130390102729 . Windows job: https://github.com/mdev34-lab/silvercode/actions/runs/42980679036/job/130390103215 .Windows completed with a different failure:
workspace sync state > sync history sends the local sequence fence and replays returned events in workspace contextinpackages/opencode/test/control-plane/workspace.test.ts:1388, interrupted after 22959.16ms. Theowned-deadline.ts:333stack frame rethrows the interruption; it does not identify its origin. Opencode finished with 5074 pass, 61 skip, 1 todo, 1 fail, 21894 expectations across 346 files (1738.23s). Windows core passed 1530 tests with 27 skips; TUI passed 938 tests with 9 skips. These passing packages do not clear either failed OS gate. The Windows job did not hit its 40-minute limit.Bounded source inspection found no explicit owned-deadline timer for this test, but did not identify the interrupted step, fiber or interruptor or reproduce the Windows sequence. In-body interruption is a hypothesis, not a proven exclusion of wider host or harness involvement. No shared cause with the separate #836 scrollback paint failure is established.
Separate local exact-head core runs passed (plain: 1553 pass, 3 skip; CI environment: 1547 pass, 9 skip). They did not reproduce the remote stderr failure and do not clear it. A bounded scratch capture also did not reproduce it; exact CI test order and the failed captured stderr contents remain unavailable. No cause or fix is claimed. The local full prompt run hit its cap without a result. No blind rerun, assertion relaxation or merge exemption is requested. Required exact-head full-suite and CI gates remain open.
#830 still needs focused core failure-branch coverage (no head, oversized summary prompt, provider failure, empty summary), real replay behavior, stop/error behavioral tests, the exact v1 auto=false exhausted-trigger test and manual blank-compaction handling. Source inspection and existing disabled-overflow coverage do not replace these tests. This PR must not close #830.
Screenshots / recordings
Not applicable: no UI change.
Checklist