Repository navigation
fix(channels): scope HTTP routes to account lifetimes - #133297
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 6:29 AM ET / 10:29 UTC. ClawSweeper reviewWhat this changesThis PR binds dynamically registered Gateway HTTP routes to channel account start and stop attempts so abandoned callbacks cannot retain or replace recovered ingress. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep this PR open. Current main still lacks the channel-account route lease, and the introduced lifecycle and registry changes address that gap without a concrete correctness or security defect found; the stale test-merge snapshot means final integration should be refreshed against current main before landing. Priority: P1 Review scores
Verification
How this fits togetherChannel plugins register HTTP ingress in the Gateway’s plugin route registry while account lifecycle code starts, stops, and recovers accounts. The lease makes route registration expire with the owning lifecycle attempt while preserving static plugin routes owned by the registry. flowchart LR
A[Channel account lifecycle] --> B[Start or stop attempt]
B --> C[Capability lease]
C --> D[Gateway route registry]
D --> E[HTTP ingress handler]
B --> F[Timed-out recovery]
F --> C
C --> G[Route cleanup or retained owner]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +25, Tests +245, Docs +2. Total +272 across 10 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the generic lifecycle lease only after current-main integration confirms that start and stop routes cannot be resurrected by abandoned callbacks while registry-owned static routes remain intact. Do we have a high-confidence way to reproduce the issue? Yes, source reproducibly identifies the timed-out account task retaining its route while recovery starts a replacement; the introduced test encodes start and stop variants through a real loopback Gateway HTTP server, though this review did not execute contributor code. Is this the best way to solve the issue? Yes, the shared lease at the channel lifecycle and route-registry boundary is preferable to restoring per-plugin route replacement because it revokes stale authority centrally and retains genuine cross-owner conflict checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 90dba1a51877. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
Give each bounded channel stop attempt an independent route lease, preserve static API route ownership when borrowed by dynamic callers, and remove redundant shared-holder state. Exercise late callbacks through the real Gateway HTTP server after successful and failed replacement. Co-authored-by: zhang-guiping <[email protected]>
|
@clawsweeper re-review The improved head adds an independent bounded lease for stop hooks and preserves registry-owned static routes when borrowed by dynamic callers. Six original-order failures were reproduced before repair; 232 owner/sibling tests, real Gateway HTTP recovery checks, all changed-file gates, the full build, and fresh independent review pass. The body records the remaining live-channel limitation and the documented failed-replacement behavior. Please review the current head. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
The escaped-output fixture previously announced readiness before its IPC handshake finished. A watchdog could kill the parent first, causing an unhandled EPIPE and invalidating the intended live-pipe cleanup scenario. Publish readiness from the disconnect event after the handshake. The original whole-file run passed 50 tests; forcing that ordering reproduced the exact CI assertion failure. The repaired whole file passes 50 tests under normal scheduling and 50 with the same forced ordering. Deadlines, cleanup assertions and production code are unchanged. Co-authored-by: zhang-guiping <[email protected]>
|
Merged via squash.
|
* fix: prevent channel recovery crash-loops after timed-out stops * fix(channels): bind shutdown routes to their lifetime Give each bounded channel stop attempt an independent route lease, preserve static API route ownership when borrowed by dynamic callers, and remove redundant shared-holder state. Exercise late callbacks through the real Gateway HTTP server after successful and failed replacement. Co-authored-by: zhang-guiping <[email protected]> * test(scripts): publish escaped child readiness after IPC closes The escaped-output fixture previously announced readiness before its IPC handshake finished. A watchdog could kill the parent first, causing an unhandled EPIPE and invalidating the intended live-pipe cleanup scenario. Publish readiness from the disconnect event after the handshake. The original whole-file run passed 50 tests; forcing that ordering reproduced the exact CI assertion failure. The repaired whole file passes 50 tests under normal scheduling and 50 with the same forced ordering. Deadlines, cleanup assertions and production code are unchanged. Co-authored-by: zhang-guiping <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: zhang-guiping <[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` (#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` (#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 `1a0a24dcd2cf`. 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): #203572 (comment)
- Local review rejected finding: #203572 (comment)
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]>
Closes #132886
What Problem This Solves
Channel recovery can repeatedly fail when a timed-out account task leaves its HTTP route behind. Account start tasks and bounded stop attempts now own separate revocable route leases. Recovery revokes abandoned ownership before admitting a replacement, so late callbacks cannot replace the new handler or restore withdrawn ingress.
The maintainer pass also fixes two gaps in the initial implementation: asynchronous stop hooks run in the correct Gateway registry, and dynamic callers borrowing a static
api.registerHttpRouteentry cannot remove it during cleanup. Shared dynamic routes retain independent holders. Zalo now uses that central lifetime owner, removing its separate reference count and redundant cleanup state.Evidence
node scripts/check-changed.mjs -- <all nine changed files>passes formatting, production/test type checks, lint, SDK boundaries, import-cycle checks and repository guards. The full production build passes; all five production source hashes match the final candidate.The first published-head CI run exposed a separate escaped-output test race: the fixture published readiness before finishing IPC, allowing timeout cleanup to kill its parent and cause an unhandled
EPIPE. The fixture now publishes readiness from itsdisconnectevent. The original full file passed 50 tests, and forcing the bad ordering reproduced the exact CI assertion failure. The repaired full file passes all 50 tests under both normal and forced ordering, with every original assertion and deadline preserved. All selected script/test gates and a fresh full-candidate managed review pass. This test-only correction adds three net lines and is published indf64c6993078b4c42c70af135d29d5b857d61b30; CI on this exact commit now passes. The September1 10:18UTC ClawSweeper review has no actionable findings; its remaining exact-head CI move is satisfied.These runs use an isolated Linux worker and synthetic channel hooks. Gateway HTTP behavior is real; external Zalo account traffic is not exercised.
When replacement preflight fails, abandoned ingress stays withdrawn and the account records its stopped/error state. The plugin architecture documentation now explains this availability behavior and the distinction between registry-owned static routes and shared dynamic routes. Existing stop deadlines and recovery ordering are preserved.
Whole-PR production delta is +162/−137, net +25; tests/support +303/−58, docs +2. The shared 38-line capability primitive moves out of services so account callbacks and service lifetimes use the same revocation mechanism; a service-only scope cannot represent a settled start task and its later independent stop attempt. The maintainer repair itself adds three net production lines: independent shutdown ownership is offset by simpler registry state. Configuration, schemas, persistence and public API surfaces are unchanged.
Thanks @zhangguiping-xydt for the original repair.