Skip to content

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

Merged
code-yeongyu merged 19 commits into
mainfrom
code-yeongyu/fix-compaction-overflow-recovery
Jul 20, 2026
Merged

fix(coding-agent): compact before tool-loop continuation#202
code-yeongyu merged 19 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.

@gitguardian

gitguardian Bot commented Jul 20, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
34886147 Triggered Generic High Entropy Secret d39dd7d packages/ai/scripts/generate-models.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@code-yeongyu
code-yeongyu merged commit dc5cd08 into main Jul 20, 2026
6 checks passed
@code-yeongyu
code-yeongyu deleted the code-yeongyu/fix-compaction-overflow-recovery branch July 20, 2026 06:51
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