Skip to content

chore: carry and enforce participant limits on admitted runs - #204847

Merged
jalehman merged 1 commit into
mainfrom
participate-split/p2-participant-limits
Nov 25, 2026
Merged

jalehman merged 1 commit into
mainfrom
participate-split/p2-participant-limits

Conversation

@jalehman

@jalehman jalehman commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Related: #202552

Part 2 of 6 of the split of #202552 (invite someone to help in one session).

The six parts are meant to land in order. Review each part against the branch below it.

What Problem This Solves

#202552 lets a session creator invite another person into one session, and part 4 lets that person send messages that start agent runs. Those runs execute with the creator's agent, workspace and tools, so before anyone can be admitted, the Gateway needs a hard limit that travels with every piece of work the invited person causes: the run itself, its queued follow-ups, the children it spawns, scheduled work it creates, and anything recovered after a restart. Without that limit, an invited person could reach the creator's full tool set, files, approvals or Gateway settings.

User Impact

User impact: none visible yet. This part adds the enforcement, but nothing can trigger it until part 4 admits participants. Ordinary runs, owners, cron jobs, subagents and restarts behave as they do today.

Inert until part 4. Every check in this part keys off a participationCeiling carried by an admitted run. Only part 4's chat.send admission creates one, and only when a role opts in with sessions.maxInvitedAccess (plus invitedTools / invitedPermission). Until then, no run carries a ceiling and every branch here falls through to today's behaviour. Where a missing ceiling matters, the code fails closed: recovering a persisted participant source with no current invitation is refused, not run with owner authority.

What reaches every upgraded Gateway, opted in or not:

  • No visible behaviour change found for ordinary users. Tool lists, prompt snapshots, config baselines and generated outputs are unchanged. The ordinary-upgrade fixture replays queued and cron sources written before this change and they still recover unchanged.
  • Private JSON payloads may carry new optional fields (participationCeiling, delegatedOperatorSource on session entries; the constraint on subagent run records). Nothing writes them before part 4; existing rows are not rewritten. See the storage note in docs/reference/database-schemas/storage-changes.md.
  • Docs: docs/gateway/background-process.md gains one sentence about what process can see in participating turns.

Why This Change Was Made

The rule for the stack is restrict before you admit: the limits land and are reviewed before anything can be admitted, so there is never a released build where a participant can run without them.

