Skip to content

fix(coding-agent): compact before model requests - #241

Closed
Issacboy123 wants to merge 1 commit into
fix/bound-proactive-compaction-attemptsfrom
fix/compact-before-model-requests
Closed

Issacboy123 wants to merge 1 commit into
fix/bound-proactive-compaction-attemptsfrom
fix/compact-before-model-requests

Conversation

@Issacboy123

Copy link
Copy Markdown
Contributor

Summary

Long tool loops could exceed the reserve threshold before the next compaction check. Checks before a prompt also missed the new input. This PR connects the request-preparation hook to automatic compaction. Each normal request checks its context after new input and tool results arrive, then continues with the rebuilt history.

Depends on fix/bound-proactive-compaction-attempts.

Reasoning

Checking at this point includes queued input and tool results. AgentSession still owns compaction and saves the result. Before rebuilding context, it verifies that live messages match the selected session history. If a hook changes messages so they no longer match, Diffex warns and continues with those messages. Changes made by later request-only transforms are outside the budget check.

Changes

  • Checked the budget after any existing preparation hook, using the context window of the model selected for the pending request.
  • Preserved pending user and custom messages, images, and the full latest group of tool calls and results.
  • Adjusted where proactive compaction cuts history so large tool batches remain complete.
  • Checked for changes to the selected history after asynchronous preparation and rejected extension cuts that would discard pending input or separate tool results from their calls.
  • Returned rebuilt messages, system prompt, and tools to the running loop. Kept retained message objects without rerunning tools or restarting the run.
  • Added tests that inspect messages sent to the model and when compaction occurs. Covered thresholds, input preservation, existing hooks, cancellation, repeated attempts, later context growth, and separate summarization requests.
  • Updated compaction documentation and the Unreleased changelog.

Testing

  • node ../../node_modules/vitest/dist/cli.js --run test/agent-loop.test.ts test/agent.test.ts
  • node ../../node_modules/vitest/dist/cli.js --run test/suite/agent-session-compaction.test.ts test/agent-session-compaction.test.ts test/compaction.test.ts test/agent-session-auto-compaction-queue.test.ts test/suite/agent-session-prompt.test.ts test/suite/agent-session-queue.test.ts test/agent-session-stats.test.ts test/suite/agent-session-current-plan-restoration.test.ts test/session-manager/compaction-rollback.test.ts test/suite/regressions/pre-prompt-compaction-no-continue.test.ts test/suite/regressions/177-compaction-busy-state.test.ts test/suite/regressions/6647-compaction-retries-transient-stream-drop.test.ts test/suite/agent-session-context-usage.test.ts test/suite/agent-session-proactive-compaction.test.ts test/suite/subagent-coordination.test.ts test/suite/agent-session-request-compaction.test.ts
  • node ../../node_modules/vitest/dist/cli.js --run test/interactive-mode-compaction.test.ts test/print-mode.test.ts test/rpc-jsonl.test.ts test/rpc-prompt-response-semantics.test.ts
  • npm run check

@Issacboy123 Issacboy123 added bug Something isn't working coding-agent labels Sep 20, 2026
@Issacboy123 Issacboy123 self-assigned this Sep 20, 2026
@Pepps233
Pepps233 added this pull request to stack #245 September 23, 2026 12:48
@Pepps233 Pepps233 closed this Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working coding-agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants