Skip to content

fix: abort Agent Manager prompts during startup - #11152

Merged
marius-kilocode merged 4 commits into
mainfrom
resisted-conchoraptor
Jun 12, 2026
Merged

fix: abort Agent Manager prompts during startup#11152
marius-kilocode merged 4 commits into
mainfrom
resisted-conchoraptor

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

Agent Manager shows the first Local prompt and its working indicator immediately while the backend is still creating the real session. During that startup window, the UI can display active feedback such as "Considering next steps," but Escape previously used only the backend session status to decide whether a prompt was stoppable. The status was still idle and a new Local tab still had only a draft ID, so Escape did nothing even though the interface looked active.

The problem also had a narrower backend ordering component. Prompt work was forked before the runner state transition to Running was committed. The child fiber could publish session.status = busy first, allowing the UI to send an abort while SessionRunState.cancel() still observed an idle runner and returned without interrupting anything.

This explains why the problem also reproduces in ordinary Agent Manager sessions that were never moved to a worktree. Directory reassignment is not required. The repeated Agent Manager Session Stopped telemetry showed that some Escape requests reached the extension, but that telemetry records stop intent before the backend confirms that a cancellable runner exists.

Cause and history

PR #11103 made initial Local prompt feedback optimistic so cold session creation no longer looked unresponsive. That behavior is desirable, but it exposed the pre-session interval as visible work without extending Escape semantics to the same interval.

Cold session creation became more noticeable after the OpenCode v1.14.48 integration, which also brought the current Effect-based asynchronous prompt and runner lifecycle. Together these changes created two related gaps:

  1. The webview could show submitting work before it had a real session ID or a non-idle backend status.
  2. A busy event could become observable before runner cancellation state was committed.

The earlier hypothesis that continuing a running session in another worktree was the primary cause did not explain the ordinary Local reproduction. The durable fix therefore addresses startup cancellation and runner ordering directly rather than routing aborts across worktree directories.

Durable behavior

Submitting is now a stoppable prompt state. Both the focused composer Escape handler and the document-level fallback treat optimistic submission like backend busy work.

When Escape is pressed before a real session is ready, the webview records cancellation intent against the specific optimistic message instead of sending an invalid abort with a draft ID. That intent:

  • moves from the pending draft ID to the real session ID when sessionCreated arrives;
  • sends the abort when the first non-idle status proves the session is cancellable;
  • is removed when the matching submission fails or finishes before becoming active;
  • is removed on terminal idle or session deletion; and
  • cannot leak into a later prompt because pending intent is scoped to the original message ID.

Normal busy sessions still abort immediately, and repeated Escape remains available while the same turn remains active.

The runner now gates work behind a latch. It commits the Running state before opening the latch, so work cannot publish busy before cancel() can find it. Latch opening is uninterruptible after the state commit, which prevents an interrupted first caller from leaving a permanently blocked runner. The same ordering applies when queued work begins after a shell command.

Constraints

The optimistic Local prompt remains visible immediately; this does not restore the old blank waiting period. The change also preserves the existing HTTP and SSE contracts, so no SDK regeneration or protocol migration is required.

Cancellation state stays in the webview because it bridges a UI-only draft ID to a backend session ID. The runner ordering guarantee lives in the CLI because busy must represent cancellable work for every client, not only VS Code.

@kilo-code-bot

kilo-code-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The new commit (fc68b93) refactors the runner startup ordering logic by extracting KiloRunner into a dedicated Kilo-owned file (packages/opencode/src/kilocode/effect/runner.ts), which correctly follows the fork isolation pattern from AGENTS.md. The shared upstream file (packages/opencode/src/effect/runner.ts) is now reduced to a single import and three call-sites, minimising the Kilo diff against upstream.

All logic from the previous review remains correct and unchanged. The new abstraction is clean:

  • KiloRunner.start faithfully reproduces the original latch/fork pattern.
  • KiloRunner.commit correctly returns the [openAction, Running state] tuple that SynchronizedRef.modifyEffect consumes.
  • StoryProviders.tsx gains submitting: () => false to match the updated session context interface — correct stub value.
  • Visual regression baseline PNGs are CI-generated; no review needed.
Files Reviewed (4 files, incremental from b23d3df)
  • packages/opencode/src/kilocode/effect/runner.ts (new)
  • packages/opencode/src/effect/runner.ts
  • packages/kilo-vscode/webview-ui/src/stories/StoryProviders.tsx
  • Visual regression PNG baselines (CI-generated, skipped)

Reviewed by claude-4.6-sonnet-20260217 · 423,899 tokens

Review guidance: REVIEW.md from base branch main

@marius-kilocode marius-kilocode changed the title fix(vscode): abort moved active sessions fix: abort Agent Manager prompts during startup Jun 12, 2026
@marius-kilocode
marius-kilocode merged commit 579caef into main Jun 12, 2026
24 checks passed
@marius-kilocode
marius-kilocode deleted the resisted-conchoraptor branch June 12, 2026 17:33
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
fix: abort Agent Manager prompts during startup
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.

2 participants