Repository navigation
refactor(infra): check exec approvals once at commit - #203572
Conversation
Delete the retained current exec-policy read (retainExecApprovalsCurrentRead). A prepared policy read now returns the policy read at preparation, and the post-commit launch guard only observes Stop. The worker commit still checks the current policy once per command. Drop createPluginRuntimeCapabilityLease from LIFETIME_CHECK_CALLS: it fences channel account, plugin service and plugin CLI lifetimes, not operator authority. 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. |
|
|
Rejected review findings:
|
|
Head E2E on verdict.json{
"pass": true,
"prefix": "HEAD",
"sessionKey": "agent:main:one-admission-76c1ff88",
"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": true,
"detail": {
"accepted": true,
"providerRequestsWithQueuedMarker": 0,
"visibleRefusalInTranscript": true
}
},
{
"id": "S.stop-cancels",
"pass": true,
"detail": {
"abort": {
"ok": true,
"aborted": true,
"runIds": [
"86c9d439-bf0e-4423-8312-e9be48661ba7"
]
},
"state": "aborted",
"requestsWithStopMarker": 1
}
}
],
"elapsedMs": 83661
}```
</details>
<details><summary>results.jsonl</summary>
```json
{"t":"2026-11-22T17:32:47.436Z","step":"admin#1.hello","data":{"scopes":["operator.admin","operator.approvals","operator.pairing","operator.read","operator.write"],"role":"operator"}}
{"t":"2026-11-22T17:32:47.628Z","step":"worker#1.hello","data":{"scopes":["operator.read","operator.write"],"role":"operator"}}
{"t":"2026-11-22T17:32:48.237Z","step":"worker.users.self","data":{"method":"users.self","ok":true,"res":{"profile":{"id":"2427e258-8e3b-4e94-acb2-82956726423c","displayName":"worker","avatarMime":null,"mergedInto":null,"createdAt":1795368767622,"updatedAt":1795368767622,"emails":["[email protected]"],"githubIdentity":null,"hasAvatar":false,"gitCoauthorAvailable":false}}}}
{"t":"2026-11-22T17:32:48.278Z","step":"worker#1.close","data":{"code":4001,"reason":"operator role changed"}}
{"t":"2026-11-22T17:32:48.282Z","step":"admin.setRole.worker","data":{"method":"users.setRole","ok":true,"res":{"profile":{"id":"2427e258-8e3b-4e94-acb2-82956726423c","displayName":"worker","avatarMime":null,"mergedInto":null,"role":"worker","createdAt":1795368767622,"updatedAt":1795368768262,"emails":["[email protected]"],"githubIdentity":null,"hasAvatar":false}}}}
{"t":"2026-11-22T17:32:53.461Z","step":"worker#2.hello","data":{"scopes":["operator.read","operator.write"],"role":"operator"}}
{"t":"2026-11-22T17:32:59.046Z","step":"admin.sessions.create","data":{"method":"sessions.create","ok":true,"res":{"ok":true,"key":"agent:main:one-admission-76c1ff88","sessionId":"a750445d-352e-464c-99bd-56eace3b02b2","entry":{"sessionId":"a750445d-352e-464c-99bd-56eace3b02b2","lifecycleRevision":"9a18bf86-e623-413d-89c3-79dc1d36298d","updatedAt":1795368778751,"sessionRoot":"/private/tmp/one-admission-e2e.JTLoOl/workspace","delivery":{"kind":"none"},"createdVia":"operator","createdActor":{"type":"human","source":"profile","id":"a6153c64-edb2-4c48-8f06-e18c6e782954"},"createdAt":1795368778754,"skillLibrarySelections":[],"visibility":"shared","spawnDepth":0,"modelOverrideSource":"default","chatType":"direct","parentSessionKey":"agent:main:main","totalTokens":0,"totalTokensFresh":true,"totalTokensVersion":2},"runStarted":false,"publicRead":false,"resolved":{"modelProvider":"openai","model":"gpt-5.5"}}}}
{"t":"2026-11-22T17:32:59.167Z","step":"admin.members.add","data":{"method":"session.members.add","ok":true,"res":{"ok":true,"sessionKey":"agent:main:one-admission-76c1ff88","identityId":"2427e258-8e3b-4e94-acb2-82956726423c"}}}
{"t":"2026-11-22T17:32:59.866Z","step":"R.worker.chat.send","data":{"method":"chat.send","ok":true,"res":{"runId":"31a709e1-7b5a-4a7f-a295-97114d044677","status":"started","messageSeq":1,"serverTiming":{"receivedToAckMs":384.941,"loadSessionMs":16.007}}}}
{"t":"2026-11-22T17:33:18.418Z","step":"Q.worker.chat.send.queued","data":{"method":"chat.send","ok":true,"res":{"runId":"f059314d-f93c-4f2c-b07f-72f742b4da9a","status":"started","serverTiming":{"receivedToAckMs":58.135,"loadSessionMs":6.546}}}}
{"t":"2026-11-22T17:33:20.865Z","step":"Q.admin.history.beforeRevoke","data":{"method":"chat.history","ok":true,"res":{"sessionKey":"agent:main:one-admission-76c1ff88","sessionId":"a750445d-352e-464c-99bd-56eace3b02b2","messages":[{"role":"user","content":"Execute exactly three separate exec tool calls sequentially, waiting for each result before the next. First: sleep 6; printf FIRST. Second: sleep 6; printf SECOND. Third: sleep 6; printf THIRD. Do not combine them. After all three complete, reply exactly RUNNING_DONE_HEAD.","timestamp":1795368779495,"idempotencyKey":"31a709e1-7b5a-4a7f-a295-97114d044677:user","provenance":{"kind":"external_user"},"__openclaw":{"senderId":"2427e258-8e3b-4e94-acb2-82956726423c","senderName":"worker","senderIdentity":{"type":"profile","id":"2427e258-8e3b-4e94-acb2-82956726423c"},"transport":{"clients":[{"id":"openclaw-control-ui","mode":"webchat"}]},"chatRequestIdentity":"9afae9db56387fbc5394d4331b7a42a3eabd1166f8558a285433a0e7d1a0af35","chatSendDelivery":{"deliver":false},"modelSelection":{"provider":"openai","model":"gpt-5.5"},"id":"ed09b8c5-8e7d-400c-ad58-fb5516b2845e","idempotencyKey":"31a709e1-7b5a-4a7f-a295-97114d044677:user","recordTimestampMs":1795368779720,"transcriptPosition":{"source":"xVLA-H8iw0krdPsuUneF5O_KI5jkRAZpUEffGU5ptuI","rawSeq":1},"seq":1,"senderProfileAvatarUrl":"/api/users/2427e258-8e3b-4e94-acb2-82956726423c/avatar?v=1795368768262"}},{"role":"assistant","content":[{"type":"toolCall","id":"call_01fc908a44b04c95a3d9455e009a2485|fc_030ef3a259c03014016b03275d8b6087d181d40f815f00c21f","name":"exec","arguments":{"command":"sleep 6; printf FIRST","workdir":"/tmp/one-admission-e2e.JTLoOl/workspace","awaitResults":true,"timeoutSeconds":20,"title":"Run first timed command"}}],"api":"openai-responses","provider":"openai","model":"gpt-5.5","usage":{"input":4535,"output":58,"totalTokens":4593,"cacheRead":0,"cacheWrite":0,"usageReport":{"state":"available"},"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0,"total":0},"contextUsage":{"state":"available","promptTokens":4535,"totalTokens":4593}},"stopReason":"toolUse","timestamp":1795368794356,"responseId":"resp_030ef3a259c03014016b03275ca50c87d1a2376b95d6c5c849","responseModel":"gpt-5.5-2026-04-23","diagnostics":[{"type":"openai_responses_terminal","timestamp":1795368798250,"details":{"eventType":"response.completed","stopReason":"toolUse","endTurn":"absent"}}],"__openclaw":{"runId":"31a709e1-7b5a-4a7f-a295-97114d044677","id":"c3189aa1-3d82-44ec-bccc-4fdddb65b2e6","recordTimestampMs":1795368798267,"transcriptPosition":{"source":"xVLA-H8iw0krdPsuUneF5O_KI5jkRAZpUEffGU5ptuI","rawSeq":7},"seq":2}}],"activity":[{"messageId":"c3189aa1-3d82-44ec-bccc-4fdddb65b2e6","items":[{"itemId":"tool:call_01fc908a44b04c95a3d9455e009a2485|fc_030ef3a259c03014016b03275d8b6087d181d40f815f00c21f","toolCallId":"call_01fc908a44b04c95a3d9455e009a2485|fc_030ef3a259c03014016b03275d8b6087d181d40f815f00c21f","name":"exec","kind":"tool","phase":"end","title":"Exec","meta":"Run first timed command","commandBearing":true,"unpairedCall":true}]}],"hasMore":false,"totalMessages":2,"pendingInputs":{"items":[{"id":"82315e37-73ea-4621-a85e-8cd0e76f29ba","acceptedAt":1795368798760,"state":"queued","message":{"role":"user","content":"/followup Do not use tools. Reply exactly QUEUED_MUST_NOT_RUN_HEAD.","timestamp":1795368798760,"provenance":{"kind":"external_user"},"__openclaw":{"senderId":"2427e258-8e3b-4e94-acb2-82956726423c","senderName":"worker","senderIdentity":{"type":"profile","id":"2427e258-8e3b-4e94-acb2-82956726423c"},"transport":{"clients":[{"id":"openclaw-control-ui","mode":"webchat"}]},"chatRequestIdentity":"0b6d5975b55e7f4585f5844ee9b0f0a2e358572e7852c09ef8b1e01c178ff735","chatSendDelivery":{"deliver":false},"modelSelection":{"provider":"openai","model":"gpt-5.5","previous":{"provider":"openai","model":"gpt-5.5"}},"senderProfileAvatarUrl":"/api/users/2427e258-8e3b-4e94-acb2-82956726423c/avatar?v=1795368768262","id":"pending:82315e37-73ea-4621-a85e-8cd0e76f29ba"}},"runId":"f059314d-f93c-4f2c-b07f-72f742b4da9a","queued":true}],"total":1,"queuedCount":1},"deltaCursor":"eyJhZ2VudElkIjoibWFpbiIsImdlbmVyYXRpb24iOiI5N2IzYWViZjAxMzc0YTcwOGVlNzc4MTEwNDk5NjcxMCIsImxhc3RTZXEiOjcsInNlc3Npb25JZCI6ImE3NTA0NDVkLTM1MmUtNDY0Yy05OWJkLTU2ZWFjZTNiMDJiMiIsInZlcnNpb24iOjF9","defaults":{"modelProvider":"openai","model":"gpt-5.5","contextTokens":null,"agentRuntime":{"id":"openclaw","cloudPlacementSupported":true,"cloudPlacementExecutionMode":"worker-turn","devicePlacement":{"requiredNodeCommands":[],"consumesWorkerSlot":true},"devicePlacementSupported":true,"source":"model"},"thinkingDefault":"low","communication":{"send":"always","receive":"always"},"modelSelectionTarget":"session"},"sessionInfo":{"key":"agent:main:one-admission-76c1ff88","sessionModelRevision":"63seGc3svd5cXNJaCDh5eV2o2p7_wGD1bDsPYOOtdsY","visibility":"shared","effectiveCommunication":{"send":"always","receive":"always"},"permissionModePending":false,"spawnDepth":0,"createdVia":"operator","createdActor":{"type":"human","id":"a6153c64-edb2-4c48-8f06-e18c6e782954","identity":{"type":"profile","id":"a6153c64-edb2-4c48-8f06-e18c6e782954"},"label":"admin","avatarUrl":"/api/users/a6153c64-edb2-4c48-8f06-e18c6e782954/avatar?v=1795368767397"},"owner":{"actor":{"type":"human","id":"a6153c64-edb2-4c48-8f06-e18c6e782954","identity":{"type":"profile","id":"a6153c64-edb2-4c48-8f06-e18c6e782954"},"label":"admin","avatarUrl":"/api/users/a6153c64-edb2-4c48-8f06-e18c6e782954/avatar?v=1795368767397"}},"participants":[{"identity":{"type":"profile","id":"2427e258-8e3b-4e94-acb2-82956726423c"},"label":"worker","avatarUrl":"/api/users/2427e258-8e3b-4e94-acb2-82956726423c/avatar?v=1795368768262"}],"expandedParticipants":[{"identity":{"type":"profile","id":"2427e258-8e3b-4e94-acb2-82956726423c"},"label":"worker","avatarUrl":"/api/users/2427e258-8e3b-4e94-acb2-82956726423c/avatar?v=1795368768262"}],"participantCount":1,"createdAt":1795368778754,"kind":"direct","classification":"direct","agentId":"main","isMain":false,"isDock":false,"isBackground":false,"chatType":"direct","updatedAt":1795368798764,"archived":false,"pinned":false,"sidebarRoot":false,"unread":true,"lastInteractionAt":1795368798567,"sessionId":"a750445d-352e-464c-99bd-56eace3b02b2","lifecycleRevision":"9a18bf86-e623-413d-89c3-79dc1d36298d","systemSent":true,"abortedLastRun":false,"thinkingDefault":"low","effectiveFastMode":false,"effectiveFastModeSource":"default","fastAutoOnSeconds":60,"parentSessionKey":"agent:main:main","effectiveResponseUsage":"off","effectiveQueueMode":"steer","modelProvider":"openai","model":"gpt-5.5","modelOverrideSource":null,"runtimeSelectionLocked":false,"agentRuntime":{"id":"openclaw","cloudPlacementSupported":true,"cloudPlacementExecutionMode":"worker-turn","devicePlacement":{"requiredNodeCommands":[],"consumesWorkerSlot":true},"devicePlacementSupported":true,"source":"model"},"snapshotAt":1795368800849,"status":"running","suppressErrorNotice":false,"startedAt":1795368779554,"totalTokens":5999,"totalTokensFresh":true,"activeModelProvider":"openai","activeModel":"gpt-5.5-2026-04-23","placement":{"state":"local","generation":0,"createdAtMs":1795368786285,"updatedAtMs":1795368786285,"stateChangedAtMs":1795368786285},"activitySummary":{"state":"unavailable","canEnsure":true},"hasBoard":false,"titlePending":false,"childOwnerSessionKeys":["agent:main:main"],"hiddenFromInvolvingMe":false,"sharingRole":"admin","sendDisabledReason":null,"workspaceReadDisabledReason":null,"hasActiveRun":true,"activeRunIds":["31a709e1-7b5a-4a7f-a295-97114d044677","f059314d-f93c-4f2c-b07f-72f742b4da9a"],"activeLeafEntryId":"c3189aa1-3d82-44ec-bccc-4fdddb65b2e6"},"thinkingLevel":"low","inFlightRun":{"runId":"31a709e1-7b5a-4a7f-a295-97114d044677","text":"","startedAt":1795368794193,"events":[{"runId":"31a709e1-7b5a-4a7f-a295-97114d044677","seq":8,"stream":"usage","ts":1795368798258,"data":{"outputTokens":58},"sessionKey":"agent:main:one-admission-76c1ff88","agentId":"main"},{"runId":"31a709e1-7b5a-4a7f-a295-97114d044677","seq":9,"stream":"item","ts":1795368798288,"data":{"itemId":"tool:call_01fc908a44b04c95a3d9455e009a2485|fc_030ef3a259c03014016b03275d8b6087d181d40f815f00c21f","toolCallId":"call_01fc908a44b04c95a3d9455e009a2485|fc_030ef3a259c03014016b03275d8b6087d181d40f815f00c21f","name":"exec","kind":"tool","phase":"start","title":"Exec","status":"running","meta":"Run first timed command","commandBearing":true,"startedAt":1795368798287},"sessionKey":"agent:main:one-admission-76c1ff88","agentId":"main"},{"runId":"31a709e1-7b5a-4a7f-a295-97114d044677","seq":10,"stream":"tool","ts":1795368798288,"data":{"phase":"start","name":"exec","toolCallId":"call_01fc908a44b04c95a3d9455e009a2485|fc_030ef3a259c03014016b03275d8b6087d181d40f815f00c21f","args":{"command":"sleep 6; printf FIRST","workdir":"/tmp/one-admission-e2e.JTLoOl/workspace","awaitResults":true,"timeoutSeconds":20,"title":"Run first timed command"}},"sessionKey":"agent:main:one-admission-76c1ff88","agentId":"main"}]}}}}
{"t":"2026-11-22T17:33:20.865Z","st```
</details> |
|
Codex review: needs maintainer review before merge. What this changesThis PR checks exec approvals at command admission and removes policy rechecks that could refuse an already admitted launch. Example: Exec policy changes to deny after
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR makes a focused, intentional change to exec admission that current main still needs; no actionable code defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe exec approval owner receives command authorization and policy inputs, checks canonical SQLite policy through its worker, and returns a launch guard consumed by Gateway and node execution paths. flowchart LR
A[Command request] --> B[Policy preparation]
B --> C[Authorization worker]
D[SQLite approval policy] --> C
C --> E[Committed launch guard]
F[Stop signal] --> E
E --> G[Process launch]
Technical reviewBest possible solution: Keep the existing worker as the command admission owner and remove the redundant retained policy checks while preserving cancellation and resource ownership. Do we have a high-confidence way to reproduce the issue? The base launch guard reads the published policy again after worker authorization and rejects a later denial; the changed supervisor-admission regression directly exercises that sequence, but no reproduction was executed during this read-only review. Is this the best way to solve the issue? The patch follows the accepted admission contract with the existing worker and snapshot cache, removes the competing policy projection, and adds no replacement machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5626902006c8. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -101, Tests -145, Docs 0, Other -2. Total -248 across 12 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, 12:41 PM ET / 17:41 UTC. |
|
Landed as c0ead5b. An exec command is now checked against the policy once, at the worker commit. A policy change after that applies to the next command, and Stop still cancels the launch. |
…tart (#203847) ## Problem After a request was admitted, some paths still re-read permission and refused or aborted part-way through: - Model selection from plugin/SDK code (`captureOperatorToolGatewayAuthority`) re-checked the caller's live Gateway authority at commit. Revoking access mid-request turned an accepted selection into "Gateway caller authority is no longer active". - Session requests from a personal-tool turn (`resolveSessionRuntimeAuthority`) re-checked the turn at every response, every commit guard and every shared-read delivery. - `GET /sessions/{key}/history` re-authenticated the bearer, re-read scopes and re-read session membership before every streamed SSE update. A revoked token or a removed member closed a stream that was already open. - `POST /tools/invoke` aborted the running tool when the operator-access revocation signal fired. The rule in `AGENTS.md` ("Choose good compromises") is to check authority once, when the work starts. Revocation applies to the next request. ## Fix - `operator-invocation-authority.ts`: delete `captureOperatorToolGatewayAuthority`. `captureAmbientGatewayOperatorAuthority` reads the admitted grant once. Its invocation check keeps only Stop (direct and scope signals) and the tool caller's session fences. A direct operator source with no Gateway binding gets the existing missing-binding error at the start. - `apply-session-model-selection.ts`: read the admitted grant once and refuse at the start when an operator source has no grant (same message as before). The commit guard keeps the model-policy check. The session store fences the write itself (`initialEntry`, model-selection lock). - `session-runtime-authority.ts`: the personal-tool turn check runs once in `handleGatewayRequest`, before dispatch. In-process dispatch also goes through that path. Every `runtimeAuthority.assertCurrent` re-check is deleted from `server-methods.ts` and `server-plugin-in-process-authority.ts`. - `sessions-history-http.ts`: each SSE publish keeps the data fences (captured storage owner, session id, lifecycle revision, start time). It no longer re-authenticates, re-reads scopes or re-reads membership. - `tools-invoke-http.ts`: the tool signal ends only on client disconnect and request end. - `LIFETIME_CHECK_CALLS` loses `captureOperatorToolGatewayAuthority`, `resolveSessionRuntimeAuthority` and `captureMediaGenerationAdmission`. Kept on purpose (cut less): - `captureMediaGenerationAdmission`: code unchanged, name removed from the ratchet. Its own checks are data fences: the run-registry lifecycle generation and the transcript storage location, which guard the task launch and the image review action's queue writes. Its remaining authority piece is `captureGatewayToolCallerAssertion`, and the tool-caller PRs remove that. Same call as #203572 made for the capability lease. - `plugin-node-host.ts` `prepareExecAuthorization`: the plugin calls it when it launches the command, and its `assertCurrent` runs before the spawn of that same launch. This is launch-time admission, not a mid-run check. - Stop and every session data fence. Accepted edge cases: - A request that started before a revoke finishes. - An SSE history stream opened before a revoke keeps streaming until the client reconnects; the reconnect is refused. ## Tests - New: `tools-invoke-http.abort.test.ts` "finishes an admitted tool when operator access is revoked mid-run" (red on base `40d8a3953663`, green on head). - New: `sessions-history-http.revocation.test.ts` "keeps streaming an admitted stream after profile revocation" (red on base, green on head). - Deleted, because they assert a mid-request refusal: initial-history revocation/authentication during the read, "withholds a pending refresh after profile revocation", "withholds a delayed inline message after sharing", "rechecks SSE auth against live proxy config", "rechecks profiled authority after model preparation before mutation". - `local-request-context.session-tools.test.ts`: an ended personal-tool turn is still refused, now when the next request starts. - Kept: Stop, session replacement, reset and response close still withhold history. - CI round 1: the unbound-operator cases in `decisions/runtime.test.ts` and `runtime-llm.operator-model-policy.test.ts` are still refused, now at the start with the caller's missing-binding error, so only the expected text changed. Deleted the `sessions-history-http.model-policy` case "uses a policy committed during final current-profile acquisition": it hooked the per-publish re-authentication that this PR removes. ## Evidence - E2E on head `237ac19d9fe8` (isolated Gateway, real model): Q revoke-while-queued refused visibly, R revoke-while-running finishes, S Stop cancels, all pass. `verdict.json` and `results.jsonl`: #203847 (comment) - Local review: clean, 0 findings, on `237ac19d9fe8` and on the final head `a927e93e57fe` (that push changes only tests; production bytes are identical to the E2E head). - Pre-push: one `ocx test` run over the touched tests and every importer test (290 files). Each remaining failure also fails on the merge base `40d8a3953663` (`question.*`, `stop`, `sessions-groups.create`, `chat-pending-inputs-dismiss-handler`, `chat.abort-session-fence`, `github-publication-imported-actions`, `github-pr-workspace-preparation`, `mcp-http.async-scope`) or is a known MAIN-ALSO red (`server-cron-failure-repair.final-effect`). `tsgo:core`, `tsgo:test`, oxfmt and oxlint pass, and so do the lifetime, session-identity and mock-export ratchets. Co-authored-by: Ayaan Zaidi <[email protected]>
## What Problem This Solves
Exec approvals were checked twice for one command. The worker commit (`execApprovals.commitAuthorizations`) checks the command against the current policy row. After that, `retainExecApprovalsCurrentRead` kept a per-database policy view that the launch guard read again right before spawn. A policy write that landed between the commit and the spawn refused a command that was already admitted ("Exec approval changed before execution", "Exec approval policy is unavailable or changing before execution"). Under the one-admission rule, a policy change applies to the next command; a command that has started finishes.
## Fix
- `src/infra/exec-approvals-store.ts`: delete `retainExecApprovalsCurrentRead`, the `currentPolicies` map and its publication/lifecycle bookkeeping.
- `prepareExecApprovalsCurrentRead` returns the policy it read at preparation, through the existing prepared-snapshot cache, which a publication still clears for the next reader.
- The launch guard from `commitExecAuthorizations` keeps Stop (`signal.throwIfAborted()`) and the caller's own `assertCurrent`, and returns the committed file.
- `src/infra/exec-approvals-authorization.ts`: `commitExecAuthorizationLocked` no longer runs `assertCurrentUsageAuthorization` again on the file it just committed. The worker already ran that check inside the commit transaction.
- `scripts/check-lifetime-check-ratchet.mts`: remove `retainExecApprovalsCurrentRead` (it is gone) and `createPluginRuntimeCapabilityLease` from `LIFETIME_CHECK_CALLS`.
### Classification
| Name | Class | Action |
|---|---|---|
| `retainExecApprovalsCurrentRead` (openclaw#169584) | authority. It re-read the exec policy, which is the permission for the command, after the worker commit had admitted it. It refused while a policy write was pending or after one committed. | deleted |
| `createPluginRuntimeCapabilityLease` (openclaw#133297, "scope HTTP routes to account lifetimes") | resource lifetime fence. Its only `revoke()` callers are channel account stop (`server-channels.ts`), plugin service stop (`services.ts`), plugin CLI scheduler close (`cli-service-scheduler.ts`) and shutdown drain. It never reads role, scopes, profile or grants. It retires HTTP routes, listeners and schedulers that a stopped account or service still holds. | code kept; name removed from the ratchet list |
Kept: Stop on the launch guard, the worker commit check against the current row (it protects the usage/grant write), and the DB-lifecycle fences inside the shared-state reads.
Not in scope (accepted for now): `plugin-node-host.ts` still compares the node exec **config** (`resolveNodeExecConfigPolicy`) at launch. The ratchet does not list it; it can go in a later PR.
## User Impact
- If you tighten exec approvals while a command is between approval and spawn, that command now runs. The next command uses the new policy. Before this change, the command failed with "Exec approval changed before execution".
- Stop still cancels the launch.
- A policy change made before the worker commit still refuses the command.
## Tests
Deleted or flipped. Each one asserted a refusal after the commit had admitted the command, which this change removes:
- `bash-tools.exec-authorization.integration.test.ts`: "revalidates … after asynchronous shell preparation" ×3, "rechecks policy after deferred supervisor admission", the PTY fallback `revoked=true` case. Added "finishes an admitted launch when policy is revoked during supervisor admission" (real exec tool → supervisor).
- `invoke-system-run.test.ts`, `invoke-agent-cli-claude.test.ts`: the revoke cases now expect the admitted launch to finish (real node `system.run` / Claude CLI entry points).
- `plugin-exec-policy.test.ts`: approvals tightened after the invocation started → the launch is allowed. A config change is still refused.
- `agent-tools.browser-loopback-current.e2e.test.ts`: deleted the approvals-revocation case. The abort (Stop) and config cases stay.
- `exec-approvals-store*.test.ts`, `operator-approval-store.worker.test.ts`: the pending-write / committed-change refusals are replaced by "the prepared read keeps its admitted policy; a fresh preparation sees the write".
## Evidence
Pre-push: one `ocx test` run of the 78 importer/touched files (continue-on-failure); the remaining reds there (`server-methods/exec-approvals.test.ts` ×4, `agents-mutate.test.ts`, `bash-tools.exec-gateway-approval.e2e.test.ts` hook-token reload) fail the same way on the merge base `75564d96e6eb`. Touched tests rerun green (202 cases). `pnpm tsgo:core`, `pnpm tsgo:test`, oxfmt, oxlint, lifetime ratchet pass. Head E2E and CI follow in comments.
- Head E2E (Q/R/S pass): openclaw#203572 (comment)
- Local review rejected finding: openclaw#203572 (comment)
Co-authored-by: Ayaan Zaidi <[email protected]>
…tart (openclaw#203847) ## Problem After a request was admitted, some paths still re-read permission and refused or aborted part-way through: - Model selection from plugin/SDK code (`captureOperatorToolGatewayAuthority`) re-checked the caller's live Gateway authority at commit. Revoking access mid-request turned an accepted selection into "Gateway caller authority is no longer active". - Session requests from a personal-tool turn (`resolveSessionRuntimeAuthority`) re-checked the turn at every response, every commit guard and every shared-read delivery. - `GET /sessions/{key}/history` re-authenticated the bearer, re-read scopes and re-read session membership before every streamed SSE update. A revoked token or a removed member closed a stream that was already open. - `POST /tools/invoke` aborted the running tool when the operator-access revocation signal fired. The rule in `AGENTS.md` ("Choose good compromises") is to check authority once, when the work starts. Revocation applies to the next request. ## Fix - `operator-invocation-authority.ts`: delete `captureOperatorToolGatewayAuthority`. `captureAmbientGatewayOperatorAuthority` reads the admitted grant once. Its invocation check keeps only Stop (direct and scope signals) and the tool caller's session fences. A direct operator source with no Gateway binding gets the existing missing-binding error at the start. - `apply-session-model-selection.ts`: read the admitted grant once and refuse at the start when an operator source has no grant (same message as before). The commit guard keeps the model-policy check. The session store fences the write itself (`initialEntry`, model-selection lock). - `session-runtime-authority.ts`: the personal-tool turn check runs once in `handleGatewayRequest`, before dispatch. In-process dispatch also goes through that path. Every `runtimeAuthority.assertCurrent` re-check is deleted from `server-methods.ts` and `server-plugin-in-process-authority.ts`. - `sessions-history-http.ts`: each SSE publish keeps the data fences (captured storage owner, session id, lifecycle revision, start time). It no longer re-authenticates, re-reads scopes or re-reads membership. - `tools-invoke-http.ts`: the tool signal ends only on client disconnect and request end. - `LIFETIME_CHECK_CALLS` loses `captureOperatorToolGatewayAuthority`, `resolveSessionRuntimeAuthority` and `captureMediaGenerationAdmission`. Kept on purpose (cut less): - `captureMediaGenerationAdmission`: code unchanged, name removed from the ratchet. Its own checks are data fences: the run-registry lifecycle generation and the transcript storage location, which guard the task launch and the image review action's queue writes. Its remaining authority piece is `captureGatewayToolCallerAssertion`, and the tool-caller PRs remove that. Same call as openclaw#203572 made for the capability lease. - `plugin-node-host.ts` `prepareExecAuthorization`: the plugin calls it when it launches the command, and its `assertCurrent` runs before the spawn of that same launch. This is launch-time admission, not a mid-run check. - Stop and every session data fence. Accepted edge cases: - A request that started before a revoke finishes. - An SSE history stream opened before a revoke keeps streaming until the client reconnects; the reconnect is refused. ## Tests - New: `tools-invoke-http.abort.test.ts` "finishes an admitted tool when operator access is revoked mid-run" (red on base `3e3338482129`, green on head). - New: `sessions-history-http.revocation.test.ts` "keeps streaming an admitted stream after profile revocation" (red on base, green on head). - Deleted, because they assert a mid-request refusal: initial-history revocation/authentication during the read, "withholds a pending refresh after profile revocation", "withholds a delayed inline message after sharing", "rechecks SSE auth against live proxy config", "rechecks profiled authority after model preparation before mutation". - `local-request-context.session-tools.test.ts`: an ended personal-tool turn is still refused, now when the next request starts. - Kept: Stop, session replacement, reset and response close still withhold history. - CI round 1: the unbound-operator cases in `decisions/runtime.test.ts` and `runtime-llm.operator-model-policy.test.ts` are still refused, now at the start with the caller's missing-binding error, so only the expected text changed. Deleted the `sessions-history-http.model-policy` case "uses a policy committed during final current-profile acquisition": it hooked the per-publish re-authentication that this PR removes. ## Evidence - E2E on head `237ac19d9fe8` (isolated Gateway, real model): Q revoke-while-queued refused visibly, R revoke-while-running finishes, S Stop cancels, all pass. `verdict.json` and `results.jsonl`: openclaw#203847 (comment) - Local review: clean, 0 findings, on `237ac19d9fe8` and on the final head `a927e93e57fe` (that push changes only tests; production bytes are identical to the E2E head). - Pre-push: one `ocx test` run over the touched tests and every importer test (290 files). Each remaining failure also fails on the merge base `3e3338482129` (`question.*`, `stop`, `sessions-groups.create`, `chat-pending-inputs-dismiss-handler`, `chat.abort-session-fence`, `github-publication-imported-actions`, `github-pr-workspace-preparation`, `mcp-http.async-scope`) or is a known MAIN-ALSO red (`server-cron-failure-repair.final-effect`). `tsgo:core`, `tsgo:test`, oxfmt and oxlint pass, and so do the lifetime, session-identity and mock-export ratchets. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Exec approvals were checked twice for one command. The worker commit (
execApprovals.commitAuthorizations) checks the command against the current policy row. After that,retainExecApprovalsCurrentReadkept a per-database policy view that the launch guard read again right before spawn. A policy write that landed between the commit and the spawn refused a command that was already admitted ("Exec approval changed before execution", "Exec approval policy is unavailable or changing before execution"). Under the one-admission rule, a policy change applies to the next command; a command that has started finishes.Fix
src/infra/exec-approvals-store.ts: deleteretainExecApprovalsCurrentRead, thecurrentPoliciesmap and its publication/lifecycle bookkeeping.prepareExecApprovalsCurrentReadreturns the policy it read at preparation, through the existing prepared-snapshot cache, which a publication still clears for the next reader.commitExecAuthorizationskeeps Stop (signal.throwIfAborted()) and the caller's ownassertCurrent, and returns the committed file.src/infra/exec-approvals-authorization.ts:commitExecAuthorizationLockedno longer runsassertCurrentUsageAuthorizationagain on the file it just committed. The worker already ran that check inside the commit transaction.scripts/check-lifetime-check-ratchet.mts: removeretainExecApprovalsCurrentRead(it is gone) andcreatePluginRuntimeCapabilityLeasefromLIFETIME_CHECK_CALLS.Classification
retainExecApprovalsCurrentRead(#169584)createPluginRuntimeCapabilityLease(#133297, "scope HTTP routes to account lifetimes")revoke()callers are channel account stop (server-channels.ts), plugin service stop (services.ts), plugin CLI scheduler close (cli-service-scheduler.ts) and shutdown drain. It never reads role, scopes, profile or grants. It retires HTTP routes, listeners and schedulers that a stopped account or service still holds.Kept: Stop on the launch guard, the worker commit check against the current row (it protects the usage/grant write), and the DB-lifecycle fences inside the shared-state reads.
Not in scope (accepted for now):
plugin-node-host.tsstill compares the node exec config (resolveNodeExecConfigPolicy) at launch. The ratchet does not list it; it can go in a later PR.User Impact
Tests
Deleted or flipped. Each one asserted a refusal after the commit had admitted the command, which this change removes:
bash-tools.exec-authorization.integration.test.ts: "revalidates … after asynchronous shell preparation" ×3, "rechecks policy after deferred supervisor admission", the PTY fallbackrevoked=truecase. Added "finishes an admitted launch when policy is revoked during supervisor admission" (real exec tool → supervisor).invoke-system-run.test.ts,invoke-agent-cli-claude.test.ts: the revoke cases now expect the admitted launch to finish (real nodesystem.run/ Claude CLI entry points).plugin-exec-policy.test.ts: approvals tightened after the invocation started → the launch is allowed. A config change is still refused.agent-tools.browser-loopback-current.e2e.test.ts: deleted the approvals-revocation case. The abort (Stop) and config cases stay.exec-approvals-store*.test.ts,operator-approval-store.worker.test.ts: the pending-write / committed-change refusals are replaced by "the prepared read keeps its admitted policy; a fresh preparation sees the write".Evidence
Pre-push: one
ocx testrun of the 78 importer/touched files (continue-on-failure); the remaining reds there (server-methods/exec-approvals.test.ts×4,agents-mutate.test.ts,bash-tools.exec-gateway-approval.e2e.test.tshook-token reload) fail the same way on the merge base1a0a24dcd2cf. Touched tests rerun green (202 cases).pnpm tsgo:core,pnpm tsgo:test, oxfmt, oxlint, lifetime ratchet pass. Head E2E and CI follow in comments.