Repository navigation
refactor(gateway): admit background turns from their recorded source - #205015
Conversation
A durable exec completion saved before a Gateway restart now stores the requester's recorded operator source on its owed row and is woken after the restart as that requester, admitted again through decideOperatorAdmission. Older rows keep the session-principal path. Source-less system turns admit the session's person through a new `person` admission facts kind (their named role, or the owner principal) instead of a scope rule and a second authority producer in session-sharing-authorization-async.ts. session-system-turn-authority.ts is folded into it and deleted. Restart command-owner binding reads grant.owner. 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. |
|
|
Rejected review findings:
|
|
Codex review: blocked before merge. What this changesThis PR records requester sources for saved exec completions and consolidates background-turn authorization in the existing admission owner. Example: A member's command finishes in an administrator's session before a Gateway restart.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep open: this maintainer-authored PR addresses a real requester-authority defect, but its new metadata writer discards unavailable sources and leaves that case running as the session principal. Reviewed head: Before merge
Findings
Tests
Agent review detailsHow this fits togetherExec completion producers store pending inputs; Gateway restart replay restores their requester sources and submits completion turns to ordinary session execution. flowchart TD
A[Background command exits] --> B[Capture requester source]
B --> C[Stored pending input]
C --> D[Restart replay]
D --> E[Operator admission]
E --> F[Session completion turn]
Technical reviewBest possible solution: Persist every defined captured source, including unavailable, and let the existing recovery owner refuse unrecoverable completions while preserving the documented source-less fallback. Do we have a high-confidence way to reproduce the issue? Source traces both the reported principal substitution on main and the remaining unavailable-source case; no target code was executed during this read-only review. Is this the best way to solve the issue? Reusing admission and owed storage is the smallest coherent approach, but the producer must preserve the distinction between absent and explicitly unavailable requester sources. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f47267698a5d. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: The unavailable-source filter leaves a reachable cross-principal restart authorization failure. EvidenceSecurity concerns:
What I checked:
PR surfaceSource -71, Tests +53, Docs 0, Other -2. Total -20 across 24 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 24, 2026, 8:54 PM ET / November 25, 2026, 01:54 UTC. |
The person admission already refuses a session whose id changed; the system turn picker only needs the entry to exist. Keeps the session identity ratchet at its old counts after session-system-turn-authority.ts moved. Co-authored-by: obviyus <[email protected]>
|
Rejected review findings:
|
|
Landed as b5af51a (OA2 PR 4, background starts).
|
…penclaw#205015) A durable exec completion saved before a Gateway restart stores the requester's recorded operator source on its owed row and is woken after the restart as that requester, admitted again through decideOperatorAdmission; older rows keep the session-principal path. Source-less system turns admit the session's person through a new `person` admission facts kind instead of a scope rule plus a second authority producer; session-system-turn-authority.ts is folded in and deleted. Restart command-owner binding reads grant.owner. Production net -70. Co-authored-by: Ayaan Zaidi <[email protected]>
#205082) ## Problem OA2 PR 4b (background leftovers from #205015). A scheduled run still decided its owner status from something other than its admission: - **A legacy parent-bound cron source made any non-member requester the owner** (`requesterOwner = principal?.kind !== "member"` in `decideOperatorAdmission`). A writer's parent-bound automation ran with owner status (`senderIsOwner: true`) that the same writer never has on a fresh turn (D12 / matrix M8). ## Fix - **Parent-bound owner rule deleted, with the whole `requesterOwner` field.** Its only reader (scheduled occurrence minting, `cron/execution-context-admission.ts`) now reads `grant.owner`, the same answer as the requester's fresh turn. The `operatorSource` parameter threaded through `restoreGatewayOperatorSource` / `restoreGatewayQueuedOperatorRecovery` / `restoreScheduledAutomationOperator` existed only for that rule; it is gone from the queue lifecycle, cron, cron stream, plugin command and session-event callers. - **Lint allowlist shrinks:** owner producers 51 → 50 (`operator-admission.ts` no longer writes an owner field). ## Decisions (recorded, not asked) **Cut less: `grant.automations` is not in this PR.** I implemented it (Fable 5.2 consult: `manage` iff owner, `self` iff `operator.cron`; the classifier keeps its fresh-user-turn gate and reads the grant instead of connect scopes) and removed it before the first push: - A direct socket with no admitted operator authority has no grant. `gateway.auth.mode: "none"` local clients are such sockets (`prepareGatewayOperatorRunAuthority` returns `undefined`: no profile, no shared secret). Today they get local automation management from the connect facts; reading the grant would silently take it away. That is a UX regression, so I did not land it. - The same gap shows in 5 suites whose clients carry no admitted authority (`agent-run-local-operator-authority`, `cron-creator-transports`, `requester-cron-authority.integration`, `cron-stream-approval.integration`, `message-handler.post-connect-health`, chat-b local turns). - **Next split (PR 4c):** admit an authless local socket as the local-host principal (DESIGN §2 `local-host`), then add `grant.automations` and move the classifier and the channel-owner mint onto it. The channel mint has its own blocker: a configured owner linked to a non-admin personal profile is admitted as that profile (#204904), so reading the grant would drop their management. - **Children:** unchanged. A subagent child or `sessions_send` target gets no automation capability (fresh-user-turn gate). `requester-cron-authority.ts` keeps the **parent's** capability for the parent's own completion turn after `sessions_yield`; it is not a child right. - **Channel-owner recorded source: not added** (Fable fork C2). A channel-owner-created cron job already stores its `channelRequester`, and every occurrence re-checks `commands.ownerAllowFrom`, so it survives a restart and honours removal from the owner list. Channel-owner durable wakes still fall back to the session principal: not patched; it needs a stored source kind, which is a stored-row decision. - **The durable process record gets no source in this PR**; its storage is a separate decision. - **Cut less: `automations-run-scope.ts` trigger fallback stays.** With it deleted, `run.operator-continuation.test.ts` (self removal, queued owner payload edit) went red: an in-session scheduled continuation builds its tools without the admitted scheduled scope registered for that run, so the fallback is what restricts it to its own job. Deleting the fallback first needs that continuation to carry its admitted scope. - **Cut less: `attempt-session-target.ts` keeps its source dispatch.** The admission source it dispatches also carries the pre-start session-event config gate (`session-event-policy.ts`, a no-op once the turn starts); with the dispatch removed, `session-run.session-model-strictness.integration.test.ts` "selected-model-denied" lost its pre-start refusal. Splitting that gate out of the source is the next step before the R7 re-check can go. - **Tests changed:** the `cron-operator-source` table cell expects the parent-bound writer occurrence to have the writer's fresh grant (`grant.owner` and `senderIsOwner` false); `operator-run-recovery.start-grant.test.ts` and `execution-context-admission.test.ts` drop the removed `operatorSource` / `requesterOwner` inputs. ## User impact - A writer's or member's automation created in a parent conversation no longer runs with owner status (owner-only tools); it gets what that person gets on a new turn. ## Evidence - **Production lines** (`src` + `scripts`, non-test): +5 / −40. - **Red on base `4369ec1e2a91`:** `operator-admission.table.test.ts` `cron-operator-source` `after-start` and `stop` (real token-mode Gateway, real `chat.send` creates a parent-bound automation as a writer, real scheduled occurrence): on base the occurrence ran with `senderIsOwner: true`; on head it gets the writer's fresh grant (`grant.owner` false) and still runs. - **Pre-push:** one `ocx test` call over 162 files (touched tests plus importer tests of every changed source and test-support file, except the very broad importer sets of `admitted-run-context.ts`/`operator-admission.ts`, which CI runs). It included the removed `grant.automations` classifier change; after removing it, the 11 failed files plus the start-grant and table tests ran again: 434/434 green. CI round 1 reds (`run.operator-continuation`, `execution-context-owner-authority`, `session-run.session-model-strictness.integration`) came from the trigger-fallback and session-target cuts, now restored; those files plus `run-attempt-dispatch.owner` and the boundary guards pass locally. The first run's other reds were the classifier fixtures above and a mid-run `node_modules` re-materialization (`ERR_MODULE_NOT_FOUND` in `@openclaw/fs-safe`), not this diff. `pnpm tsgo:core` and `pnpm tsgo:test` clean; oxfmt and oxlint clean on changed files. - **E2E Q/R/S** (`one-admission-e2e/run.sh` on `f676d7804421`, isolated Gateway, live `gpt-5.5`): queued input refused visibly, running turn finishes after revoke, Stop cancels: all pass; rerun on the final head `7bc86192fe5f`: all pass. - **Discord owner cron after restart** (isolated Gateway, live Discord QA bots, live model, `commands.ownerAllowFrom` = the driver, no linked profile): the owner asked in Discord for a one-shot automation; the job persisted (`sessionTarget: current`, delivery `announce` to the Discord channel); the Gateway restarted about 3.5 minutes before it was due; after the restart the run finished `ok`, `deliveryStatus: delivered`, and the SUT posted `OA2CRON_3D017BC29D FIRED` in the channel. Live Peanutto Gateway pid unchanged. - **Local review:** clean on `f676d7804421` and on the final head `7bc86192fe5f` (patch is correct, no findings). Co-authored-by: Ayaan Zaidi <[email protected]>
openclaw#205082) ## Problem OA2 PR 4b (background leftovers from openclaw#205015). A scheduled run still decided its owner status from something other than its admission: - **A legacy parent-bound cron source made any non-member requester the owner** (`requesterOwner = principal?.kind !== "member"` in `decideOperatorAdmission`). A writer's parent-bound automation ran with owner status (`senderIsOwner: true`) that the same writer never has on a fresh turn (D12 / matrix M8). ## Fix - **Parent-bound owner rule deleted, with the whole `requesterOwner` field.** Its only reader (scheduled occurrence minting, `cron/execution-context-admission.ts`) now reads `grant.owner`, the same answer as the requester's fresh turn. The `operatorSource` parameter threaded through `restoreGatewayOperatorSource` / `restoreGatewayQueuedOperatorRecovery` / `restoreScheduledAutomationOperator` existed only for that rule; it is gone from the queue lifecycle, cron, cron stream, plugin command and session-event callers. - **Lint allowlist shrinks:** owner producers 51 → 50 (`operator-admission.ts` no longer writes an owner field). ## Decisions (recorded, not asked) **Cut less: `grant.automations` is not in this PR.** I implemented it (Fable 5.2 consult: `manage` iff owner, `self` iff `operator.cron`; the classifier keeps its fresh-user-turn gate and reads the grant instead of connect scopes) and removed it before the first push: - A direct socket with no admitted operator authority has no grant. `gateway.auth.mode: "none"` local clients are such sockets (`prepareGatewayOperatorRunAuthority` returns `undefined`: no profile, no shared secret). Today they get local automation management from the connect facts; reading the grant would silently take it away. That is a UX regression, so I did not land it. - The same gap shows in 5 suites whose clients carry no admitted authority (`agent-run-local-operator-authority`, `cron-creator-transports`, `requester-cron-authority.integration`, `cron-stream-approval.integration`, `message-handler.post-connect-health`, chat-b local turns). - **Next split (PR 4c):** admit an authless local socket as the local-host principal (DESIGN §2 `local-host`), then add `grant.automations` and move the classifier and the channel-owner mint onto it. The channel mint has its own blocker: a configured owner linked to a non-admin personal profile is admitted as that profile (openclaw#204904), so reading the grant would drop their management. - **Children:** unchanged. A subagent child or `sessions_send` target gets no automation capability (fresh-user-turn gate). `requester-cron-authority.ts` keeps the **parent's** capability for the parent's own completion turn after `sessions_yield`; it is not a child right. - **Channel-owner recorded source: not added** (Fable fork C2). A channel-owner-created cron job already stores its `channelRequester`, and every occurrence re-checks `commands.ownerAllowFrom`, so it survives a restart and honours removal from the owner list. Channel-owner durable wakes still fall back to the session principal: not patched; it needs a stored source kind, which is a stored-row decision. - **The durable process record gets no source in this PR**; its storage is a separate decision. - **Cut less: `automations-run-scope.ts` trigger fallback stays.** With it deleted, `run.operator-continuation.test.ts` (self removal, queued owner payload edit) went red: an in-session scheduled continuation builds its tools without the admitted scheduled scope registered for that run, so the fallback is what restricts it to its own job. Deleting the fallback first needs that continuation to carry its admitted scope. - **Cut less: `attempt-session-target.ts` keeps its source dispatch.** The admission source it dispatches also carries the pre-start session-event config gate (`session-event-policy.ts`, a no-op once the turn starts); with the dispatch removed, `session-run.session-model-strictness.integration.test.ts` "selected-model-denied" lost its pre-start refusal. Splitting that gate out of the source is the next step before the R7 re-check can go. - **Tests changed:** the `cron-operator-source` table cell expects the parent-bound writer occurrence to have the writer's fresh grant (`grant.owner` and `senderIsOwner` false); `operator-run-recovery.start-grant.test.ts` and `execution-context-admission.test.ts` drop the removed `operatorSource` / `requesterOwner` inputs. ## User impact - A writer's or member's automation created in a parent conversation no longer runs with owner status (owner-only tools); it gets what that person gets on a new turn. ## Evidence - **Production lines** (`src` + `scripts`, non-test): +5 / −40. - **Red on base `1686137e00b6`:** `operator-admission.table.test.ts` `cron-operator-source` `after-start` and `stop` (real token-mode Gateway, real `chat.send` creates a parent-bound automation as a writer, real scheduled occurrence): on base the occurrence ran with `senderIsOwner: true`; on head it gets the writer's fresh grant (`grant.owner` false) and still runs. - **Pre-push:** one `ocx test` call over 162 files (touched tests plus importer tests of every changed source and test-support file, except the very broad importer sets of `admitted-run-context.ts`/`operator-admission.ts`, which CI runs). It included the removed `grant.automations` classifier change; after removing it, the 11 failed files plus the start-grant and table tests ran again: 434/434 green. CI round 1 reds (`run.operator-continuation`, `execution-context-owner-authority`, `session-run.session-model-strictness.integration`) came from the trigger-fallback and session-target cuts, now restored; those files plus `run-attempt-dispatch.owner` and the boundary guards pass locally. The first run's other reds were the classifier fixtures above and a mid-run `node_modules` re-materialization (`ERR_MODULE_NOT_FOUND` in `@openclaw/fs-safe`), not this diff. `pnpm tsgo:core` and `pnpm tsgo:test` clean; oxfmt and oxlint clean on changed files. - **E2E Q/R/S** (`one-admission-e2e/run.sh` on `f676d7804421`, isolated Gateway, live `gpt-5.5`): queued input refused visibly, running turn finishes after revoke, Stop cancels: all pass; rerun on the final head `7bc86192fe5f`: all pass. - **Discord owner cron after restart** (isolated Gateway, live Discord QA bots, live model, `commands.ownerAllowFrom` = the driver, no linked profile): the owner asked in Discord for a one-shot automation; the job persisted (`sessionTarget: current`, delivery `announce` to the Discord channel); the Gateway restarted about 3.5 minutes before it was due; after the restart the run finished `ok`, `deliveryStatus: delivered`, and the SUT posted `OA2CRON_3D017BC29D FIRED` in the channel. Live Peanutto Gateway pid unchanged. - **Local review:** clean on `f676d7804421` and on the final head `7bc86192fe5f` (patch is correct, no findings). Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
OA2 PR 4 (DESIGN §9 row 4, background starts). The same person got a different answer depending on how a background turn started:
originFacts(requester,commandOwner,operatorProfileId) that nothing read. A member's command in an admin's session woke with the admin's grant; a revoked requester's command still woke.prepareSessionPrincipalRunAuthority) decided scopes outside admission: owner profile →["operator.admin"], person → role scopes, then a second producer (P2prepareGatewayOperatorRunAuthority) built the authority from a synthetic client.session-system-turn-authority.tswas a third place that picked and admitted the source.scopes.includes("operator.admin"); other continuations readoperatorScopeSatisfied(D16).Fix
notifyOnExitstores the requester'sQueuedOperatorRecoverySource(existing codec payload) in the owed row'soriginFacts(Ayaan approved 11-24: no new table or column). After a restart,continueSessionQueuedInputsadmits it again throughrestoreGatewayQueuedOperatorRecoveryand wakes the turn with that requester's target, the same shape the live wake uses. The unreadrequester/commandOwner/operatorProfileIdfields are gone.personindecideOperatorAdmission: the person's current named role, nothing else (owner profile → owner principal). It replaces P4'sreadScopesand the P2 call. Same rule as before, no widening.prepareSessionSystemTurnAuthoritymoves intosession-sharing-authorization-async.tsnext to the person admission;session-system-turn-authority.tsis deleted.captureSessionRestartOperatorSourcemoves to its only caller (session-restart-resume-selection.ts).grant.owner(one rule instead of a literalincludesvsoperatorScopeSatisfied, D16); the session-principal turn'ssenderIsOwnerreadsgrant.owner.ADMISSION_FILES62 → 61 and turn-kind flags 20 → 19 (session-sharing-authorization-async.tsleaves both).gateway/background-process.mdsays who a restarted completion runs as.Provenance kind → restored source (Fable fork 4A: turn kind only selects the source)
restart)marker.operatorSource); none → session personrestoreGatewayQueuedOperatorRecovery; elsepersonfacts or the person's recorded per-session sourcerequesterOperatorSource; none → session personexec, owed row)operatorSource(new); older row or channel-owner requester → session personrestoreGatewayQueuedOperatorRecovery; else as aboveexec, adopted)personfacts or recorded per-session source (unchanged scope; now through admission)exec)sessionPrincipalTurn), Stop of a system turnpersonfacts or recorded per-session sourcecron)operatorSourcerestoreScheduledAutomationOperator(unchanged)plugin,tool_handoffNo system-origin turn restores a human owner source it did not already restore.
Decisions (recorded, not asked)
bash-process-durable-notify.ts) with no requester; its wake runs as the session person. Preserving its requester needs the source on the durable process record, a separate storage decision; not in this PR.operatorSource: they wake as today's session principal. No widening.grant.automationsreplacing the cron-creator classifier (cron-creator-authority-admission.ts) and the channel-owner mint (get-reply-run.cron-requester.ts). The rule is not settled (channel owner has no socket; Fable fork 2 picksmanage iff grant.owner, a named widening for remote admin sockets), and its subagent half is PR 5.Session is unavailable for this principal.), and a missing session still refuses.attempt-session-target.ts:65-76. The run's active assertion composes the run's bound session sources (session data fences, Stop, closed admission) with the policy grant; the owner test (run-attempt-dispatch.owner.test.tssource-closed,target) shows lifetime and target fences flow through the same call. Deleting it needs those sources split first (R7 has 5 log lines total).requesterOwnerrule (D12/M8). Deleting it stopped a writer's parent-bound automation from running (operator-admission.table.test.tscron-operator-source, green on base, red with the cut): scheduled runs still readrequesterOwner. It goes with the cron cut in PR 4b.cron/execution-context-admission.tsandagent-turn/agent-session-persist.tsstay inADMISSION_FILESwith the cron cut (PR 4b).User impact
Evidence
src, non-test): +187 / −257 (net −70).operator-run-authority.principal.test.ts, real owed row in the pending-input store, realcontinueSessionQueuedInputs, real admission; requester ≠ session owner): admin → requester,grant.ownertrue; writer and member → requester, owner false; guest/revoked → refused, no wake. All 4 red on baseddc834013375(admin/writer/member: woken with no requester target, i.e. as the session principal; guest: woken anyway). This is the base-red proof for the durable-wake column.session-operator-sources.test.ts"admits a restart wake for a Tailscale Control UI person…" stays green on head (refused before a recorded source, admitted after), now throughpersonfacts. Not base-red any more.ocx testcall over 80 test files (touched tests plus importer tests of every changed source and test-support file): 943 passed; 2cron-operator-sourcetable cells red from the parent-boundrequesterOwnercut (green on base, cut reverted) and 13 files invalidated by a mid-run format edit; those 17 files rerun: all green (table 151/151, principal 19/19, boundary guards 36/36).pnpm tsgo:coreclean;pnpm tsgo:testclean exceptextensions/matrixmodule resolution from the local install (no changed file). oxfmt and oxlint clean on changed files.pnpm check:changed: dead-export scan flaggedresolveSessionSystemTurnProfileId(fixed); still onlint coreat 15 min, pushed per pipeline, CI runs it.one-admission-e2e/run.shon2400b6af866e): Q queued input refused visibly, R running turn finishes after revoke, S Stop cancels: all pass (verdict.json+results.jsonlkept in the task proof directory). The follow-up commit only drops a session-id compare that the person admission already makes (session-identity ratchet).openai/gpt-5.5): the person's turn startsexecwithbackground: true, durable: true(sleep 45), repliesSTARTED_HEAD; the runner stops the Gateway and starts it again on the same state (01:55:19Z); the durable command exits after the restart and its completion wake is admitted and runs: assistant replyWAKE_DONE_HEADat 01:56:08Z, no refusal in the transcript. Live Peanutto Gateway pid unchanged.