fix(agent-core): block turns during auto compaction - #2755
Conversation
🦋 Changeset detectedLatest commit: f9417c7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0e9417447
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| this.activeTurnId = turnId; | ||
| this.checkAutoCompaction(); | ||
| if (this.strategy.shouldBlock(this.tokenCountWithPending())) { | ||
| if (this._compacting !== null || this.strategy.shouldBlock(this.tokenCountWithPending())) { |
There was a problem hiding this comment.
Avoid compacting before tool continuations consume results
When compactionTriggerRatio is below the blocking ratio, afterStep() can start a soft auto-compaction immediately after a step that ended with tool calls; with this new condition the next continuation step now waits for that compaction to finish before making its LLM request. The compaction rewrite keeps user messages plus the generated summary and drops the raw assistant/tool-result messages, so the continuation that is supposed to consume fresh tool results may only see a lossy summary even though the context is still below the hard block threshold. This affects multi-step tool turns under lower-ratio auto compaction; consider not blocking/compacting ahead of tool-call continuations unless the hard block condition is actually met.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch. I reproduced the ordering as agent -> compaction -> continuation -> compaction.
Updated in f9417c7: soft auto compaction is now deferred across tool-call continuations, while hard-threshold compaction still blocks before the continuation. The new regression asserts agent -> continuation -> compaction and verifies that the continuation sees the raw tool result. The full test file is 75/75; typecheck, import boundaries, and oxlint also pass.
Signed-off-by: Errant <2843409461@qq.com>
e0e9417 to
f9417c7
Compare
Related Issue
Resolve #2720
Problem
See linked issue.
What changed
Wait for an in-flight auto compaction before starting the next agent step, even when the context is still below the blocking threshold. This keeps the compaction snapshot stable until commit and prevents the repeated cancel/abort cycle.
Defer soft auto compaction across tool-call continuations so the next model request can consume fresh tool results. Hard-threshold compaction still runs and blocks before the continuation.
Added regressions for both the in-flight race and the soft-compaction/tool-continuation ordering.
Validation:
vitest run packages/agent-core-v2/test/agent/fullCompaction/fullCompaction.test.ts(75 passed)tsc -p packages/agent-core-v2/tsconfig.json --noEmitnode packages/agent-core-v2/scripts/check-import-boundaries.mjsoxlinton the changed TypeScript filesChecklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.