Repository navigation
feat(agent-core-v2): make /init runs cancellable - #1667
Conversation
The init run spawns a coder subagent through agentLifecycle.run with an AbortController that was a local of generateAgentsMd, so nothing outside the service could cancel it: Ctrl+C in clients only cancels the main agent's loop turn, which does not exist during /init. ISessionInitService gains cancelInit(): the service keeps the in-flight run's AbortController (cleared in finally), and cancelInit aborts it with a user-cancellation reason. Cancellations propagate unwrapped from generateAgentsMd (UserCancellationError / AbortError, never SESSION_INIT_FAILED, no subagent.failed event) so callers can distinguish "aborted" from "failed".
|
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3a6187445
ℹ️ 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".
a3a6187 to
a8d21e9
Compare
CoreSession.cancel() now also calls sessionInit.cancelInit() (a no-op while idle): /init runs outside the main agent's loop turns, so the RPC turn cancel alone could not reach it. Builds on the engine support that landed in #1667.
The init run spawns a coder subagent through agentLifecycle.run with an AbortController that was a local of generateAgentsMd, so nothing outside the service could cancel it: Ctrl+C in clients only cancels the main agent's loop turn, which does not exist during /init. ISessionInitService gains cancelInit(): the service keeps the in-flight run's AbortController (cleared in finally), and cancelInit aborts it with a user-cancellation reason. Cancellations propagate unwrapped from generateAgentsMd (UserCancellationError / AbortError, never SESSION_INIT_FAILED, no subagent.failed event) so callers can distinguish "aborted" from "failed".
Related Issue
No tracking issue — the problem is explained below.
Problem
In the v2 engine,
/init(SessionInitService.generateAgentsMd) spawns acodersubagent throughagentLifecycle.runwith anAbortControllerthat is a local ofgenerateAgentsMd. Nothing outside the service can reach it, so there is no way to cancel an init run: a client's cancel path (e.g. Ctrl+C in a TUI) only cancels the main agent's loop turn, which does not exist during/init. The run simply continues to completion. This was hit by the tui-v2 client, the first v2 consumer that exposes/init.What changed
ISessionInitServicegainscancelInit(). The service keeps the in-flight run'sAbortControlleron the instance (assigned before the run, cleared infinally), andcancelInit()aborts it with a user-cancellation reason. It is a no-op while idle, so callers can invoke it unconditionally alongside the main agent's turn cancel.generateAgentsMdno longer wraps cancellations intoSESSION_INIT_FAILED:UserCancellationError/AbortErrorpropagate unwrapped (andmirrorAgentRunsuppresses thesubagent.failedevent for them), so callers can distinguish "aborted" from "failed".cancelInitis a no-op when idle.This is additive only — no existing signatures change. Verified: package typecheck clean, full agent-core-v2 suite passes (236 files / 3302 tests),
lint:domainOK.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.