Skip to content

perf(gateway): pause reconnect bootstrap during restart - #167407

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-reconnect-bootstrap-restart-window-20260919
Oct 8, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-reconnect-bootstrap-restart-window-20260919

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated bootstrap RPC rejections while a connected Gateway drains for restart. Identity reads, session subscriptions, groups, pending questions, and session lists previously retried independently against the same unavailable connection.

User Impact

The Control UI waits through the restart window and resumes loading on readiness or reconnect. Browser and embedded web views share this client. Original request deadlines and cancellation remain effective, and writes are never replayed. No configuration or stored-data changes.

Why This Change Was Made

Extend the protocol client's existing identity suspension parking to the five bootstrap methods and structured restart refusals/shutdown notices. One jittered probe honors the longest outstanding server retry hint (at least five seconds for restart). Only a successful probe of the current pause revision releases the queue. Canceled or expired reads cannot become probes.

A bounded probe is necessary because a restart signal fence can roll back without a readiness event or socket replacement. An empty expired pause therefore lets the next read probe immediately. This complements #167020's read-acknowledgement pacing.

Production LOC: +62 net (85 added, 23 removed; tests/docs excluded). The identity-only path is replaced in place. Growth is required for four additional idempotent methods and the existing deadline, cancellation, and connection-generation contracts while enforcing a single probe. There is one pause owner and no additional retry scheduler or configuration.

Evidence

Real isolated Gateway, synthetic state, two scripted protocol clients sharing the same SIGUSR2 restart and 30,001 ms admitted-RPC hold. Each client retries the five-method bootstrap batch after one second when it settles. Baseline client source: 7d59b5b98bd00aef301c9f7ef33a991be8e86d5c.

Measurement Baseline Candidate
Rejected bootstrap calls during drain 150 10
Bootstrap completion after replacement hello 170 ms 4 ms
Full recovery after restart signal 34.43 s 34.65 s

15× fewer rejected calls, exceeding the 10× target. Both clients recovered; independent reconnect jitter explains the small difference in total recovery time.

Remote proof uses Crabbox provider aws, lease cbx_7122670587a7, after Blacksmith Testbox tbx_01m4e6qh92ybq0cvbqpccmtxkj completed an earlier gate but timed out syncing subsequent corrections. Both leases were stopped after use.

  • node scripts/run-vitest.mjs packages/gateway-client/src/protocol-client.request.test.ts --maxWorkers=1: 22 passed, 1.20 s Vitest / 2.34 s wrapper wall time.
  • node scripts/run-vitest.mjs packages/gateway-client/src/*.test.ts: 373 passed across 27 files, 8.73 s wall time.
  • Targeted Control UI gateway, identity, and session-hydration tests: 81 passed across four files, 4.54 s wall time.
  • Negative controls reproduced the original storm (6,000 restart and 4,840 suspension rejections in 30 simulated seconds across 40 clients), plus every corrected probe/deadline/cancellation lifecycle defect on its preceding implementation. The fixed storm cases permit at most 40 rejections and recover every client.
  • node --import ./scripts/tsx.mjs scripts/build-all.mts sourcePerformance: passed, 51.4 s.
  • Standalone real-Gateway restart proof: passed, measurements above.
  • node scripts/check-changed.mjs -- docs/web/control-ui.md packages/gateway-client/src/pending-request.ts packages/gateway-client/src/protocol-client.ts packages/gateway-client/src/protocol-client.request.test.ts: passed, including production/test types, formatting, lint, dead exports, and repository guards.
  • Independent review: clean through P2, all accepted findings resolved.

No rendered UI changes or browser automation. This proves the shared protocol bootstrap; native Swift UI interaction and device behavior were not exercised. Remote proof ran on base 7d59b5b98bd0; the patch was rebased unchanged onto 082c68a9cbd8 before publication. All four changed files retained identical hashes. Exact-head CI passed in 547 seconds (46 successful jobs, 22 scope-skipped jobs; no reruns). The PR merged as d51345aaf72c.

Extend the existing request parking owner to reconnect bootstrap reads. Respect server retry floors with one probe per connection, retain pause revisions, and preserve cancellation and request deadlines.

A real isolated Gateway restart reduced rejected bootstrap calls from 150 to 10, with bootstrap recovery 4 ms after the replacement hello. Remote gateway-client and UI tests, runtime build, and the changed-check gate passed.
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 18:47
@steipete
steipete enabled auto-merge (squash) October 8, 2026 18:49
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 2:53 PM ET / 18:53 UTC.

ClawSweeper review

What this changes

The PR coordinates five Gateway bootstrap requests during restart or suspension, allowing one delayed probe before resuming queued reads.

Example: The Control UI reloads data during a Gateway restart

  • Before: The reported baseline run produces 150 rejected bootstrap calls during the drain.
  • After: The candidate run produces 10 rejected calls and completes bootstrap 4 ms after the replacement connection’s hello.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful shared-owner repair with real restart recovery evidence and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The fully inspected body reports production protocol clients exercising a real isolated Gateway restart over WebSocket, reducing rejected bootstrap calls from 150 to 10 and recovering both clients after replacement hello. The recorded unchanged-file rebase preserves that proof's applicability; native device interaction was outside its claim. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: During a Gateway restart, Control UI loading repeatedly sends requests that the draining connection rejects.
Reason: The measured request storm warrants a focused reliability repair, and prior area history establishes the author's ownership of the existing parking behavior.

Merge readiness

✅ Ready for maintainer review

This PR earns its place: current main does not cover the bootstrap retry storm, real Gateway evidence supports the improvement, and no actionable introduced defect was found.

Priority: P2
Reviewed head: c5174ea5a3c8abec482415d89cfaedde10270e2b

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared Gateway client carries requests from browser and Node clients over WebSocket. Its pending-request owner coordinates response matching, deadlines, cancellation, and recovery while the Gateway temporarily refuses work.

flowchart TD
  A[Browser and Node bootstrap reads] --> B[Shared pending requests]
  C[Restart refusals and lifecycle notices] --> B
  B --> D{Gateway paused?}
  D -->|No| E[Gateway WebSocket]
  D -->|Yes| F[Queue with original deadlines]
  F --> G[One delayed probe]
  G --> E
  E -->|Successful current probe or readiness| B
Loading

Technical review

Best possible solution:

Keep restart recovery in the shared pending-request owner, with one bounded probe and unchanged request lifetimes.

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

Yes: current main lacks coordinated restart parking, and the supplied real-Gateway baseline records 150 rejected bootstrap calls during a controlled restart drain.

Is this the best way to solve the issue?

Yes: extending the existing shared request owner avoids competing retry policies while preserving cancellation, deadlines, and write behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1339b6fd3e73.

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 1.

Security

None.

Evidence

What I checked:

  • Introduced production behavior: The pinned introduced diff extends the existing pending-request owner to five methods, preserves original cancellation and deadlines, retains the longest retry deadline, and releases queued requests only after readiness or a successful current-revision probe. (packages/gateway-client/src/pending-request.ts:242, c5174ea5a3c8)
  • Current main still needs this work: REST contents checks confirmed that all four touched files at fetched main have the same blob identities as the merge base. Main therefore retains the identity-only suspension path and lacks this coordinated restart bootstrap behavior. (packages/gateway-client/src/pending-request.ts:203, 1339b6fd3e73)
  • Real restart recovery evidence: The fully read PR body reports two production protocol clients against a real isolated Gateway with synthetic state, SIGUSR2 restart, and a 30,001 ms admitted-request hold: rejected calls fell from 150 to 10; both clients recovered; candidate bootstrap completed 4 ms after replacement hello. The body records an unchanged-file rebase before publication. Captured context source identity: 17cff819c0a58416590228a90e645f38dd0108b3d7ed92abc93cc9c7b9282f73. These are contributor-supplied observations, not reviewer-executed tests. (c5174ea5a3c8)
  • Existing owner and intent: The introducing patch and merged PR perf(gateway): wait for resume before retrying identity reads #158779 establish identity suspension parking in this same owner, preserving deadlines, cancellation, disconnect settlement, and synchronous writes. The current proposal explains why restart rollback requires a bounded single probe. (packages/gateway-client/src/pending-request.ts, 20a865cd0402)
  • Related merged work is complementary: perf(ui): stop read acknowledgement storms during gateway drains #167020 is merged and addresses automatic read-acknowledgement pacing and UI availability handling; it does not replace the shared bootstrap queue reviewed here. (06dc2c0d64d2)
  • Lifecycle regression coverage: The changed request suite covers restart and suspension storms, retry floors, rollback probes, stale probe revisions, shared-signal aborts, due deadlines, disconnect retirement, and immediate write/control dispatch. The body reports failing negative controls and 22 passing focused tests; no tests were executed during this read-only review. (packages/gateway-client/src/protocol-client.request.test.ts:93, c5174ea5a3c8)

Likely related people:

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

PR surface

Source +62, Tests +278, Docs +2. Total +342 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 85 23 +62
Tests 1 345 67 +278
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 432 90 +342

Review metrics

Metric Value Why it matters
Restart drain traffic 150 → 10 rejected bootstrap calls; 15× reduction The supplied real-Gateway comparison demonstrates the practical value of coordinating bootstrap reads.
Production versus tests Runtime +62 net lines; tests +278 net lines Runtime growth extends one existing owner to four additional methods and enforces probe, deadline, and cancellation invariants.

Labels

Label changes:

  • add P2: This repairs avoidable request storms during temporary Gateway unavailability without evidence of an emergency outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This repairs avoidable request storms during temporary Gateway unavailability without evidence of an emergency outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

@steipete
steipete merged commit d51345a into main Oct 8, 2026
167 checks passed
@steipete
steipete deleted the steipete/perf-micro-reconnect-bootstrap-restart-window-20260919 branch October 8, 2026 18:57
steipete added a commit that referenced this pull request Oct 8, 2026
The restart bootstrap change in d51345a (#167407) intentionally
parks sessions.list while the Gateway is draining or prepared. The two
suspension fixtures waited for that roster before they could emit accepting.
Use the existing initial-roster opt-out at those fixture owners, retaining
all lifecycle, loading, failure, empty-state, and recovery assertions.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
)

Extend the existing request parking owner to reconnect bootstrap reads. Respect server retry floors with one probe per connection, retain pause revisions, and preserve cancellation and request deadlines.

A real isolated Gateway restart reduced rejected bootstrap calls from 150 to 10, with bootstrap recovery 4 ms after the replacement hello. Remote gateway-client and UI tests, runtime build, and the changed-check gate passed.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
The restart bootstrap change in 6f07486 (openclaw#167407) intentionally
parks sessions.list while the Gateway is draining or prepared. The two
suspension fixtures waited for that roster before they could emit accepting.
Use the existing initial-roster opt-out at those fixture owners, retaining
all lifecycle, loading, failure, empty-state, and recovery assertions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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