Skip to content

refactor(gateway): admit background turns from their recorded source - #205015

Merged
obviyus merged 2 commits into
mainfrom
refactor/oa2-background-grant
Nov 25, 2026
Merged

obviyus merged 2 commits into
mainfrom
refactor/oa2-background-grant

Conversation

@obviyus

@obviyus obviyus commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

OA2 PR 4 (DESIGN §9 row 4, background starts). The same person got a different answer depending on how a background turn started:

  • An exec completion saved before a restart (owed row stored at exit, wake not yet run) woke after the restart as the session principal, not the requester who started the command. The owed row stored 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.
  • Source-less system turns (P4, prepareSessionPrincipalRunAuthority) decided scopes outside admission: owner profile → ["operator.admin"], person → role scopes, then a second producer (P2 prepareGatewayOperatorRunAuthority) built the authority from a synthetic client.
  • session-system-turn-authority.ts was a third place that picked and admitted the source.
  • Command-owner binding on restart read a literal scopes.includes("operator.admin"); other continuations read operatorScopeSatisfied (D16).

Fix

  • Durable exec wake replays the requester. notifyOnExit stores the requester's QueuedOperatorRecoverySource (existing codec payload) in the owed row's originFacts (Ayaan approved 11-24: no new table or column). After a restart, continueSessionQueuedInputs admits it again through restoreGatewayQueuedOperatorRecovery and wakes the turn with that requester's target, the same shape the live wake uses. The unread requester/commandOwner/operatorProfileId fields are gone.
  • Session person through admission. New facts kind person in decideOperatorAdmission: the person's current named role, nothing else (owner profile → owner principal). It replaces P4's readScopes and the P2 call. Same rule as before, no widening.
  • One system-turn picker. prepareSessionSystemTurnAuthority moves into session-sharing-authorization-async.ts next to the person admission; session-system-turn-authority.ts is deleted. captureSessionRestartOperatorSource moves to its only caller (session-restart-resume-selection.ts).
  • Owner from the grant. Restart and owner-continuation command-owner binding read grant.owner (one rule instead of a literal includes vs operatorScopeSatisfied, D16); the session-principal turn's senderIsOwner reads grant.owner.
  • Lint allowlists shrink: ADMISSION_FILES 62 → 61 and turn-kind flags 20 → 19 (session-sharing-authorization-async.ts leaves both).
  • Docs: gateway/background-process.md says who a restarted completion runs as.

Provenance kind → restored source (Fable fork 4A: turn kind only selects the source)

Turn Restored source Admission
Restart resume (restart) interrupted requester's captured source (marker.operatorSource); none → session person restoreGatewayQueuedOperatorRecovery; else person facts or the person's recorded per-session source
Restart completion custody (subagent requester settle) stored requesterOperatorSource; none → session person same
Exec completion saved before restart (exec, owed row) owed row's operatorSource (new); older row or channel-owner requester → session person restoreGatewayQueuedOperatorRecovery; else as above
Durable process that exits after restart (exec, adopted) none recorded: adopted as fresh host input → session person person facts or recorded per-session source (unchanged scope; now through admission)
Live exec wake (exec) producer's captured target (requester's admitted authority, same process) unchanged
Unattributed system event (sessionPrincipalTurn), Stop of a system turn session person person facts or recorded per-session source
Scheduled cron run (cron) job operatorSource restoreScheduledAutomationOperator (unchanged)
Scheduler notice, plugin, tool_handoff target's captured operator authority unchanged
Heartbeat, unattributed event with no human session principal none (System) unchanged

No system-origin turn restores a human owner source it did not already restore.

Decisions (recorded, not asked)

  • Parked: adopted durable processes. A durable process that exits after the restart is adopted as fresh host input (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.
  • Old owed rows (written before this change) have no operatorSource: they wake as today's session principal. No widening.
  • Configured channel owner requesters record no source (refactor(channels): admit channel senders through the turn grant #204904), so their durable wake also keeps the session-principal path. Keeping channel-owner work alive across restart needs a channel-owner source kind: PR 4b.
  • A requester without session write at restart (revoked) is refused at start: the saved completion shows as not run with its cause, like queued human input. Before, it ran as the session principal.
  • Untiered person without a recorded source is still refused (no widening, DESIGN M1 stays a cell for PR 4b); the refusal text is now admission's "Gateway access is not active for this requester; ask an administrator to restore access." instead of "Session principal has no current run authority."
  • Cut less, moved to PR 4b (Fable 5.2 consult, fork 1B): grant.automations replacing 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 picks manage iff grant.owner, a named widening for remote admin sockets), and its subagent half is PR 5.
  • Session-identity ratchet: the moved system-turn picker no longer compares the stored session id itself; the person admission's sharing check already refuses a changed session (Session is unavailable for this principal.), and a missing session still refuses.
  • Cut less, kept: 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.ts source-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).
  • Cut less, kept: the parent-bound requesterOwner rule (D12/M8). Deleting it stopped a writer's parent-bound automation from running (operator-admission.table.test.ts cron-operator-source, green on base, red with the cut): scheduled runs still read requesterOwner. It goes with the cron cut in PR 4b.
  • cron/execution-context-admission.ts and agent-turn/agent-session-persist.ts stay in ADMISSION_FILES with the cron cut (PR 4b).

