Skip to content

fix(gateway): avoid stale wake delays after node re-pairing - #109647

Merged
steipete merged 33 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-removing-a-paired-node-leaves-wake-throttle-and-nudge-state-behi
Jul 21, 2026
Merged

steipete merged 33 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-removing-a-paired-node-leaves-wake-throttle-and-nudge-state-behi

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Removing, revoking, reapproving, pruning, or replacing a paired node could leave process-local runtime authority behind. A retired transport could remain visible to dispatch or projections, stale pending/wake state could be inherited by a same-ID replacement, and APNs work could outlive the pairing generation that authorized it.

Why This Change Was Made

The repair makes durable pairing state the canonical owner of node transport authority:

  • Internal registry sessions always carry the authenticated pairing identity. Approved surfaces additionally carry the exact pairing generation, and registry dispatch uses an exact session/connection/identity/generation lease.
  • Shared pairing projection, wake lifecycle, and runtime cleanup live at infra or gateway owner boundaries rather than under RPC handlers. WebSocket, Watch, pruning, and server methods call the same owners.
  • Pairing removal and APNs ownership deletion remain in one SQLite transaction. Runtime cleanup is driven from that mutation result without adding a second persistence owner.
  • Pending work, wake/nudge state, subscriptions, remote node/skill/bin projections, presence, notifications, and inbound/outbound node operations reuse the existing registry, generation, cache, dispatch, and persistence flows.
  • Detached voice and agent work repeat connection-currentness fences before durable or process-local mutation, and rejected attachment media is cleaned up.
  • APNs delegates CONNECT routing, proxy authentication/TLS, timeout, cancellation, and socket lifecycle to @openclaw/proxyline 0.3.4; OpenClaw no longer carries a parallel CONNECT implementation.

Maintainer decision: pairing generation is the canonical ownership boundary for approved node authority. Pairing identity remains the boundary for authenticated pre-approval sessions, while connection ID selects the exact live transport.

User Impact

A removed or replaced node can no longer continue using retired transport authority, send or consume replacement-owned work, retain stale wake delays, refresh replacement presence, advertise stale remote capabilities, expose retired node-hosted tools or skills, or leave proxy/APNs connection setup running after its pairing is invalidated. Ordinary same-generation reconnects continue to retain state that belongs to the same pairing.

Evidence

Exact reviewed head: 5912f471675c7d7801c2c70b5761212467edea39.

Lifecycle matrix:

Transition Registry and route Pending work Wake and APNs Subscriptions and projections Presence
Same-generation reconnect New connection ID becomes current; stale routes cannot dispatch Preserved under the same generation Same-generation state remains valid Preserved and rebound to the current connection Old connection cannot update activity
Live surface approval promotes G1 to G2 Exact live session is promoted after persistent recheck G1 work remains isolated from G2 G1 lifecycle is invalidated; G2 receives a new owner Subscription and active-node leases are rebound to G2 First G2 heartbeat is not throttled by G1
Token rotation, revocation, or reapproval Exact session is invalidated immediately and then disconnected Retired queues are inaccessible Active CONNECT, HTTP/2 stream, and APNs work are cancelled Retired tools, skills, bins, and fanout are removed Stale session is excluded from projections
Node or device removal/pruning Route is invalidated before success is returned Pending actions and work are cleared Wake lifecycle and APNs ownership are removed transactionally Subscriptions and remote projections are cleared Active context is cleared

Validation and review:

  • Proxyline cancellation support shipped in Proxyline 0.3.4; npm latest resolves to @openclaw/[email protected].
  • Sanitized fresh-PR AWS proof for the dependency update installed the frozen lockfile, verified the published 0.3.4 declaration contract, and passed 13/13 APNs HTTP/2 proxy tests.
  • Full branch AutoReview against current main found stale-session, APNs acknowledgement, presence-throttle, detached-media, and remote-projection races. Independent authority, persistence, and APNs reviews found active-node lease, node-tool retirement, and active-stream cancellation gaps. Commit c01388f54 fixes all accepted findings with focused regressions.
  • Final lifecycle-fix AutoReview reported no accepted or actionable findings at 0.91 confidence.
  • OpenGrep's pending-action alert identified internal acknowledgement/removal helpers rather than a delivery path; commit 6dd26c546 makes those helpers call the private pruning primitive directly. Incremental AutoReview was clean at 0.93 confidence.
  • Hosted CI on 6dd26c546 exposed stale test mocks/fixtures, test-only export ownership, type-check gaps, and two max-lines ratchets. Commit 4fcda24ad moves wake-state test access behind the test-support convention, preserves APNs cancellation and both remote-projection regressions in focused coverage, and aligns the fixtures with the current connection contract. Incremental AutoReview was clean at 0.93 confidence.
  • Hosted CI on 4fcda24ad passed every runtime, type, dependency, platform, and security lane; only remote.test.ts remained above the max-lines ratchet. Commit 67c34ca74 moves the reconciliation cases into a focused test file. Incremental AutoReview was clean at 0.99 confidence.
  • Hosted CI on 67c34ca74 passed all changed runtime/type/security paths; one unrelated media-store cleanup test flaked, while the lint lane identified nine formatting drifts. Commit 5912f4716 applies only the trusted formatter output. Formatter-diff AutoReview was clean at 0.99 confidence.
  • Exact-head hosted CI is the final runtime, formatting, type, and broad test validation for landing.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL labels Jul 17, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 20, 2026, 9:26 AM ET / 13:26 UTC.

