Skip to content

fix(vscode): offer compact-and-retry when the context window overflows - #3082

Open
skymecode wants to merge 2 commits into
MoonshotAI:mainfrom
skymecode:fix/vscode-context-overflow-compact
Open

fix(vscode): offer compact-and-retry when the context window overflows#3082
skymecode wants to merge 2 commits into
MoonshotAI:mainfrom
skymecode:fix/vscode-context-overflow-compact

Conversation

@skymecode

Copy link
Copy Markdown

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 /compact by hand.

What changed

  • New compactContext bridge 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.failed now map to friendly messages instead of leaking raw engine text.
  • The inline error banner offers a Compact & Retry action for 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

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update. (Extension-only change; the docs site covers the CLI.)

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-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 215cc1a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kimi-code Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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