Repository navigation
refactor: drop tool-caller re-checks from session tools and subagent registry - #203516
Conversation
…ubagent registry Admission checks permission once; Stop stays on the tool signal and session fences stay on the in-process Gateway caller. 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. |
|
|
Codex review: needs changes before merge. What this changesThis PR removes redundant caller assertions from session tools and subagent bookkeeping while retaining existing cancellation, custody, and write-fence owners. Example: An admitted parent sends "continue" to paused child agent:main:worker.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: the simplification follows the accepted admission contract, but an edited module mock introduces a concrete CI blocker. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherSession tools translate admitted agent requests into Gateway operations, session-controller steering, and subagent registry updates; existing owners enforce destination access, cancellation, and durable writes. flowchart TD
A[Admitted agent request] --> B[Session tools]
B --> C[Communication admission]
C --> D[In-process Gateway]
C --> E[Session controller]
D --> F[Session storage]
B --> G[Subagent registry]
Technical reviewBest possible solution: Keep the focused assertion removal, preserve real exports in the edited test mock, and prune its obsolete baseline entry. Do we have a high-confidence way to reproduce the issue? The mock-export failure is source-reproducible: removing a factory property changes its exact fingerprint, while the unchanged ledger permits only the old factory; hosted CI independently reports that check failing. Is this the best way to solve the issue? The production change is a small continuation of the accepted admission design, reusing existing Gateway and custody owners without adding machinery; the remaining repair belongs entirely in test setup and its generated baseline. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8d1e59c2fddc. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -65, Tests +1. Total -64 across 16 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 22, 2026, 10:07 AM ET / 15:07 UTC. |
Keep the follow-up test mock factory unchanged for the mock-exports ratchet. Co-authored-by: obviyus <[email protected]>
|
Head E2E (one-admission journey) on
{
"pass": true,
"prefix": "HEAD",
"sessionKey": "agent:main:one-admission-dd74f089",
"models": [
"gpt-5.5-2026-04-23",
null
],
"relayStatuses": [
200,
421
],
"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,
"runIds": [
"4b673922-b4a6-4d27-8c4d-0761c65896b2"
]
},
"state": "aborted",
"requestsWithStopMarker": 1
}
}
],
"elapsedMs": 57631
}
|
|
Maintainer override: the remaining reds on
ci-triage output: |
|
Landed as cc7b482. The session tools and the subagent registry no longer re-check the tool caller mid-call (production −65 lines). Stop still cancels through the tool signal, and session write fences stay on the in-process Gateway caller. Proof: head E2E Q/R/S pass, local review clean, remaining CI reds are main-side (override comment above). |
…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 (openclaw/openclaw#203516 (comment)). Local review on the final head: patch correct, zero findings.
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]>
…anded policy Three more test files fail on main but are not selected by main push CI: - doctor-health.legacy-update: the notification heartbeat-owner variants expected the 10th failure to auto-disable the job and send a safety notice. #203106 (8bdaed5) removed run-failure auto-disable, so Doctor now settles the interrupted run and the job keeps its schedule. - auth-api-key: asserted a mid-request requester-revocation refusal that one-time admission retired (#203516, cc7b482). - server.sessions.create.projects: the repository-child revocation phases asserted the same retired refusal; keep the parent-reassigned data fence.
…ttle-batch receipts (#203892) ## Problem R2 of the one-admission receipt cluster. After #203760 (R1c), two receipt producers still returned a boolean, and the receipt boolean itself (`ReceiptAuthority = () => boolean | void`, the `composeReceiptAuthority` check loop, `assertAllowed` in `captureGatewayToolReceiptAssertion`) still hid permission re-checks from the lifetime-check ratchet: - **MCP loopback grant receipt** (`mcp-http.ts`, `isGrantAndLineageCurrent` as `receiptAuthority`): every effect inside a started tool call re-checked the CLI grant row and the requester lineage. - **Settle-batch receipt** (`agent-tools.caller.ts`, `settleBatch.isCurrent` as `receiptAuthority`): every effect inside a started tool call re-checked the subagent settle batch. Both answer "may this requester still act?" in the middle of a call. R1c showed that turning them into throws is a new mid-request re-check (both ratchets went red), so they are deleted. ## Change - **Deleted** the MCP grant receipt and the settle-batch receipt. The grant row and lineage are still checked once at each tool-call dispatch (`authorizeToolCall`); the settle batch is still checked at handoff admission (`subagent-announce-handoff.ts`). Stop still reaches the call through the grant's `abortSignal` and the run signal. - **Deleted the receipt boolean:** the `ReceiptAuthority` type, the boolean check loop in `composeReceiptAuthority`, `captureGatewayToolReceiptAssertion` (and its lifetime-ratchet entry), and the `approvalAuthorityCheck` field (a duplicate of the receipt). `receiptAuthority` is now a plain `SessionSourceAssertion`: it throws or returns. `composeReceiptAuthority` only de-duplicates sources into `composeSessionSourceAssertion` and keeps its existing `assertScopeCurrent` forwarding. - Readers that compared `receiptAuthority() === false` now call it and let it throw (or catch where the reader already returns `false`): before-tool-call decision receipt, cron tool, sessions access, terminal tool, session event target, node skill runtime, delegated approval, skill authoring, question broker, plugin hooks, cron management/owner bindings, harness host source and embedded tool authority. - The "no delegated run" receipt `() => false` becomes a throw with the same message the boolean path already produced ("agent tool caller authority is no longer active"). Production: 17 files, +55/−173 (plus one session-identity allowlist entry pruned: `cron-tool.ts` lost its "no longer active" refusal string). No new export, name, hook, flag, guard, timer or state. ## Tests - **Deleted (obsolete):** `mcp-http.test.ts` "fences caller authority when the grant is replaced during tool execution". It asserts that a started MCP tool call is refused at its commit after the grant row is replaced mid-call, i.e. the mid-call permission re-check this PR removes. Replacement is still refused at the next dispatch. - About 60 test fixtures returned `false` from `receiptAuthority` to mean "run closed / revoked" (`() => validateAgentRunDelegatedAuthority(a)`, `() => current`, `() => !signal.aborted`, `() => false`). TypeScript accepts `() => boolean` as `() => void`, so these would silently stop refusing. Each now throws on the same condition (or uses `signal.throwIfAborted()`), so every refusal test keeps its meaning. Assertions on the boolean (`receiptAuthority()).toBe(false)`) became `toThrow`. The `hooks.before-tool-call.test.ts` "authority reports stale" row is gone (no boolean to report); both settlements now run with a throwing authority. - `server.visible-spawn-fallback.product-proof.test.ts` no longer passes `currentGrant.isCurrent` as a receipt, matching production `mcp-http.ts`. - Run-instance, claim, disconnect and stale-writer refusal tests keep their assertions. Two only changed the expected wording, because the refusal now comes from the run's own assertion instead of the deleted receipt wrapper: `session-event-handoff.test.ts` "rejects invocation retirement" (`no longer owns its invocation` → `no longer active`) and the retained-receipt check in `tool-authority.runtime.retention.test-support.ts` (`=== false` → throws). ## What users see A tool call already running through a CLI (MCP loopback) or a subagent settle turn finishes when the grant or batch is replaced mid-call. The next call is refused before it starts, as before. Stop still cancels a running call. Error text for a closed run inside some tools (terminal, skill authoring, session events) now comes from the run's own assertion instead of the caller-specific wording. ## Evidence - **Typecheck / lint / ratchets:** `pnpm tsgo:core`, `pnpm tsgo:test` clean on the head; oxfmt and oxlint clean on changed files; lifetime-check ratchet OK, session-identity ratchet OK (after prune). - **Tests (pre-push):** importer set of every changed source and test-support file (816 files) with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1`, run in lanes (the runner aborted once on a vitest resource-claim error after the gateway lanes, so the rest ran in a second call), then a focused rerun of every repaired file and a post-merge rerun after merging `main` for a ratchet-list conflict with #203847. Remaining reds, all not ours: red on the base locally (`dd56cf3d6457` / `49795c31df01`): `slack-download-read-authority` (claim at result), `github-pr-workspace-preparation`, `server.sessions.create.{durability,lifecycle,projects}`, `sessions-create-device-folder`, `provider-destroy-authority`, `service.pr-automation{,-feedback}`, `openclaw-tools.subagents.sessions-spawn.lifecycle`, `mcp-http.personal-authority`; known main reds from #203664/#203590/#203516: `server-cron-failure-repair.final-effect`, `cron.scheduled-policy-adoption`, `github-publication-imported-actions`, `question.communication`/`.recovery`, `mcp-http.async-scope`, `agent.test`, `plugin-reload-send-revocation.product`. - **Local ClawSweeper review** on exact head `eb077c177329`: `review_status: complete`, "patch is correct", 0 findings. - **One-admission E2E** (isolated Gateway, real model, exact head `eb077c177329`, `ocx build --dist`): `pass: true`. `results.jsonl` (28 rows) kept with the task proof. `verdict.json` checks: ```json [{"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}}] ``` 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#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]>
…ttle-batch receipts (openclaw#203892) ## Problem R2 of the one-admission receipt cluster. After openclaw#203760 (R1c), two receipt producers still returned a boolean, and the receipt boolean itself (`ReceiptAuthority = () => boolean | void`, the `composeReceiptAuthority` check loop, `assertAllowed` in `captureGatewayToolReceiptAssertion`) still hid permission re-checks from the lifetime-check ratchet: - **MCP loopback grant receipt** (`mcp-http.ts`, `isGrantAndLineageCurrent` as `receiptAuthority`): every effect inside a started tool call re-checked the CLI grant row and the requester lineage. - **Settle-batch receipt** (`agent-tools.caller.ts`, `settleBatch.isCurrent` as `receiptAuthority`): every effect inside a started tool call re-checked the subagent settle batch. Both answer "may this requester still act?" in the middle of a call. R1c showed that turning them into throws is a new mid-request re-check (both ratchets went red), so they are deleted. ## Change - **Deleted** the MCP grant receipt and the settle-batch receipt. The grant row and lineage are still checked once at each tool-call dispatch (`authorizeToolCall`); the settle batch is still checked at handoff admission (`subagent-announce-handoff.ts`). Stop still reaches the call through the grant's `abortSignal` and the run signal. - **Deleted the receipt boolean:** the `ReceiptAuthority` type, the boolean check loop in `composeReceiptAuthority`, `captureGatewayToolReceiptAssertion` (and its lifetime-ratchet entry), and the `approvalAuthorityCheck` field (a duplicate of the receipt). `receiptAuthority` is now a plain `SessionSourceAssertion`: it throws or returns. `composeReceiptAuthority` only de-duplicates sources into `composeSessionSourceAssertion` and keeps its existing `assertScopeCurrent` forwarding. - Readers that compared `receiptAuthority() === false` now call it and let it throw (or catch where the reader already returns `false`): before-tool-call decision receipt, cron tool, sessions access, terminal tool, session event target, node skill runtime, delegated approval, skill authoring, question broker, plugin hooks, cron management/owner bindings, harness host source and embedded tool authority. - The "no delegated run" receipt `() => false` becomes a throw with the same message the boolean path already produced ("agent tool caller authority is no longer active"). Production: 17 files, +55/−173 (plus one session-identity allowlist entry pruned: `cron-tool.ts` lost its "no longer active" refusal string). No new export, name, hook, flag, guard, timer or state. ## Tests - **Deleted (obsolete):** `mcp-http.test.ts` "fences caller authority when the grant is replaced during tool execution". It asserts that a started MCP tool call is refused at its commit after the grant row is replaced mid-call, i.e. the mid-call permission re-check this PR removes. Replacement is still refused at the next dispatch. - About 60 test fixtures returned `false` from `receiptAuthority` to mean "run closed / revoked" (`() => validateAgentRunDelegatedAuthority(a)`, `() => current`, `() => !signal.aborted`, `() => false`). TypeScript accepts `() => boolean` as `() => void`, so these would silently stop refusing. Each now throws on the same condition (or uses `signal.throwIfAborted()`), so every refusal test keeps its meaning. Assertions on the boolean (`receiptAuthority()).toBe(false)`) became `toThrow`. The `hooks.before-tool-call.test.ts` "authority reports stale" row is gone (no boolean to report); both settlements now run with a throwing authority. - `server.visible-spawn-fallback.product-proof.test.ts` no longer passes `currentGrant.isCurrent` as a receipt, matching production `mcp-http.ts`. - Run-instance, claim, disconnect and stale-writer refusal tests keep their assertions. Two only changed the expected wording, because the refusal now comes from the run's own assertion instead of the deleted receipt wrapper: `session-event-handoff.test.ts` "rejects invocation retirement" (`no longer owns its invocation` → `no longer active`) and the retained-receipt check in `tool-authority.runtime.retention.test-support.ts` (`=== false` → throws). ## What users see A tool call already running through a CLI (MCP loopback) or a subagent settle turn finishes when the grant or batch is replaced mid-call. The next call is refused before it starts, as before. Stop still cancels a running call. Error text for a closed run inside some tools (terminal, skill authoring, session events) now comes from the run's own assertion instead of the caller-specific wording. ## Evidence - **Typecheck / lint / ratchets:** `pnpm tsgo:core`, `pnpm tsgo:test` clean on the head; oxfmt and oxlint clean on changed files; lifetime-check ratchet OK, session-identity ratchet OK (after prune). - **Tests (pre-push):** importer set of every changed source and test-support file (816 files) with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1`, run in lanes (the runner aborted once on a vitest resource-claim error after the gateway lanes, so the rest ran in a second call), then a focused rerun of every repaired file and a post-merge rerun after merging `main` for a ratchet-list conflict with openclaw#203847. Remaining reds, all not ours: red on the base locally (`d6b84a4c90a1` / `2f6261e2a4ec`): `slack-download-read-authority` (claim at result), `github-pr-workspace-preparation`, `server.sessions.create.{durability,lifecycle,projects}`, `sessions-create-device-folder`, `provider-destroy-authority`, `service.pr-automation{,-feedback}`, `openclaw-tools.subagents.sessions-spawn.lifecycle`, `mcp-http.personal-authority`; known main reds from openclaw#203664/openclaw#203590/openclaw#203516: `server-cron-failure-repair.final-effect`, `cron.scheduled-policy-adoption`, `github-publication-imported-actions`, `question.communication`/`.recovery`, `mcp-http.async-scope`, `agent.test`, `plugin-reload-send-revocation.product`. - **Local ClawSweeper review** on exact head `eb077c177329`: `review_status: complete`, "patch is correct", 0 findings. - **One-admission E2E** (isolated Gateway, real model, exact head `eb077c177329`, `ocx build --dist`): `pass: true`. `results.jsonl` (28 rows) kept with the task proof. `verdict.json` checks: ```json [{"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}}] ``` Co-authored-by: Ayaan Zaidi <[email protected]>
…anded policy Three more test files fail on main but are not selected by main push CI: - doctor-health.legacy-update: the notification heartbeat-owner variants expected the 10th failure to auto-disable the job and send a safety notice. #203106 (8bdaed5) removed run-failure auto-disable, so Doctor now settles the interrupted run and the job keeps its schedule. - auth-api-key: asserted a mid-request requester-revocation refusal that one-time admission retired (#203516, cc7b482). - server.sessions.create.projects: the repository-child revocation phases asserted the same retired refusal; keep the parent-reassigned data fence.
Release adaptation: extract the independent mixed-requester repair and its queue regression. Stable already strips display/owner flags but copies requester origin and the private owner capability. The wider saved-requester cutover needs the newer fixed-request and Cron occurrence authorities and the durable queue owner; do not replace the stable custody or restart contract. Companions: #203468 and #203521 are separate selected start-grant repairs. #201334, #201377, #200533 and #202318 are missing full-cutover prerequisites; #203516, #202522 and #202520 are later distinct lifetime refactors, not needed by the isolated mixed-requester repair. (cherry picked from commit 3ad2cce) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a26e1e7b02425b94d31c3e6bc6add8d417dc3fda)
What Problem This Solves
#203487 made
captureGatewayToolCallerAssertionstop re-checking permission in the middle of a started tool call; it now only checks Stop and carries the caller receipt's session fences. Thesessions_*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 infinalize; the tool signal check stays.sessions-tool.ts(assign_owner),sessions-tool-control.ts(captureSessionStopCaller,stopSessionTool): the admitted-run gate readscaller.operationalRunInstance, which is the condition the capture tested. The tool signal check stays at each step.sessions-operator-authority.ts: thesessions.patchcapture is removed from the composed control source.sessions-send-communication.ts: the capture is removed fromassertSource, which already checks the tool call'ssignaland closes on abort. The approval gate readscaller.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 throughassertSendCurrent(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 noassertCurrent. A host-retained replay keeps its retained source assertion.requirePausedChildrunscaller.assertCurrent?.(); admission is decided once incaptureSessionsSendResumeCaller(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 intosessionMutationCommitGuard. 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):
acknowledgeSubagentResultForRequesterTurnandclaimSubagentYieldno 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.prepareSessionsSendFollowupno 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.assignOwnerno longer carriesassertDispatchCurrent.sessions-send-communication.test.ts: the mocked caller now has anoperationalRunInstance(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
ocx testrun 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") andquestion.communication.test.ts("retains creator/admin rights without treating assigned responsibility as authority"): also red on the merge base6ff7a062e54e.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 refactor(gateway): admit saved requesters once when work starts #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.