Summary
The branch introduces authenticated pairing identity and generation checks across gateway node sessions, pending work, wake/APNs delivery, subscriptions, and asynchronous node dispatch to prevent retired pairings from retaining authority or state.

PR surface: Source +2883, Tests +4178. Total +7061 across 79 files.

Reproducibility: yes. from source, with medium confidence: current main keeps pending work and connected node ownership keyed by node ID/connection rather than a durable pairing generation. A live race reproduction for removal or same-ID replacement was not independently executed in this read-only review.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/gateway/gateway-misc.test.ts, serialized state: src/gateway/server-methods/nodes-wake-state.ts, vector/embedding metadata: src/gateway/server-node-events.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Rebase and attribute every failed required check on the exact merge head.
  • Provide one concise lifecycle matrix covering ordinary reconnect, removal, revocation, reapproval, and same-ID replacement.
  • Obtain gateway-owner confirmation that pairing generation is the intended shared authority invariant.

Risk before merge

  • [P1] Merging changes authority and lifecycle semantics for already paired nodes: a missed generation boundary could reject valid reconnects, retain retired authority, or misroute pending work and wake delivery.
  • [P1] The branch changes both process-local state and pairing/APNs persistence across 79 files; clean mergeability does not establish that all reconnect, approval, revocation, and replacement paths preserve current-user behavior.
  • [P1] The supplied current-head checks include failed lint, type-test, and compact test shards, so the PR needs a fresh failure-attribution pass after rebase before merge.

Maintainer options:

  1. Validate the full lifecycle invariant before merge (recommended)
    Rebase and prove removal, token rotation, surface reapproval, same-ID replacement, ordinary reconnect, pending drain, and APNs wake behavior on the exact head.
  2. Pause for gateway architecture confirmation
    Do not merge the branch if gateway owners do not want pairing generation to become the shared ownership contract across all node transports and state holders.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase onto current main, attribute every failed required check, and add focused evidence for removal, reapproval, replacement, and ordinary reconnect lifecycle transitions.

Next step before merge

  • [P2] Gateway-owner confirmation and exact-head failure attribution are required; the remaining work is not a safe mechanical repair lane.

Maintainer decision needed

  • Question: Should OpenClaw adopt this broad pairing-generation authority model across node sessions, pending work, APNs, subscriptions, and asynchronous dispatch, or require a narrower repair focused on stale wake-state cleanup?
  • Rationale: The branch changes the gateway's authorization and ownership boundary across many independent transports and persistent-state paths; the intended long-term invariant and acceptable compatibility tradeoff require gateway-owner judgment.
  • Likely owner: Gateway ownership unresolved — No reliable current-main ownership trail could be read without guessing; the decision belongs with the people responsible for gateway pairing and node-session lifecycle.
  • Options:
    • Adopt the shared generation invariant (recommended): Approve the model after a rebased current-head validation demonstrates all lifecycle transitions and gateway owners confirm the shared boundary is the intended architecture.
    • Request a narrower lifecycle repair: Keep the PR open but reduce it to the removal/re-pairing wake-state and queue cleanup paths if the broader generation model is not wanted as a gateway-wide contract.

Security
Cleared: No concrete new security or supply-chain defect was established from the supplied diff; the patch is security-sensitive because it strengthens stale-pairing authority checks and needs owner review of that boundary.

Review details

Best possible solution:

Have gateway owners confirm one authoritative pairing-generation invariant, then land only after the exact rebased head proves removal, revocation, reapproval, and same-ID replacement behavior without regressing ordinary reconnects.

Do we have a high-confidence way to reproduce the issue?

Yes from source, with medium confidence: current main keeps pending work and connected node ownership keyed by node ID/connection rather than a durable pairing generation. A live race reproduction for removal or same-ID replacement was not independently executed in this read-only review.

