Repository navigation
fix(gateway): detached work keeps its origin's authority when the parent chat is edited - #200176
Conversation
…ent chat is edited A child run, a subagent completion and a node event reused the live authority object of the request that accepted them. That object also checked the requester chat.send's admitted input, so editing (rewinding) the parent chat revoked every running child and dropped its completion, although nothing had revoked the person's access. Accepted work now restores its authority from the origin's saved facts (the recovery snapshot that restart recovery already uses), checked against current policy: device, shared-secret generation, profile, role and access grant. The accepting request, turn or run is not part of it. A source without saved facts keeps its live authority. The continuation map and the independentContinuation flag are deleted; captureGatewayOperatorContinuation is the one path. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Co-authored-by: obviyus <[email protected]>
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
…e for its holders Co-authored-by: obviyus <[email protected]>
270c3e4 to
5fc3d22
Compare
|
|
Maintainer override:
|
|
Landed in f4fa17a.
|
…ent chat is edited (openclaw#200176) ## Scope This is the first slice of "authority from saved facts". It moves accepted work onto the saved-facts path and fixes the user-visible bug. The next slice deletes the machinery this makes redundant: the subagent completion custody map, the store-replaced suspend path, the remaining parent-authority reads for detached children, the follow-up queue's silent cancel, the cron occurrence authority and the duplicated restore glue. ## What Problem This Solves Editing a message in a chat stopped every subagent that chat had started, and dropped their results. The people involved still had access; nothing had revoked it. How it happened: accepted work that outlives its request (a child run, a subagent completion, a node event) reused the live authority object of the request that accepted it. For a child, that object also checked the parent `chat.send`'s admitted input, which asserts that the parent chat's transcript revision has not changed. An edit (`sessions.rewind` plus a new send) changes that revision. So at its next boundary the child failed with `source_authority_refused` / "admitted run authority is no longer active | session changed before chat.send", its exec calls failed with "tool invocation authority is no longer active", and its completion failed with "requester settle wake failed: session changed before chat.send". The bug class: detached work held a closure over a live owner (request, turn or run) as its authority. When that owner ended or its target changed, the work lost authority although nothing revoked it. ## Why This Change Was Made Accepted work now carries values, not the accepting closure. `captureGatewayOperatorContinuation` restores the work's authority from the origin's saved facts (the operator recovery snapshot that restart recovery already uses) and checks it against current policy. The accepting request, turn or run is no longer part of the chain. - One path: `captureGatewayOperatorContinuation` (in `operator-run-recovery.ts`) replaces the `independentContinuation` flag. It is used for accepted agent turns (`retainGatewayOperatorRun`: child launches, sent turns), subagent completion custody (`captureOperatorToolGatewayContinuationContext`) and node event sources. - Deleted: the `continuationAuthorities` map, `bindGatewayOperatorContinuationAuthority` and the `independentContinuation` parameter. The restored authority in restart recovery is now one object instead of a policy object plus a claim wrapper. - A source without saved facts (`unavailable` in the recovery codec) keeps its live authority, as before. - Continuations of one origin keep its opaque `source` identity, so sibling children still settle as one completion batch. The accepted work still retains the inherited object for its lifetime, because other holders of that object (for example the queued input's transcript write) keep using it; its checks no longer gate the work. - No schema, stored-row or protocol change. Production delta: −3 lines (+60 / −63). ## Security model - **Revokes authority now:** a change of the origin's policy: paired device revoked, shared Gateway token or password rotated (shared-secret generation), profile identity or email binding changed, role assignment or role policy changed, access grant ended, OpenClaw ID membership changed. These are the checks restart recovery already runs, with the same revocation subscriptions, so a refusal arrives at the same boundaries as before (each authority check: admission, model request, tool call). - **No longer revokes:** the accepting request ending, the parent turn ending or being replaced, and an edit or new message in the parent chat. - **Explicit stops are unchanged:** Stop / `chat.abort` cancels descendants; reset (`/new`, `/reset`) stops controlled subagents, as `docs/concepts/session-controller.md` documents; delete stops them during lifecycle cleanup. - **Ceiling:** the restored authority is the saved snapshot's scopes intersected with the caller's scopes (the same narrowing as before) and the current role; the model policy is the intersection of the saved and the current policy. Saved facts are captured only from a live host-issued authority (`captureQueuedOperatorRecoverySource` asserts it current first) and decoded by the strict codec. Work can never hold more than its origin had when it was accepted, and less if policy tightened since. ## User Impact - A subagent keeps running and its result reaches the parent chat when the person edits or resends a message in that chat. - Revoking access still stops the work: rotating the Gateway token cancels a running child at once. ## Evidence Real agent on an isolated source Gateway (`ocx src`, scratch state, port and HOME, scrubbed env), Claude Opus through the shared Claude proxy. base = merge base `2c94bae9`, head = this PR. | Journey | base | head | |---|---|---| | J1: parent spawns a child and yields; the person sends a second message, then edits it (`sessions.rewind` + resend) while the child runs | child refused (`source_authority_refused`, "session changed before chat.send"); completion dropped (`delivery=not_required`); parent never gets the result | child finishes; parent replies `parent-got child-final`; registry `delivery=delivered` | | J2: child running; the operator rotates `gateway.auth.token` | child cancelled ("operator source authority is no longer active") | child cancelled within a second of the reload ("Restart recovery operator authority changed; start a new user turn."; the restored authority reuses the restart-recovery messages); no further tool call ran | | J3: input A queued behind a busy turn, then human message B | A and B both run (`busy-done a-ack b-ack`) | A and B both run (`busy-done a-ack b-ack`) | | J1b: parent spawns two children and yields; the person edits a later message; both children settle as one batch | both children refused (`source_authority_refused`); no result | both finish; parent replies `parent-got one-final two-final` | | J4: cron occurrence; job edited mid-run | occurrence finishes (`cron-done`) | occurrence finishes (`cron-done`) | | Parent gets a new message / `chat.abort` + new message while a child runs (yielded and busy shapes) | child survives, completion delivered | child survives, completion delivered | The first journey matches the production incident: the transcript there shows a user message, a `leaf` (branch) event and the resent message, and every running child of that chat failed in the same second. `/new` while the parent is yielded on a running child stops the child on both arms. That is the documented reset behavior (reset stops controlled subagents), so this PR keeps it. Not covered by E2E: role downgrade and device revocation for a running child (the scratch Gateway uses shared-token owner auth). Unit tests cover device revocation and email reassignment of retained child authority (`operator-run-recovery.test.ts`, `operator-run-cancellation.test.ts`). Gates: oxfmt, oxlint on changed files, `pnpm tsgo:core`, `pnpm check:test-types`, import-cycle and madge checks, `ocx test` on the operator-run authority, cancellation and recovery suites, in-process dispatch suites, requester pause authority, session restart resume and `src/agents/subagents/`. Co-authored-by: Ayaan Zaidi <[email protected]>
Bounded backport of f4fa17a (#200176). Restore accepted detached work through the existing saved-source owner while retaining current policy, device revocation, scope ceilings and original source identity. Remove the alternate continuation map and flag. Parent independent review complete; unchanged worker proof: genuine committed-parent-edit regression red, 95 owner tests and 42 Stop/reset tests green. Parent canonical scoped typed lint passed across eight files. No live-model rewind E2E qualification claimed. Publication held. Co-authored-by: RomneyDa <[email protected]>
Scope
This is the first slice of "authority from saved facts". It moves accepted work onto the saved-facts path and fixes the user-visible bug. The next slice deletes the machinery this makes redundant: the subagent completion custody map, the store-replaced suspend path, the remaining parent-authority reads for detached children, the follow-up queue's silent cancel, the cron occurrence authority and the duplicated restore glue.
What Problem This Solves
Editing a message in a chat stopped every subagent that chat had started, and dropped their results. The people involved still had access; nothing had revoked it.
How it happened: accepted work that outlives its request (a child run, a subagent completion, a node event) reused the live authority object of the request that accepted it. For a child, that object also checked the parent
chat.send's admitted input, which asserts that the parent chat's transcript revision has not changed. An edit (sessions.rewindplus a new send) changes that revision. So at its next boundary the child failed withsource_authority_refused/ "admitted run authority is no longer active | session changed before chat.send", its exec calls failed with "tool invocation authority is no longer active", and its completion failed with "requester settle wake failed: session changed before chat.send".The bug class: detached work held a closure over a live owner (request, turn or run) as its authority. When that owner ended or its target changed, the work lost authority although nothing revoked it.
Why This Change Was Made
Accepted work now carries values, not the accepting closure.
captureGatewayOperatorContinuationrestores the work's authority from the origin's saved facts (the operator recovery snapshot that restart recovery already uses) and checks it against current policy. The accepting request, turn or run is no longer part of the chain.captureGatewayOperatorContinuation(inoperator-run-recovery.ts) replaces theindependentContinuationflag. It is used for accepted agent turns (retainGatewayOperatorRun: child launches, sent turns), subagent completion custody (captureOperatorToolGatewayContinuationContext) and node event sources.continuationAuthoritiesmap,bindGatewayOperatorContinuationAuthorityand theindependentContinuationparameter. The restored authority in restart recovery is now one object instead of a policy object plus a claim wrapper.unavailablein the recovery codec) keeps its live authority, as before.sourceidentity, so sibling children still settle as one completion batch. The accepted work still retains the inherited object for its lifetime, because other holders of that object (for example the queued input's transcript write) keep using it; its checks no longer gate the work.Security model
chat.abortcancels descendants; reset (/new,/reset) stops controlled subagents, asdocs/concepts/session-controller.mddocuments; delete stops them during lifecycle cleanup.captureQueuedOperatorRecoverySourceasserts it current first) and decoded by the strict codec. Work can never hold more than its origin had when it was accepted, and less if policy tightened since.User Impact
Evidence
Real agent on an isolated source Gateway (
ocx src, scratch state, port and HOME, scrubbed env), Claude Opus through the shared Claude proxy. base = merge baseedbc5bce, head = this PR.sessions.rewind+ resend) while the child runssource_authority_refused, "session changed before chat.send"); completion dropped (delivery=not_required); parent never gets the resultparent-got child-final; registrydelivery=deliveredgateway.auth.tokenbusy-done a-ack b-ack)busy-done a-ack b-ack)source_authority_refused); no resultparent-got one-final two-finalcron-done)cron-done)chat.abort+ new message while a child runs (yielded and busy shapes)The first journey matches the production incident: the transcript there shows a user message, a
leaf(branch) event and the resent message, and every running child of that chat failed in the same second./newwhile the parent is yielded on a running child stops the child on both arms. That is the documented reset behavior (reset stops controlled subagents), so this PR keeps it.Not covered by E2E: role downgrade and device revocation for a running child (the scratch Gateway uses shared-token owner auth). Unit tests cover device revocation and email reassignment of retained child authority (
operator-run-recovery.test.ts,operator-run-cancellation.test.ts).Gates: oxfmt, oxlint on changed files,
pnpm tsgo:core,pnpm check:test-types, import-cycle and madge checks,ocx teston the operator-run authority, cancellation and recovery suites, in-process dispatch suites, requester pause authority, session restart resume andsrc/agents/subagents/.