Repository navigation
feat: add a run-once reservation mechanism to the workspace agent process API - #27369
ibetitsmike wants to merge 1 commit into
Conversation
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
d3be23b to
c6f4fb5
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, 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". |
c6f4fb5 to
d9b87ba
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
mafredri
left a comment
There was a problem hiding this comment.
I think the atomic reservation in this PR is the right core idea, but it is being added at the wrong level.
The reusable rule is not specific to process starts:
For selected mutating tool calls, the workspace agent should perform one operation for a given ID and return the same work or result when that ID is repeated.
This stack does not need to convert every tool. It should add that shared mechanism and use execute as its first and only operation.
For example, the agent could keep an in-memory record containing:
tool-call ID
operation name
accepted input
running or completed state
result
A new ID reserves the record before doing any work. Repeating the same ID and input returns the existing state or result. Reusing the ID with different input fails.
execute would use this mechanism to start one process and retain its process ID. The existing process manager would continue to own process output, exit state, and signals.
This split keeps the useful work in this PR, especially reservation before cmd.Start and concurrent callers waiting for the owner. It also avoids embedding the shared replay rule inside process management, where another mutating tool could not reuse it later.
The scope can remain small: build the shared mechanism, connect execute, and leave every other tool unchanged.
🤖 This review was automatically generated with Coder Agents.
f3c8095 to
3dfed86
Compare
121599a to
3f1ac82
Compare
|
Revised. Your composite-key suggestion turned out to be the largest change here, and it cascaded into #27370 and #27372 as well. Design Registry keys are now Naming and structure
Comments You stopped flagging partway through PR1 and never reached #27370 or #27372, so I measured the whole stack instead of fixing only the eleven you named. Added comments were 44-53% of added code in the four core files, against roughly 20% in the same files at base:
One pushback I kept the 60-minute retention rather than switching to last-N-per-chat, reasoning in the thread. Short version: retention starts at process exit, so your 2-hour case already works, and a per-chat count needs a global bound plus a cross-chat eviction order to be safe. Happy to do that as its own change if you still want it.
|
…cess API Adds agent/agentrunonce, a keyed reservation registry that makes a repeated operation run once: the first caller to reserve a key performs the work, later callers presenting the same input attach to the value it published. The registry never interprets that value, so operations whose results have nothing in common can share the rule. Process starts are its first adapter; the process manager keeps owning output, exit state, signals, and git-watcher registration. Process starts pass a client token as the key and a digest of the fields that decide what gets spawned (command, requested workdir, env, background, chat) as the input fingerprint. Recording the fingerprint when the key is reserved lets a mismatched retry fail immediately rather than first waiting out a start it could never attach to. Start conflicts now carry a machine-readable code so callers do not have to match error text: input_mismatch is permanent, start_pending means the owning start had not published a process yet and a retry may still attach.
3f1ac82 to
22dc279
Compare
|
@mafredri The stale bot closed all four PRs in this stack while they sat idle; they are reopened, and the whole stack is now rebased onto current main (about 520 commits of drift). Rebase notes:
When you have time, another pass over the stack would be appreciated. All 31 of your earlier threads have replies, including the two where I pushed back with evidence and left the final call to you.
|
|
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
Part 1 of the CODAGT-757 stack. Replaces the earlier "idempotent start tokens" version of this PR after review: the reservation rule now lives in its own mechanism rather than inside process management.
Why
A chat that resumes after a crash replays tool calls history still shows as unresolved. For
executethat means running the shell command a second time. Preventing it needs a rule the agent can apply to a repeated request: perform the operation once, and answer a repeat with what the first attempt produced.That rule is not specific to starting processes.
edit_filesis the clearest second candidate: replaying it is actively harmful, because the text it searched for has already been replaced, so the retry either fails or matches a changed file differently.What
agent/agentrunonceholds the rule and nothing else:The registry is generic over both the key and the published value, and never interprets either. That is what lets operations with unlike results share the rule: this PR's adapter publishes a handle to a live process that the process manager keeps managing, while a future
edit_filesadapter would publish a plain response value. Both fake adapters are covered in the registry's own tests.Process starts are the only adapter here. The process manager still owns output buffers, exit state, signals, and git-watcher registration.
Reservations are scoped to the chat
Following review, the registry key is a composite of the chat and the idempotency key, so two chats that send the same key value get independent reservations instead of colliding. Chat is therefore no longer part of the fingerprint, and cross-chat reuse no longer produces a false conflict.
The fingerprint covers only what decides what gets spawned: command, requested workdir, env, and the background flag. Display intent and how long the caller waits are excluded, since neither changes the process.
Two behavioral notes:
Machine-readable conflicts
Start conflicts carry a code, so callers do not classify them by matching error text:
input_mismatchstart_pendingThe code rides a route-specific
ProcessConflictErrorrather than a new field on the globalcodersdk.Response, following the existingWatchErrorprecedent. Agents that predate this never answered 409 here, so an uncoded conflict is reported as permanent: treating an unresolved start as permanent costs an error result, while the reverse risks running the command twice.Review changes in this revision
{chatID, idempotencyKey}composites; the cross-chat conflict test became a cross-chat independence test.ClientTokenis nowIdempotencyKeyon the wire (idempotency_key) and in Go. Noclient_tokenreference existed anywhere at merge-base, so there is no compatibility cost.ErrOwnerPendingis nowErrPublicationPending, andOutcome.Owneris nowOutcome.Ticket, so the API no longer uses "owner" for a concept the reviewer found unclear.Reservemoved intotryReservepluswaitForPublication, so no method unlocks a mutex it did not take.process_internal_test.gowas rewritten around shared helpers (newTestManager,startGate,startAsync,awaitStart), and the two close-before-spawn tests collapsed into one table.