User impact

  • A background command that finished just before a Gateway restart (its completion saved, its turn not yet run) now wakes after the restart as the person who started it, with that person's current access, instead of as the session's owner.
  • A restarted completion for someone whose access was revoked shows as not run with its cause instead of running under another person's access.

Evidence

  • Production lines (src, non-test): +187 / −257 (net −70).
  • Matrix cells, durable exec wake after restart (operator-run-authority.principal.test.ts, real owed row in the pending-input store, real continueSessionQueuedInputs, real admission; requester ≠ session owner): admin → requester, grant.owner true; writer and member → requester, owner false; guest/revoked → refused, no wake. All 4 red on base ddc834013375 (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.
  • Tailscale restart wake (R9 shape): after fix(gateway): record Tailscale Control UI sources without a paired browser key #204388 it passes on main once the person's source is recorded; 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 through person facts. Not base-red any more.
  • Pre-push: one ocx test call over 80 test files (touched tests plus importer tests of every changed source and test-support file): 943 passed; 2 cron-operator-source table cells red from the parent-bound requesterOwner cut (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:core clean; pnpm tsgo:test clean except extensions/matrix module resolution from the local install (no changed file). oxfmt and oxlint clean on changed files. pnpm check:changed: dead-export scan flagged resolveSessionSystemTurnProfileId (fixed); still on lint core at 15 min, pushed per pipeline, CI runs it.
  • E2E Q/R/S (one-admission-e2e/run.sh on 2400b6af866e): Q queued input refused visibly, R running turn finishes after revoke, S Stop cancels: all pass (verdict.json + results.jsonl kept in the task proof directory). The follow-up commit only drops a session-id compare that the person admission already makes (session-identity ratchet).
  • Real restart proof (isolated Gateway, trusted-proxy (Tailscale-like) person, live openai/gpt-5.5): the person's turn starts exec with background: true, durable: true (sleep 45), replies STARTED_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 reply WAKE_DONE_HEAD at 01:56:08Z, no refusal in the transcript. Live Peanutto Gateway pid unchanged.
  • Not run here: a cron job created from a Discord-owner session after restart. The cron cut moved to PR 4b, so this PR does not change that path.

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]>
@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: a67cfa195d2b0ee4b91dfd4da9f3c0fdb4ce80ff
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/session-sharing-authorization-async.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-system-turn-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Rejected review findings:

  • [P1] "Preserve the requester source when folding completion rows" (src/sessions/owed.ts:123): rejected, the source is already preserved. fold() stages over the existing row, and both pending-input kernels write that row through restagePendingInputMessageJson(row.message_json, input.messageJson): src/config/sessions/session-pending-input-operations.kernel.ts:195 (SQLite) and src/config/sessions/session-actor-memory-pending.ts:265 (actor memory). That function (src/config/sessions/session-pending-input-value.ts:32-39) takes the new bytes (the joined text) and keeps the stored row's kind and originFacts. So the folded head row keeps its own operatorSource; the owedMessage(first) bytes never replace it. Members only fold when combineSessionEventTargetsForHost accepts their targets as one authority (session-event-batch.ts flush), so the head's source is the shared turn's source. No code change.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 25, 2026
@clawsweeper

clawsweeper Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This 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.

  • Before: The saved completion wakes as the session principal.
  • After: A recoverable source wakes as the original member under current access.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful consolidation, but requester fallback remains unsafe and shipped restart proof is pending; the changed session_pending_inputs.message_json.originFacts format also lacks upgrade proof preserving existing settings and rows.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A saved background completion can resume as the session owner instead of the person who started the command.
Reason: The maintainer-authored direction repairs a concrete authority mismatch using existing owners, with adopted processes and legacy rows explicitly scoped.

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: 2400b6af866e52a1b9cfc177a6c08eca5cc6f399

Before merge

  • [P1] Preserve explicitly unavailable requester sources (P1) - A valid live requester can produce { kind: "unavailable" }, for example a linked channel requester whose model policy exceeds the recovery codec's 256-wildcard bound; the existing recovery test covers 257 exclusions. This condition discards that sentinel and writes no originFacts. After a restart, queued-chat-inputs treats the missing source as legacy source-less work and wakes under the session principal, bypassing the requester's unrecoverable source and potentially its narrower model or owner limits. Store every defined operatorSource, including unavailable, so existing restoration refuses it instead of substituting another principal.
  • Resolve security concern: Unrecoverable requester restrictions can be replaced - A non-owner's saved completion can reach model and tool execution under an administrator session's principal when durable source capture returns unavailable.
  • Resolve merge risk - Before merge, the author must preserve explicitly unavailable requester sources so restart replay cannot substitute the session principal.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P1] [P1] Preserve explicitly unavailable requester sources — src/agents/bash-tools.exec-notify.ts:364-366
  • [high] Unrecoverable requester restrictions can be replaced — src/agents/bash-tools.exec-notify.ts:364

Tests

  • Missing end-to-end proof: Provide the pending real-Gateway restart result showing requester identity and refusal after access loss; the new test stops before the actual completion wake.
Agent review details

How this fits together

Exec 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]
Loading

Technical review

Best 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:

  • [P1] [P1] Preserve explicitly unavailable requester sources — src/agents/bash-tools.exec-notify.ts:364-366
    A valid live requester can produce { kind: "unavailable" }, for example a linked channel requester whose model policy exceeds the recovery codec's 256-wildcard bound; the existing recovery test covers 257 exclusions. This condition discards that sentinel and writes no originFacts. After a restart, queued-chat-inputs treats the missing source as legacy source-less work and wakes under the session principal, bypassing the requester's unrecoverable source and potentially its narrower model or owner limits. Store every defined operatorSource, including unavailable, so existing restoration refuses it instead of substituting another principal.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f47267698a5d.

Merge-risk options

Maintainer options:

  1. Preserve the unavailable source (recommended)
    The author should retain the existing unavailable sentinel in originFacts and cover production capture through restart refusal.

Provenance checked

  • Saved exec completion authority changes intended behavior with a stated reason (463d774: The owed-result implementation first made completions durable and explicitly deferred using requester metadata for admission.)
  • System continuation source selection keeps the original intent (52bc4b5: Caller-started continuations must retain caller permissions; only unattributed host work may use the session principal.)
  • Start-time operator admission keeps the original intent (3ad2cce: Saved and queued starts share one admission decision, while live-only sources remain usable within their original process.)

Testing

Proof path: in-process harness.

Security

Needs attention: The unavailable-source filter leaves a reachable cross-principal restart authorization failure.

Evidence

Security concerns:

  • [high] Unrecoverable requester restrictions can be replaced — src/agents/bash-tools.exec-notify.ts:364
    A non-owner's saved completion can reach model and tool execution under an administrator session's principal when durable source capture returns unavailable.
    Confidence: 0.98

What I checked:

PR surface

Source -71, Tests +53, Docs 0, Other -2. Total -20 across 24 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 12 186 257 -71
Tests 9 66 13 +53
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 0 2 -2
Total 24 254 274 -20

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: Discarding an unrecoverable requester source can run its saved completion under a different, more privileged session principal.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • merge-risk: 🚨 security-boundary: Discarding an unrecoverable requester source can run its saved completion under a different, more privileged session principal.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

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]>
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Rejected review findings:

  • [P1] "Preserve requester metadata when folding completion rows" (src/sessions/owed.ts:123, round 2, same finding as round 1): rejected, verified wrong. fold() restages the existing row; both kernels write restagePendingInputMessageJson(row.message_json, input.messageJson) (session-pending-input-operations.kernel.ts:195, session-actor-memory-pending.ts:265), which keeps the stored row's kind and originFacts and takes only the new text. Local check on head a67cfa195d2b: the existing fold test, with the first row owed with originFacts and fold() called with an Owed without them (exactly the session-event-batch.ts shape), stores { content: joined text, kind: "exec", originFacts }: passed. The source is not erased, so the session-principal fallback is not reached for folded rows. No code change.
  • Security review "[high] Requester authority substitution after restart": same claim as above; rejected for the same reason.
  • Real behavior proof "missing": the PR body has a real isolated-Gateway restart run with a live model (durable exec started, Gateway restarted, command exits after the restart, completion wake admitted, assistant replies WAKE_DONE_HEAD) plus Q/R/S on this head; the reviewer context did not include it.

@obviyus
obviyus merged commit b5af51a into main Nov 25, 2026
144 of 145 checks passed
@obviyus
obviyus deleted the refactor/oa2-background-grant branch November 25, 2026 02:22
@obviyus

obviyus commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as b5af51a (OA2 PR 4, background starts).

  • Exec completions saved before a restart now wake after it as the requester who started them. The requester is admitted again from the source recorded on the owed row. Older rows keep the session-principal path.
  • Source-less system turns admit the session's person through the new person admission facts kind. session-system-turn-authority.ts is deleted. Production net −70.
  • Proof: the durable-wake matrix (admin/writer/member/guest) is red on base and green on head. A real Gateway restart with a durable exec ran its completion wake after the restart. Q/R/S passed on the exact head.
  • Moved to PR 4b: grant.automations (the cron-creator classifier and the channel-owner mint), the parent-bound requesterOwner rule, channel-owner sources across restart, the source on adopted durable processes, and the attempt-session-target source re-assertion.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…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]>
obviyus added a commit that referenced this pull request Nov 25, 2026
#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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts security-sensitive-changed size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant