fix(vscode): offer compact-and-retry when the context window overflows - #3082
fix(vscode): offer compact-and-retry when the context window overflows#3082skymecode wants to merge 2 commits into
Conversation
When the engine's auto-compaction gives up, the session surfaces context.overflow and the Webview only offered a Retry button that resent the same prompt into the same wall. Add a compactContext bridge method, a friendly error message for context.overflow / compaction.failed, and a Compact & Retry action on the inline error that compacts first and then resends the pending input.
🦋 Changeset detectedLatest commit: 215cc1a 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: 95e12f843d
ℹ️ 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".
| const compactContext: Handler<void, { ok: boolean }> = async (_, ctx) => { | ||
| const runtime = ctx.getSession(); | ||
| if (runtime === undefined || runtime.isBusy) return { ok: false }; | ||
| await runtime.session.compact(); |
There was a problem hiding this comment.
Wait for compaction completion before retrying
When Compact & Retry is used with the default v2 runtime, Session.compact() only starts the background compaction worker and returns immediately (packages/node-sdk/src/sdk-rpc-client-v2.ts:1816-1829). This handler therefore reports { ok: true } before any compaction.completed event, causing compactAndRetry() to resend while compaction is still active or before the context has shrunk; the retry can be rejected or overflow again, and asynchronous compaction failure is also reported as success. Wait for the completed/cancelled/error event before resolving, as the existing SessionRuntime.compactHostAction() path does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 215cc1a: compactContext now goes through a new SessionRuntime.runCompaction(), which registers a pending compaction and resolves on the compaction.completed / compaction.cancelled engine events (the same pattern as compactHostAction()), so the webview only retries after the context has actually shrunk. Cancelled compactions report { ok: false }. Added tests covering the wait, the cancelled path, and the busy rejection.
Related Issue
None — the problem is explained below.
Problem
In the VS Code extension, once a conversation grows past the model's context window, sending a message fails with a raw engine error (
context.overflow, e.g. "Compaction failed to bring the context under the model window after 3 attempts."). By that point the engine's auto-compaction has already exhausted its retries, and the only action the Webview offers is Retry, which resends the identical prompt into the same wall. The only way out is knowing to type/compactby hand.What changed
compactContextbridge method (params-validated) that runs compaction on the view's active session and refuses while the session is busy. It drives the engine's normal compaction pipeline, so the existing compaction progress card renders as-is.context.overflow/compaction.failednow map to friendly messages instead of leaking raw engine text.context.overflow: it compacts first and only then resends the pending input through the existing retry path. If compaction itself fails, the failed turn is left untouched and a toast reports the reason.Tests: bridge validation + handler behavior for
compactContext(no session / busy session / happy path), and Webview store coverage for compact-then-resend, compaction failure, and the streaming guard.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update. (Extension-only change; the docs site covers the CLI.)