What this part enforces for a run that carries a participation ceiling:

  • Tools. The admitted tool list (role invitedTools, or the participant defaults) is intersected with every other policy layer. It is applied in tool assembly, tool search and tool_describe, bundled plugin tools, provider tool schemas and in-process plugin dispatch. A self-authority deny set blocks Gateway methods that would change the participant's own authority or the host (config, plugins, roles, membership, visibility, restart, update), and tools cannot act under another admitted person's identity.
  • Permission and exec. The permission mode and exec security/ask floors captured at admission are intersected with current policy. They can only narrow, never widen.
  • Files and processes. File tools, apply_patch and exec working directories are contained to the invited session's root, including symlink escapes. process only sees the invited session's own processes, not ancestors'. Sandbox attachments follow the same root.
  • Where the limit travels. Queued inputs, cron jobs created from the run, spawned children and grandchildren (spawn, completion batches, delegated sources, reactivation, restart custody, requester yield) and durable context-engine maintenance all carry the original ceiling and re-check it.
  • Revocation and recovery. Removing a member, or lowering them below send, cancels their queued work through the membership writer (the hook into part 1's sharing store is in this part). After a restart, every retained source re-admits the original person against the current invitation and role, then intersects the stored limit. A missing or revoked invitation refuses the work. Revoked queued inputs stay visible only to their author.
  • Runtimes that can't enforce it. Worker environments and non-OpenClaw (CLI) runtimes refuse a ceiling-bearing run instead of running it unrestricted.

Two parts of the enforcement land later on purpose: part 3 denies a participant's exec allowlist misses and routes their exec approvals to the session creator, and part 4 adds the admission itself. Both land before anyone can be admitted.

Reading order and split notes

Suggested order: src/agents/participation-ceiling.ts → src/config/sessions/session-participation-source.ts → src/gateway/operator-run-invocation.ts / operator-run-authority.ts → session-principal-run-authority.ts and session-participation-recovery.ts → queue custody (session-participation-queue.kernel.ts, auto-reply/reply/queue/*) → cron (cron-operator-source.ts, jobs-tool-policy.ts) → children (subagents/spawn/*, subagent-completion-batch-authority.ts, session-delegated-operator-source.ts) → tool and file clamp (agent-tools.assembly.ts, security/dangerous-tools.ts, session-permission-policy.ts, workspace-sandbox.ts, host-mutation-operations.ts, bash-tools.*).

resolveSessionSystemTurnProfileId moves unchanged from session-sharing-authorization-async.ts to session-principal-run-authority.ts, which keeps that file under its line cap. prepareSessionSystemTurnAuthority (folded into session-sharing-authorization-async.ts by #205015) first asks prepareSessionParticipantSystemTurnAuthority in session-delegated-operator-source.ts whether the turn belongs to a participant child or retained participant work; only otherwise does it take #205015's recorded-source or session-person path. prepareSessionPrincipalRunAuthority accepts an optional retained participation ceiling, which restart recovery uses to re-admit the original participant.

Four files that part 4 finishes get small hunks here so this part compiles on its own: session-sharing-authorization-async.ts (the profile-id move-out, the participant ceiling on principal admission, the participant check in system turns, and delegated child sources), session-sharing-authorization.ts (two request fields), session-sharing-policy.ts (an invitedSession parameter that part 4 starts using) and server-methods/shared-types.ts (ceiling and signal fields on the mutation authorization).

Tests that prove behaviour through real admission live in later parts: the participant cases of context-engine-turn-authority, operator-run-participation and queued-chat-inputs.metadata need part 4's role keys and admission, and the exec allowlist-miss cases of core-coding-tools.exec-workdir need part 3.

Evidence

Upgrade from the released 2026.11.9

I upgraded a real state directory from the latest stable release to this branch, through the shipped CLI and Gateway entry points. Only the model provider was a loopback mock (scripts/e2e/mock-openai-server.mjs). Setup used ordinary onboarding, config set and authenticated Gateway RPCs, with an owner and a separate non-admin member; there were no SQL fixture writes. The candidate was this branch built at 9731e3c (on main 230456c). The current head d604e1d only rebases it onto newer main, resolving one line in sessions-spawn-tool.ts after #205062.

  • On [email protected] (npm, commit 0032b1d): the member created a session and completed a turn. The owner added an isolated cron agent-turn job (0 0 1 1 *, UTC) and force-ran it once. The member then started a turn that the mock held open and queued a follow-up behind it, and the Gateway shut down. The follow-up was stored as queued. The agent database was at schema 38.
  • On this branch, same state directory and config:
    • Startup migrated the agent database 38 → 44 through the normal chain. The gateway and cron config sections were byte-identical.
    • The queued follow-up written by 2026.11.9 ran after startup and completed (agent.wait status ok). All 3 messages from 2026.11.9 were unchanged in chat.history.
    • The cron job kept its id, name, schedule, session target, payload and enabled state. A forced run after the upgrade completed, and its run history shows both runs as ok.
    • A new member turn completed. No session row gained delegatedOperatorSource or participationCeiling.
    • integrity_check reported ok on the agent and state databases.
  • Comparison with main: the same flow with a candidate built from main a4be1ce gave the same results. The one tool-list difference from 2026.11.9 (session_project is offered on the new member turn) appears on main as well, so it isn't from this PR.
  • Version guard: the current head carries package version 2026.11.9, so the run needed no override. Earlier runs (on c9c1ea0, and the main a4be1ce comparison) used a package version of 2026.11.8, below the release, so the candidate needed OPENCLAW_ALLOW_OLDER_BINARY_DESTRUCTIVE_ACTIONS=1 to open state written by 2026.11.9; their results were the same.
  • Repository upgrade lane from 2026.11.8: scripts/e2e/upgrade-survivor-docker.sh with the published 2026.11.8 baseline passed the base scenario on c9c1ea0 (Upgrade survivor Docker E2E passed [email protected] scenario=base) and the cron-scheduled-authority scenario on an earlier head of this branch.

Not covered: a downgrade back to 2026.11.9, and PostgreSQL deployments. This part adds no table, column or schema version. Its only stored additions are optional private JSON fields, which nothing writes until part 4 admits participants.

Checks

Checked on this branch. The full test pass below ran with part 1 on main 7651c99. After part 1 landed, the branch was rebased onto main 230456c, which adds the turn-grant authority model and #205015 (background turns admitted from their recorded source). All gates were rerun there, along with the 56 test files that this part changes or that exercise system-turn, principal and participant recovery admission.

  • This part's tests: all 52 test files that this part adds or changes pass with only part 1 below it. They cover ceiling intersection, source capture and revocation across storage reopen, queued-input custody, cron and child inheritance, restart custody, context-engine maintenance authority, worker and CLI refusal, exec workdir and process isolation, file containment and the in-process deny set.

  • Ordinary behaviour unchanged: about 150 nearby existing suites (operator-run and recovery, queued inputs, subagent registry and spawn, cron) pass. The only failures are six subagent-registry.requester-wake.e2e receipt cases that time out after 120 s; they time out the same way on main 7651c99 on the same host.

  • Typechecks: core, UI, extensions, scripts, core test shards and root tests.

  • Repository checks: lint and format on changed files; docs format; regenerated worker inventory, protocol output, config baselines and prompt snapshots (all unchanged or reproduced); madge and import cycles; session-identity, assertion-safety and wrapper-shadowing ratchets; Vitest inventory ownership.

  • Test-line budget: this part adds 3,422 net test lines. The allocation record in config/test-lines-allocations/ covers the 3,022 above the allowance, measured against main 230456c.

  • Review: an independent read-only review focused on P0–P2 issues and on behaviour changes for users who don't opt in. It found no P0 or P1 issues and no change that breaks ordinary users. It confirmed that nothing in this part creates a participation ceiling, and that recovering a stored one fails closed. It raised two P2 points, both inert until part 4:

    • Denying a participant's off-allowlist exec commands (instead of asking an approver) is computed here but enforced in part 3's exec approval path, along with the participant guidance for the exec auto-reviewer. Part 3 lands before part 4, so no admitted participant runs without it.
    • If an admin explicitly lists owner-only tools (or a broad wildcard) in a role's invitedTools / invitedAlsoAllow, the participant gets them. This is the documented design in part 4's config help: explicit tools delegate agent capabilities, calls still run under the participant's own role scopes, and the self-authority deny set and the openclaw tool denial still apply. The default participant tools include no owner-only tools.

    It also listed internal behaviour changes that reach ordinary runs without changing outcomes: in-process request limits are now checked when a run is admitted, compaction and context-engine work carry the run's operator authority, member removal also cancels that member's queued inputs (one scan of queued inputs inside the membership write), and spawning or steering re-checks that the run is still active. A storage-doc wording mismatch it found is fixed.

Inherited CI failures

PR CI run 45546662998 (attempt 1, merge of d604e1d into main cc79ae6) passed every job except three node shards and the openclaw/ci-gate aggregate. Each shard failed one test that fails the same way on main without this PR. This PR doesn't change any of those tests or the code they name.

  • checks-node-changed-compact-large-31-2: test/scripts/ci-scheduled-coverage.test.ts › keeps live and non-Vitest tests out of the secretless every-file lane (it reports .agents/skills/openclaw-writing/scripts/writing.test.mjs). The same case fails in the scheduled main run 45540497955 and locally on merge base 032a2b3.
  • checks-node-changed-compact-large-23: src/gateway/mcp-http.session-controls.test.ts › MCP HTTP preserves archive final-effect authority: profile-revoked (the archive succeeds where the test expects isError: true). The same assertion fails locally on merge base 032a2b3, and in unrelated PR fix(voice): answer phone, meeting and FaceTime consults on Claude CLI agents #202209's run 45546496829 against the same main cc79ae6.
  • checks-node-changed-compact-large-38-2: src/gateway/server.beam-owned-view.test.ts › preserves model admission and rolls back revoked owned Beam adoption (UNAVAILABLE: Could not load this Beam at line 591). This test fails intermittently on main. It failed with the same error at the same line in PR fix(voice): answer phone, meeting and FaceTime consults on Claude CLI agents #202209's run 45546496829 against main cc79ae6, and in one of five local runs of the same 16-file shard on main. The full shard passes locally on this head.

The end-to-end proof that a real admitted participant is held to these limits (spawn, children, recovery, restart, configured tools) is in part 4, because admission only exists from there.

🦞 Made with OpenClaw

@clawsweeper

clawsweeper Bot commented Nov 24, 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 app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: XL labels Nov 24, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Nov 24, 2026
@clawsweeper

clawsweeper Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR carries participant tool, permission, filesystem, and process limits through runs, queued work, children, scheduling, and restart recovery.

Example: A future admitted participant has read-only access to agent:main:invited.

  • Before: The run machinery has no participant-specific ceiling to retain across child runs and recovery.
  • After: The retained ceiling restricts tools and execution, and recovered work must pass current invitation admission before starting.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful enforcement foundation with supplied upgrade proof and no established code blocker; it intentionally delivers only part of the linked participant feature, and current-head CI remains pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied CLI/Gateway upgrade report exercises ordinary queued-input recovery, cron execution, history preservation, and unchanged settings from v2026.11.9; participant enforcement has in-process coverage here and becomes reachable with the later admission stage. The inspected screenshots show invitation UI states and add no enforcement proof for this split.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Partial
User problem: Inviting someone into one session needs limits that prevent their subsequent work from inheriting unrestricted creator capabilities.
Reason: The maintainer-authored stack deliberately lands restrictions before admission; this PR supplies that prerequisite without exposing the complete invitation feature.

Merge readiness

✅ Ready for maintainer review

Keep this PR open as the maintainer-directed enforcement stage of the participation stack; the previous conflict is resolved, and no concrete introduced blocker was found in the inspected authority, containment, and recovery paths.

Reviewed head: d604e1d3d3df195a8f5ac8cbafd4f652cae77340

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway admission supplies run authority to agent execution, while queue, cron, subagent, and context-engine owners retain restrictions for subsequent work.

flowchart TD
  A[Gateway admission] --> B[Admitted run authority]
  B --> C[Tool and filesystem policy]
  B --> D[Queued inputs and cron]
  B --> E[Subagent children]
  D --> F[Recovery admission]
  E --> F
  F --> B
Loading

Technical review

Best possible solution:

Land this enforcement stage through the existing admission and storage owners before enabling participant admission in the later stack.

Do we have a high-confidence way to reproduce the issue?

This is an inert foundation for participant admission rather than a report of currently reachable broken behavior.

Is this the best way to solve the issue?

The inspected paths consistently narrow existing authority and retain restrictions through existing continuation owners, which supports landing enforcement before admission.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit b5af51a adds src/gateway/session-sharing-authorization-async.ts:99 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b5af51a7cc3b; files: src/gateway/session-sharing-authorization-async.ts)

PR surface

PR surface statistics unavailable: the file list is incomplete.

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 proof: sufficient: Contributor real behavior proof is sufficient.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-11-24T19:11:54.636Z sha e77c823 :: blocked before merge. :: [P3] Inline the sole session-ID comparison
  • reviewed 2026-11-25T01:07:25.494Z sha c9c1ea0 :: blocked before merge. :: none
  • reviewed 2026-11-25T02:54:25.026Z sha c9c1ea0 :: needs changes before merge. :: none
  • reviewed 2026-11-25T04:14:43.002Z sha 9731e3c :: needs changes before merge. :: none

Reviewed November 24, 2026, 11:32 PM ET / November 25, 2026, 04:32 UTC (Revision 5).

@jalehman
jalehman force-pushed the participate-split/p2-participant-limits branch from e77c823 to 84bdf51 Compare November 24, 2026 19:21
@openclaw-barnacle openclaw-barnacle Bot removed app: web-ui App: web-ui commands Command implementations labels Nov 24, 2026
Base automatically changed from participate-split/p1-access-storage to main November 24, 2026 19:44
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui commands Command implementations labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 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: d604e1d3d3df195a8f5ac8cbafd4f652cae77340
  • Maintainer: @jalehman
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/admitted-run-operator-authority.types.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/conversation-tool-policy-pipeline.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/delegated-tool-policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/harness/context-engine-turn-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/harness/tool-authority.runtime.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/requester-tool-policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/subagents/registry/subagent-completion-batch-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/workspace-sandbox.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/operator-run-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-plugin-in-process-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-method-policy.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-principal-run-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-sharing-authorization-async.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-sharing-authorization.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/exec-policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/security/dangerous-tools.ts: Controls product security checks or trust decisions. Check whether the change weakens detection, protection, or remediation.

Carefully review these changes before merging.

@jalehman
jalehman force-pushed the participate-split/p2-participant-limits branch from 84bdf51 to 795ef79 Compare November 24, 2026 20:13
@openclaw-barnacle openclaw-barnacle Bot removed app: web-ui App: web-ui commands Command implementations labels Nov 24, 2026

@THE-NAVVV THE-NAVVV left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

​

@jalehman
jalehman force-pushed the participate-split/p2-participant-limits branch from 9731e3c to d604e1d Compare November 25, 2026 04:25
@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 25, 2026
@jalehman
jalehman merged commit d2699a8 into main Nov 25, 2026
240 of 247 checks passed
@jalehman
jalehman deleted the participate-split/p2-participant-limits branch November 25, 2026 05:42
@jalehman

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

obviyus added a commit that referenced this pull request Nov 25, 2026
…their requester (#205129)

## Problem

A background command that exits after a Gateway restart wakes its chat under the wrong person.

- A durable process record (and the record of an ordinary wake-armed process the restart lost) saved no requester. At exit, the wake ran as the **session principal**:
  - A member's job in the owner's session finished with the owner's power.
  - An admin's job in another person's session failed with "Session principal has no current run authority".
- A configured channel owner (`commands.ownerAllowFrom`, for example a Discord owner) recorded no source at all (`captureQueuedOperatorRecoverySource` returned nothing). After a restart, their owed or queued work lost the owner grant.

## Fix

The fix follows the OA2 storage decision: store the requester's source on the work item and admit it again when the work starts.

1. **Durable process record.** `record_json` now holds the requester's `QueuedOperatorRecoverySource`, for both `durable` and `ordinary` kinds.
   - The source comes from the target captured at exec start. Nothing is stored when capture is `unavailable`.
   - Incognito sessions still never write a row.
   - At exit, the restored process admits that source again (`restoreGatewayQueuedOperatorRecovery`, then `captureSessionEventTargetForHost`). This is the same function the restart replay of owed rows uses; `captureOwedRequesterTarget` now serves both paths.
   - The source is copied into the owed row's `originFacts`, so a second restart follows the same requester.
   - If the requester's access ended, the stored result is withheld with its cause (`revoked`). It stays visible in the chat as not run; it is never dropped.
2. **Channel owner.** `queuedSourceSchema` gets `{ kind: "channel-owner", sender: { channelId, accountId, senderId } }`. `captureQueuedOperatorRecoverySource` returns it for a configured channel owner. Restore runs `decideChannelOwnerPrincipal(config, sender)` again, then `decideOperatorAdmission` (live facts).
   - A sender no longer in `ownerAllowFrom` is refused, with a cause the user can see.
   - Same-process work keeps its live authority, as before.
   - Nothing is written to the session `operatorSources` store, so in a shared guild session a member's job never borrows the owner's grant.

Comments updated: `bash-durable-process-store.ts:13`, `operator-run-recovery-source.ts:28`, `bash-process-durable-notify.ts`, `initializeDurableProcesses`. Docs updated: `docs/gateway/background-process.md`, `docs/reference/database-schemas/layout.md`.

## Decisions

- **Old rows:** no migration. A process record or owed row written before this change has no source. It wakes as the session principal, as before, until it settles.
- **Deleted sessions:** session delete does not remove durable process rows. Durable processes deliberately survive reset and delete (`stopSessionExecProcesses`), and the row is what lets the registry clean up the unit and its log. So the row stays until the process ends. Its stored source is never admitted: exit-time preparation disarms the wake when the session entry is gone or archived (`prepareAdoptedDurableProcessNotification`). Ordinary rows are removed, because delete stops ordinary processes and their exit deletes the row.
- **Wider capture:** the channel-owner source reaches every existing capture point (owed rows, queue, subagent launch, environment provisioning, scheduled plugin commands). A Discord owner now gets the same answer there as the Control UI owner. This is the intended "same principal, same answer" rule (OA2 DESIGN §1).
- **Production lines:** net positive (+142/−45 in `src` non-test). This PR adds approved stored-source behavior (storage decision, Fable 5.2 consult 2). The replay path in `queued-chat-inputs.ts` now shares `captureOwedRequesterTarget` instead of its own copy.
- **Admission lifetime (review rounds 1-2, fixed):** a restored requester's admission is held until the wake and its one retry settle. `wakeOwedExec` now resolves at that point, and both restart callers release then. Before, a participant-limited source (#204847) was released before the event queue retained it, and the retry reused a released target.

## Evidence

- New test `src/gateway/owed-exec-requester.test.ts`. All 5 cases fail on base `79e42e0877d9` and pass on head:
  - (a) a member's restored job in an owner session wakes as the member;
  - (b) an admin's restored job in another person's session wakes as the admin;
  - (c) a Discord owner's owed result after a restart, and a restored owner's job at exit, keep the owner grant;
  - (d) a removed owner's result ends `cancelled`/`revoked`, and a requester without session write gets the same visible cause;
  - (e) in the same guild session, a member's owed result wakes without the owner grant.
- Matrix: E11 (durable exec wake) and channel-owner replay cells live in that file; the table test's comment points there.
- Real isolated Gateway restart, real model (`member-restart-proof.ts`). `admin@` owns the session, and `worker@` (role `worker`: read + write, no admin) starts `durable: true` `sleep 45`. The Gateway restarts, the command exits, and the woken turn calls `gateway config.get`:
  - base `79e42e0877d9`: the call returned the config; the wake ran with the session principal's (admin) owner grant;
  - head: "gateway needs the owner's authority, and this turn was not started by the owner. Do not retry gateway." The wake ran as the worker, with no refusal of the wake itself.
- Live Discord QA bot (live channel driver, live model, real Gateway restart). The driver is the configured `ownerAllowFrom` owner. It checks that its own turn can call `gateway config.get` (owner grant), then starts `durable: true` `sleep 75`. The Gateway restarts, and the completion turn calls `gateway config.get` again:
  - base `79e42e0877d9`: `WAKE MEMBER: gateway needs the owner's authority, and this turn was not started by the owner.`
  - head: `WAKE OWNER`.
- One-admission E2E Q/R/S pass on each pushed head.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 26, 2026
…their requester (openclaw#205129)

## Problem

A background command that exits after a Gateway restart wakes its chat under the wrong person.

- A durable process record (and the record of an ordinary wake-armed process the restart lost) saved no requester. At exit, the wake ran as the **session principal**:
  - A member's job in the owner's session finished with the owner's power.
  - An admin's job in another person's session failed with "Session principal has no current run authority".
- A configured channel owner (`commands.ownerAllowFrom`, for example a Discord owner) recorded no source at all (`captureQueuedOperatorRecoverySource` returned nothing). After a restart, their owed or queued work lost the owner grant.

## Fix

The fix follows the OA2 storage decision: store the requester's source on the work item and admit it again when the work starts.

1. **Durable process record.** `record_json` now holds the requester's `QueuedOperatorRecoverySource`, for both `durable` and `ordinary` kinds.
   - The source comes from the target captured at exec start. Nothing is stored when capture is `unavailable`.
   - Incognito sessions still never write a row.
   - At exit, the restored process admits that source again (`restoreGatewayQueuedOperatorRecovery`, then `captureSessionEventTargetForHost`). This is the same function the restart replay of owed rows uses; `captureOwedRequesterTarget` now serves both paths.
   - The source is copied into the owed row's `originFacts`, so a second restart follows the same requester.
   - If the requester's access ended, the stored result is withheld with its cause (`revoked`). It stays visible in the chat as not run; it is never dropped.
2. **Channel owner.** `queuedSourceSchema` gets `{ kind: "channel-owner", sender: { channelId, accountId, senderId } }`. `captureQueuedOperatorRecoverySource` returns it for a configured channel owner. Restore runs `decideChannelOwnerPrincipal(config, sender)` again, then `decideOperatorAdmission` (live facts).
   - A sender no longer in `ownerAllowFrom` is refused, with a cause the user can see.
   - Same-process work keeps its live authority, as before.
   - Nothing is written to the session `operatorSources` store, so in a shared guild session a member's job never borrows the owner's grant.

Comments updated: `bash-durable-process-store.ts:13`, `operator-run-recovery-source.ts:28`, `bash-process-durable-notify.ts`, `initializeDurableProcesses`. Docs updated: `docs/gateway/background-process.md`, `docs/reference/database-schemas/layout.md`.

## Decisions

- **Old rows:** no migration. A process record or owed row written before this change has no source. It wakes as the session principal, as before, until it settles.
- **Deleted sessions:** session delete does not remove durable process rows. Durable processes deliberately survive reset and delete (`stopSessionExecProcesses`), and the row is what lets the registry clean up the unit and its log. So the row stays until the process ends. Its stored source is never admitted: exit-time preparation disarms the wake when the session entry is gone or archived (`prepareAdoptedDurableProcessNotification`). Ordinary rows are removed, because delete stops ordinary processes and their exit deletes the row.
- **Wider capture:** the channel-owner source reaches every existing capture point (owed rows, queue, subagent launch, environment provisioning, scheduled plugin commands). A Discord owner now gets the same answer there as the Control UI owner. This is the intended "same principal, same answer" rule (OA2 DESIGN §1).
- **Production lines:** net positive (+142/−45 in `src` non-test). This PR adds approved stored-source behavior (storage decision, Fable 5.2 consult 2). The replay path in `queued-chat-inputs.ts` now shares `captureOwedRequesterTarget` instead of its own copy.
- **Admission lifetime (review rounds 1-2, fixed):** a restored requester's admission is held until the wake and its one retry settle. `wakeOwedExec` now resolves at that point, and both restart callers release then. Before, a participant-limited source (openclaw#204847) was released before the event queue retained it, and the retry reused a released target.

## Evidence

- New test `src/gateway/owed-exec-requester.test.ts`. All 5 cases fail on base `2719e6162d55` and pass on head:
  - (a) a member's restored job in an owner session wakes as the member;
  - (b) an admin's restored job in another person's session wakes as the admin;
  - (c) a Discord owner's owed result after a restart, and a restored owner's job at exit, keep the owner grant;
  - (d) a removed owner's result ends `cancelled`/`revoked`, and a requester without session write gets the same visible cause;
  - (e) in the same guild session, a member's owed result wakes without the owner grant.
- Matrix: E11 (durable exec wake) and channel-owner replay cells live in that file; the table test's comment points there.
- Real isolated Gateway restart, real model (`member-restart-proof.ts`). `admin@` owns the session, and `worker@` (role `worker`: read + write, no admin) starts `durable: true` `sleep 45`. The Gateway restarts, the command exits, and the woken turn calls `gateway config.get`:
  - base `2719e6162d55`: the call returned the config; the wake ran with the session principal's (admin) owner grant;
  - head: "gateway needs the owner's authority, and this turn was not started by the owner. Do not retry gateway." The wake ran as the worker, with no refusal of the wake itself.
- Live Discord QA bot (live channel driver, live model, real Gateway restart). The driver is the configured `ownerAllowFrom` owner. It checks that its own turn can call `gateway config.get` (owner grant), then starts `durable: true` `sleep 75`. The Gateway restarts, and the completion turn calls `gateway config.get` again:
  - base `2719e6162d55`: `WAKE MEMBER: gateway needs the owner's authority, and this turn was not started by the owner.`
  - head: `WAKE OWNER`.
- One-admission E2E Q/R/S pass on each pushed head.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…l UI (#204325)

* fix(agents): default Access to a model's only advertised program

Cyber models advertise only Daybreak Red and reject Standard, but the runtime default fell back to Standard whenever no accessPrograms.cyber was configured, so unconfigured cyber-model turns outside the Control UI failed with invalid_access_program. The default now follows the selected account's advertised programs from the prepared model catalog for both the catalog projection and the physical request.

* test(agents): satisfy test typecheck for Access default contracts

* test(agents): give the overflow-compaction runtime fixture its isCurrent contract

* fix(agents): read advertised Access programs only on routes that send one

Dispatch now skips the prepared-catalog account read for providers and routes that never send an Access program, so non-OpenAI turns do no extra account-catalog work. The default resolver and dispatch share one route predicate.

(cherry picked from commit 862c71e)

Release adaptation: Keep stable's Daybreak toggle and separate Access selector wording; document the advertised single-program default and stale-choice error without importing the UI behavior from #204302. Include eccac8a (#204461), which keeps the attempt lookup private and tests the dispatch wrapper. Role, current-account, and entitlement checks are unchanged.

Later same-file changes not needed: a1ba2bc (#204545) is newer Control UI behavior; d2699a8 (#204847) adds separate participation limits; f00839d adds MCP requester propagation; 26f82df (#205687) adds streaming preflight progress; 41dc731 (#195479) retains transcript targets across catalog reloads; 4ff18a0 changes project-move prompt inputs. None is a dependency of the Access default.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Preserve the existing requester restart reason in announce classification so unconsumed completed results remain pending for startup custody. Existing consumption receipts prevent replay; permanent refusals, explicit cancellation, and ambiguous sends retain their policies.

(cherry picked from commit b8b06c4)

Follow-ups: fca5133 fix: preserve child completion inputs across Gateway restarts (#208367) [not selected for this narrow backport]; b7967b2 fix: deliver a saved child answer after a Gateway crash (#207706) [not selected for this narrow backport]; 17e2ec9 fix: tell the user when a finished subagent's report can't start in their chat (#207194) [not selected for this narrow backport]; 811f999 refactor(subagents): centralize completion delivery decisions (#206383) [not selected for this narrow backport]; 50a6774 fix: retain channel requester when child completion resumes parent [separately ordered lane row]; d2699a8 chore: carry and enforce participant limits on admitted runs (#204847) [not selected for this narrow backport]; 57dd84b fix(agents): settle every undelivered child completion into history; drop delivery dispositions (#204260) [separately ordered lane row]; cded11f fix(agents): deliver a child's end state as parent history, not a turn obligation (#204178) [not selected for this narrow backport]; 92e92d7 fix: preserve restarted child results and gateway test ownership (#203839) [not selected for this narrow backport]; 09d956b fix(subagents): wake a yielded requester for each ready child result (#203176) [not selected for this narrow backport]; 9f35510 fix: retain child results behind live requester turns (#203198) [separately ordered lane row]; c23cd7f fix: preserve private child results during restart (#203156) [separately ordered lane row]

Release adaptation: Keep stable requester fixture setup and insert the two consumed/unconsumed restart cases without moving its existing lost-yield test.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Co-authored-by: sallyom <[email protected]>
(cherry picked from commit 3f00a51)

Companion audit: #204847 participant-limit propagation, #205572 worker exec settings, #204805 deferred tools, #206762 tool-description perf, and #206537 prompt manifest redesign touch neighboring owners but are not prerequisites for stable worker spawn guidance.

Release adaptation: Render the dedicated-worker hint only for worker placement; preserve stable local workflow text and keep both render sites on one delegation section binding, and let the worker hint suppress the duplicate full-surface messaging hint.

Co-authored-by: RomneyDa <[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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants