Repository navigation
feat: stop foreground execute processes when a user interrupts a chat - #27372
ibetitsmike wants to merge 1 commit into
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
1bd6649 to
a45190d
Compare
7b7cd6d to
2cc3b31
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
a45190d to
e1c9876
Compare
2cc3b31 to
c717bbb
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
e1c9876 to
7fc8022
Compare
c717bbb to
1191ea5
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
1191ea5 to
1e65a02
Compare
202fa50 to
a3f2866
Compare
7c5cfc1 to
6a84991
Compare
|
Revised, and re-parented onto #27370. Re-parenting This PR no longer sits on #27371. You rejected that PR's premise twice, so it should not gate the two run-once PRs below it. The dependency turned out to be prose only: three mentions of "attempt watchdog", now "attempt timeout". #27371 is parked as a draft and its six items are answered there. Your pending-reservation question was a live bug
The window is not exotic: the reservation is inserted before the spawn, and the by-key path is used precisely when the start response was lost, so a pending reservation is the expected state there.
Pulling that thread found a second bug in the same classifier: the by-key route answered an uncoded 409 for an exited process, the SDK ran every by-key 409 through the start-conflict decoder, and an uncoded conflict is coerced to Both fixes are red-green: reverting either makes its test fail and nothing else. Route change
Other items
One pushback I did not add the mutex on the stopper. All four call sites are in
|
A user action that replaces the current turn should stop unresolved foreground work, while an internal retry or worker move should leave it running so the next attempt can recover it. The runner now cancels the active task with an explicit cause (chattool.ErrUserInterrupt) when a user interrupt, an edit, or a message sent with busy_behavior=interrupt supersedes it. A foreground execute call unwinding on that cause stops its process on a detached, bounded context. Runner shutdown and rebalancing cancel without the cause, so their processes keep running and a retried attempt re-attaches instead of running the command twice. Background processes are deliberately spared. The stop is armed before the start request rather than after it, which closes the case where the agent started the process but the response never reached chatd. There is no process ID to signal then, but the idempotency key is still known, so the agent resolves the key to the process it started through a new by-token signal route. The route is chat-scoped and answers 404 for a foreign or unknown key rather than disclosing it. The stop stays best-effort: an unreachable agent or a worker crash before unwinding leaves the process running, still visible and killable through the process list.
6a84991 to
a8c96d4
Compare
a3f2866 to
0599aa1
Compare
|
Closing: #29946 (merged) and #29954 replace this stack. The workspace agent now runs each chat tool call once per tool call ID, so a retry reuses the first run, and an interrupt cancels unresolved
|

Stack context
Now based on #27370, not #27371. #27371 is parked as a draft while its timeout policy is reworked; this PR never depended on it beyond three prose mentions of "attempt watchdog", which are now "attempt timeout".
Spans
agent/,codersdk/, andcoderd/x/chatd/, so the title is scopeless.What
A user action that replaces the current turn stops unresolved foreground work; an internal retry or worker move leaves it running so the next attempt can recover it.
The runner cancels the active task with an explicit cause (
chattool.ErrUserInterrupt) when a user interrupt, an edit, or a message sent withbusy_behavior=interruptsupersedes it. A foregroundexecutecall unwinding on that cause stops its process on a detached, bounded context. Runner shutdown, rebalancing, and attempt timeouts cancel without that cause, so their processes keep running and a retried attempt re-attaches through its idempotency key instead of running the command twice. Background processes are deliberately spared; they are addressable through their handle and the process list.Cancelling by identity, not by process ID
Requiring the process ID from
StartProcessleaves nothing to cancel when the agent starts the process but the response does not reach chatd.The stop is armed before the start request rather than after it. When the response did arrive, the process ID is used. When it did not, chatd still knows the idempotency key, and a chat-scoped route resolves that key to the process it started:
The key travels in the body rather than the path. It carries a provider-supplied tool call ID, and chi's path handling makes an opaque path segment fiddly: chi routes on
RawPathwhen it is set and onPathotherwise, sochi.URLParamreturns an escaped value in the first case and a decoded one in the second. A key containing a literal%lands in the second case, whereurl.PathUnescapethen fails withinvalid URL escape. Keeping the key out of the path removes that class of bug rather than handling it.TestSignalProcessByIdempotencyKey/AcceptsKeysNeedingURLEscapingcovers/,%, a space,?,#, and...The stored reservation does the translation, so process details stay behind the operation that owns them. Reservations are chat-scoped after #27369, so another chat's key is simply absent here rather than needing a separate ownership check.
SignalProcessByIdempotencyKeyonAgentConnis the client side. Agents that predate the route answer a plain 404, which the SDK reports asErrProcessKeySignalUnsupportedrather than "not found", because such an answer says nothing about the process.Fix: a pending reservation no longer swallows the interrupt
Review asked what distinguishes a pending reservation from a missing one on this path. Traced end to end, the old code lost the kill:
falsefor both an absent key and a pending one;errProcessNotFound;isAlreadyGoneErrorread that code as "the process is gone" and returned without logging.The interrupt was dropped silently and the command kept running, which is what this PR exists to prevent. The window is not exotic: the reservation is inserted before the spawn, and the by-key path is used precisely when the start response was lost, so a pending reservation is the expected state there.
The registry now exposes
Await, which waits out a pending reservation inside the caller's context and distinguishes three outcomes:process_key_not_found. A genuine not-found.start_pending. chatd logs it instead of treating the command as gone.Red-green: removing the wait makes
TestSignalByKeyWaitsForPendingStartandTestSignalByKeyReportsPendingAtDeadlinefail, and restoring it makes them pass.TestExecuteToolInterruptKill/PendingStartIsNotTreatedAsGonecovers the chatd side.Other review changes in this revision
interruptStopperis nowuserInterruptStopper: the old name read as stopping interrupts.IdempotencyKeyrename.decodeSignalRequestbecamevalidateSignal, since the two routes decode different bodies.ARCHITECTURE.mdwas rewritten.Limitations
The stop stays best-effort. An unreachable agent, or a worker crash before unwinding, leaves the process running; it remains visible and killable through the process list. No state needs to survive the workspace agent's lifetime.