Skip to content

fix: allow session tools in system continuations - #187105

Merged
steipete merged 1 commit into
mainfrom
codex/system-turn-principal-authority
Oct 29, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/system-turn-principal-authority

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #185730

What Problem This Solves

Fixes person-scoped session tools refusing authorized system continuations after background command completion.

User Impact

System-triggered turns can spawn and continue work using the session principal's current authority, without another user message. Revocation or ownership changes still prevent later effects. Scheduled jobs keep their existing authority model.

Why This Change Was Made

The restart redesign resolved principal authority for restart input, but other system admissions still depended on the previous turn's caller or had no person authority. Trusted host inputs now share the existing principal resolver at admission, selecting the assigned human owner or verified human creator and checking current grants before effects. Public provenance alone cannot select this path. This removes the restart-specific resolver and inherited person grants from ordinary transcript continuations.

Sessions without a human principal gain no person authority; their refusal now explains that a person must resume the work. There are no configuration, dependency, schema, or persisted-shape changes.

Evidence

The exec-completion regression fails on the base and passes with the fix through real event admission and the managed sessions_spawn tool, omitting user. Its second child launch is refused after the principal is demoted at the effect boundary. Only model decisions and the final child launch are synthetic; no live Gateway or real user state was used.

Local proof passed with nice -n 5 and at most eight Vitest workers: 177 tests across nine focused files, followed by 29 passing tests in the two files with final fixture corrections. The existing operator-run cancellation suite also passed all 15 tests. Core typecheck, the three affected test type graphs, targeted lint, formatting of all 27 changed files, and git diff --check passed. Prompt-prefix stability is included in the 177-test run.

The final exec regression was replayed on the base with production changes temporarily reversed: event execution started but principal authority was absent, and the test failed. Production edits were restored and the final principal suite passed all seven tests.

The complete change is production +429/−220 (net +209), tests +161/−167 (net −6), and docs +7. Necessary growth covers shared admission, current-owner validation and release ownership; no limit or baseline was raised. Codex autoreview found no actionable P0–P2 findings in the final snapshot. The local ClawSweeper checkout was unavailable, so the documented autoreview route was used.

Resolve trusted system turns through the existing current-principal authority owner, and revalidate principal ownership and grants before effects. Remove restart-specific resolution and prior-person grants from ordinary transcript continuations while preserving scheduled authority.
@clawsweeper

clawsweeper Bot commented Oct 29, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T00:06:45.351396Z 19dc2f3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

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: 19dc2f358e23e74dc5cb3a6e7a7c7f70f336e4d4
  • Maintainer: @steipete
  • 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19dc2f358e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

sessionId: operation.sessionId,
storePath: params.defaults.storePath,
resolveGatewayContext: params.defaults.resolveGatewayContext,
assertCurrent: assertOperationCurrent,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Separate retained principal authority from the admitting operation

When a system continuation spawns a child or yields to a tool handoff, its accepted work must outlive the admitting reply operation. However, prepareSessionPrincipalRunAccess retains this assertCurrent callback inside the principal authority, and assertOperationCurrent throws as soon as operation.result is set. Both child admission and captureOperatorToolGatewayContinuationContext retain that same authority; independentContinuation cannot detach this callback. Consequently, a child loses authority when its parent finishes, and a github_publish handoff—which explicitly waits for operation.ownerSettlement before executing—fails its authority check after yielding. Use the operation check during admission without permanently binding accepted continuation authority to that operation, while retaining current principal, role, and session checks.

AGENTS.md reference: AGENTS.md:L97-L97

Useful? React with 👍 / 👎.

@steipete
steipete enabled auto-merge (squash) October 29, 2026 00:12
@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. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

System continuations resolve the session’s current human principal instead of inheriting the previous caller’s authority.

Example: A background command completes in agent:main:resume-principal and requests sessions_spawn.

  • Before: The continuation lacks person authority and cannot launch the requested child.
  • After: The continuation resolves the recorded principal’s current grants and admits the launch while those grants remain valid.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful maintainer-directed repair, blocked by a definite authority-lifetime defect, affected consumer failures, and synthetic final-effect evidence.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
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: Authorized background completions cannot use person-scoped session tools without another human message.
Reason: The maintainer-authored direction addresses a concrete workflow failure and consolidates existing authorization ownership without adding configuration.

Merge readiness

⛔ Blocked before merge - 8 items remain

Keep open: this maintainer-authored PR addresses a concrete continuation failure, but retained authority expires with the admitting reply and affected consumer checks fail.

Priority: P1
Reviewed head: 19dc2f358e23e74dc5cb3a6e7a7c7f70f336e4d4

Before merge

  • Add real behavior proof - Authority-chain proof required: the supplied exec regression reaches real event admission and managed sessions_spawn, but final child launch is mocked and demotion is injected inside that mock. Provide allowed continuation execution after parent settlement and rejection of public provenance, revoked grants, and owner reassignment before actual launch or publication I/O; redact credentials and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Detach retained principal authority from reply completion (P1) - Passing assertOperationCurrent into the principal resolver permanently embeds operation.result and the reply abort signal in the captured source authority. A system continuation can admit a child or capture a github_publish handoff while active, but the retained authority then rejects when the parent completes. The handoff always waits for operation.ownerSettlement before executing, so it reaches this refusal after yielding. independentContinuation cannot remove the embedded callback. Check operation liveness during admission, and retain principal, role, session, revocation, and explicit cancellation checks under the accepted work’s own lifetime. This confirms the existing discussion at fix: allow session tools in system continuations #187105 (comment).
  • Migrate event consumer fixtures to current-principal admission (P2) - Dropping inherited operatorAuthority changes every ordinary event consumer, but the existing background-completion and plugin-reload regressions still create caller-only fixtures and expect that caller’s capability after resume. Head CI consequently fails bash-tools.exec-background-followup.test.ts:613 and multiple plugins-reload-handoff.test.ts cases. Record the intended current human principal in authorized fixtures and update the source-revocation expectations to the new policy, preserving forbidden-principal and cancellation controls rather than deleting coverage.
  • Update the preparation test for the new empty-roster refusal (P2) - The empty-roster branch now emits a different error, while reply-run-registry.preparation.test.ts:499 still requires 'User is not a participant'. Head CI reports this exact mismatch. Update that consumer to assert the intended no-person-authority rejection while retaining its indeterminate-injection and acceptance assertions.
  • Resolve security review attention item - No concrete privilege bypass was established, but the changed system-to-human authority boundary requires final-effect isolation evidence.
  • Resolve merge risk - Before merge, the PR author must establish that public provenance cannot acquire session-owner authority and that revocation or owner reassignment blocks retained work before actual child-launch or publication I/O.
  • Improve patch quality - Add final-effect proof for the nearest unauthorized principal and prove revocation or reassignment invalidates retained authority before I/O.
  • Explain or restore the original intent of Accepted child authority lifetime - 76cf9fe: fix(gateway): retain continuation authority for every child run #178693 made accepted children independent of parent completion while preserving revocation and Stop; the new retained reply-operation callback defeats that invariant without explaining the change.

Findings

  • [P1] Detach retained principal authority from reply completion — src/auto-reply/reply/reply-agent-turn-preparation.ts:309-315
  • [P2] Migrate event consumer fixtures to current-principal admission — src/auto-reply/reply/session-event-handoff.ts:508-513
  • [P2] Update the preparation test for the new empty-roster refusal — src/sessions/session-controller.tool-authority.ts:103-105

Provenance

Tests

  • Missing end-to-end proof: Supply production-boundary evidence for accepted children and handoffs after parent settlement, including denied public, revoked, and reassigned principals; the reported base-red/head-green exec regression covers initial admission only.
Agent review details

How this fits together

Host events, transcript follow-ups, and internal agent requests enter session admission, which resolves current principal and session access before supplying authority to agent tools and accepted work.

flowchart TD
  A[Host event or transcript followup] --> B[Session admission]
  B --> C[Current session principal]
  C --> D[Existing role and session authorization]
  D --> E[Admitted tool authority]
  E --> F[Child launch or tool handoff]
  D --> G[Current authority checks]
Loading

Technical review

Best possible solution:

Resolve current principals through the existing authorization owner while keeping admission liveness separate from independently retained work authority.

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

Source establishes missing person authority on ordinary system admission and the introduced retained-lifetime failure; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Sharing the existing principal resolver is appropriate, but its retained authority must not permanently capture the admitting reply’s completion check.

Full review comments:

  • [P1] Detach retained principal authority from reply completion — src/auto-reply/reply/reply-agent-turn-preparation.ts:309-315
    Passing assertOperationCurrent into the principal resolver permanently embeds operation.result and the reply abort signal in the captured source authority. A system continuation can admit a child or capture a github_publish handoff while active, but the retained authority then rejects when the parent completes. The handoff always waits for operation.ownerSettlement before executing, so it reaches this refusal after yielding. independentContinuation cannot remove the embedded callback. Check operation liveness during admission, and retain principal, role, session, revocation, and explicit cancellation checks under the accepted work’s own lifetime. This confirms the existing discussion at fix: allow session tools in system continuations #187105 (comment).
    Confidence: 0.99
  • [P2] Migrate event consumer fixtures to current-principal admission — src/auto-reply/reply/session-event-handoff.ts:508-513
    Dropping inherited operatorAuthority changes every ordinary event consumer, but the existing background-completion and plugin-reload regressions still create caller-only fixtures and expect that caller’s capability after resume. Head CI consequently fails bash-tools.exec-background-followup.test.ts:613 and multiple plugins-reload-handoff.test.ts cases. Record the intended current human principal in authorized fixtures and update the source-revocation expectations to the new policy, preserving forbidden-principal and cancellation controls rather than deleting coverage.
    Confidence: 0.98
  • [P2] Update the preparation test for the new empty-roster refusal — src/sessions/session-controller.tool-authority.ts:103-105
    The empty-roster branch now emits a different error, while reply-run-registry.preparation.test.ts:499 still requires 'User is not a participant'. Head CI reports this exact mismatch. Update that consumer to assert the intended no-person-authority rejection while retaining its indeterminate-injection and acceptance assertions.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Verify authority at final effects (recommended)
    The PR author should exercise allowed system continuations and forbidden public, revoked, and reassigned principals through production launch or publication boundaries.

Provenance checked

Testing

Proof path: in-process harness.

Security

Needs attention: No concrete privilege bypass was established, but the changed system-to-human authority boundary requires final-effect isolation evidence.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9344233 adds src/gateway/session-sharing-authorization-async.ts:51 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9344233e7a66; files: src/gateway/session-sharing-authorization-async.ts)
  • Paul Bohm: Raw commit 41f55f5 adds src/agents/tools/session-tool-handoff.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 41f55f5a9dec; files: src/agents/tools/session-tool-handoff.ts)
  • PollyBot13: Raw commit 7c9cb97 adds src/agents/tools/session-tool-handoff.ts:110 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 7c9cb9742933; files: src/agents/tools/session-tool-handoff.ts)

PR surface

Source +209, Tests -6, Docs +7. Total +210 across 27 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 20 429 220 +209
Tests 6 161 167 -6
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 27 597 387 +210

Review metrics

Metric Value Why it matters
Production versus test changes Production +429/−220; tests +161/−167 Shared principal admission and release ownership explain the production growth; no additional state manager or persisted representation is introduced.

Labels

Label changes:

  • add P1: The introduced lifetime coupling can interrupt accepted children and prevent deferred tool handoffs from executing.
  • add merge-risk: 🚨 security-boundary: The PR changes system-to-human authority selection and retention; final-effect isolation from public, revoked, and reassigned principals remains unproven.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P1: The introduced lifetime coupling can interrupt accepted children and prevent deferred tool handoffs from executing.
  • merge-risk: 🚨 security-boundary: The PR changes system-to-human authority selection and retention; final-effect isolation from public, revoked, and reassigned principals remains unproven.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 October 28, 2026, 8:20 PM ET / October 29, 2026, 00:20 UTC.

@steipete
steipete merged commit d821a7f into main Oct 29, 2026
132 of 143 checks passed
@steipete
steipete deleted the codex/system-turn-principal-authority branch October 29, 2026 00:22
steipete added a commit that referenced this pull request Oct 29, 2026
Reverts #187105 (d821a7f). It merged over six failed CI jobs, including a privilege-boundary regression: a guest-started background exec completion continued with the session principal's authority and lost the guest's AutoReview policy. The four failing test files pass locally on this revert head (99 tests).
@steipete

Copy link
Copy Markdown
Contributor Author

Reverted in #187126 (5be92b4). This merged while exact-head CI had six failed jobs, which my merge step should have caught. One failure is a privilege-boundary regression. In src/agents/bash-tools.exec-background-followup.test.ts ("background completion keeps AutoReview", expected undefined to be 'original-guest'), a guest-started background exec completion continued with the session principal's authority instead of the guest's, and lost the guest's AutoReview policy. reply-run-registry.preparation.test.ts and server.chat-goal.test.ts also failed. The fix will be redone so that work a caller started keeps that caller's current authority and policy.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…ity (openclaw#187105)

Turns started by the system (background exec completion events, transcript continuations, goal continuations, synthetic system RPC) now act with the session principal's current authority. That principal is the assigned owner, or else the human profile creator, and authority is revalidated at the point of effect. These turns had no participants, so person-scoped tools like sessions_spawn refused with "User is not a participant of this turn" (8 refusals on the Team server since 10-02; 4 in the real-model stress run on main). The agent silently stopped work as soon as it continued from an event instead of a fresh message.

- One resolver (prepareSessionSystemTurnAuthority -> prepareSessionPrincipalRunAuthority, sessionPrincipal) shared with restart resume; no per-trigger special cases.
- An explicit non-human assignment never falls back to a former human creator. Sessions without a human principal gain no person authority, and their refusal now says so ("This turn has no person authority. A person must resume this work...").
- Cron keeps its own authority model.

Proof: the exec-completion regression is red on base. A second child launch is refused after principal demotion at effect. 177 focused tests pass at the PR head (prompt-prefix stability included). The touched suites (113 tests) pass locally on current main merged with this head. No CI job failed. Merged at the pinned head per Peter's local-proof merge rule.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
Reverts openclaw#187105 (60e218e). It merged over six failed CI jobs, including a privilege-boundary regression: a guest-started background exec completion continued with the session principal's authority and lost the guest's AutoReview policy. The four failing test files pass locally on this revert head (99 tests).
steipete added a commit that referenced this pull request Oct 29, 2026
#187346)

System-started turns now continue with the current authority of whoever started the work they continue. Before, they had no person authority: person-scoped tools like sessions_spawn refused with "User is not a participant of this turn" (8 Team-server refusals since 10-02; 4 in real-model stress on main), and the agent silently stopped work as soon as it continued from an event.

- A guest's background exec, subagent or goal continues as that guest, keeping the guest's current policy (AutoReview etc.), revalidated at the point of effect.
- Only system work with no originating caller (restart resume, unattributed events) falls back to the session principal's current authority. An explicit non-human assignment never falls back to a former human creator; no-principal turns get no person authority and an honest refusal.
- Node exec completions keep the captured logical target and agent; the prefixed queue key is used only for storage and cleanup.
- Cron keeps its own authority model.

This redoes #187105, which was reverted in #187126 after it continued a guest-started background completion with owner authority (lost the guest's AutoReview).

Proof at exact head b16e958:
- The exec-completion sessions_spawn regression is red on base; guest-continuation, revocation and delayed-node custody tests pass; the node-owner regression is red on dc07bd4 and green here.
- Locally, 21 files (430 tests) and ten static checks pass, including zero-cycle guards.
- Exact-head CI: 93 jobs passed. The single failed job, checks-node-changed-compact-large-23, is sessions-create-thinking-claim.test.ts "...at the same timestamp (delivered-event)". It passed on both previous heads (dc07bd4, 425cbfb), the only change since is the unrelated 4-line node-owner fix, and it passed 6/6 locally on this head, so it is a timing intermittent.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
openclaw#187346)

System-started turns now continue with the current authority of whoever started the work they continue. Before, they had no person authority: person-scoped tools like sessions_spawn refused with "User is not a participant of this turn" (8 Team-server refusals since 10-02; 4 in real-model stress on main), and the agent silently stopped work as soon as it continued from an event.

- A guest's background exec, subagent or goal continues as that guest, keeping the guest's current policy (AutoReview etc.), revalidated at the point of effect.
- Only system work with no originating caller (restart resume, unattributed events) falls back to the session principal's current authority. An explicit non-human assignment never falls back to a former human creator; no-principal turns get no person authority and an honest refusal.
- Node exec completions keep the captured logical target and agent; the prefixed queue key is used only for storage and cleanup.
- Cron keeps its own authority model.

This redoes openclaw#187105, which was reverted in openclaw#187126 after it continued a guest-started background completion with owner authority (lost the guest's AutoReview).

Proof at exact head b16e958:
- The exec-completion sessions_spawn regression is red on base; guest-continuation, revocation and delayed-node custody tests pass; the node-owner regression is red on dc07bd4 and green here.
- Locally, 21 files (430 tests) and ten static checks pass, including zero-cycle guards.
- Exact-head CI: 93 jobs passed. The single failed job, checks-node-changed-compact-large-23, is sessions-create-thinking-claim.test.ts "...at the same timestamp (delivered-event)". It passed on both previous heads (dc07bd4, 425cbfb), the only change since is the unrelated 4-line node-owner fix, and it passed 6/6 locally on this head, so it is a timing intermittent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. docs Improvements or additions to documentation gateway Gateway runtime security-sensitive-changed size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant