Skip to content

fix(ui): back off requests while the Gateway starts - #190159

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-control-ui-startup-unavailable-retry-storm-20260919
Nov 1, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-control-ui-startup-unavailable-retry-storm-20260919

Conversation

@steipete

@steipete steipete commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated Control UI requests overwhelming a Gateway while it is still starting. Four outstanding chat reads could each retry every 500 ms for the entire startup window.

User Impact

Chat metadata loads automatically once its request is admitted, with substantially fewer startup failures. Repeated startup refusals now back off up to eight seconds; recovery can consequently take up to eight seconds after admission opens. Longer server retry hints remain authoritative. Original request deadlines and cancellation still apply.

Why This Change Was Made

The four UI owners already share pending loads. The shared Gateway client's pending-request owner retained startup refusals but retried every time at the unchanged server hint. It now doubles that request's wait, retaining the existing timer, correlation, settlement, and connection lifecycle. A slow agent does not hold unrelated requests. The server already provides retryable, retryAfterMs, and a correlated startup reason; it does not publish a method/agent startup-ready WebSocket signal, so no protocol extension is needed.

Runtime production delta: +3 lines for one delay value and its update; no new cache, configuration, schema, or per-store retry path. The fixed-delay path is replaced. Documentation describes the latency tradeoff. The committed measurement script is proof tooling, separate from production LOC.

Evidence

Acceptance rule recorded before measurement: 30 synthetic connections × four outstanding startup reads, 13 seconds of correlated UNAVAILABLE with a 500 ms server hint; at most five attempts per pending read before readiness, then all reads recover. Five interleaved A/A/B triplets, 100 waves/sample; separate untraced timing and sampled-allocation passes.

Metric Before After
Startup refusals per 30-client wave 3,240 600
Total requests, including 120 recovered reads 3,360 720
Owner elapsed median / p95 per 100 waves 757.330 / 781.856 ms 163.967 / 170.013 ms
CPU median / p95 per 100 waves 828.515 / 850.408 ms 216.334 / 218.173 ms
Sampled allocation median per 100 waves 667,573,972 B 149,926,952 B

Baseline A/A medians: elapsed 758.831 / 749.280 ms; CPU 830.681 / 813.855 ms; allocation 667,612,440 / 667,084,144 B. Startup refusal count falls 81.5%. Recovery in this fixture is at 13.5 seconds before versus 15.5 seconds after. Allocation sampling uses a 4 KiB interval and includes collected objects. Separate CPU profiling identifies send/encoding/timer work as the hot path.

Run node --import ./scripts/tsx.mjs scripts/perf/control-ui-startup-retry-measure.mts [owner-module] against separately bundled owner modules from each revision (same esbuild options: bundle, Node platform, ESM). This isolates retry-owner work and wire serialization; it does not benchmark database/handler work, filesystem size, btrfs, or whole-Gateway latency. Startup refusals precede those handlers. No production data or runtime was used.

  • Owner regression fails on the exact main parent: a third frame arrives before the second backoff window expires. Candidate: 65/65 focused pending-request, protocol-client and device-authority tests pass, including cancellation, deadlines and correlated refusal safeguards.
  • Actual production-build Control UI E2E fails on the base: mentions.list makes 26 additional retries in 13 seconds, above the budget of five. Candidate passes for all four request families and displays recovered mentions, model, effective tool, and GitHub account options; successful reads stop retrying. Test execution 2.772 seconds, wrapper 13.82 seconds.
  • Local UI browser model picker and browser-client adapter: 49/49 tests pass. No Node-only runtime import was added to the browser graph.
  • Nonvisual change; no layout or appearance change. The 173-line test allocation covers the distinct capped/server-hint owner contract and production UI recovery/import boundary.

Independent Codex autoreview through P2: scoped-clean, no actionable findings. Simplification pass retained the existing owner and timer rather than adding a scheduler or store-specific policy.

pnpm check:changed passed all selected checks except dead exports. The exact main parent 4475bed8cf500c9be80257b2f142c1136bd9dfbd, checked in an isolated worktree with node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts, reproduces the identical findings:

Main regression Introducing commit / PR
collectModelAllowlistWildcardOffers exported without an external production caller 887cf720aab8, #190031
allowProviderModels exported without an external production caller 8f606d9ec191, #190019
materializeSessionRepositoryWorkspaceOnGateway left exported after its external caller migrated af7cee293365, #189350

Production scan flags all three; full-tree scan flags the first. These are separate main regressions, left for their owners; this PR changes none of their files or the scan configuration. No failure was suppressed or reclassified as passing.

The first CI run (41286025904) exposed seven PR-caused test timeouts in four long-startup delivery fixtures: they advanced fake time only 500–1,000 ms after readiness before awaiting a retry. Updated those four advances to the documented eight-second backoff bound. No test timeout or delivery/cancellation/identity/deadline assertion was relaxed. All seven failures reproduced locally; 80/80 tests across the affected files now pass (3.67 s). Follow-up Codex review is scoped-clean. pnpm check:changed --base HEAD for this test-only correction passed every selected check except the same independently reproduced main dead exports above. The production implementation and before/after measurements are unchanged.

Replace fixed startup-refusal retries in the shared pending-request owner with bounded exponential waits while honoring server hints. Preserve request deadlines, cancellation, and correlated non-delivery proof. All four chat data owners recover automatically with substantially less startup pressure.
@clawsweeper

clawsweeper Bot commented Nov 1, 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 app: web-ui App: web-ui scripts Repository scripts size: M labels Nov 1, 2026
@steipete
steipete marked this pull request as ready for review November 1, 2026 07:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T08:06:50.487379Z 83981bc New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
Advance fake clocks through the eight-second startup backoff before checking delivery. Keep the existing deadlines, cancellation, original request identity, and single-delivery assertions; no test timeout is increased.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR adds bounded exponential backoff to requests refused while the Gateway starts.

Example: A models.list request receives repeated startup refusals with retryAfterMs: 500.

  • Before: It retries every 500 ms.
  • After: It waits 500, 1000, 2000, 4000, then 8000 ms between attempts, honoring longer server hints.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused production change is sound, but affected consumer tests fail and supplied behavioral evidence uses simulated transport.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repeated pending chat reads add request pressure while the Gateway is still preparing.
Reason: The maintainer-authored direction accepts slower recovery in exchange for fewer startup requests, without adding configuration or another retry owner.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: the shared-owner fix is useful, but its longer retry interval breaks seven existing startup tests and the required UI checks.

Priority: P2
Reviewed head: 5a337022030d6f4303acee6e85b9a7c8e5b1900c

Before merge

  • Update startup consumer tests for the longer retry window (P2) - The new backoff also applies to chat.send and sessions.create, but four existing consumer suites still advance only 500–1000 ms after making their fixture ready, then await a promise whose next retry can be several seconds away. Consequently, seven cases time out and both required checks-ui shards fail on this head. Update session-placement-startup.test.ts, chat-send-deadline.test.ts, chat-pane-startup-admission.test.ts, and draft-submission-flow.test.ts to advance through the supported eight-second window before awaiting completion, retaining their exactly-once, cancellation, and deadline assertions.

Findings

  • [P2] Update startup consumer tests for the longer retry window — packages/gateway-client/src/pending-request.ts:297-301

Tests

  • Missing end-to-end proof: Provide an after-fix startup-refusal and recovery trace through the production client and real WebSocket transport; supplied base/head regressions cover simulated transport.
Agent review details

How this fits together

Browser and Node adapters send requests through GatewayPendingRequests, which owns correlation, deadlines, cancellation, startup retries, and final settlement.

flowchart LR
  A[Control UI data owners] --> B[Gateway protocol client]
  B --> C[Pending request owner]
  C --> D[WebSocket transport]
  D --> E[Gateway admission]
  E --> F[Method handler]
  E -->|Startup refusal| C
Loading

Technical review

Best possible solution:

Keep backoff in the existing request owner and update the four affected consumer suites to advance through the supported retry window while preserving their delivery and cancellation assertions.

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

Current-main source retries every matching startup refusal at the unchanged server hint; the supplied base/head regressions exercise that path, and GitHub annotations independently confirm the affected consumer-test failures.

Is this the best way to solve the issue?

The production change is the smallest complete fix: retain one delay per pending request in the existing owner, reuse its timer, and preserve correlation, settlement, cancellation, and deadlines.

Full review comments:

  • [P2] Update startup consumer tests for the longer retry window — packages/gateway-client/src/pending-request.ts:297-301
    The new backoff also applies to chat.send and sessions.create, but four existing consumer suites still advance only 500–1000 ms after making their fixture ready, then await a promise whose next retry can be several seconds away. Consequently, seven cases time out and both required checks-ui shards fail on this head. Update session-placement-startup.test.ts, chat-send-deadline.test.ts, chat-pane-startup-admission.test.ts, and draft-submission-flow.test.ts to advance through the supported eight-second window before awaiting completion, retaining their exactly-once, cancellation, and deadline assertions.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1e293027afc0.

Provenance checked

  • Shared pending-request startup retry scheduling changes intended behavior with a stated reason (543dd39: Retain authoritatively refused startup requests with their original frames, deadlines, cancellation signals, and independent agent progress.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm --dir ui test src/lib/sessions/session-placement-startup.test.ts src/pages/chat/chat-send-deadline.test.ts src/pages/chat/chat-pane-startup-admission.test.ts src/pages/new-session/draft-submission-flow.test.ts
  • pnpm test packages/gateway-client/src/pending-request.test.ts
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 543dd39 adds packages/gateway-client/src/pending-request.ts:273 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 543dd39563e4; files: packages/gateway-client/src/pending-request.ts)

PR surface

Source +3, Tests +173, Docs +7, Other +117. Total +300 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 5 2 +3
Tests 2 173 0 +173
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 2 117 0 +117
Total 6 302 2 +300

Labels

Label changes:

  • add P2: Reduces repeated requests during startup with a bounded, explicitly accepted recovery delay.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Reduces repeated requests during startup with a bounded, explicitly accepted recovery delay.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 execution lanes are retired.

Reviewed November 1, 2026, 3:01 AM ET / 08:01 UTC.

@steipete
steipete merged commit ebc9d7e into main Nov 1, 2026
112 of 114 checks passed
@steipete
steipete deleted the steipete/perf-micro-control-ui-startup-unavailable-retry-storm-20260919 branch November 1, 2026 09:16
@steipete

steipete commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

roboclaw-bot added a commit that referenced this pull request Nov 1, 2026
## What Problem This Solves

Fixes two jobs in [run 41288828221](https://github.com/openclaw/openclaw/actions/runs/41288828221):

- [checks-node-compact-large-14](https://github.com/openclaw/openclaw/actions/runs/41288828221/job/124795798742): `gateway-chat.startup.test.ts:246`, both “send waits through startup and writes once” and “new waits through startup and writes once” time out at 120000ms.
- [checks-node-compact-large-19](https://github.com/openclaw/openclaw/actions/runs/41288828221/job/124795798949): `server-methods.startup-deadline.test.ts:195`, `startup agent: ready` and `startup sessions.create: ready` time out at 120000ms.

## User Impact

Test-only CI repair; production startup backoff remains unchanged.

## Why This Change Was Made

Introduced by ebc9d7e (#190159): repeated startup refusals back off to eight seconds. Advancing only one second after readiness leaves the awaited retry frozen. Advance to the already scheduled next timer in both fixtures. Existing deadline, cancellation, serialized-request-byte, and exactly-one-write assertions remain unchanged. Production delta 0; tests +2/-2, with no new machinery.

## Evidence

- Ownership rechecked against fresh main and recent/targeted open PR file inventories; no competing fix found.
- Lane l201 reproduced all four ready-case failures through the Gateway/TUI boundaries. Complete Gateway startup, TUI startup, and pending-request/backoff owner suites passed 33/33 on pinned Bun and 33/33 on Node. Scoped typecheck, type-aware lint, format, and whitespace passed.
- Independent Codex autoreview with both complete fixtures and the request/backoff owner on base `42d5039f0aa8`: P0–P2 scoped-clean, no findings. The rebased patch is identical; affected fixtures and backoff owner are unchanged on main.
- After rebasing onto `2423623c3461610130360fa978cd364653fee1b2`, reran both complete touched test files through `OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs ... --maxWorkers=1`: 22/22 passed (10 Gateway and 12 TUI cases, no skipped cases).
- No retries, skipped tests, timeout increases, weakened assertions, baseline growth, or workflow reruns.

Co-authored-by: steipete <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
* fix(ui): back off requests while the Gateway starts

Replace fixed startup-refusal retries in the shared pending-request owner with bounded exponential waits while honoring server hints. Preserve request deadlines, cancellation, and correlated non-delivery proof. All four chat data owners recover automatically with substantially less startup pressure.

* test(ui): allow the bounded startup retry window

Advance fake clocks through the eight-second startup backoff before checking delivery. Keep the existing deadlines, cancellation, original request identity, and single-delivery assertions; no test timeout is increased.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
)

## What Problem This Solves

Fixes two jobs in [run 41288828221](https://github.com/openclaw/openclaw/actions/runs/41288828221):

- [checks-node-compact-large-14](https://github.com/openclaw/openclaw/actions/runs/41288828221/job/124795798742): `gateway-chat.startup.test.ts:246`, both “send waits through startup and writes once” and “new waits through startup and writes once” time out at 120000ms.
- [checks-node-compact-large-19](https://github.com/openclaw/openclaw/actions/runs/41288828221/job/124795798949): `server-methods.startup-deadline.test.ts:195`, `startup agent: ready` and `startup sessions.create: ready` time out at 120000ms.

## User Impact

Test-only CI repair; production startup backoff remains unchanged.

## Why This Change Was Made

Introduced by fbb3769 (openclaw#190159): repeated startup refusals back off to eight seconds. Advancing only one second after readiness leaves the awaited retry frozen. Advance to the already scheduled next timer in both fixtures. Existing deadline, cancellation, serialized-request-byte, and exactly-one-write assertions remain unchanged. Production delta 0; tests +2/-2, with no new machinery.

## Evidence

- Ownership rechecked against fresh main and recent/targeted open PR file inventories; no competing fix found.
- Lane l201 reproduced all four ready-case failures through the Gateway/TUI boundaries. Complete Gateway startup, TUI startup, and pending-request/backoff owner suites passed 33/33 on pinned Bun and 33/33 on Node. Scoped typecheck, type-aware lint, format, and whitespace passed.
- Independent Codex autoreview with both complete fixtures and the request/backoff owner on base `0082e6368c96`: P0–P2 scoped-clean, no findings. The rebased patch is identical; affected fixtures and backoff owner are unchanged on main.
- After rebasing onto `1f4d22031c73bcd1c42b48d5c84c9a9192b37099`, reran both complete touched test files through `OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs ... --maxWorkers=1`: 22/22 passed (10 Gateway and 12 TUI cases, no skipped cases).
- No retries, skipped tests, timeout increases, weakened assertions, baseline growth, or workflow reruns.

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

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant