Repository navigation
refactor(auto-reply): drop mid-run operator re-checks in reply runner (R6c part 4a) - #204069
Conversation
… (part 4a) Delete operatorAuthority.assertCurrent reads in agent-runner, followup, queue, reply admission/workspace/source-binding, goal continuation and get-reply paths. Abort signals, lifecycle generation and data fences stay. Reword the GitHub publication worktree data-fence refusal. Delete tests that asserted mid-run permission refusals. Co-authored-by: obviyus <[email protected]>
The local review input scanner reads the whole touched test file, whose redaction fixture carries a credential-shaped URL, so this PR cannot touch it. 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 maintainer review before merge. What this changesThis PR removes repeated operator-authority checks from reply execution while retaining queued-start admission, cancellation signals, and lifecycle and data checks. Example: Alice loses operator.write after her reply starts.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR implements the approved admission policy without an identified introduced defect; required CI remains unresolved. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe auto-reply runner turns admitted messages and queued continuations into agent executions, transcript updates, and delivered replies. flowchart TD
A[Incoming message] --> B[Request admission]
B --> C[Reply queue]
C --> D[Queued start admission]
D --> E[Reply execution]
F[Stop and lifecycle signals] --> E
E --> G[Transcript and delivery]
Technical reviewBest possible solution: Keep admission with its existing owners and remove redundant execution-time policy checks while preserving Stop, source custody, and session identity checks. Do we have a high-confidence way to reproduce the issue? Current-main source contains the repeated assertions identified by the PR; no target code was executed during this read-only review. Is this the best way to solve the issue? The deletion-based approach uses the existing admission and cancellation owners, adds no competing machinery, and preserves the meaningful lifecycle and source checks inspected. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4ff5ebdd239a. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -50, Tests -257. Total -307 across 30 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 23, 2026, 8:32 AM ET / 13:32 UTC. |
A retired cron delivery fence rides on the queued source's assertion. Without the start check the claimed input left session-controller cleanup pending. Co-authored-by: obviyus <[email protected]>
|
Landed as 24167fa. Reply-runner paths (agent runner, follow-up, queue, reply admission/workspace/source binding, goal continuation, get-reply) no longer re-read operator permission mid-run; abort signals, lifecycle and data fences stay, and the queued-start check before the mailbox claim stays because it carries the cron delivery fence. Proof: CI green on 3094468, local review clean, one-admission E2E R/Q/S pass. Remaining: 17 auto-reply caller files (part 4a-2), src/agents callers (part 4b), and the GitHub publication worktree wording (blocked by the review scanner on the test fixture). |
… session events (R6c part 4a-2) (#204105) ## Problem Authority is checked once, when work starts. A started run may finish, Stop cancels it, and data fences stay. After parts 1-3 and 4a (#203999, #204031, #204048, #204069), 17 files in `src/auto-reply/**` still call `operatorAuthority.assertCurrent()` while a run is in progress. This is part 4a-2 of the refusal sweep for agents, sessions and auto-reply. Part 4b (`src/agents/**`) runs separately. ## Fix The test for each site: can it fire when only a permission, approval or config changes, while nothing about the run or its data changes? If yes, it is an authority re-check, and this PR deletes it. If no, it is Stop, run close or a data fence, and this PR keeps it. `operatorAuthority.assertCurrent()` reads the requester's source again (request or ingress lifetime, held reference, caller check). Stop still works: every site below keeps its own abort-signal, lifecycle-generation, session-data or occurrence check. Where a reply has one, the reply's upstream signal already includes `operatorAuthority.signal`. | Site | Kind | Action | |---|---|---| | `dispatch-from-config.gather.ts`: `assertRequestCurrent` (session lookups ×3, progress check), check after runtime/TTS preparation | authority | **deleted**; abort signal, dispatch signal and lifecycle generation stay | | `dispatch-from-config.lifecycle.ts` / `.prepare-operation.ts` `assertRequestCurrent`: the `replyOptions.operatorAuthority` branch | authority | **deleted**; the reserved input's own source (`sourceAdapter.authority`) is kept as the queued-start check before the claim, the same as in 4a. `internalEventExecution`, channel authority, retirement and abort checks stay | | `dispatch-from-config.prepare-context.ts`, `.prepare-delivery.ts` | authority | **deleted**; pre-dispatch abort stays | | `get-reply-inline-actions.ts` (before an inline tool, before commands) | authority | **deleted**; abort stays | | `get-reply-run-admission.ts` preparation assertion | authority | **deleted** from the composition; internal-event and scheduled-automation sources (cron fence) stay | | `get-reply-run-context.ts` scheduled path | authority | **deleted**; `scheduledAutomation.assertCurrent()` (cron run fence) and abort signals stay | | `get-reply.types.ts` `prepareInternalGetReplyOptions` | authority | **deleted**; the host-issuer check `assertAdmittedRunOperatorAuthority` stays | | `model-selection.ts` (entry, reset `commitGuard`, `assertSelectionCurrent`) | authority | **deleted**; host-issuer check, model-policy checks and the session-entry/selection data fence stay | | `request-native-subagent.ts` (invocation `assertCurrent`, accepted-child `assertSourceCurrent`) | authority | **deleted**; guard, abort, state and `owner.assertOwnerCurrent` stay | | `session-event-context.ts` (event preparation, owner successor `isCurrent`) | authority | **deleted**; the occurrence assertion and `operatorAuthority.signal` (Stop) stay | | `session-event-handoff.ts` (`assertOwnerCurrent`, `captureSources`) | authority | **deleted**; settlement, acceptance, target, scheduled-automation, generation-lease, controller-operation and config-policy fences stay | | `session-event-target.ts` (capture entry, `assertCaptureCurrent`) | authority | **deleted**; host-issuer check, capture/producer assertions and caller-occurrence checks stay | | `commands-compact.ts` (entry, before acceptance) | authority | **deleted**; `rejectUnauthorizedCommand` at start, owner and current-read fences stay | | `conversation-label-generator.ts` | authority | **deleted**; caller assertion, abort and model-policy check stay | | `channel-run-admission.ts` `assertSourceCurrent` before admission | authority | **deleted**; caller's `assertSourceCurrent` and closed checks stay | Left unchanged: - `reply-agent-turn-preparation.ts` pre-claim check: the 4a cut-less site (cron delivery fence). - `agents/worktrees/errors.ts`: parked (see #204069). - No production authority-refusal strings remain in `src/auto-reply/**` or `src/sessions/**`. The lifetime-check ratchet reports 0 in changed files. ## User impact - A requester whose access changes while a reply is being prepared (dispatch, model selection, inline actions, `/compact`, native subagents, session events, label generation) sees the turn finish. The next request goes through admission again. - Queued input still goes through admission again when it starts, so a revoke while queued is still refused visibly. - Stop still cancels. - No new refusal, prompt or wait. ## Tests Deleted (they assert a mid-run permission refusal through `assertCurrent`): - `model-selection.test.ts` `authority` row of "rejects a changed … after awaiting missing-pin provider facts" (the pin/source/provider/session data rows stay). - `commands-compact.lifecycle.test.ts` `adoption`/`operator` row of "rechecks … authority for … before effects" (CI round 1; the caller, plugin-owner, writer, invocation and session rows stay). - `session-event-config-readmission.test.ts` "finalizes a failed-before-reply event …": only the assertion that the operator source is re-read after its policy scope closes; the failed-outcome assertions stay. Pre-push (local): - `ocx test` with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 61 related test files: every importer test of a changed file that builds an operator authority or tests revocation, plus the direct tests of the changed modules. The full set of 180 importers is over the 150 cap, so CI runs the rest. Reds: the two rows above (fixed; rerun 47/47 pass), and `gateway/server-methods/system-event-routing.test.ts` (3 tests). Those 3 are stale on main: they mock `captureTarget` and expect "Gateway requester authority changed" from the system-event and set-heartbeats handlers, which no longer throw it. They do not import any changed code path. - `pnpm tsgo:core`, `pnpm tsgo:test`: clean. oxfmt and oxlint on changed files: clean. - `pnpm check:changed`: all lanes green except the dead-export scan (`scripts/lib/docker-e2e-watchdog.mjs: parseTimeoutMs`, inherited from main; this PR does not touch it). - Lifetime-check ratchet: OK (0 in changed files). Session-identity ratchet: OK. ## Evidence One-admission E2E (isolated Gateway, real model) on head `ddbcdf98f7b6`, `verdict.json` `pass: true`: - R `running-turn-finishes`: pass (revoke while running → the turn finishes) - Q `queued-input-refused-visibly`: pass (revoke while queued → refused visibly in the transcript; 0 provider requests with the queued marker) - S `stop-cancels`: pass (Stop → `aborted`) Local review on `ddbcdf98f7b6`: "patch is correct", no findings. CI round 1 (`ddbcdf98f7b6`): `commands-compact.lifecycle.test.ts` (OURS: a mid-run operator refusal row, deleted above) and `server.chat-goal.test.ts` "lets an admitted owner Goal successor's tool effect finish after ownership is revoked". That test asserts the behavior this PR keeps, and it passes locally on the head (69/69, the same as in #204069 round 1). The round-2 push (`e01a0ebc21bb`) changes one test only, so the E2E above still applies: production code is the same. Co-authored-by: Ayaan Zaidi <[email protected]>
…203176) ## Problem A requester that calls `sessions_yield` after spawning several completion-mode subagents was woken only when every member of the frozen yield batch was ready. A sibling that keeps running, or that pauses on its own `sessions_yield` while a background command runs, held every finished result back. Production incident (2026-11-21): a dashboard parent spawned 3 children and yielded at 16:20 IST. Two children finished at 16:26:58 and 16:29:41 with reports that needed a decision. The third kept cycling through exec-yield and resume. The Gateway log has no `announce:requester-settle:…` run for that parent. The parent ran again only at 18:32, when the user typed into the chat. A copy of the state database shows why: both finished rows were `terminal`/`ok` with `delivery.status: pending` and a pending `requesterSettleWake` (`batchRunIds` = all 3, `rearmGeneration: 1`). The third row was still `running`. The gate in `subagent-announce.requester-settle-wake.ts` returned `false` unless every frozen member passed `isRequesterSettleMemberReady`. #200967 had already made an exception for siblings that wait for a message. An exec-yielded or running sibling is the same bug class. ## Change Rule: every ready result wakes the yielded parent. Siblings that are still working keep their wake, with the same `rearmGeneration`, and wake the parent again when they finish. Each result is delivered once. - **Settle wake:** removed the all-or-nothing gate and the message-wait exception (`isEndedSubagentMessageWait` is deleted). The wake delivers the ready members of the frozen batch as one partition, and lists the members that are still working. A member whose partition has already started dispatch records its own batch, so a later partition never offers it again. When a partition holds only results that were already delivered and siblings are still pending, it settles without a redundant wake. - **Wake message:** a partition that leaves members pending no longer says "every subagent has settled… do not call sessions_yield again". It names the siblings that are still working (label, task name or run ID, at most 5, each truncated) and tells the parent: if the request needs those results, call `sessions_yield` to wait; otherwise act on the ready results without reporting the batch as finished. - **Lifecycle failure path:** `offeredBatch` now offers only ready members, so failure settlement can never consume the wake of a sibling that is still running or exec-yielded. - **Yield transfer:** when a child ended before the yield and a sibling is still running, `afterRelease` now schedules the settle for the finished child. Before, nothing woke the parent until the sibling ended. - **Followup owners** (`sessions_send` wait-for-reply, `agent-step`, nested `agent-run-subagent`): the caller is waiting for a single reply. Only the partition that leaves no member pending continues the followup. Earlier partitions wake the session as ordinary settle turns. `successor()` accepts that last partition as a subset of its cohort, so it no longer throws and records the result as a permanent failure. - **Automation authority:** a yield that carried cron-management authority keeps it for the partition that leaves no member pending. Earlier partitions run without borrowing it, and settling them shrinks the retained cohort instead of discarding the authority. - **Silent waits:** while siblings are still working, the parent may stay silent (`NO_REPLY`) and wait. Such a turn is not treated as a missing visible reply, so it is not retried. - **Goal return:** an earlier partition leaves the Goal cohort when it settles. The partition that settles the cohort last resumes the Goal once. - `isRequesterSettleMemberReady` moved to `subagent-run-liveness.ts`, its only owner, and replaces the deleted message-wait predicate. - Docs: `tools/subagents/announce.md` and `concepts/subagent-yield-handoff.md`. Product decisions, under the rules "no stranded user" and "no false done": - A stopped child is a settled outcome, so its report now wakes the parent right away instead of waiting for its siblings. - A followup caller gets one reply, after all results are in. The session itself is still woken for each result. ## Evidence **Regression test** (`subagent-registry.requester-wake.e2e.test.ts`, real registry, lifecycle, yield tool and wake entry point): spawn 2 children, yield, finish one, keep the other exec-yielded. The parent is woken with the finished result, and the wake names the working sibling. The sibling's continuation then wakes the parent again with only its own result. A sweep adds no third wake. A second case covers a child that ended before the yield, while the requester's turn held it. - Base `eb7ca3d33375`: both cases red (`expected [] to have a length of 1`: no wake). - Head: both cases green. **Owner tests:** cron authority (`requester-cron-authority.test.ts`: the early partition neither borrows nor consumes the authority, and the last partition is admitted with it), followup partition (`subagent-announce.requester-settle-followup.test.ts`: early partition runs with no followup successor, last partition carries it). Goal partition (`goal-continuation.test.ts`: early partition does not resume the Goal, last partition resumes it once). **Updated tests that asserted the all-at-once rule:** `requester-settle-cross-turn` (paused member), `subagent-control.worker` progress card (one wake per result; the card retires once), `requester-wake-settlement` (stopped child). **Real-Gateway E2E**, incident shape. Scratch `ocx src` Gateway under `env -i`, OpenAI `gpt-5.5` on the OpenClaw runtime. Parent spawns `alpha` (replies at once) and `beta` (`exec` with `background: true` running `sleep 90`, then `sessions_yield`), then yields. | | alpha ended | first parent wake | beta yielded | beta ended | second parent wake | |---|---|---|---|---|---| | base | 19:47:10 | **19:48:53** (one combined run, after beta) | 19:47:13 | 19:48:50 | none | | head | 19:40:08 | **19:40:11** (`announce:requester-settle:…:<alpha>:yield-1`) | 19:40:12 | 19:41:55 | 19:41:59 (`…:<beta>:yield-1`) | The parent's replies on head were `alpha: ALPHA-RESULT-7`, then `alpha: ALPHA-RESULT-7 / beta: BETA-RESULT-9`. The live Peanutto launchd pid and `openclaw.json` hash did not change. **Live sibling suites** (`subagent-yield-pause`, `subagent-followup-yield`, `subagent-yield-resume`, real OpenAI `gpt-5.5`): the same tests fail on base `eb7ca3d33375` and on this branch, with the same assertions (missing `completion.resultText` after a resumed or paused child completes, a Gateway shutdown timeout, an interim reply in the follow-up watch case; follow-up-yield failed 2 of 2 on base). One run of this branch showed a parent that wrote its final report as soon as the first result arrived; the wake message now says to keep waiting when the request needs the remaining results, and that failure no longer appears. The real-Gateway restart e2e files (`test/gateway-*-restart*.e2e.test.ts`) fail locally on base too (11 of 26 on base, 9 of 26 here, same assertions). **Gates:** `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt on the changed files. Every test file in `src/agents/subagents` and `goal-continuation.test.ts` was run across the unit-fast, infra, agents-support, spawn-boundary, core-isolated and e2e projects. Two infra tests failed once under host load and passed when run alone, on head and on base. ## Size Production code is +96 / −56. The gate, the message-wait exception and its predicate are deleted. The added lines are the partition support the old gate did not need: pending members in the message, the followup last-partition rule, Goal cohort shrink, and pre-yield scheduling, and cron-authority cohort shrink. A census of `batchRunIds`, `requesterYieldBatch`, the frozen branch and `selectConnectedSettledSubagentWave` found every remaining reader still in use. v8 coverage could not attribute lines under the compiled-worker test runner (0 files collected in two attempts), so the census was done by reading the code. ## Accepted edge cases - If a Goal cohort's last partition is rejected for an unrelated reason (for example, a rearm-generation mismatch), the Goal return stays retained until Stop or a lifecycle rotation. That is the same outcome as a failed final delivery today. - A nested requester whose early partition answers without yielding reports that answer to its parent. The later result wakes it again as a separate completion. ## Merge danger - **Two-way door.** No schema, stored-row or config change: the wake rows keep their existing fields and generation. A revert restores the all-at-once wake for every cohort, including rows written while this change ran. - **Blast radius:** requesters that yield on two or more completion children (dashboard, chat and nested subagent requesters). A defect here would show as an extra or a missing wake for the parent, not as a lost child result: every result stays saved in its child session. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 09d956b) Release adaptation: Kept stable QA Gateway fixture lifecycle; filtered intentionally silent partial-result wakes. Companion audit: #203222 selected. #204249, #204069, #204048, #203892, #202513, #198960 not applicable (refactors/test cleanup); #204260, #204178, #204098, #204089, #203839, #203271 missing in lane and not prerequisites. Co-authored-by: RomneyDa <[email protected]>
… (R6c part 4a) (openclaw#204069) ## Problem Authority is checked once, when work starts. A started run may finish; Stop cancels; data fences stay. After parts 1-3 (openclaw#203999, openclaw#204031, openclaw#204048), `src/auto-reply/**` still calls `operatorAuthority.assertCurrent()` mid-run in ~37 production files. This is part 4a of the agents/sessions/auto-reply refusal sweep. ## Fix Test for each site: can it fire when only a permission, approval or config changes while nothing about the run or data changes? Yes → authority re-check, deleted. No → Stop, run close or data fence, kept and reworded. `operatorAuthority.assertCurrent()` re-reads the requester's source (request/ingress lifetime, held reference, caller check). Stop is not lost: every site below already checks the run's own abort signal next to it, and `resolveFollowupAbortSignal` already folds `operatorAuthority.signal` into the queued run's abort signal and the reply operation's upstream signal. | Site | Kind | Action | |---|---|---| | `reply-agent-turn-preparation.ts` `assertOperatorCurrent` after the claim (×4) and the preflight-failure `beforeFreshMessageCommit` check | authority (queued start already re-admits through `prepareFollowupRunOperatorAuthority`, unchanged) | **deleted**; `operation.abortSignal` and lifecycle-generation checks stay | | same file, the one check before the mailbox claim | queued start + data fence: a retired cron delivery fence (`createCronCompletionDeliveryFence`) rides on the queued source's `assertCurrent` | **kept** (cut less, CI round 1: without it a retired cron follow-up was claimed and left session-controller cleanup pending, `cron/service.restart-delivery.test.ts`) | | `agent-runner-run.ts` (start + enqueue `assertCurrent`) | authority | **deleted**; lifecycle-generation check stays | | `agent-runner-execute.ts` stalled-turn continuation | authority | **deleted**; the recorded `operatorAuthority.signal` refusal stays (now an `aborted` read, no try/catch) | | `agent-runner-memory.ts` compaction `assertActive`, memory-flush `assertMemoryFlushCurrent` | authority | **deleted**; abort signal + `authorize()` stay | | `agent-runner-session-activity.ts` activity commit | authority (only input of its `assertCurrent` param) | **deleted** with the param | | `agent-runner-steer-adoption.ts`, `agent-runner-question-input.ts` | authority | **deleted**; abort signals stay | | `followup-delivery-tts.ts` (×2), `followup-turn-execution.ts` (×3) | authority | **deleted**; `turn.operation.abortSignal` stays | | `queue/delivery-context.ts`, `queue/enqueue.ts`, `queue/lifecycle.ts` (×2) | authority | **deleted**; cancellation/abort checks stay | | `reply-input-admission.ts`, `reply-source-admission.ts` | authority | **deleted**; abort, lifecycle generation and controller-operation fences stay | | `reply-source-binding.ts` | authority | **deleted**; source signal stays | | `reply-tool-authority-inbound.ts` incoming collaborative-steering participant | authority | **deleted**; host-issuer check `assertAdmittedRunOperatorAuthority` stays | | `reply-workspace.ts` + `get-reply.ts` plumbing | authority | **deleted** `operatorAuthority` param; preprocessing abort stays | | `get-reply.ts` (×2: after agent scope, before reset hooks) | authority | **deleted**; preprocessing abort stays | | `goal-continuation.ts` (×2), `goal-continuation-return.ts` (×2) | authority | **deleted**; eligibility, rearm-generation and session fences stay | Left unchanged: - `agents/worktrees/errors.ts` "GitHub publication worktree authority changed" (a registry data fence; reword planned: "GitHub publication worktree changed"). Cut less: its only expectation is in `gateway/github-publication.test.ts`, and the local review input scanner scans the whole touched file, including the base blob whose redaction fixture has a `user:password@` URL (trufflehog URI finding at line 403). Replacing the fixture still puts the old line in the reviewed input, so any PR that touches the file is refused until the scanner approves that synthetic value. - Split per the ~25-file rule (this PR touches 20 production files, +11/−59): `operatorAuthority.assertCurrent` callers in `channel-run-admission`, `commands-compact`, `conversation-label-generator`, `dispatch-from-config.{gather,lifecycle,prepare-context,prepare-delivery,prepare-operation}`, `get-reply-inline-actions`, `get-reply-run-admission`, `get-reply-run-context`, `get-reply.types`, `model-selection`, `request-native-subagent`, `session-event-{context,handoff,target}` (17 files) go to part 4a-2; the `src/agents/**` callers are part 4b. ## User impact - A requester whose access changes while their reply runs (preparation, compaction, memory flush, steering, TTS, goal continuation) sees the turn finish. The next request is admitted again. - Queued input still re-admits at its start (`prepareFollowupRunOperatorAuthority`), so revoke-while-queued stays a visible refusal. - Stop still cancels. - No new refusal, prompt or wait. ## Tests Deleted (they assert a mid-run permission refusal through `assertCurrent`): - `agent-runner-memory.test.ts` `operator` invalidation row; `agent-runner-memory.accounting.test.ts` "rechecks live authority after delayed … accounting". - `agent-runner.stalled-turn.test.ts` "unrecorded refusal" row (the recorded-revocation row stays). - `agent-runner-direct-runtime-config.test.ts` "refused during preflight" and "revoked while resolving input" rows. - `get-reply.workspace-failure.test.ts` operator-revocation half (the abort half stays). - `agent-runner-steer-adoption.worker.test.ts` "keeps refused pre-handoff steering …" (used `assertCurrent` as the fault trigger). - `goal-continuation.test.ts` `revoked` row; `queue/enqueue.steering.test.ts` "rechecks channel execution authority after waiting …" and "queues an unaccepted steer after an unrecorded authority refusal". - `agent-runner-fallback-steering.test.ts` `backend-ready` + `caller revoked` row (the fingerprint rows still pass through agents-side readers, part 4b). - `reply-agent-turn-preparation.test.ts` `revoked=true` row (operator signal abort during a mocked admission; real admissions follow it through the upstream signal) and the `assertCurrent` call-count expectation. Pre-push (local): - CI round 1 (`3c3c172b476d`): OURS `cron/service.restart-delivery.test.ts` teardown (fixed above by cutting less) and `server.chat-goal.test.ts` "lets an admitted owner Goal successor's tool effect finish" (69/69 pass locally on the fix head). Rerun of both plus `reply-agent-turn-preparation.test.ts`: 125/125 pass. - `ocx test` with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 33 related test files (every direct importer test that builds an operator authority, plus the touched tests; the 382-file direct importer set is over the 150 cap, so CI runs the rest). 16 reds, all mid-run refusals through `assertCurrent`; deleted as listed above. Rerun of all 10 touched test files: 282/282 pass. - `pnpm tsgo:core`, `pnpm tsgo:test`: clean. oxfmt and oxlint on changed files: clean. - lifetime-check ratchet: OK (0 in changed files). session-identity ratchet: OK. ## Evidence One-admission E2E (isolated Gateway, real model) on head `3094468004d1` (and before on `3c3c172b476d`), `verdict.json` `pass: true` both times: - R `running-turn-finishes`: pass (revoke while running → the turn finishes; 3 tool ends after revoke) - Q `queued-input-refused-visibly`: pass (revoke while queued → refused visibly in the transcript) - S `stop-cancels`: pass (Stop → aborted) Local review: "patch is correct", no findings, on `3c3c172b476d` and on `3094468004d1`. Co-authored-by: Ayaan Zaidi <[email protected]>
… session events (R6c part 4a-2) (openclaw#204105) ## Problem Authority is checked once, when work starts. A started run may finish, Stop cancels it, and data fences stay. After parts 1-3 and 4a (openclaw#203999, openclaw#204031, openclaw#204048, openclaw#204069), 17 files in `src/auto-reply/**` still call `operatorAuthority.assertCurrent()` while a run is in progress. This is part 4a-2 of the refusal sweep for agents, sessions and auto-reply. Part 4b (`src/agents/**`) runs separately. ## Fix The test for each site: can it fire when only a permission, approval or config changes, while nothing about the run or its data changes? If yes, it is an authority re-check, and this PR deletes it. If no, it is Stop, run close or a data fence, and this PR keeps it. `operatorAuthority.assertCurrent()` reads the requester's source again (request or ingress lifetime, held reference, caller check). Stop still works: every site below keeps its own abort-signal, lifecycle-generation, session-data or occurrence check. Where a reply has one, the reply's upstream signal already includes `operatorAuthority.signal`. | Site | Kind | Action | |---|---|---| | `dispatch-from-config.gather.ts`: `assertRequestCurrent` (session lookups ×3, progress check), check after runtime/TTS preparation | authority | **deleted**; abort signal, dispatch signal and lifecycle generation stay | | `dispatch-from-config.lifecycle.ts` / `.prepare-operation.ts` `assertRequestCurrent`: the `replyOptions.operatorAuthority` branch | authority | **deleted**; the reserved input's own source (`sourceAdapter.authority`) is kept as the queued-start check before the claim, the same as in 4a. `internalEventExecution`, channel authority, retirement and abort checks stay | | `dispatch-from-config.prepare-context.ts`, `.prepare-delivery.ts` | authority | **deleted**; pre-dispatch abort stays | | `get-reply-inline-actions.ts` (before an inline tool, before commands) | authority | **deleted**; abort stays | | `get-reply-run-admission.ts` preparation assertion | authority | **deleted** from the composition; internal-event and scheduled-automation sources (cron fence) stay | | `get-reply-run-context.ts` scheduled path | authority | **deleted**; `scheduledAutomation.assertCurrent()` (cron run fence) and abort signals stay | | `get-reply.types.ts` `prepareInternalGetReplyOptions` | authority | **deleted**; the host-issuer check `assertAdmittedRunOperatorAuthority` stays | | `model-selection.ts` (entry, reset `commitGuard`, `assertSelectionCurrent`) | authority | **deleted**; host-issuer check, model-policy checks and the session-entry/selection data fence stay | | `request-native-subagent.ts` (invocation `assertCurrent`, accepted-child `assertSourceCurrent`) | authority | **deleted**; guard, abort, state and `owner.assertOwnerCurrent` stay | | `session-event-context.ts` (event preparation, owner successor `isCurrent`) | authority | **deleted**; the occurrence assertion and `operatorAuthority.signal` (Stop) stay | | `session-event-handoff.ts` (`assertOwnerCurrent`, `captureSources`) | authority | **deleted**; settlement, acceptance, target, scheduled-automation, generation-lease, controller-operation and config-policy fences stay | | `session-event-target.ts` (capture entry, `assertCaptureCurrent`) | authority | **deleted**; host-issuer check, capture/producer assertions and caller-occurrence checks stay | | `commands-compact.ts` (entry, before acceptance) | authority | **deleted**; `rejectUnauthorizedCommand` at start, owner and current-read fences stay | | `conversation-label-generator.ts` | authority | **deleted**; caller assertion, abort and model-policy check stay | | `channel-run-admission.ts` `assertSourceCurrent` before admission | authority | **deleted**; caller's `assertSourceCurrent` and closed checks stay | Left unchanged: - `reply-agent-turn-preparation.ts` pre-claim check: the 4a cut-less site (cron delivery fence). - `agents/worktrees/errors.ts`: parked (see openclaw#204069). - No production authority-refusal strings remain in `src/auto-reply/**` or `src/sessions/**`. The lifetime-check ratchet reports 0 in changed files. ## User impact - A requester whose access changes while a reply is being prepared (dispatch, model selection, inline actions, `/compact`, native subagents, session events, label generation) sees the turn finish. The next request goes through admission again. - Queued input still goes through admission again when it starts, so a revoke while queued is still refused visibly. - Stop still cancels. - No new refusal, prompt or wait. ## Tests Deleted (they assert a mid-run permission refusal through `assertCurrent`): - `model-selection.test.ts` `authority` row of "rejects a changed … after awaiting missing-pin provider facts" (the pin/source/provider/session data rows stay). - `commands-compact.lifecycle.test.ts` `adoption`/`operator` row of "rechecks … authority for … before effects" (CI round 1; the caller, plugin-owner, writer, invocation and session rows stay). - `session-event-config-readmission.test.ts` "finalizes a failed-before-reply event …": only the assertion that the operator source is re-read after its policy scope closes; the failed-outcome assertions stay. Pre-push (local): - `ocx test` with `OPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1` on 61 related test files: every importer test of a changed file that builds an operator authority or tests revocation, plus the direct tests of the changed modules. The full set of 180 importers is over the 150 cap, so CI runs the rest. Reds: the two rows above (fixed; rerun 47/47 pass), and `gateway/server-methods/system-event-routing.test.ts` (3 tests). Those 3 are stale on main: they mock `captureTarget` and expect "Gateway requester authority changed" from the system-event and set-heartbeats handlers, which no longer throw it. They do not import any changed code path. - `pnpm tsgo:core`, `pnpm tsgo:test`: clean. oxfmt and oxlint on changed files: clean. - `pnpm check:changed`: all lanes green except the dead-export scan (`scripts/lib/docker-e2e-watchdog.mjs: parseTimeoutMs`, inherited from main; this PR does not touch it). - Lifetime-check ratchet: OK (0 in changed files). Session-identity ratchet: OK. ## Evidence One-admission E2E (isolated Gateway, real model) on head `ddbcdf98f7b6`, `verdict.json` `pass: true`: - R `running-turn-finishes`: pass (revoke while running → the turn finishes) - Q `queued-input-refused-visibly`: pass (revoke while queued → refused visibly in the transcript; 0 provider requests with the queued marker) - S `stop-cancels`: pass (Stop → `aborted`) Local review on `ddbcdf98f7b6`: "patch is correct", no findings. CI round 1 (`ddbcdf98f7b6`): `commands-compact.lifecycle.test.ts` (OURS: a mid-run operator refusal row, deleted above) and `server.chat-goal.test.ts` "lets an admitted owner Goal successor's tool effect finish after ownership is revoked". That test asserts the behavior this PR keeps, and it passes locally on the head (69/69, the same as in openclaw#204069 round 1). The round-2 push (`e01a0ebc21bb`) changes one test only, so the E2E above still applies: production code is the same. Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
Authority is checked once, when work starts. A started run may finish; Stop cancels; data fences stay. After parts 1-3 (#203999, #204031, #204048),
src/auto-reply/**still callsoperatorAuthority.assertCurrent()mid-run in ~37 production files.This is part 4a of the agents/sessions/auto-reply refusal sweep.
Fix
Test for each site: can it fire when only a permission, approval or config changes while nothing about the run or data changes? Yes → authority re-check, deleted. No → Stop, run close or data fence, kept and reworded.
operatorAuthority.assertCurrent()re-reads the requester's source (request/ingress lifetime, held reference, caller check). Stop is not lost: every site below already checks the run's own abort signal next to it, andresolveFollowupAbortSignalalready foldsoperatorAuthority.signalinto the queued run's abort signal and the reply operation's upstream signal.reply-agent-turn-preparation.tsassertOperatorCurrentafter the claim (×4) and the preflight-failurebeforeFreshMessageCommitcheckprepareFollowupRunOperatorAuthority, unchanged)operation.abortSignaland lifecycle-generation checks staycreateCronCompletionDeliveryFence) rides on the queued source'sassertCurrentcron/service.restart-delivery.test.ts)agent-runner-run.ts(start + enqueueassertCurrent)agent-runner-execute.tsstalled-turn continuationoperatorAuthority.signalrefusal stays (now anabortedread, no try/catch)agent-runner-memory.tscompactionassertActive, memory-flushassertMemoryFlushCurrentauthorize()stayagent-runner-session-activity.tsactivity commitassertCurrentparam)agent-runner-steer-adoption.ts,agent-runner-question-input.tsfollowup-delivery-tts.ts(×2),followup-turn-execution.ts(×3)turn.operation.abortSignalstaysqueue/delivery-context.ts,queue/enqueue.ts,queue/lifecycle.ts(×2)reply-input-admission.ts,reply-source-admission.tsreply-source-binding.tsreply-tool-authority-inbound.tsincoming collaborative-steering participantassertAdmittedRunOperatorAuthoritystaysreply-workspace.ts+get-reply.tsplumbingoperatorAuthorityparam; preprocessing abort staysget-reply.ts(×2: after agent scope, before reset hooks)goal-continuation.ts(×2),goal-continuation-return.ts(×2)Left unchanged:
agents/worktrees/errors.ts"GitHub publication worktree authority changed" (a registry data fence; reword planned: "GitHub publication worktree changed"). Cut less: its only expectation is ingateway/github-publication.test.ts, and the local review input scanner scans the whole touched file, including the base blob whose redaction fixture has auser:password@URL (trufflehog URI finding at line 403). Replacing the fixture still puts the old line in the reviewed input, so any PR that touches the file is refused until the scanner approves that synthetic value.operatorAuthority.assertCurrentcallers inchannel-run-admission,commands-compact,conversation-label-generator,dispatch-from-config.{gather,lifecycle,prepare-context,prepare-delivery,prepare-operation},get-reply-inline-actions,get-reply-run-admission,get-reply-run-context,get-reply.types,model-selection,request-native-subagent,session-event-{context,handoff,target}(17 files) go to part 4a-2; thesrc/agents/**callers are part 4b.User impact
prepareFollowupRunOperatorAuthority), so revoke-while-queued stays a visible refusal.Tests
Deleted (they assert a mid-run permission refusal through
assertCurrent):agent-runner-memory.test.tsoperatorinvalidation row;agent-runner-memory.accounting.test.ts"rechecks live authority after delayed … accounting".agent-runner.stalled-turn.test.ts"unrecorded refusal" row (the recorded-revocation row stays).agent-runner-direct-runtime-config.test.ts"refused during preflight" and "revoked while resolving input" rows.get-reply.workspace-failure.test.tsoperator-revocation half (the abort half stays).agent-runner-steer-adoption.worker.test.ts"keeps refused pre-handoff steering …" (usedassertCurrentas the fault trigger).goal-continuation.test.tsrevokedrow;queue/enqueue.steering.test.ts"rechecks channel execution authority after waiting …" and "queues an unaccepted steer after an unrecorded authority refusal".agent-runner-fallback-steering.test.tsbackend-ready+caller revokedrow (the fingerprint rows still pass through agents-side readers, part 4b).reply-agent-turn-preparation.test.tsrevoked=truerow (operator signal abort during a mocked admission; real admissions follow it through the upstream signal) and theassertCurrentcall-count expectation.Pre-push (local):
3c3c172b476d): OURScron/service.restart-delivery.test.tsteardown (fixed above by cutting less) andserver.chat-goal.test.ts"lets an admitted owner Goal successor's tool effect finish" (69/69 pass locally on the fix head). Rerun of both plusreply-agent-turn-preparation.test.ts: 125/125 pass.ocx testwithOPENCLAW_NODE_TEST_PLAN_CONTINUE_ON_FAILURE=1on 33 related test files (every direct importer test that builds an operator authority, plus the touched tests; the 382-file direct importer set is over the 150 cap, so CI runs the rest). 16 reds, all mid-run refusals throughassertCurrent; deleted as listed above. Rerun of all 10 touched test files: 282/282 pass.pnpm tsgo:core,pnpm tsgo:test: clean. oxfmt and oxlint on changed files: clean.Evidence
One-admission E2E (isolated Gateway, real model) on head
3094468004d1(and before on3c3c172b476d),verdict.jsonpass: trueboth times:running-turn-finishes: pass (revoke while running → the turn finishes; 3 tool ends after revoke)queued-input-refused-visibly: pass (revoke while queued → refused visibly in the transcript)stop-cancels: pass (Stop → aborted)Local review: "patch is correct", no findings, on
3c3c172b476dand on3094468004d1.