Repository navigation
fix(gateway): hot config reloads no longer cancel accepted runs - #160909
Conversation
Separate transport policy fencing from each admitted principal's access grant. Keep accepted runs, queued inputs, and delegated effects alive across proxy policy reloads; revoke them when identity grants, allowlist membership, admission methods, or their shared credential end. Preserve proxy handshake generations and ordinary token/password rotation, including the local proxy password fallback. Keep role-policy enforcement with run authority and document reconnect behavior.
|
🦞👀 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. Reviewed September 29, 2026, 3:36 AM ET / 07:36 UTC (Revision 7). ClawSweeper reviewWhat this changesThe branch changes Gateway hot reloads so clients reconnect after transport-policy edits while accepted runs continue under their original live grants, with regression tests and operator documentation. Merge readiness✅ Ready for maintainer review Keep open. Current main still revokes accepted work when certain Gateway transport settings change, and this branch addresses that distinct problem. The reviewed authority paths and recorded final-effect proof support the fix; I found no discrete introduced defect. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway authenticates WebSocket clients and applies configuration changes to live connections. Accepted requests then pass to session and run owners, which must either continue the work or cancel it when its access grant ends. flowchart LR
A[Client request] --> B[Gateway authentication]
C[Committed config edit] --> D[Reload policy]
B --> E[Captured access grant]
D --> F[Reconnect decision]
D --> G[Grant recheck]
E --> G
G --> H[Continue or cancel accepted work]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +248, Tests +863, Docs +9. Total +1120 across 28 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep reconnect fencing with the Gateway transport owner and grant revocation with the retained-authority owner, including checks before disconnected and initial-turn effects. Do we have a high-confidence way to reproduce the issue? Yes. Current main's reconciliation path shows the transport-to-source coupling, and the PR records a pre-fix failure and after-fix result at the managed reload boundary; this read-only review did not execute it. Is this the best way to solve the issue? Yes. The branch uses existing Gateway admission, reload-publication, and retained-source owners while preserving revocation before final effects. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b4ae783fbfd2. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
Retain handshake origin facts in the principal grant and recheck their current admission through the existing committed config publication. Origin revocation now cancels accepted execution after its socket and RPC have retired, while unrelated origin edits preserve the run. Keep origin-specific close responses. Prove the fenced-socket sequence with the managed reloader, dispatcher, and a real exec/file effect, including irreversible revocation after config restore. Follow-up to #160909.
Retain the auth resolver's fixed startup mode in the admitted principal and reapply it when reconstructing the access grant. A raw config snapshot no longer falsely fences connections whose effective startup auth mode is unchanged. Configured mode disablement and the existing source revocation checks remain. Repair the five real-Gateway CI suites and cover ordinary token requests across an unrelated config write through the real config IO owner. Follow-up to #160909.
…-runs # Conflicts: # src/gateway/server-methods/shared-types.ts
|
Merged via squash.
|
…its its row cap Since 32d3642 (#160909) the hybrid hourly Node plan needed 80 rows against its 79-row cap, failing keeps the hybrid hourly plan within the main-tier cap on main and in every PR's ci-gate. The new Gateway auth-policy test reshuffled four agent-chat stripes, and greedy initial packing then stranded three 140-second storage groups in separate rows. Hybrid initial packing now places exclusive serial Gateway groups before flexible parallel groups so parallel work fills the remaining space. The plan returns to 77 rows (75 Node + 2 dist); caps, budgets, timing baselines, and worker policies are unchanged.
…claw#160909) * fix(gateway): keep accepted runs alive across auth policy reloads Separate transport policy fencing from each admitted principal's access grant. Keep accepted runs, queued inputs, and delegated effects alive across proxy policy reloads; revoke them when identity grants, allowlist membership, admission methods, or their shared credential end. Preserve proxy handshake generations and ordinary token/password rotation, including the local proxy password fallback. Keep role-policy enforcement with run authority and document reconnect behavior. * fix(gateway): revoke detached runs when their browser origin is removed Retain handshake origin facts in the principal grant and recheck their current admission through the existing committed config publication. Origin revocation now cancels accepted execution after its socket and RPC have retired, while unrelated origin edits preserve the run. Keep origin-specific close responses. Prove the fenced-socket sequence with the managed reloader, dispatcher, and a real exec/file effect, including irreversible revocation after config restore. Follow-up to openclaw#160909. * fix(gateway): keep startup auth mode stable across config reads Retain the auth resolver's fixed startup mode in the admitted principal and reapply it when reconstructing the access grant. A raw config snapshot no longer falsely fences connections whose effective startup auth mode is unchanged. Configured mode disablement and the existing source revocation checks remain. Repair the five real-Gateway CI suites and cover ordinary token requests across an unrelated config write through the real config IO owner. Follow-up to openclaw#160909. * fix(gateway): retain grants for committed initial turns
…its its row cap Since 730285d (openclaw#160909) the hybrid hourly Node plan needed 80 rows against its 79-row cap, failing keeps the hybrid hourly plan within the main-tier cap on main and in every PR's ci-gate. The new Gateway auth-policy test reshuffled four agent-chat stripes, and greedy initial packing then stranded three 140-second storage groups in separate rows. Hybrid initial packing now places exclusive serial Gateway groups before flexible parallel groups so parallel work fills the remaining space. The plan returns to 77 rows (75 Node + 2 dist); caps, budgets, timing baselines, and worker policies are unchanged.
What Problem This Solves
Fixes: every in-flight agent run on a Gateway is cancelled (
authority-revoked) when a committed hot reload changes authentication transport policy, even though no connected owner's access changed. Observed on the Team Gateway on 2026-09-28: a file edit ofgateway.auth.trustedProxy.cloudflareAccessOidcclosed every client with 4001 "gateway policy changed" and aborted every running turn, queued input, and subagent follow-up within one second, with no visible notice in the chat.Related: #154461, #154792
User Impact
Operators can update proxy headers, OIDC mapping, trusted proxy addresses, IP fallback, or device auto-approval without losing accepted runs, queued inputs, or delegated work whose original grant remains valid. Existing connections may close with code 4001 and must reauthenticate before sending new requests. Removing the owner's identity-scope grant, proxy allowlist membership, or admitted browser origin, or disabling its admission method, still cancels accepted work; restoring the grant does not revive it.
Why This Change Was Made
Connection policy now carries separate transport and principal-grant fingerprints. Admission fences stale transports, while retained source authority follows committed grant changes, including after disconnect. Shared-generation publication receives the previous and next runtime configurations so proxy policy changes do not masquerade as credential rotation; allowlist revocations reach only affected retained principals.
Roles decision:
gateway.rolesstays outside the connection grant because each accepted run already enforces its assigned source-role policy and model ceiling through the existing run-authority owner.Fence choice: preserve the existing broad transport fingerprint and proxy generation hash so policy changes require a new handshake without reconstructing admission from incomplete request facts; unrelated identity-scope edits and reordered grants keep the connection open.
Credential-rotation exception: changing the effective shared token/password still revokes sources and publishes generation invalidation exactly as before, cancelling work admitted with the old credential. Explicit all-source revocation is also unchanged. Trusted-proxy local password fallback carries its own hashed credential grant because the proxy transport hash omits that password; rotation revokes fallback-authenticated work without revoking proxy identities.
Origin-grant decision: browser-origin admission is part of the principal grant. The handshake captures immutable
requestHost,origin, andisLocalClientfacts; the grant fingerprints the existing origin check's result under current configuration. This includes inheritedpublicOriginand host-header fallback policy. Committed config publication already rechecks retained source authority after socket and RPC retirement, so no new hook or store is needed. Removing an unrelated origin leaves the grant unchanged, and origin-specific close responses are preserved.Evidence
Current initial-turn validation head:
2db5b714c829239d155993162942d206e6694c85(fourth commit; pushed by the coordinator, CI on that head pending at the time of writing).Current initial-turn follow-up: 23 suites, 300 tests passed, zero failures (271.14 s command wall), all four tsgo lanes passed, and one independent P2 autoreview ended
scoped-clean. No CI workflow was dispatched for this local validation; the pushed head's PR CI runs normally.Prior CI-repair validation head:
e5171afa7811069fd3c0f7f67bbeb38558fd0b5d(third commit; pushed by the coordinator).Prior origin-grant follow-up validation head:
d13d79b82a81631e70eaf83528043c2ee3751365.The pre-fix managed-reload regression failed in both grant-removal cases immediately after the OIDC reload: the accepted authority signal was aborted. The repaired regression uses a real operator authority and exec effect, removes the closed socket from the live-client set, survives OIDC followed by required-header reloads, and then proves irreversible revocation on scope or allowlist removal.
Independent review identified the local password fallback edge case. Its added regression failed before the repair (11 passed, 1 failed), then passed after the grant-owner repair (12 passed). Validation results and measured test costs follow below. No live Gateway was modified. No CI workflow was dispatched for this follow-up; CI seconds for the new unpushed head are unavailable.
Current CI-repair validation covers the five reported failing files and the earlier 13 suites: 18 suites, 238 tests passed, zero failures (207.58 s command wall time). The commands below are the per-file equivalents of the combined
node scripts/run-vitest.mjs <all 18 listed files> --maxWorkers=2invocation:node scripts/run-vitest.mjs src/gateway/server/ws-origin-policy.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server-reload-handlers.identity-scopes.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server/ws-connection/authenticated-request-dispatch.mutation-authority.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server-shared-auth-generation.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server-methods/config.shared-auth.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server-methods/chat-send-auth-policy.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server-reload-handlers.operator-model-policy.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server/ws-connection/message-handler.post-connect-health.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server/ws-shared-generation.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server.shared-token-hot-reload.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server-reload-managed-secrets.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server/ws-connection/authenticated-request-dispatch.policy-close.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server-aux-handlers.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server-startup-secret-owner-isolation.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server.health-store-scheduling.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server.channels-start-outcomes.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server.approval-request-lifetime.test.ts --maxWorkers=2node scripts/run-vitest.mjs src/gateway/server.worker-placement-startup-context.test.ts --maxWorkers=2Changed-test cost, measured serially with the required single-worker command (origin-policy and worker-placement costs refreshed for the CI repair; identity-scopes retains its origin-follow-up measurement and the other files retain their first-commit measurements):
pnpm test src/gateway/server/ws-origin-policy.test.ts --maxWorkers=1pnpm test src/gateway/server-reload-handlers.identity-scopes.test.ts --maxWorkers=1pnpm test src/gateway/server/ws-connection/authenticated-request-dispatch.mutation-authority.test.ts --maxWorkers=1pnpm test src/gateway/server-shared-auth-generation.test.ts --maxWorkers=1pnpm test src/gateway/server-methods/config.shared-auth.test.ts --maxWorkers=1pnpm test src/gateway/server-methods/chat-send-auth-policy.test.ts --maxWorkers=1pnpm test src/gateway/server.worker-placement-startup-context.test.ts --maxWorkers=1The managed-reload integration measured 66.33 s command wall time, including 7.742 s of test execution. It exercises the production dispatcher, committed reload publication, retained operator authority, native child launch, and filesystem effect held at the asynchronous prelaunch boundary; a cheaper mocked authority cannot prove this composition. That observable effect distinguishes preserved authority from a mock that merely remains un-aborted. Its refreshed 66.33 s command wall time includes compilation and fixture startup; no full Gateway boots, sleeps, or timer polling were added. Original baseline single-worker wall times were 52.56 s for ws-origin-policy and 77.03 s for identity-scopes; compilation/cache conditions differ, so these are cost measurements rather than a performance claim.
Typechecks passed (exit 0):
node scripts/run-tsgo.mjs -p tsconfig.core.jsonnode scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.gateway-root.jsonnode scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.gateway-server.jsonnode scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.gateway-methods.jsonPreparation:
node scripts/worktree-setup.mjs gatewaypassed. The gateway preparation excludes UI dependencies reached by two test type graphs;pnpm --filter openclaw-control-ui... install --frozen-lockfilerestored those existing dependencies, and all typechecks then passed without manifest or lockfile changes.Scoped oxlint,
node_modules/.bin/oxfmt <all changed files>, the correspondingoxfmt --check, andgit diff --checkpassed. The origin-grant follow-up received one independent Codex autoreview pass with--max-priority P2, which finished scoped-clean with no actionable P0–P2 findings. An old queued-chat expectation that IP-fallback edits cancel accepted work was updated to require transport fencing with the queue and authority preserved.No production Gateway replay or live deployment was performed; the incident proof uses the isolated managed-reloader and dispatcher with a real retained operator authority and real exec effect.
The following accounting remains unchanged for the original commit
08918a8b364dc; the follow-up is listed separately.Production line delta: +224/−54 across the gateway auth, reload, and dispatch owners (tests +474/−51, docs +20/−14). This is a security-boundary correctness fix; no unrelated cleanup was bundled to keep the auth change reviewable on its own.
Origin-grant regression on the prior head: 35 passed, 5 failed, including the retained exec authority remaining active after its origin was removed. The repaired regression removes an unrelated origin while the socket and RPC are absent from the client index and proves the real effect succeeds; it then removes the admitted origin, observes synchronous authority abort, restores the config, and proves the held effect is still denied.
Redacted excerpt from the passing regression (test-owned marker paths only):
Review disposition: installed-update/published-driver × candidate proof does not apply because this PR changes only running-Gateway hot-reload policy reconciliation, not
openclaw update, Doctor, service lifecycle, config shape, or migrations.Review disposition: additional live-production behavior proof is not required under the maintainer-authored exemption; this regression drives the production managed reloader and dispatcher, retains real operator authority, and checks a real exec/file effect, as shown above.
Origin follow-up line delta: production +41/−32 across six existing owners, tests +101/−4, docs +2/−0. No unrelated cleanup, new store, or new publication hook was added.
CI repair: exact-head run
36516232884exposed lost startup auth-mode provenance inserver-startup-secret-owner-isolation.test.ts,server.health-store-scheduling.test.ts,server.channels-start-outcomes.test.ts,server.approval-request-lifetime.test.ts, andserver.worker-placement-startup-context.test.ts(all undersrc/gateway/). The failures reproduced locally: 11 failed, 12 passed. The Gateways admitted clients under a fixedauth.mode: "none"startup override, while the RPC fixture republished a token-mode source snapshot. The transport fingerprint was unchanged and committed authority remained current, but grant reconstruction omitted the resolver's fixed override and changedmethodEnabledfrom true to false. The handshake now retains the resolver-attested override mode, and grant reconstruction applies it through the existing auth resolver. File-selected modes still revoke when disabled. No existing failing test or fixture-publication behavior was changed.The CI repair adds a real-Gateway token-client control that reads, writes an unrelated
messages.ackReactionScopekey through the real config IO owner, verifies the write throughconfig.get, and keeps issuing requests on the same connection. The new override-vs-file-mode unit case was red before the repair: 38 passed, 1 failed.The new real-Gateway control initially reached the fixture's stubbed write path, which reported an unclaimed
config.patch; it now calls the actual config-write owner with production startup enabled. Existing failure cases and fixture helpers remain unchanged. The final independent autoreview pass (--max-priority P2) was scoped-clean. The worker-placement file cost includes the existing production-startup worker test and the new real-Gateway/config-write case; that integration cannot be replaced by a mocked policy predicate without losing the admission-to-request boundary proof.CI-repair line delta: production +15/−2 across three existing owners; tests +62/−2 across two files. No new config option, manager, store, or compatibility path was added.
Exact final CI-repair test command:
All four tsgo lanes passed; the gateway-server lane was also rerun after the new fixture selected real config IO. Scoped oxlint, oxfmt/check,
git diff --check, and one P2 autoreview pass were clean. No CI workflow was dispatched for that local validation.Initial-turn follow-up:
sessions.createcommitted its new row but carried transport-bound mutation guards into the requested initial turn. A transport-only reload could therefore strand that turn after session creation. The existing request source owner now records a one-way acceptance at the new-row commit, so the original callback and mutation guards follow retained source authority for that continuation. The turn receives the existing transport-independent principal snapshot; profile, role, session target, device, explicit cancellation, and hosted-child custody checks remain intact. Only a live, retained source can enter this phase, and releasing its final holder ends that authority even while the socket remains open. No new store, manager, config option, or hook was added.The finalized real-Gateway regression admits two explicit non-main
sessions.createrequests before one committed transport fence. Both initial turns reach dispatch; one persists its real user transcript and reaches the provider boundary, while rotating the shared token before the other's persistence attempt denies that final write and leaves its transcript absent. The fixture waits for the production config-write application receipt, not merely file persistence, before checking either outcome. On the previous head the finalized regression fails withinitial turn retired before dispatch(1 failed, 0 passed;pnpm test src/gateway/server.sessions.create.auth-policy.test.ts --maxWorkers=1, 54.72 s wall); with the owner repair the focused regression passes (1 passed, 0 failed). Earlier fixture iterations incorrectly used an asynchronous synchronous-hook callback and did not await runtime application; those fixture issues were corrected without weakening the grant assertions.The original, origin-grant, and CI-repair production LOC statements above remain unchanged. Initial-turn follow-up delta: production +62/−6 across three existing owners, tests +283/−0 across two files, docs +2/−1. The production growth carries the commit-to-initial-turn phase through existing guards; it does not change ordinary request fencing or hosted child admission.
The final follow-up reran every earlier suite at the same counts shown above, plus:
src/gateway/device-revocation.test.tssrc/gateway/server.sessions.create.auth-policy.test.tssrc/gateway/server-methods/sessions-create.child-custody.test.tssrc/gateway/server.sessions.create.dispatch.test.tssrc/gateway/server.sessions.create.authority.test.tsExact final test invocation (wrapped with
/usr/bin/time -p):The four typecheck commands listed above all passed on the repair. Scoped oxlint,
node_modules/.bin/oxfmtandoxfmt --checkon the six changed files, andgit diff --checkpassed. The independent review command was.agents/skills/autoreview/scripts/autoreview --mode local --engine codex --max-priority P2 --dataset .local/initial-turn-review-context.md; its machine result wasscoped-clean, exit 0, with no actionable P0–P2 findings. The ignored review context supplied the relevant unchanged authority, dispatch, creation, and config-application owners.This regression boots one isolated Gateway for two accepted initial turns and verifies real transcript writes; inference is mocked. No production Gateway or live model call was exercised; CI seconds for the fourth commit follow from its PR run.
Changed-test cost for the initial-turn follow-up:
pnpm test src/gateway/server.sessions.create.auth-policy.test.ts --maxWorkers=1pnpm test src/gateway/device-revocation.test.ts --maxWorkers=1The integration shares one Gateway and two admitted initial turns. Its real WebSocket/session commit, managed config application, source handoff, and durable transcript boundary are the contract under test; a direct predicate test cannot establish that composition. No sleeps, polling, per-case Gateway boots, or worker pin were added. Wall time includes fixture startup and compilation, varies with host load, and is recorded as cost rather than a performance claim.