Repository navigation
refactor: let started agent tool calls finish after a permission change - #203487
Conversation
…ange Admission checks permission once. captureGatewayToolCallerAssertion no longer re-checks operator selection, operator authority, the receipt boolean or the cron method capability at each effect. Stop (approvalSignals) and the receipt's prepared session-store write fences stay. Tests that asserted a mid-run refusal are deleted; Stop and session-conflict cases stay. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Head E2E on
{
"pass": false,
"prefix": "HEAD",
"sessionKey": "agent:main:one-admission-c651ef91",
"models": [
null,
"gpt-5.5-2026-04-23"
],
"relayStatuses": [
421,
200
],
"checks": [
{
"id": "R.running-turn-finishes",
"pass": true,
"detail": {
"state": "final",
"toolEnds": 3,
"toolEndsAfterRevoke": 3
}
},
{
"id": "Q.queued-input-refused-visibly",
"pass": false,
"detail": {
"accepted": true,
"providerRequestsWithQueuedMarker": 1,
"visibleRefusalInTranscript": false
}
},
{
"id": "S.stop-cancels",
"pass": true,
"detail": {
"abort": {
"ok": true,
"aborted": true,
"runIds": [
"1e281926-236e-4cf8-a0e9-863f15279aaa"
]
},
"state": "aborted",
"requestsWithStopMarker": 1
}
}
],
"elapsedMs": 56380
}
|
|
Codex review: needs changes before merge. What this changesThis PR removes repeated permission checks from started agent tool calls while preserving cancellation and prepared session-write fences. Example: A user’s role changes from worker to readonly while an admitted tool request is running.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 3 items remain Keep open: this maintainer-authored change follows the repository’s admission rule, but introduced test failures and a stale ratchet allowance need repair. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe caller-context adapter carries admitted agent identity into Gateway tools and supplies synchronous cancellation checks and prepared storage assertions to downstream owners. flowchart TD
A[Request admission] --> B[Agent run]
B --> C[Gateway caller context]
C --> D[Gateway tool operation]
C --> E[Prepared session assertion]
E --> F[Session store]
G[Stop signal] --> C
Technical reviewBest possible solution: Keep the focused owner change, complete its consumer-test cutover, and shrink the obsolete ratchet allowance. Do we have a high-confidence way to reproduce the issue? Current-main source directly rechecks receipt, operator, selected-user, and Cron authority on synchronous assertions after admission; no target code was executed during this review. Is this the best way to solve the issue? Removing those repeated checks at their shared adapter is the smallest coherent repair, and preserving cancellation and prepared storage assertions respects the existing owners. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 450441b90403. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -27, Tests -473. Total -500 across 33 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 22, 2026, 7:46 AM ET / 12:46 UTC. |
…lowlist - Shrink the session-identity allowlist entry for gateway-caller-context.ts to 2. - Delete receipt-revocation cases in sessions-create child custody, dashboard commit and personal USER.md tests. - Match the runtime-neutral abort text "operation was aborted". Co-authored-by: obviyus <[email protected]>
|
Head E2E on
{
"pass": false,
"prefix": "HEAD",
"sessionKey": "agent:main:one-admission-cbd9fac0",
"models": [
null,
"gpt-5.5-2026-04-23"
],
"relayStatuses": [
421,
200
],
"checks": [
{
"id": "R.running-turn-finishes",
"pass": true,
"detail": {
"state": "final",
"toolEnds": 3,
"toolEndsAfterRevoke": 3
}
},
{
"id": "Q.queued-input-refused-visibly",
"pass": false,
"detail": {
"accepted": true,
"providerRequestsWithQueuedMarker": 1,
"visibleRefusalInTranscript": false
}
},
{
"id": "S.stop-cancels",
"pass": true,
"detail": {
"abort": {
"ok": true,
"aborted": true,
"runIds": [
"acd19625-6e09-40b0-9d3d-b3e415784070"
]
},
"state": "aborted",
"requestsWithStopMarker": 1
}
}
],
"elapsedMs": 63260
}
|
|
Maintainer override: one red job on head
|
|
Landed as adb2f7c.
|
…registry (#203516) ## What Problem This Solves #203487 made `captureGatewayToolCallerAssertion` stop re-checking permission in the middle of a started tool call; it now only checks Stop and carries the caller receipt's session fences. The `sessions_*` tools and the subagent registry still captured it and called it again at each step. Those calls are dead weight. Some of them also used "the capture returned a function" to mean "this is an admitted agent run". ## Why This Change Was Made Admission checks permission one time, when work starts. This PR removes the leftover capture from the session tools and the subagent registry: - `sessions-list-tool.ts`: the capture and its call in `finalize`; the tool signal check stays. - `sessions-tool.ts` (`assign_owner`), `sessions-tool-control.ts` (`captureSessionStopCaller`, `stopSessionTool`): the admitted-run gate reads `caller.operationalRunInstance`, which is the condition the capture tested. The tool signal check stays at each step. - `sessions-operator-authority.ts`: the `sessions.patch` capture is removed from the composed control source. - `sessions-send-communication.ts`: the capture is removed from `assertSource`, which already checks the tool call's `signal` and closes on abort. The approval gate reads `caller.operationalRunInstance`. - `sessions-send-tool.delivery.ts`, `sessions-send-tool.steering.ts`: the steering guard still uses the guarded (V2) injection for an admitted run. Stop reaches it through `assertSendCurrent` (the communication assertion, which is signal-bound). - `sessions-send-followup.ts`, `sessions-send-followup-custody.ts`: the follow-up checks are the prepared custody (`request.custody.assertCurrent`) only. - `sessions-send-resume.ts`, `gateway/session-subagent-resume.ts`: a live admitted caller has no `assertCurrent`. A host-retained replay keeps its retained source assertion. `requirePausedChild` runs `caller.assertCurrent?.()`; admission is decided once in `captureSessionsSendResumeCaller` (the only producer of this caller). - `subagent-registry-public-api.ts`, `subagent-registry-requester-claim.ts`: the registry writes keep the state-worker source check and the continuation custody. Session write fences are not dropped. Every sessions tool write goes through the in-process Gateway caller (`in-process-gateway.ts`, PR 1d), which still composes the caller's receipt into `sessionMutationCommitGuard`. The removed captures were all sync closures (Stop only) or duplicated that composed fence. No new export, name, hook, flag or guard. Production: 13 files, +43 / −108. Accepted edge cases (no code for them): - `acknowledgeSubagentResultForRequesterTurn` and `claimSubagentYield` no longer check Stop before their registry write. These are internal bookkeeping writes for a result the run already has (mark delivered, record the yield), not user-visible effects. - `prepareSessionsSendFollowup` no longer checks the tool Stop during its preparation reads. The dispatch that follows stays signal-fenced through the communication assertion. ### Changed tests - `sessions-tool.self-archive.test.ts`, `agent-tools.session-owner.test.ts`: `sessions.assignOwner` no longer carries `assertDispatchCurrent`. - `sessions-send-communication.test.ts`: the mocked caller now has an `operationalRunInstance` (that is what "admitted" means now); the removed capture mock is gone. No test asserted a mid-run refusal through these callers, so no test was deleted. ## User Impact None visible. An admitted session tool call runs to the end; Stop still cancels it; writes to a replaced or locked session still fail with the session conflict. ## Evidence - Pre-push: one `ocx test` run with fail-fast off over 41 files (every direct importer of a changed source, plus importers of the test-support files that import them). After the test fixes, everything is green except: - `agent.test.ts` ("honors owner cancellation while explicit recipient session routing is pending", "does not deliver prepared identity after the client loses authority") and `question.communication.test.ts` ("retains creator/admin rights without treating assigned responsibility as authority"): also red on the merge base `6ff7a062e54e`. - `server.plugin-reload-send-revocation.product.test.ts`: it expects "Operator access was revoked; start a new user turn.", which no production code emits since #202513. On head the revoked replay is still refused with 0 effects; the notice says "Restart recovery operator authority changed; start a new user turn.". On the base it timed out under host load. - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. - Head E2E: Q, R and S pass (#203516 (comment)). Local review on the final head: patch correct, zero findings. Co-authored-by: Ayaan Zaidi <[email protected]>
## What Problem This Solves #203487 made `captureGatewayToolCallerAssertion` stop re-checking permission in the middle of a started tool call. Its Gateway-side callers still captured it and called it again at every step. That is dead weight: after #203487 the call only checks Stop, and most of these callers already check Stop through their own request signal or commit guard. ## Why This Change Was Made Admission checks permission one time, when work starts. This PR removes the leftover capture from the Gateway-side callers, so the per-step re-check path is gone there. Removed (capture and its calls): - `server-methods/themes.ts`, `tools-github.ts`, `users-personal-file.ts`, `environments.session.ts`, `request-authorization.ts` (startup exemption for admitted runs); - `session-access-authority.ts`, `session-runtime-authority.ts`; - `server-plugin-in-process-dispatch.ts` (`runWithInProcessGatewaySessionMutation`); - `server-plugin-in-process-authority.ts` (continuation capture); - `github-publication-auto-fix.ts`; - `plugins/service-session-work.ts`. Where a caller used "capture returned a function" only to mean "this is an admitted agent run", it now reads `caller.operationalRunInstance`, which is the same condition the capture tested. `resolveSessionRuntimeAuthority` now returns nothing when no runtime identity exists (the caller-only branch was a Stop check only). Stop still applies at every changed site: - In-process Gateway methods (themes, GitHub read, personal file, environments, auto-fix, session mutation) still call `sessionMutationCommitGuard` / `resolved.assertContextCurrent`, which keeps the caller's Stop and receipt fence (see below). - `tools-github` and `environments.session` already combine `caller.approvalSignals` into their signal. - Service session work keeps Stop through `captureAmbientGatewayOperatorAuthority().assertInvocationCurrent`. - The continuation capture now checks `caller.approvalSignals` directly at the same point. Kept on purpose (cut less): two sites carry the capture's receipt fence into session commit guards, so they keep it until PR 6 removes the lease at `captureAdmittedRunActiveAssertion`: - `resolveInProcessGatewayDispatch().assertContextCurrent` (`server-plugin-in-process-authority.ts`); - `captureOperatorToolGatewayAuthority` / `captureAmbientGatewayOperatorAuthority` (`operator-invocation-authority.ts`, left unchanged). The receipt fences the writing run (lease held, same run instance), which the session owner's `sessionMutationAuthorization` does not cover; an abort signal cannot replace it. No new export, name, hook, flag or guard. ## User Impact None visible. A tool call that was admitted keeps running to the end; Stop still cancels it; writes to a replaced or locked session still fail with the session conflict. Gateway methods during startup still accept admitted agent runs. ## Evidence - Pre-push: one `ocx test` run with fail-fast off over 113 files (the touched sources' own tests, every direct importer of a changed file, importers of the 12 touched `*.test-support.ts` dependencies, and every test that names `captureGatewayToolCallerAssertion`): 112 files green. `server.private-completion.test.ts` timed out one case under host load (22.9 s wait) and cascaded into its sibling case; alone it passes 27/27. - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. - No test asserted a refusal through these callers, so no test was deleted. - Production: 11 files, +43 / −91. `config/session-identity-allowlist.txt`: `request-authorization.ts` 7 → 6 (the removed refusal string was a counted pin). - Real Gateway E2E (one-admission journey) on the final head `f3c8465e7234`: Q (revoke while queued → refused visibly), R (revoke while running → finishes), S (Stop → cancels) all pass: #203503 (comment) - Local review on the final head: patch correct, zero findings. - CI: every red job is MAIN-ALSO, with per-test base evidence in #203503 (comment) (#203512, #203527). Co-authored-by: Ayaan Zaidi <[email protected]>
## What Problem This Solves Fixes #203512. Since #203487, Stop does not cancel an MCP loopback tool call from a CLI-backed turn (Claude CLI and other CLI runtimes). If the user stops the turn while a message action waits on a channel lookup, the action still finishes: `test/cli-message-authority.integration.test.ts > stops the reaction lookup after abort retirement` gets `isError: false`. ## Why The MCP loopback server rebuilds the tool caller from the CLI grant (`src/gateway/mcp-http.ts`). That caller had no `approvalSignals`. The turn's abort signal reached the tool only through the receipt boolean `isGrantAndLineageCurrent` → `isMcpLoopbackClientGrantCurrent`. That boolean also checks the grant row, the admitted run's delegated authority and the capture, so it mixes run lifecycle with permission. #203487 removed the synchronous receipt boolean from `captureGatewayToolCallerAssertion` as an authority re-check. Stop was lost with it. ## Fix - `resolveMcpLoopbackClientGrant` now returns the grant's existing `abortSignal`, which is the CLI turn's abort signal. The MCP caller passes it as `approvalSignals`, the lifecycle channel that `captureGatewayToolCallerAssertion` already checks. The permission part of the receipt stays out of the synchronous check, as #203487 intended. - Removed: the MCP `cronAuthorityCheck` pass-through (grant field, mint copy, resolved field, caller field) and `bindActiveCronAuthorityCurrentness`. #203487 removed the only reader of the identity `cronAuthorityCheck`, so this chain had no reader left. - No new export, name, flag or guard. Production: +3 / −17. ## Sweep of #203487, #203503 and #203516 - I traced every production caller that sets `receiptAuthority` (`agent-tools.caller`, embedded `attempt-gateway-tools`, `settled-turn-finalization`, harness `tool-authority.runtime`, `plugin-native-subagent`, `scheduled-owner-tool-guard`, `cron-tool`, `node-claude-skill-runtime`, worker `placement-turn-claim-events` and `worker-turn-tool-surface`, plugin `hooks`). Each one still delivers Stop through `approvalSignals` or through the tool's own execute signal. The MCP loopback was the only caller where the receipt carried Stop alone. - The 1b and 1c call sites run inside in-process Gateway dispatch. That dispatch still runs the caller assertion (`in-process-gateway.ts`, `server-plugin-in-process-authority.ts`), or the tool's own signal covers them. No other instance was found, so this PR has one fix and one test. ## User Impact When you stop a CLI-backed turn, a running message action is cancelled before its write. The tool result reads "The message turn has ended. Start a new turn to retry." A permission change in the middle of a call still does not interrupt a started call (#203487). ## Tests - `test/cli-message-authority.integration.test.ts` "stops the reaction lookup after abort retirement": red on main (`isError: false`). Green on head, with no PATCH or PUT after Stop. The expected text is now the message route's "message turn has ended". Before #203487 the text was the generic "authority is no longer active", which #203487 removed. - `test/cron-message-read.integration.test.ts` (claude-cli, disabled before 429): Stop now reaches the tool, so the result text is the message route's "message turn has ended". The regex now accepts it. The single PATCH and the absent retry are unchanged. - `cron-creator-authority-context.test.ts`: the two lines that read the deleted helper are removed. The revocation assertion on the creator stays. ## Evidence - Pre-push: one `ocx test` run with fail-fast off over the touched tests and every test importing a changed file (60 files). Green except `mcp-http.async-scope` "keeps each CLI grant's own ceiling" and `cron.scheduled-policy-adoption.integration` ×3, both red on main before this PR (see #203503 override), plus `cron-message-read` (updated above, then green 9/9). - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. - Real Gateway E2E on the final head `7e1c3b07ffde`: R, Q and S (Stop → cancels) pass (#203551 (comment); first head: #issuecomment-7081968622). - Local review on the final head `7e1c3b07ffde`: patch correct, zero findings. - Session-identity allowlist: `cron-creator-authority-context.ts` shrinks from 41 to 39. Co-authored-by: Ayaan Zaidi <[email protected]>
…203561) ## What Problem This Solves #203487 made `captureGatewayToolCallerAssertion` stop re-checking permission in the middle of a started tool call. Its synchronous call now only checks Stop (`approvalSignals`); its prepared form carries the caller receipt's session fences. Agent-side callers still captured it just to call it synchronously, and some used "the capture returned a function" to mean "this is an admitted agent run". ## Why This Change Was Made Admission checks permission one time, when work starts. This PR removes the capture where it was only a synchronous Stop check: - `agent-tools.before-tool-call.approval.ts`, `bash-tools.exec-approval-request.ts`, `harness/gateway-question.ts`, `tools/agents-wait-tool.ts`: the capture only fed watchdog `isCurrent` callbacks. They keep their tool/request signal check where they had one. Exec approval has no signal in scope; its watchdog wait ends with the run's attempt, and the approval wait ends with `run-aborted`. - `openclaw-plugin-tools.ts` (node MCP elicitation): the gate is `caller.operationalRunInstance`; Stop is the same signal the elicitation registers with (tool signal + caller `approvalSignals`). - `tools/computer-tool-bindings.ts`: the gate is the existing `operationalRunInstance` check; Stop is `params.signal` / `request.signal`. - `tools/personal-instructions-tool.ts`, `tools/presence-tool-authority.ts`: the gate reads `caller.operationalRunInstance`; personal instructions checks the tool signal. **Kept on purpose (cut less):** where the capture is composed into a session source assertion or passed whole as one, it still carries the receipt's prepared session fence to the write. The brief says that fence must not be dropped, so these stay unchanged: - `tools/in-process-gateway.ts`: composes it into `sessionMutationCommitGuard` for every in-process Gateway write (#203516). - `tools/message-tool-execution.ts` / `message-tool-turn-authority.ts`, `tools/media-generate-background-shared.ts`, `tools/agent-step.ts`, and plugin tool `assertInvocationCurrent` in `openclaw-plugin-tools.ts`. Replacing the capture with `captureGatewayToolReceiptAssertion` would bring back the "agent tool caller authority is no longer active" refusal on the synchronous path, and copying the 1a body would make a second implementation (Fable 5.2 consult: keep the carrier). PR 1e, when it deletes the declaration, must move the body to the remaining fence carriers as one implementation. No new export, name, hook, flag or guard. Production: 8 files, +30 / −69. Accepted edge case (no code for it): exec approval's watchdog `isCurrent` no longer checks Stop itself (no signal in scope); Stop still ends the run's watchdog attempt and the approval wait. ### Changed tests None. No test asserted a mid-run refusal through the removed calls. ## User Impact None visible. A started agent tool call runs to the end; Stop still cancels it; writes to a replaced or locked session still fail with the session conflict. ## Evidence - Pre-push: one `ocx test` run, fail-fast off, over 146 files (direct importers of every changed source, importers of test-support files that import them, and every test that names `captureGatewayToolCallerAssertion`), then the repaired and re-touched set (37 files) again on the final tree. Green except: - `slack-download-read-authority.integration.test.ts` "rejects revoked output ... after result (revoke: claim)": also red on the merge base `cc7b482f887b` (run there with `ocx test`); not this PR. - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. `check:lifetime-check-ratchet`: OK, no growth. `check:changed` SQLite worker ratchet OOMs locally on its 4 GB heap (known, whole-repo scan); CI covers it. Co-authored-by: Ayaan Zaidi <[email protected]>
…body (#203664) ## Problem R1 of the one-admission receipt cluster: remove the authority reads from the receipt bodies (`captureGatewayToolReceiptAssertion`, `composeReceiptAuthority`, `captureAdmittedRunActiveAssertion`, `captureAgentRunDelegatedSourceAssertion`). Admission already checks authority once. This PR lands the part of R1 that holds up. Step 0 below shows why the rest cannot be cut inside these bodies yet. ## Change - `captureAdmittedRunActiveAssertion`: removed `scopeOperatorAccessDecisions` (operator access-decision sharing) and the authority-lease identity compares (`lease.authority !== authority`, `delegatedAuthorityLeases.get(context) !== lease`). Each production caller passes the lease's root authority, and the run instance plus the registry claim already cover replacement. Kept: Stop (`signal.aborted`), run occurrence, `foregroundClosed` (run close does not abort the caller's optional `signal`) and the registry source. - Removed the reader-less `cronAuthorityCheck` field from the Gateway tool caller identity and its one producer. #203487 removed its only reader. Production: 3 files, +4/−16. No test changes. No new export, name, hook, flag or guard. ## Step 0: leaf reads and how each is classified Test: can the answer change when only a permission, approval or config changes and no session data changes? Yes → authority. No → data fence or Stop. | Body | Leaf read | Classification | Result | |---|---|---|---| | `captureAdmittedRunActiveAssertion` | `scopeOperatorAccessDecisions` | Authority (shares operator access decisions) | **Removed** | | same | `lease.authority !== authority`, `delegatedAuthorityLeases.get(context) !== lease` | Authority-lease identity, not a writer lease | **Removed** | | same | `signal?.aborted` | Stop | Kept | | same | `context.operationalRunInstance !== operationalRunInstance` | Run occurrence | Kept | | same | `lease.foregroundClosed` | Lifecycle. Run close does not abort the caller's optional `signal` | Kept | | same | `readAgentRunDelegatedAuthorityFailure` | Diagnostic `cause` only | Kept | | `captureAgentRunDelegatedSourceAssertion` | `context.assertSourceCurrent` (registry run source) | **Mixed:** the caller's run source (data fences, for example `session-fork-run.ts` transcript write token and entry lifecycle) composed with `operatorAuthority.assertCurrent` | Kept. Removing it turned `admitted-run-context.test.ts` red (stale transcript writes) | | same | `current !== context`, `current.assertSourceCurrent !== source`, `readActiveAgentRunDelegatedAuthority` claim/instance/generation | Run occurrence and generation | Kept | | same | `isCurrentAgentRunApprovalAuthority` (approval leases) | Run occurrence plus approval-lease abort signals (Stop for one tool call) | Kept | | `composeReceiptAuthority` | `check()` loop over predicate booleans | **Mixed:** bare predicate booleans carry authority *and* occurrence fences (MCP grant lineage `isGrantAndLineageCurrent`, node claim loss and disconnect, cron invocation close, caller-turn retirement) | Kept. Removing the boolean turned `mcp-http.test.ts` "fences caller authority when the grant is replaced during tool execution" and `node-claude-skill-runtime.test.ts` "rejects publication after awaited file work when claim-loss / disconnect wins" red | | `captureGatewayToolReceiptAssertion` | `receipt()` boolean + `assertAllowed` on the callable and prepared `assertCurrent` | Same mix; the prepared path is the one that refuses a bare-boolean fence at commit | Kept (same evidence) | | same | `nativeSource`, `opaqueCommitGuard`, `prepareSessionSource*`, `release`, `assertScopeCurrent` | Session data and writer custody | Kept | | `prepareAgentRunAdmission` | `prepared.assertCurrent()` | Preparation lifecycle, Stop, run occurrence and generation | Kept | ## What remains (proposed split) The receipt boolean and the registry run source cannot be cut inside their bodies, because each mixes authority with real data fences. 1. **Registry run source:** `prepareAgentRunAdmission` binds `compose([callerSource, operatorAuthority.assertCurrent])` into the registry. Bind only the caller's source. Then `captureAgentRunDelegatedSourceAssertion` (and `validateAgentRunDelegatedAuthority`) keep the data fences and lose the operator re-check. 2. **Receipt boolean:** convert the boolean receipt leaves that carry occurrence fences into throwing fences or signals at their producers: `mcp-http.ts` `isGrantAndLineageCurrent`, the cron automation invocation receipt, `settleBatch.isCurrent`, the node skill-runtime claim. Then `composeReceiptAuthority` can become `composeSessionSourceAssertion` and `captureGatewayToolReceiptAssertion` a pass-through (R2). ## What users see Nothing changes. Refusals, Stop and fences behave as on `main`. ## Evidence Exact head `aaec361a54e1`: - **Local ClawSweeper review:** `review_status: complete`, "patch is correct", 0 findings (report `aaec361a54e1.md`). - **One-admission E2E** (isolated Gateway, real model, exact head): `pass: true`. `results.jsonl` (50 KB transcript) is kept with the task proof. `verdict.json`: ```json {"pass":true,"checks":[{"id":"R.running-turn-finishes","pass":true,"detail":{"state":"final","toolEnds":3,"toolEndsAfterRevoke":3}},{"id":"Q.queued-input-refused-visibly","pass":true,"detail":{"accepted":true,"providerRequestsWithQueuedMarker":0,"visibleRefusalInTranscript":true}},{"id":"S.stop-cancels","pass":true,"detail":{"abort":{"ok":true,"aborted":true},"state":"aborted","requestsWithStopMarker":1}}]} ``` - **Typecheck / lint / ratchets:** `pnpm tsgo:core` clean. `pnpm tsgo:test` clean on the first revision; re-run on this head pending CI. oxfmt and oxlint clean on the 3 files. The session-identity, lifetime-check, SQLite dialect, test-timeout-race and mock-export ratchets are OK. Locally, `pnpm check:changed` crashed in the SQLite worker ratchet with an abort, exit 134 (known local heap limit, see #203466). CI covers it. - **Importer run:** one `ocx test` call on 441 test files (each one imports `gateway-caller-context.ts`, `admitted-run-context.ts` or `attempt-gateway-tools.ts`, plus the files that name the receipt symbols or messages), with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1`. 11 files went red: - Also red on the merge base `8866e18656c5` (separate run): `mcp-http.async-scope`, `github-publication-imported-actions` (3 "requester" cases), `question.communication`, `question.recovery` ("current client") and `settled-turn-finalization.incomplete`. `cron.scheduled-policy-adoption` ("No model is configured", MAIN-ALSO in earlier program PRs) was not re-run on base here. - Red only inside the full 441-file run (load average 44-63), green when run on their own on this head with `--no-memo`: `isolated-completion`, `cron-tool.stream-exec-policy.e2e` (the Gateway entrypoint prep failed with an update-publication refusal), `bash-tools.exec-background-followup`, `subagent-registry-lifecycle`. One standalone run of `subagent-registry-lifecycle` failed 4 *different* cases, and the next run passed. I read this as load flakiness; I have not proven the cause. - **Earlier revisions (cut too deep, reverted):** removing the registry run source turned `admitted-run-context.test.ts` red. Removing the receipt boolean turned `mcp-http.test.ts` (grant replaced) and `node-claude-skill-runtime.test.ts` (claim-loss and disconnect) red. That evidence is behind the split above. Co-authored-by: Ayaan Zaidi <[email protected]>
…ge (openclaw#203487) ## What Problem This Solves A started agent tool call can fail in the middle with "agent tool caller authority is no longer active" or "Automation caller authority is no longer active". This happens when, during the call, permission is revoked or reloaded, a selected user's source changes, cron permission changes, or the run that started the call releases its claim. The agent loses work it was allowed to start, and the user sees a refusal for a request that was already accepted. ## User Impact User impact: a tool call that started under a valid admission now finishes. A permission change applies to the next request. Stop still cancels the running call. Writes to a replaced or locked session still fail with the session conflict. ## Why This Change Was Made Admission checks permission one time, when work starts (repository rule "Check authority one time, when work starts"). `captureGatewayToolCallerAssertion` checked permission again at every effect. This PR removes these checks from its body: - the operator selection check (`resolveGatewayToolOperatorSelection().assertCurrent`); - `caller.operatorAuthority.assertCurrent`; - the synchronous receipt boolean call (`receiptAuthority()`) and its catch-all rethrow as "agent tool caller authority is no longer active"; - the `cron.*` method check (`cronAuthorityCheck`), "Automation caller authority is no longer active". What stays: - **Stop:** the synchronous call runs `signal.throwIfAborted()` on every `approvalSignals` signal. Production feeds this list with lifecycle signals only: the tool call and run abort signals, the harness capability close, the trigger-script deadline and the scheduled-turn signal. No permission revocation aborts them. A Stop now reports the abort reason, not "authority is no longer active". - **Session-store write fences:** the receipt is still a composed source. `prepareSessionSource*`, `nativeSource` and `opaqueCommitGuard` still reach the session store, so a prepared write still runs the receipt's lease and generation check at commit. The signature does not change, so the 43 production callers compile without edits. No new export, name, hook, flag or guard. Production: one file, +10 / −37. Accepted edge cases (no code for them): - The prepared receipt fence at a session write still reaches the run's source assertion, which today includes the operator source. Later PRs in this series remove that read at its owner (`captureAdmittedRunActiveAssertion`, `AdmittedRunOperatorAuthority.assertCurrent`). - Code that keeps running in a closed run's async context (a retained tool object, a terminal hook) is no longer refused by this function. New requests go through the request owners' own admission; the follow-up caller PRs remove this function from those owners. ### Deleted or changed tests Each deleted case asserted a refusal in the middle of a started call: the receipt or caller flips to inactive, the run claim is released, the operator or selected source is revoked, or the cron capability ends. That behavior is removed on purpose. Cases for Stop, session conflicts, plugin revocation, turn-capability revocation, tool policy and lifecycle generation all stay and pass. - `gateway-caller-context.test.ts`: the selected-source revocation cases, the cron-method case and the synchronous-receipt read. The prepared-receipt revocation case stays. - `local-request-context.session-tools.test.ts`: `sessions.patch` / `patchMany` / `assignOwner` "caller closes during request authorization", visible fork `retired`, and the read after turn completion. - `server.sessions.reset-acp-timeout.test.ts`: the caller-closure cases. The replacement case is kept as a session-conflict check: a replacement generation written during cleanup survives. - `session-attachment-service.test.ts`, `environments.session.test.ts`, `server-instance-runtime.approvals.test.ts` (tool route), `cron-creator-transports.integration.test.ts` (`revoked`), `ops.gateway-mutations.test.ts` (`revoked`), `server-methods.control-plane-rate-limit.test.ts`, `server.mcp-session-owner.test.ts`, `server-cron.context.test-support.ts`, `server-plugin-in-process-dispatch.continuation.test.ts` (`receipt`, `provenance only`), `in-process-gateway.test.ts` (retired caller), `agents-wait-tool.test.ts` (`revoked authority`), `embedded-agent-runner/runs.test.ts` (Stop from a retired caller), `gateway.hosted-routing.test.ts` (`caller`), `message-tool.current-prompt-reaction.test.ts` (`run close`), `message-tool.hosted-transport.test.ts` (calls after run release), `media-generate-background-retention.test.ts` (`invocation`; `cancellation` and `generation` stay), `sessions-list-privacy.test.ts` (`revoked`), `sessions-send-tool.queue-authority.test.ts` (`revoked`, `ask-revoked`, `settle-*`), `tool-factory-context.test.ts` (missing receipt), `workboard-automation-authority.test.ts` (cron.run after close). - Channel read contracts: Mattermost `run` revocation, Slack `tool-run-claim-revoked` / `bundled-tool-run-claim-revoked` / `caller` metadata, Feishu `claim`, Teams `close caller after page 2`. The plugin and turn revocation cases stay. - Message changes only (the refusal still happens): `session-scopes` and `server.sessions-send-resume` now get the Stop abort reason; `message-tool.scheduled-lifetime` gets "message action turn capability is no longer active" from its own owner; `subagent-registry-lifecycle-wake.retry` gets the abort reason; `agent-harness-completion-authority` "delivers an owned child result when its spawning caller is uncaptured" now delivers. ## Evidence - Importer set (342 test files: direct importers of `gateway-caller-context`, every test that names the two strings or mocks the function, and importers of the touched test-support files), one `ocx test` run with fail-fast off, then the repaired files again: green except the items below. - Red on the merge base `8f1fd5f931bd` as well (not this PR): `cron.scheduled-policy-adoption.integration` ("No model is configured"), `server-cron-failure-repair.final-effect`, `service.pr-automation` and `service.pr-automation-feedback`. The Gateway restart e2e files (`gateway-subagent-completion-restart`, `gateway-yield-restart`) fail different cases on head and on base under local load. - Kept and green: Stop cases (`github-pr-workspace-refresh` "Stop during refresh", Teams caller cancel, media `cancellation`, `session-scopes`, `sessions-send-resume`), session-conflict cases (media `generation`, reset replacement, `preserves a concurrent lifecycle replacement`). - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. `check:lifetime-check-ratchet`: OK, no allowance change. - Real Gateway E2E (`one-admission` journey: revoke while running → finishes; Stop → cancels): R (revoke while running → finishes) PASS, S (Stop → cancels) PASS; Q is red on the base too and belongs to the queued-input PR. Verdict and transcript: openclaw#203487 (comment) (final head; first head: #issuecomment-7079137237). Local review on the final head `2c520d990674`: patch correct, zero findings. Co-authored-by: Ayaan Zaidi <[email protected]>
…registry (openclaw#203516) ## What Problem This Solves openclaw#203487 made `captureGatewayToolCallerAssertion` stop re-checking permission in the middle of a started tool call; it now only checks Stop and carries the caller receipt's session fences. The `sessions_*` tools and the subagent registry still captured it and called it again at each step. Those calls are dead weight. Some of them also used "the capture returned a function" to mean "this is an admitted agent run". ## Why This Change Was Made Admission checks permission one time, when work starts. This PR removes the leftover capture from the session tools and the subagent registry: - `sessions-list-tool.ts`: the capture and its call in `finalize`; the tool signal check stays. - `sessions-tool.ts` (`assign_owner`), `sessions-tool-control.ts` (`captureSessionStopCaller`, `stopSessionTool`): the admitted-run gate reads `caller.operationalRunInstance`, which is the condition the capture tested. The tool signal check stays at each step. - `sessions-operator-authority.ts`: the `sessions.patch` capture is removed from the composed control source. - `sessions-send-communication.ts`: the capture is removed from `assertSource`, which already checks the tool call's `signal` and closes on abort. The approval gate reads `caller.operationalRunInstance`. - `sessions-send-tool.delivery.ts`, `sessions-send-tool.steering.ts`: the steering guard still uses the guarded (V2) injection for an admitted run. Stop reaches it through `assertSendCurrent` (the communication assertion, which is signal-bound). - `sessions-send-followup.ts`, `sessions-send-followup-custody.ts`: the follow-up checks are the prepared custody (`request.custody.assertCurrent`) only. - `sessions-send-resume.ts`, `gateway/session-subagent-resume.ts`: a live admitted caller has no `assertCurrent`. A host-retained replay keeps its retained source assertion. `requirePausedChild` runs `caller.assertCurrent?.()`; admission is decided once in `captureSessionsSendResumeCaller` (the only producer of this caller). - `subagent-registry-public-api.ts`, `subagent-registry-requester-claim.ts`: the registry writes keep the state-worker source check and the continuation custody. Session write fences are not dropped. Every sessions tool write goes through the in-process Gateway caller (`in-process-gateway.ts`, PR 1d), which still composes the caller's receipt into `sessionMutationCommitGuard`. The removed captures were all sync closures (Stop only) or duplicated that composed fence. No new export, name, hook, flag or guard. Production: 13 files, +43 / −108. Accepted edge cases (no code for them): - `acknowledgeSubagentResultForRequesterTurn` and `claimSubagentYield` no longer check Stop before their registry write. These are internal bookkeeping writes for a result the run already has (mark delivered, record the yield), not user-visible effects. - `prepareSessionsSendFollowup` no longer checks the tool Stop during its preparation reads. The dispatch that follows stays signal-fenced through the communication assertion. ### Changed tests - `sessions-tool.self-archive.test.ts`, `agent-tools.session-owner.test.ts`: `sessions.assignOwner` no longer carries `assertDispatchCurrent`. - `sessions-send-communication.test.ts`: the mocked caller now has an `operationalRunInstance` (that is what "admitted" means now); the removed capture mock is gone. No test asserted a mid-run refusal through these callers, so no test was deleted. ## User Impact None visible. An admitted session tool call runs to the end; Stop still cancels it; writes to a replaced or locked session still fail with the session conflict. ## Evidence - Pre-push: one `ocx test` run with fail-fast off over 41 files (every direct importer of a changed source, plus importers of the test-support files that import them). After the test fixes, everything is green except: - `agent.test.ts` ("honors owner cancellation while explicit recipient session routing is pending", "does not deliver prepared identity after the client loses authority") and `question.communication.test.ts` ("retains creator/admin rights without treating assigned responsibility as authority"): also red on the merge base `e7aeeb39c145`. - `server.plugin-reload-send-revocation.product.test.ts`: it expects "Operator access was revoked; start a new user turn.", which no production code emits since openclaw#202513. On head the revoked replay is still refused with 0 effects; the notice says "Restart recovery operator authority changed; start a new user turn.". On the base it timed out under host load. - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. - Head E2E: Q, R and S pass (openclaw#203516 (comment)). Local review on the final head: patch correct, zero findings. Co-authored-by: Ayaan Zaidi <[email protected]>
…law#203503) ## What Problem This Solves openclaw#203487 made `captureGatewayToolCallerAssertion` stop re-checking permission in the middle of a started tool call. Its Gateway-side callers still captured it and called it again at every step. That is dead weight: after openclaw#203487 the call only checks Stop, and most of these callers already check Stop through their own request signal or commit guard. ## Why This Change Was Made Admission checks permission one time, when work starts. This PR removes the leftover capture from the Gateway-side callers, so the per-step re-check path is gone there. Removed (capture and its calls): - `server-methods/themes.ts`, `tools-github.ts`, `users-personal-file.ts`, `environments.session.ts`, `request-authorization.ts` (startup exemption for admitted runs); - `session-access-authority.ts`, `session-runtime-authority.ts`; - `server-plugin-in-process-dispatch.ts` (`runWithInProcessGatewaySessionMutation`); - `server-plugin-in-process-authority.ts` (continuation capture); - `github-publication-auto-fix.ts`; - `plugins/service-session-work.ts`. Where a caller used "capture returned a function" only to mean "this is an admitted agent run", it now reads `caller.operationalRunInstance`, which is the same condition the capture tested. `resolveSessionRuntimeAuthority` now returns nothing when no runtime identity exists (the caller-only branch was a Stop check only). Stop still applies at every changed site: - In-process Gateway methods (themes, GitHub read, personal file, environments, auto-fix, session mutation) still call `sessionMutationCommitGuard` / `resolved.assertContextCurrent`, which keeps the caller's Stop and receipt fence (see below). - `tools-github` and `environments.session` already combine `caller.approvalSignals` into their signal. - Service session work keeps Stop through `captureAmbientGatewayOperatorAuthority().assertInvocationCurrent`. - The continuation capture now checks `caller.approvalSignals` directly at the same point. Kept on purpose (cut less): two sites carry the capture's receipt fence into session commit guards, so they keep it until PR 6 removes the lease at `captureAdmittedRunActiveAssertion`: - `resolveInProcessGatewayDispatch().assertContextCurrent` (`server-plugin-in-process-authority.ts`); - `captureOperatorToolGatewayAuthority` / `captureAmbientGatewayOperatorAuthority` (`operator-invocation-authority.ts`, left unchanged). The receipt fences the writing run (lease held, same run instance), which the session owner's `sessionMutationAuthorization` does not cover; an abort signal cannot replace it. No new export, name, hook, flag or guard. ## User Impact None visible. A tool call that was admitted keeps running to the end; Stop still cancels it; writes to a replaced or locked session still fail with the session conflict. Gateway methods during startup still accept admitted agent runs. ## Evidence - Pre-push: one `ocx test` run with fail-fast off over 113 files (the touched sources' own tests, every direct importer of a changed file, importers of the 12 touched `*.test-support.ts` dependencies, and every test that names `captureGatewayToolCallerAssertion`): 112 files green. `server.private-completion.test.ts` timed out one case under host load (22.9 s wait) and cascaded into its sibling case; alone it passes 27/27. - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. - No test asserted a refusal through these callers, so no test was deleted. - Production: 11 files, +43 / −91. `config/session-identity-allowlist.txt`: `request-authorization.ts` 7 → 6 (the removed refusal string was a counted pin). - Real Gateway E2E (one-admission journey) on the final head `f3c8465e7234`: Q (revoke while queued → refused visibly), R (revoke while running → finishes), S (Stop → cancels) all pass: openclaw#203503 (comment) - Local review on the final head: patch correct, zero findings. - CI: every red job is MAIN-ALSO, with per-test base evidence in openclaw#203503 (comment) (openclaw#203512, openclaw#203527). Co-authored-by: Ayaan Zaidi <[email protected]>
…law#203551) ## What Problem This Solves Fixes openclaw#203512. Since openclaw#203487, Stop does not cancel an MCP loopback tool call from a CLI-backed turn (Claude CLI and other CLI runtimes). If the user stops the turn while a message action waits on a channel lookup, the action still finishes: `test/cli-message-authority.integration.test.ts > stops the reaction lookup after abort retirement` gets `isError: false`. ## Why The MCP loopback server rebuilds the tool caller from the CLI grant (`src/gateway/mcp-http.ts`). That caller had no `approvalSignals`. The turn's abort signal reached the tool only through the receipt boolean `isGrantAndLineageCurrent` → `isMcpLoopbackClientGrantCurrent`. That boolean also checks the grant row, the admitted run's delegated authority and the capture, so it mixes run lifecycle with permission. openclaw#203487 removed the synchronous receipt boolean from `captureGatewayToolCallerAssertion` as an authority re-check. Stop was lost with it. ## Fix - `resolveMcpLoopbackClientGrant` now returns the grant's existing `abortSignal`, which is the CLI turn's abort signal. The MCP caller passes it as `approvalSignals`, the lifecycle channel that `captureGatewayToolCallerAssertion` already checks. The permission part of the receipt stays out of the synchronous check, as openclaw#203487 intended. - Removed: the MCP `cronAuthorityCheck` pass-through (grant field, mint copy, resolved field, caller field) and `bindActiveCronAuthorityCurrentness`. openclaw#203487 removed the only reader of the identity `cronAuthorityCheck`, so this chain had no reader left. - No new export, name, flag or guard. Production: +3 / −17. ## Sweep of openclaw#203487, openclaw#203503 and openclaw#203516 - I traced every production caller that sets `receiptAuthority` (`agent-tools.caller`, embedded `attempt-gateway-tools`, `settled-turn-finalization`, harness `tool-authority.runtime`, `plugin-native-subagent`, `scheduled-owner-tool-guard`, `cron-tool`, `node-claude-skill-runtime`, worker `placement-turn-claim-events` and `worker-turn-tool-surface`, plugin `hooks`). Each one still delivers Stop through `approvalSignals` or through the tool's own execute signal. The MCP loopback was the only caller where the receipt carried Stop alone. - The 1b and 1c call sites run inside in-process Gateway dispatch. That dispatch still runs the caller assertion (`in-process-gateway.ts`, `server-plugin-in-process-authority.ts`), or the tool's own signal covers them. No other instance was found, so this PR has one fix and one test. ## User Impact When you stop a CLI-backed turn, a running message action is cancelled before its write. The tool result reads "The message turn has ended. Start a new turn to retry." A permission change in the middle of a call still does not interrupt a started call (openclaw#203487). ## Tests - `test/cli-message-authority.integration.test.ts` "stops the reaction lookup after abort retirement": red on main (`isError: false`). Green on head, with no PATCH or PUT after Stop. The expected text is now the message route's "message turn has ended". Before openclaw#203487 the text was the generic "authority is no longer active", which openclaw#203487 removed. - `test/cron-message-read.integration.test.ts` (claude-cli, disabled before 429): Stop now reaches the tool, so the result text is the message route's "message turn has ended". The regex now accepts it. The single PATCH and the absent retry are unchanged. - `cron-creator-authority-context.test.ts`: the two lines that read the deleted helper are removed. The revocation assertion on the creator stays. ## Evidence - Pre-push: one `ocx test` run with fail-fast off over the touched tests and every test importing a changed file (60 files). Green except `mcp-http.async-scope` "keeps each CLI grant's own ceiling" and `cron.scheduled-policy-adoption.integration` ×3, both red on main before this PR (see openclaw#203503 override), plus `cron-message-read` (updated above, then green 9/9). - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. - Real Gateway E2E on the final head `7e1c3b07ffde`: R, Q and S (Stop → cancels) pass (openclaw#203551 (comment); first head: #issuecomment-7081968622). - Local review on the final head `7e1c3b07ffde`: patch correct, zero findings. - Session-identity allowlist: `cron-creator-authority-context.ts` shrinks from 41 to 39. Co-authored-by: Ayaan Zaidi <[email protected]>
…penclaw#203561) ## What Problem This Solves openclaw#203487 made `captureGatewayToolCallerAssertion` stop re-checking permission in the middle of a started tool call. Its synchronous call now only checks Stop (`approvalSignals`); its prepared form carries the caller receipt's session fences. Agent-side callers still captured it just to call it synchronously, and some used "the capture returned a function" to mean "this is an admitted agent run". ## Why This Change Was Made Admission checks permission one time, when work starts. This PR removes the capture where it was only a synchronous Stop check: - `agent-tools.before-tool-call.approval.ts`, `bash-tools.exec-approval-request.ts`, `harness/gateway-question.ts`, `tools/agents-wait-tool.ts`: the capture only fed watchdog `isCurrent` callbacks. They keep their tool/request signal check where they had one. Exec approval has no signal in scope; its watchdog wait ends with the run's attempt, and the approval wait ends with `run-aborted`. - `openclaw-plugin-tools.ts` (node MCP elicitation): the gate is `caller.operationalRunInstance`; Stop is the same signal the elicitation registers with (tool signal + caller `approvalSignals`). - `tools/computer-tool-bindings.ts`: the gate is the existing `operationalRunInstance` check; Stop is `params.signal` / `request.signal`. - `tools/personal-instructions-tool.ts`, `tools/presence-tool-authority.ts`: the gate reads `caller.operationalRunInstance`; personal instructions checks the tool signal. **Kept on purpose (cut less):** where the capture is composed into a session source assertion or passed whole as one, it still carries the receipt's prepared session fence to the write. The brief says that fence must not be dropped, so these stay unchanged: - `tools/in-process-gateway.ts`: composes it into `sessionMutationCommitGuard` for every in-process Gateway write (openclaw#203516). - `tools/message-tool-execution.ts` / `message-tool-turn-authority.ts`, `tools/media-generate-background-shared.ts`, `tools/agent-step.ts`, and plugin tool `assertInvocationCurrent` in `openclaw-plugin-tools.ts`. Replacing the capture with `captureGatewayToolReceiptAssertion` would bring back the "agent tool caller authority is no longer active" refusal on the synchronous path, and copying the 1a body would make a second implementation (Fable 5.2 consult: keep the carrier). PR 1e, when it deletes the declaration, must move the body to the remaining fence carriers as one implementation. No new export, name, hook, flag or guard. Production: 8 files, +30 / −69. Accepted edge case (no code for it): exec approval's watchdog `isCurrent` no longer checks Stop itself (no signal in scope); Stop still ends the run's watchdog attempt and the approval wait. ### Changed tests None. No test asserted a mid-run refusal through the removed calls. ## User Impact None visible. A started agent tool call runs to the end; Stop still cancels it; writes to a replaced or locked session still fail with the session conflict. ## Evidence - Pre-push: one `ocx test` run, fail-fast off, over 146 files (direct importers of every changed source, importers of test-support files that import them, and every test that names `captureGatewayToolCallerAssertion`), then the repaired and re-touched set (37 files) again on the final tree. Green except: - `slack-download-read-authority.integration.test.ts` "rejects revoked output ... after result (revoke: claim)": also red on the merge base `120fd2984e02` (run there with `ocx test`); not this PR. - `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt and oxlint on the changed files: clean. `check:lifetime-check-ratchet`: OK, no growth. `check:changed` SQLite worker ratchet OOMs locally on its 4 GB heap (known, whole-repo scan); CI covers it. Co-authored-by: Ayaan Zaidi <[email protected]>
…body (openclaw#203664) ## Problem R1 of the one-admission receipt cluster: remove the authority reads from the receipt bodies (`captureGatewayToolReceiptAssertion`, `composeReceiptAuthority`, `captureAdmittedRunActiveAssertion`, `captureAgentRunDelegatedSourceAssertion`). Admission already checks authority once. This PR lands the part of R1 that holds up. Step 0 below shows why the rest cannot be cut inside these bodies yet. ## Change - `captureAdmittedRunActiveAssertion`: removed `scopeOperatorAccessDecisions` (operator access-decision sharing) and the authority-lease identity compares (`lease.authority !== authority`, `delegatedAuthorityLeases.get(context) !== lease`). Each production caller passes the lease's root authority, and the run instance plus the registry claim already cover replacement. Kept: Stop (`signal.aborted`), run occurrence, `foregroundClosed` (run close does not abort the caller's optional `signal`) and the registry source. - Removed the reader-less `cronAuthorityCheck` field from the Gateway tool caller identity and its one producer. openclaw#203487 removed its only reader. Production: 3 files, +4/−16. No test changes. No new export, name, hook, flag or guard. ## Step 0: leaf reads and how each is classified Test: can the answer change when only a permission, approval or config changes and no session data changes? Yes → authority. No → data fence or Stop. | Body | Leaf read | Classification | Result | |---|---|---|---| | `captureAdmittedRunActiveAssertion` | `scopeOperatorAccessDecisions` | Authority (shares operator access decisions) | **Removed** | | same | `lease.authority !== authority`, `delegatedAuthorityLeases.get(context) !== lease` | Authority-lease identity, not a writer lease | **Removed** | | same | `signal?.aborted` | Stop | Kept | | same | `context.operationalRunInstance !== operationalRunInstance` | Run occurrence | Kept | | same | `lease.foregroundClosed` | Lifecycle. Run close does not abort the caller's optional `signal` | Kept | | same | `readAgentRunDelegatedAuthorityFailure` | Diagnostic `cause` only | Kept | | `captureAgentRunDelegatedSourceAssertion` | `context.assertSourceCurrent` (registry run source) | **Mixed:** the caller's run source (data fences, for example `session-fork-run.ts` transcript write token and entry lifecycle) composed with `operatorAuthority.assertCurrent` | Kept. Removing it turned `admitted-run-context.test.ts` red (stale transcript writes) | | same | `current !== context`, `current.assertSourceCurrent !== source`, `readActiveAgentRunDelegatedAuthority` claim/instance/generation | Run occurrence and generation | Kept | | same | `isCurrentAgentRunApprovalAuthority` (approval leases) | Run occurrence plus approval-lease abort signals (Stop for one tool call) | Kept | | `composeReceiptAuthority` | `check()` loop over predicate booleans | **Mixed:** bare predicate booleans carry authority *and* occurrence fences (MCP grant lineage `isGrantAndLineageCurrent`, node claim loss and disconnect, cron invocation close, caller-turn retirement) | Kept. Removing the boolean turned `mcp-http.test.ts` "fences caller authority when the grant is replaced during tool execution" and `node-claude-skill-runtime.test.ts` "rejects publication after awaited file work when claim-loss / disconnect wins" red | | `captureGatewayToolReceiptAssertion` | `receipt()` boolean + `assertAllowed` on the callable and prepared `assertCurrent` | Same mix; the prepared path is the one that refuses a bare-boolean fence at commit | Kept (same evidence) | | same | `nativeSource`, `opaqueCommitGuard`, `prepareSessionSource*`, `release`, `assertScopeCurrent` | Session data and writer custody | Kept | | `prepareAgentRunAdmission` | `prepared.assertCurrent()` | Preparation lifecycle, Stop, run occurrence and generation | Kept | ## What remains (proposed split) The receipt boolean and the registry run source cannot be cut inside their bodies, because each mixes authority with real data fences. 1. **Registry run source:** `prepareAgentRunAdmission` binds `compose([callerSource, operatorAuthority.assertCurrent])` into the registry. Bind only the caller's source. Then `captureAgentRunDelegatedSourceAssertion` (and `validateAgentRunDelegatedAuthority`) keep the data fences and lose the operator re-check. 2. **Receipt boolean:** convert the boolean receipt leaves that carry occurrence fences into throwing fences or signals at their producers: `mcp-http.ts` `isGrantAndLineageCurrent`, the cron automation invocation receipt, `settleBatch.isCurrent`, the node skill-runtime claim. Then `composeReceiptAuthority` can become `composeSessionSourceAssertion` and `captureGatewayToolReceiptAssertion` a pass-through (R2). ## What users see Nothing changes. Refusals, Stop and fences behave as on `main`. ## Evidence Exact head `aaec361a54e1`: - **Local ClawSweeper review:** `review_status: complete`, "patch is correct", 0 findings (report `aaec361a54e1.md`). - **One-admission E2E** (isolated Gateway, real model, exact head): `pass: true`. `results.jsonl` (50 KB transcript) is kept with the task proof. `verdict.json`: ```json {"pass":true,"checks":[{"id":"R.running-turn-finishes","pass":true,"detail":{"state":"final","toolEnds":3,"toolEndsAfterRevoke":3}},{"id":"Q.queued-input-refused-visibly","pass":true,"detail":{"accepted":true,"providerRequestsWithQueuedMarker":0,"visibleRefusalInTranscript":true}},{"id":"S.stop-cancels","pass":true,"detail":{"abort":{"ok":true,"aborted":true},"state":"aborted","requestsWithStopMarker":1}}]} ``` - **Typecheck / lint / ratchets:** `pnpm tsgo:core` clean. `pnpm tsgo:test` clean on the first revision; re-run on this head pending CI. oxfmt and oxlint clean on the 3 files. The session-identity, lifetime-check, SQLite dialect, test-timeout-race and mock-export ratchets are OK. Locally, `pnpm check:changed` crashed in the SQLite worker ratchet with an abort, exit 134 (known local heap limit, see openclaw#203466). CI covers it. - **Importer run:** one `ocx test` call on 441 test files (each one imports `gateway-caller-context.ts`, `admitted-run-context.ts` or `attempt-gateway-tools.ts`, plus the files that name the receipt symbols or messages), with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1`. 11 files went red: - Also red on the merge base `b55127a84b40` (separate run): `mcp-http.async-scope`, `github-publication-imported-actions` (3 "requester" cases), `question.communication`, `question.recovery` ("current client") and `settled-turn-finalization.incomplete`. `cron.scheduled-policy-adoption` ("No model is configured", MAIN-ALSO in earlier program PRs) was not re-run on base here. - Red only inside the full 441-file run (load average 44-63), green when run on their own on this head with `--no-memo`: `isolated-completion`, `cron-tool.stream-exec-policy.e2e` (the Gateway entrypoint prep failed with an update-publication refusal), `bash-tools.exec-background-followup`, `subagent-registry-lifecycle`. One standalone run of `subagent-registry-lifecycle` failed 4 *different* cases, and the next run passed. I read this as load flakiness; I have not proven the cause. - **Earlier revisions (cut too deep, reverted):** removing the registry run source turned `admitted-run-context.test.ts` red. Removing the receipt boolean turned `mcp-http.test.ts` (grant replaced) and `node-claude-skill-runtime.test.ts` (claim-loss and disconnect) red. That evidence is behind the split above. Co-authored-by: Ayaan Zaidi <[email protected]>
…op-only tool-caller captures (#203920) ## Problem R3+R4 of the one-admission receipt cluster: delete the last two names in `LIFETIME_CHECK_CALLS`, `captureAdmittedRunActiveAssertion` and `captureGatewayToolCallerAssertion`. After R1, R1b, R1c and R2 (#203664, #203788, #203760, #203892) neither body reads authority. What is left is Stop and session data fences. ## Change **Cut less (Fable 5.2 consult, option C).** This PR deletes `captureAdmittedRunActiveAssertion` and the 2 Stop-only sites of `captureGatewayToolCallerAssertion`. The ratchet keeps one name. - `captureAdmittedRunActiveAssertion` is deleted. Its body (Stop on the run signal, run occurrence, `foregroundClosed`, registry claim and the run's registry session source) moves into `resolveAdmittedRunActiveAssertion`, which already wrapped it and already has ~50 callers. The 4 other callers (`runWithPreparedRunSourceScope`, `prepareAgentRunAdmission`, `bindHarnessHostSourceAuthority`, `createAdmittedGatewayToolCallerIdentity`) call `resolveAdmittedRunActiveAssertion(context)`. Each passed the lease's own root authority, so the result is the same. `bindHarnessHostSourceAuthority` loses its now-unused `delegatedAuthority` parameter. - `captureGatewayToolCallerAssertion`, the 2 Stop-only sites: the plugin tool `assertInvocationCurrent` (`openclaw-plugin-tools.ts`) and `prepareGatewayToolCallerAssertion` now call `throwIfAborted()` on the caller's own `approvalSignals`. Both used only the synchronous call, which was Stop-only. The plugin factory context wraps the check in a closure, so the receipt's prepared properties never reached a write. - `LIFETIME_CHECK_CALLS` now holds only `captureGatewayToolCallerAssertion`. Production: 6 files, +24/−44. No new export, `capture*` name, hook, flag, guard, timer or state. Behavior is unchanged. ## What is left, and why it was not cut here I removed `captureAdmittedRunActiveAssertion` and 2 of the 9 tool-caller calls. The other 7 calls (6 files) still need the "prepared-only receipt" shape. I did not patch them. These sites compose the capture as a session source: the in-process Gateway dispatch and commit guard (`in-process-gateway.ts` ×2), media launch admission (`media-generate-background-shared.ts`), `agent-step.ts`, `operator-invocation-authority.ts`, `server-plugin-in-process-authority.ts` and the message tool (`message-tool-execution.ts`). The capture's synchronous call is Stop-only, and its prepared session-source properties carry the receipt's data fences. Detached work calls the synchronous check after the run closed. For example, media background `run` calls `assertAdmissionCurrent()` before the provider call. - Passing `caller.receiptAuthority` directly would also run the receipt's fences (including `foregroundClosed`) on those synchronous calls. Background media and other detached work would then be refused after the run closes, which is lost work. It would also reverse the edge case accepted in #203487. - Copying the "sync no-op, prepared = receipt" idiom into 7 producers removes the name, not the concept. **Proposed follow-up:** move "prepared-only source" into the `composeSessionSourceAssertion` owner as a relocation of the existing shape, then delete the last name and empty the list. If that needs a new flag or parameter on the composer, that cut is wrong too. ## What users see Nothing changes. Stop still cancels, and stale-writer, generation and run-occurrence refusals are unchanged. ## Evidence - **Stop proof on both changed tool-caller paths (new tests):** `openclaw-plugin-tools.stop.test.ts`: a plugin tool's `assertInvocationCurrent` passes, then throws the Stop reason after the run signal aborts. `gateway-caller-context.test.ts` "lets Stop on the caller refuse a prepared watch admission": same for `prepareGatewayToolCallerAssertion`. The admitted-run path keeps `signal?.aborted` → refuse unchanged. - **Tests (pre-push):** the importer set is 554 files, over the 150 cap, so CI runs it. Locally, one `ocx test` call with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 67 files: every test that names `resolveAdmittedRunActiveAssertion`, `runWithPreparedRunSourceScope`, `bindHarnessHostSourceAuthority` or the refusal string, plus the admitted-run, harness host, plugin-tools, gateway-caller-context, sessions-send-followup and ratchet tests. All green, including stale-writer, generation and occurrence tests (unedited). - **Typecheck / lint / ratchet:** `pnpm tsgo:core`, `pnpm tsgo:test` clean; oxfmt and oxlint clean on changed files; lifetime-check ratchet OK. - **One-admission E2E** on exact head `1b9812f6114c`: `pass: true`, R/Q/S all pass (#203920 (comment)). - **Local ClawSweeper review** on `1b9812f6114c`: complete, patch is correct, 0 findings. Co-authored-by: Ayaan Zaidi <[email protected]>
…op-only tool-caller captures (openclaw#203920) ## Problem R3+R4 of the one-admission receipt cluster: delete the last two names in `LIFETIME_CHECK_CALLS`, `captureAdmittedRunActiveAssertion` and `captureGatewayToolCallerAssertion`. After R1, R1b, R1c and R2 (openclaw#203664, openclaw#203788, openclaw#203760, openclaw#203892) neither body reads authority. What is left is Stop and session data fences. ## Change **Cut less (Fable 5.2 consult, option C).** This PR deletes `captureAdmittedRunActiveAssertion` and the 2 Stop-only sites of `captureGatewayToolCallerAssertion`. The ratchet keeps one name. - `captureAdmittedRunActiveAssertion` is deleted. Its body (Stop on the run signal, run occurrence, `foregroundClosed`, registry claim and the run's registry session source) moves into `resolveAdmittedRunActiveAssertion`, which already wrapped it and already has ~50 callers. The 4 other callers (`runWithPreparedRunSourceScope`, `prepareAgentRunAdmission`, `bindHarnessHostSourceAuthority`, `createAdmittedGatewayToolCallerIdentity`) call `resolveAdmittedRunActiveAssertion(context)`. Each passed the lease's own root authority, so the result is the same. `bindHarnessHostSourceAuthority` loses its now-unused `delegatedAuthority` parameter. - `captureGatewayToolCallerAssertion`, the 2 Stop-only sites: the plugin tool `assertInvocationCurrent` (`openclaw-plugin-tools.ts`) and `prepareGatewayToolCallerAssertion` now call `throwIfAborted()` on the caller's own `approvalSignals`. Both used only the synchronous call, which was Stop-only. The plugin factory context wraps the check in a closure, so the receipt's prepared properties never reached a write. - `LIFETIME_CHECK_CALLS` now holds only `captureGatewayToolCallerAssertion`. Production: 6 files, +24/−44. No new export, `capture*` name, hook, flag, guard, timer or state. Behavior is unchanged. ## What is left, and why it was not cut here I removed `captureAdmittedRunActiveAssertion` and 2 of the 9 tool-caller calls. The other 7 calls (6 files) still need the "prepared-only receipt" shape. I did not patch them. These sites compose the capture as a session source: the in-process Gateway dispatch and commit guard (`in-process-gateway.ts` ×2), media launch admission (`media-generate-background-shared.ts`), `agent-step.ts`, `operator-invocation-authority.ts`, `server-plugin-in-process-authority.ts` and the message tool (`message-tool-execution.ts`). The capture's synchronous call is Stop-only, and its prepared session-source properties carry the receipt's data fences. Detached work calls the synchronous check after the run closed. For example, media background `run` calls `assertAdmissionCurrent()` before the provider call. - Passing `caller.receiptAuthority` directly would also run the receipt's fences (including `foregroundClosed`) on those synchronous calls. Background media and other detached work would then be refused after the run closes, which is lost work. It would also reverse the edge case accepted in openclaw#203487. - Copying the "sync no-op, prepared = receipt" idiom into 7 producers removes the name, not the concept. **Proposed follow-up:** move "prepared-only source" into the `composeSessionSourceAssertion` owner as a relocation of the existing shape, then delete the last name and empty the list. If that needs a new flag or parameter on the composer, that cut is wrong too. ## What users see Nothing changes. Stop still cancels, and stale-writer, generation and run-occurrence refusals are unchanged. ## Evidence - **Stop proof on both changed tool-caller paths (new tests):** `openclaw-plugin-tools.stop.test.ts`: a plugin tool's `assertInvocationCurrent` passes, then throws the Stop reason after the run signal aborts. `gateway-caller-context.test.ts` "lets Stop on the caller refuse a prepared watch admission": same for `prepareGatewayToolCallerAssertion`. The admitted-run path keeps `signal?.aborted` → refuse unchanged. - **Tests (pre-push):** the importer set is 554 files, over the 150 cap, so CI runs it. Locally, one `ocx test` call with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 67 files: every test that names `resolveAdmittedRunActiveAssertion`, `runWithPreparedRunSourceScope`, `bindHarnessHostSourceAuthority` or the refusal string, plus the admitted-run, harness host, plugin-tools, gateway-caller-context, sessions-send-followup and ratchet tests. All green, including stale-writer, generation and occurrence tests (unedited). - **Typecheck / lint / ratchet:** `pnpm tsgo:core`, `pnpm tsgo:test` clean; oxfmt and oxlint clean on changed files; lifetime-check ratchet OK. - **One-admission E2E** on exact head `1b9812f6114c`: `pass: true`, R/Q/S all pass (openclaw#203920 (comment)). - **Local ClawSweeper review** on `1b9812f6114c`: complete, patch is correct, 0 findings. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
A started agent tool call can fail in the middle with "agent tool caller authority is no longer active" or "Automation caller authority is no longer active". This happens when, during the call, permission is revoked or reloaded, a selected user's source changes, cron permission changes, or the run that started the call releases its claim. The agent loses work it was allowed to start, and the user sees a refusal for a request that was already accepted.
User Impact
User impact: a tool call that started under a valid admission now finishes. A permission change applies to the next request. Stop still cancels the running call. Writes to a replaced or locked session still fail with the session conflict.
Why This Change Was Made
Admission checks permission one time, when work starts (repository rule "Check authority one time, when work starts").
captureGatewayToolCallerAssertionchecked permission again at every effect. This PR removes these checks from its body:resolveGatewayToolOperatorSelection().assertCurrent);caller.operatorAuthority.assertCurrent;receiptAuthority()) and its catch-all rethrow as "agent tool caller authority is no longer active";cron.*method check (cronAuthorityCheck), "Automation caller authority is no longer active".What stays:
signal.throwIfAborted()on everyapprovalSignalssignal. Production feeds this list with lifecycle signals only: the tool call and run abort signals, the harness capability close, the trigger-script deadline and the scheduled-turn signal. No permission revocation aborts them. A Stop now reports the abort reason, not "authority is no longer active".prepareSessionSource*,nativeSourceandopaqueCommitGuardstill reach the session store, so a prepared write still runs the receipt's lease and generation check at commit.The signature does not change, so the 43 production callers compile without edits. No new export, name, hook, flag or guard. Production: one file, +10 / −37.
Accepted edge cases (no code for them):
captureAdmittedRunActiveAssertion,AdmittedRunOperatorAuthority.assertCurrent).Deleted or changed tests
Each deleted case asserted a refusal in the middle of a started call: the receipt or caller flips to inactive, the run claim is released, the operator or selected source is revoked, or the cron capability ends. That behavior is removed on purpose. Cases for Stop, session conflicts, plugin revocation, turn-capability revocation, tool policy and lifecycle generation all stay and pass.
gateway-caller-context.test.ts: the selected-source revocation cases, the cron-method case and the synchronous-receipt read. The prepared-receipt revocation case stays.local-request-context.session-tools.test.ts:sessions.patch/patchMany/assignOwner"caller closes during request authorization", visible forkretired, and the read after turn completion.server.sessions.reset-acp-timeout.test.ts: the caller-closure cases. The replacement case is kept as a session-conflict check: a replacement generation written during cleanup survives.session-attachment-service.test.ts,environments.session.test.ts,server-instance-runtime.approvals.test.ts(tool route),cron-creator-transports.integration.test.ts(revoked),ops.gateway-mutations.test.ts(revoked),server-methods.control-plane-rate-limit.test.ts,server.mcp-session-owner.test.ts,server-cron.context.test-support.ts,server-plugin-in-process-dispatch.continuation.test.ts(receipt,provenance only),in-process-gateway.test.ts(retired caller),agents-wait-tool.test.ts(revoked authority),embedded-agent-runner/runs.test.ts(Stop from a retired caller),gateway.hosted-routing.test.ts(caller),message-tool.current-prompt-reaction.test.ts(run close),message-tool.hosted-transport.test.ts(calls after run release),media-generate-background-retention.test.ts(invocation;cancellationandgenerationstay),sessions-list-privacy.test.ts(revoked),sessions-send-tool.queue-authority.test.ts(revoked,ask-revoked,settle-*),tool-factory-context.test.ts(missing receipt),workboard-automation-authority.test.ts(cron.run after close).runrevocation, Slacktool-run-claim-revoked/bundled-tool-run-claim-revoked/callermetadata, Feishuclaim, Teamsclose caller after page 2. The plugin and turn revocation cases stay.session-scopesandserver.sessions-send-resumenow get the Stop abort reason;message-tool.scheduled-lifetimegets "message action turn capability is no longer active" from its own owner;subagent-registry-lifecycle-wake.retrygets the abort reason;agent-harness-completion-authority"delivers an owned child result when its spawning caller is uncaptured" now delivers.Evidence
gateway-caller-context, every test that names the two strings or mocks the function, and importers of the touched test-support files), oneocx testrun with fail-fast off, then the repaired files again: green except the items below.c8a643b6259bas well (not this PR):cron.scheduled-policy-adoption.integration("No model is configured"),server-cron-failure-repair.final-effect,service.pr-automationandservice.pr-automation-feedback. The Gateway restart e2e files (gateway-subagent-completion-restart,gateway-yield-restart) fail different cases on head and on base under local load.github-pr-workspace-refresh"Stop during refresh", Teams caller cancel, mediacancellation,session-scopes,sessions-send-resume), session-conflict cases (mediageneration, reset replacement,preserves a concurrent lifecycle replacement).pnpm tsgo:core,pnpm tsgo:test, oxfmt and oxlint on the changed files: clean.check:lifetime-check-ratchet: OK, no allowance change.one-admissionjourney: revoke while running → finishes; Stop → cancels): R (revoke while running → finishes) PASS, S (Stop → cancels) PASS; Q is red on the base too and belongs to the queued-input PR. Verdict and transcript: refactor: let started agent tool calls finish after a permission change #203487 (comment) (final head; first head: #issuecomment-7079137237). Local review on the final head2c520d990674: patch correct, zero findings.