Is this the best way to solve the issue?

Unclear: generation fencing is a coherent solution to stale ownership, but this implementation makes it a gateway-wide authority model; gateway owners should compare it with a narrower lifecycle-owner repair before accepting that permanent boundary.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against 8d4d02a3cfa4.

Label changes

Label changes:

  • add merge-risk: 🚨 compatibility: Existing paired-node reconnect, approval, and re-pair workflows gain new generation admission rules that can change behavior for deployed installations.
  • remove merge-risk: 🚨 availability: Current PR review merge-risk labels are merge-risk: 🚨 compatibility, merge-risk: 🚨 message-delivery, merge-risk: 🚨 session-state.

Label justifications:

  • P2: This is a substantial but bounded gateway reliability and authority repair, with no confirmed active exploit or release-blocking user outage in the supplied evidence.
  • merge-risk: 🚨 compatibility: Existing paired-node reconnect, approval, and re-pair workflows gain new generation admission rules that can change behavior for deployed installations.
  • merge-risk: 🚨 message-delivery: The PR changes pending work, node invoke routing, subscriptions, wake notifications, and APNs delivery ownership.
  • merge-risk: 🚨 session-state: Node sessions, active-node context, queued work, subscriptions, and wake throttles become associated with pairing generations.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR carries proof: sufficient; the supplied checks include a successful Real behavior proof job, and the prior ClawSweeper review recorded media-backed proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR carries proof: sufficient; the supplied checks include a successful Real behavior proof job, and the prior ClawSweeper review recorded media-backed proof.
Evidence reviewed

PR surface:

Source +2883, Tests +4178. Total +7061 across 79 files.

View PR surface stats
Area Files Added Removed Net
Source 44 3888 1005 +2883
Tests 35 4473 295 +4178
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 79 8361 1300 +7061

What I checked:

  • Current main lacks generation-bound sessions: Current main's NodeSession and NodeRegistry registration/invocation paths track nodeId and connId but contain no pairingGeneration, resolveCurrentPairingState, or generation-aware lookup. The PR adds those ownership checks, so the central behavior is not already implemented. (src/gateway/node-registry.ts:42, 8d4d02a3cfa4)
  • Current main keeps pending work by node ID: Current main stores pending work in a single Map keyed by normalized node ID and drains it without a pairing-generation parameter, allowing a same-ID replacement to inherit outstanding work. (src/gateway/node-pending-work.ts:58, 8d4d02a3cfa4)
  • Branch adds the missing invariant: The branch changes pending-work buckets to be generation-aware and adds pairing-generation admission around node pending work, node sessions, and wake lifecycle state. (src/gateway/server-methods/nodes-pending.ts:31, 0aa40fb3554f)
  • Existing review continuity: The prior completed ClawSweeper cycle found no discrete code finding, but explicitly required gateway-owner agreement on the cross-cutting pairing-generation model. The current review context still shows this broad model and no maintainer decision. (src/gateway/node-registry.ts:42, 0aa40fb3554f)
  • Current-head validation remains incomplete: The supplied PR checks show failed lint, test-types, and three compact test shards, while CodeQL is neutral and the real-behavior-proof job succeeded. Failures need attribution against the exact merge result before landing. (.github/workflows:1, 0aa40fb3554f)

Likely related people:

  • Gateway ownership unresolved: The available review evidence identifies the gateway session, pairing, and wake-state boundary but did not provide enough readable repository history to attribute a current-main owner without guessing. (role: likely follow-up owner; confidence: low; files: src/gateway/node-registry.ts, src/gateway/server-methods/nodes.ts, src/infra/device-pairing.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (5 earlier review cycles)
  • reviewed 2026-07-17T04:43:16.521Z sha 4387781de3f7f515037cb467a58eaaf9cb2d6f2a :: needs maintainer review before merge. :: none
  • reviewed 2026-07-19T23:28:26.047Z sha f4fa3a2dda256a1e21c9e1544b9e6a280cee3184 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T10:40:58.967Z sha 0aa40fb :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T11:23:32.316Z sha 0aa40fb :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T12:43:13.458Z sha 0aa40fb :: needs maintainer review before merge. :: none

@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/problem-removing-a-paired-node-leaves-wake-throttle-and-nudge-state-behi branch from 4387781 to f4fa3a2 Compare July 19, 2026 22:54
@zhangguiping-xydt
zhangguiping-xydt requested a review from a team as a code owner July 19, 2026 22:54
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 19, 2026
@zhangguiping-xydt
zhangguiping-xydt marked this pull request as draft July 20, 2026 10:12
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Jul 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • npm-shrinkwrap.json
  • package.json
  • pnpm-lock.yaml
  • pnpm-workspace.yaml

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile, shrinkwrap, or workspace dependency policy changes are present.
  • Treat package-lock.json and npm-shrinkwrap.json diffs as security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph change authorized

This PR includes dependency graph changes. A repository admin or member of @openclaw/openclaw-secops authorized this exact head SHA with /allow-dependencies-change.

  • Approved SHA: 5912f471675c7d7801c2c70b5761212467edea39
  • Approved by: @steipete
  • Reason: Proxyline 0.3.4 is the maintainer-released package required for the reviewed AbortSignal cancellation contract; package, pnpm lock, npm shrinkwrap, and bounded release-age policy entries were verified against the published registry integrit

A later push changes the PR head SHA and requires a fresh security approval.

Comment thread src/gateway/node-runtime-state.ts Fixed
Comment thread src/gateway/node-runtime-state.ts Fixed
@steipete

Copy link
Copy Markdown
Contributor

/allow-dependencies-change Proxyline 0.3.4 is the maintainer-released package required for the reviewed AbortSignal cancellation contract; package, pnpm lock, npm shrinkwrap, and bounded release-age policy entries were verified against the published registry integrity.

@steipete

Copy link
Copy Markdown
Contributor

/allow-dependencies-change Proxyline 0.3.4 is the maintainer-released package required for the reviewed AbortSignal cancellation contract; package, pnpm lock, npm shrinkwrap, and bounded release-age policy entries were verified against the published registry integrity.

@steipete

Copy link
Copy Markdown
Contributor

/allow-dependencies-change Proxyline 0.3.4 is the maintainer-released package required for the reviewed AbortSignal cancellation contract; package, pnpm lock, npm shrinkwrap, and bounded release-age policy entries were verified against the published registry integrity.

@clawsweeper

clawsweeper Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): avoid stale wake delays after node re-pairing This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@steipete

Copy link
Copy Markdown
Contributor

Land-ready proof for exact head 5912f471675c7d7801c2c70b5761212467edea39:

Known proof gap: a second direct AWS exact-head allocation was unavailable because the Crabbox broker returned HTTP 401 before provisioning. No contributor code ran locally; exact-head secretless GitHub CI supplied the complete final runtime and type proof.

@steipete
steipete merged commit 186c25f into openclaw:main Jul 21, 2026
126 of 127 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@zhangguiping-xydt

Copy link
Copy Markdown
Contributor Author

Merged via squash.

wow...Your work is far too efficient. Thank you for your review of this large-size PR of mine.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 22, 2026
…#109647)

* fix(gateway): clear wake state on node removal

* fix(gateway): invalidate wake flows on node removal

* fix(gateway): preserve active wakes on disconnect

* fix(gateway): share node removal runtime cleanup

* fix(gateway): clean up pending node work reliably

* fix(gateway): bind node work to pairing generations

* fix(gateway): fence stale node pairing sessions

* fix(gateway): tighten node pairing ownership

* fix(gateway): close node pairing mutation races

* fix(gateway): bind node sessions to pairing generation

* fix(gateway): harden node pairing generation guards

* fix(gateway): close node pairing generation races

* fix(gateway): guard APNs transport ownership

* fix(gateway): revoke reapproved node transports

* fix(gateway): guard retired node lifecycles

* fix(gateway): preserve pending work across reconnects

* fix(gateway): bind node subscriptions to pairing generations

* fix(gateway): settle subscription fanout failures

* fix(gateway): fence pairing generation ownership

* fix(gateway): fence asynchronous node events

* fix(gateway): fence watch results and voice wake fanout

* fix(gateway): guard voice wake generation fanout

* fix(gateway): carry authenticated snapshot generation

* fix(gateway): bind node state to pairing generation

* fix(gateway): align generation guards with current base

* fix(gateway): enforce pairing-owned node lifecycle

* fix(gateway): fence detached voice session writes

* chore(deps): bump proxyline to 0.3.4

* fix(gateway): close pairing lifecycle races

Co-authored-by: zhang-guiping <[email protected]>

* fix(gateway): distinguish pending action mutation

Co-authored-by: zhang-guiping <[email protected]>

* test(gateway): align lifecycle coverage

Co-authored-by: zhang-guiping <[email protected]>

* test(skills): split remote reconciliation coverage

Co-authored-by: zhang-guiping <[email protected]>

* style: format pairing lifecycle changes

Co-authored-by: zhang-guiping <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling dependencies-changed PR changes dependency-related files gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants