Skip to content

fix(coding-agent): compact before tool-loop continuation#202

Open
code-yeongyu wants to merge 16 commits into
mainfrom
code-yeongyu/fix-compaction-overflow-recovery
Open

fix(coding-agent): compact before tool-loop continuation#202
code-yeongyu wants to merge 16 commits into
mainfrom
code-yeongyu/fix-compaction-overflow-recovery

Conversation

@code-yeongyu

@code-yeongyu code-yeongyu commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Fix tool loops and separate follow-up prompts that cross the compaction threshold after tool results are persisted. Previously, provider call 1 could remain below the threshold while trailing tool results pushed the live context over it; terminating tool batches could then end without next-turn preparation, and the next user prompt trusted stale assistant usage instead of the assembled persisted context.

The runtime now compacts the rebuilt persisted context before every inline continuation or separate pre-prompt dispatch, fails closed when required inline compaction does not complete, preserves provider-bound context transforms and pre-existing next-turn callbacks, and avoids unnecessary preparation for terminating tool batches.

Changes

  • Check threshold compaction after tool results are persisted and before the next provider request.
  • Estimate the rebuilt session context for both inline tool-loop and separate pre_prompt checks.
  • Recompute live context after unsuccessful required compaction and stop before provider dispatch when it remains oversized.
  • Preserve provider context transforms and constructor-supplied prepareNextTurnWithContext callbacks across rebuilt compacted context.
  • Skip next-turn preparation for terminating tool batches unless queued steering or follow-up input requires another turn.
  • Add regressions for accepted/cancelled compaction, terminating tool results across separate prompts, callback preservation, transformed summarization input, and compaction races.
  • Record the behavior changes in the agent and coding-agent changelogs.

QA / Evidence

Final commit: d96d2b06a263cce3c9147125e081c307db85652f.

  • Agent loop regression: 30/30 passed. Evidence: local-ignore/qa-evidence/20260713-compaction-overflow-final-d96d2b06/agent-loop-test.txt.
  • Coding-agent compaction and race regressions: 31/31 passed. Evidence: local-ignore/qa-evidence/20260713-compaction-overflow-final-d96d2b06/coding-agent-compaction-tests.txt.
  • Full build: all four phases passed. Evidence: local-ignore/qa-evidence/20260713-compaction-overflow-final-d96d2b06/npm-run-build.txt.
  • Repository gate: npm run check exited 0, including TypeScript, browser/web checks, lock validation, and Neo build/vet/tests; no files changed. Evidence: local-ignore/qa-evidence/20260713-compaction-overflow-final-d96d2b06/npm-run-check.txt.
  • Real source CLI QA: harness isolation 9/9, RPC 4/4, all mock provider protocols 5/5, and the OpenAI Responses two-request tool loop 4/4. Every receipt confirms the real auth file was unchanged. Evidence directory: local-ignore/qa-evidence/20260713-compaction-overflow-final-d96d2b06/.
  • No-excuse audit: the four changed-file findings reproduce on origin/main; the added-line audit reports no forbidden patterns. Evidence: local-ignore/qa-evidence/20260713-compaction-overflow-final-d96d2b06/no-excuse-audit.txt.
  • Failing-first proof: before the final fix, the terminating-tool regression had 27/28 passing with provider call 2 observing zero completed compactions. After the fix, provider call 2 observes one completed pre_prompt compaction and receives rebuilt context.

Risks

  • Pre-prompt checks now estimate persisted content rather than trusting the last assistant usage. The regression proves this happens before provider call 2 and still keeps the terminating tool result while dropping older context.
  • Required inline compaction fails closed only while the recomputed context remains oversized; accepted and below-threshold paths remain covered.
  • Callback preservation is exercised through the real constructor path, proving the existing callback runs once for the compacted tool transition and receives rebuilt messages.
  • QA used local faux/mock providers, so no paid provider calls or real credentials were required.

Secret Safety

Evidence contains no tokens, API keys, auth headers, cookies, environment dumps, or raw secret-bearing service logs. Only sanitized command output and auth-integrity receipts were saved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant