Skip to content

fix(gateway): reject stale node work before enqueue - #132909

Merged
vincentkoc merged 1 commit into
mainfrom
fix/node-pending-work-lifecycle
Aug 29, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/node-pending-work-lifecycle

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where node pending work could be briefly enqueued after the node was re-paired or removed while the Gateway was checking its pairing generation.

Why This Change Was Made

Pending-work enqueue and wake stages now use the existing shared pairing-work liveness check. That check validates the wake lifecycle both before and after the asynchronous pairing-generation lookup, so invalidation during the lookup is rejected before any queue mutation.

User Impact

Operators no longer get stale node work inserted and then cleaned up when pairing changes during the initial enqueue check. The request instead returns the existing retryable PAIRING_CHANGED result without mutating the queue.

Evidence

  • Pre-fix regression: lifecycle invalidation inside isNodePairingGenerationCurrent still called enqueueNodePendingWork once
  • Post-fix regression: no enqueue occurs and the handler returns PAIRING_CHANGED
  • node scripts/run-vitest.mjs src/gateway/server-methods/nodes.pending-work.test.ts — 9 tests passed
  • focused formatting and oxlint passed
  • pnpm tsgo:core passed
  • autoreview: clean, no actionable findings
  • production delta: +6/-18 (net -12); tests: +40
  • pnpm tsgo:core:test reached the unrelated linked-install error for missing pako declarations in ui/vite.config.ts

@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@vincentkoc vincentkoc self-assigned this Aug 29, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 29, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 29, 2026 23:22
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 7:30 PM ET / 23:30 UTC.

ClawSweeper review

What this changes

The PR replaces pending-node work’s local pairing check with the existing shared liveness guard and adds a regression test for invalidation during the asynchronous generation lookup.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal maintainer review: this member-authored, maintainer-labeled PR is still needed, and the introduced change correctly prevents a stale pairing lifecycle from reaching the pending-work queue.

Priority: P2
Reviewed head: d365dabb296b6a87c8918145f6c74bf3e8d3388b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative owner-boundary refactor with credible regression coverage and no blocking source finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a MEMBER-authored internal Gateway reliability repair; the PR body reports a focused terminal regression run, while this read-only review independently verified the source-level scenario and owner boundary.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a MEMBER-authored internal Gateway reliability repair; the PR body reports a focused terminal regression run, while this read-only review independently verified the source-level scenario and owner boundary.
Evidence reviewed 7 items Introduced enqueue guard: The introduced call checks shared pairing-work liveness immediately before the first queue mutation, so the handler rejects stale state before enqueueing.
Shared owner closes the async race: The shared guard validates lifecycle state before and after awaiting the pairing-generation lookup; the final synchronous check is the missing condition in the replaced local helper.
Lifecycle invalidation owner: Pairing reapproval and node-token rotation invalidate node wake state after durable pairing mutation, establishing why a post-await lifecycle check is required before side effects.
Findings None None.
Security None None.

How this fits together

Gateway operators enqueue work for paired nodes that may reconnect later. Pairing generation and wake-lifecycle state determine whether that work may enter the queue or must return a retryable unavailable result.

flowchart LR
  A[Operator node-work request] --> B[Capture pairing generation]
  B --> C[Capture wake lifecycle]
  C --> D[Shared liveness check]
  D -->|Current| E[Enqueue pending work]
  D -->|Changed| F[Return PAIRING_CHANGED]
  E --> G[Optional node wake]
Loading

Before merge

  • Resolve merge risk (P1) - The supplied check rollup is incomplete and includes one failed shard with no available log, so merge readiness is not yet established.
  • Resolve merge risk (P1) - The supplied context omits a newer bot comment; confirm any outstanding Rank-up moves before merging.
Agent review details

Security

None.

PR surface

Source -12, Tests +40. Total +28 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 18 -12
Tests 1 40 0 +40
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 46 18 +28

Review metrics

Metric Value Why it matters
Production versus test delta production +6/-18 (net -12); tests +40/-0 The fix removes the duplicate local predicate while adding focused regression coverage, with no production growth.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Adopt the shared post-await liveness predicate at every pending-work wake checkpoint, retain the distinct non-lifecycle checks for pull and acknowledgement paths, and merge once the exact-head gate is clean.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Adopt the shared post-await liveness predicate at every pending-work wake checkpoint, retain the distinct non-lifecycle checks for pull and acknowledgement paths, and merge once the exact-head gate is clean.

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

Yes, from source: aborting the wake lifecycle during the awaited generation lookup made the prior helper return true and reach enqueue; the added handler-boundary test encodes that exact sequence.

Is this the best way to solve the issue?

Yes. Reusing the shared liveness owner is the narrowest maintainable repair because it already performs the required post-await lifecycle recheck used by node invocation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3b92e84d2934.

Labels

Label changes:

  • add P2: This prevents a bounded stale-work race in Gateway node handling without evidence of an emergency outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a MEMBER-authored internal Gateway reliability repair; the PR body reports a focused terminal regression run, while this read-only review independently verified the source-level scenario and owner boundary.

Label justifications:

  • P2: This prevents a bounded stale-work race in Gateway node handling without evidence of an emergency outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a MEMBER-authored internal Gateway reliability repair; the PR body reports a focused terminal regression run, while this read-only review independently verified the source-level scenario and owner boundary.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

@vincentkoc

Copy link
Copy Markdown
Member Author

Before-merge resolution:

Both listed Before merge items are resolved.

@vincentkoc
vincentkoc merged commit 4432c56 into main Aug 29, 2026
491 of 494 checks passed
@vincentkoc
vincentkoc deleted the fix/node-pending-work-lifecycle branch August 29, 2026 23:43
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant