Skip to content

perf(gateway): wait for resume before retrying identity reads - #158779

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-suspension-request-storm-20260919
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-suspension-request-storm-20260919

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated agent.identity.get requests while the Gateway is suspended. Control UI renders retry missing identities after each rejected request is evicted from the shared identity cache, even though the socket remains connected.

User Impact

Control UI and CLI identity reads wait for resume instead of repeatedly hitting the suspension fence. Existing request deadlines and cancellation remain in force; a CLI invocation with its default 30-second budget can still time out during a longer suspension. Other RPCs keep their current behavior.

Why This Change Was Made

The shared browser/Node pending-request owner now consumes the existing suspension event and hello snapshot. An explicit retryable suspension refusal also parks the identity read, with a 60-second retry hint as fallback when the resume event is missed. Resume wakes the pending read immediately. Disconnects retain normal request settlement and reconnect backoff.

Only identity reads can wait or replay. Writes retain their synchronous authority/send boundary. This adds 89 net runtime lines, reuses the existing pending-request map, and adds no configuration option, cache, or server queue. The existing structured details.reason: "gateway-suspending" contract is retained.

Caller inspection found render-driven UI retries, not a dedicated identity polling timer. The generic gateway CLI makes one request per invocation; re-running it creates a new connection.

Evidence

Actual shared protocol clients against a synthetic Gateway transport, with a fake clock: 40 connected clients poll identity once per second through a 30-second suspension.

Suspension notification Refusals before Refusals after
Event received before polling 1,200 0
First request learns through refusal 1,200 40

All 40 pending reads complete on the resume turn with zero simulated-time advance. The two regressions fail on the original client at the refusal-count assertion. Additional coverage protects hello snapshot admission, the bounded fallback, original deadlines, abort/disconnect retirement, and immediate write/control dispatch.

Validation uses provider blacksmith-testbox, profile openclaw-check:

  • Baseline: tbx_01m3ebww6hp2znaexnfyz75xqv, node scripts/run-vitest.mjs packages/gateway-client/src/protocol-client.request.test.ts --maxWorkers=1: both new storm cases fail with 1,200 refusals; 18 existing cases pass.
  • After: tbx_01m3ecferg94de7knbreax6v64 (lease workflow), focused request, pending-request, handshake, and Node request-timeout files: 46 tests pass, 3.02 seconds wrapper wall time. The server suspension-admission file passes all 28 tests.
  • Final fixture verification: tbx_01m3eff5msmdw0w04vzmyh7wfe, pnpm test packages/gateway-client/src/protocol-client.request.test.ts --maxWorkers=1: 25 pass, 2.28 seconds wall. pnpm test src/gateway/server-methods.suspension-admission.test.ts --maxWorkers=1: 28 pass, 25.70 seconds wall (23.57 seconds Vitest, predominantly cold transformation).
  • tbx_01m3ed5h23vt87gv0pkxv52qnn (lease workflow), node scripts/check-changed.mjs --base fd3914e0af3f76ae7545acd75f17d19408e7cd24 -- <nine changed paths>: core/UI/test-root types, all 25 test-type shards, source ratchets, formatting, dependency/boundary guards, and dead-export scans pass. The full lint lane reports the pre-existing ui/src/components/app-sidebar-session-navigation.ts maximum-line error (701 versus 700). That file is byte-unchanged from both the task base and current main. No baseline or suppression was changed.
  • After repairing the new fixture's non-null assertions, final changed-file lint (six files), package test types, script lint, test-config lint, and all remaining native guards pass on tbx_01m3eff5msmdw0w04vzmyh7wfe (lease workflow). The serialized continuation completed successfully in 258.89 seconds. Previously passing type checks and guards were reused.
  • Independent Codex review: no actionable P0–P2 findings. git diff --check passes.
  • CI for b7a83010f6b4769091d632c0cc21486c74d86c67: run 36232386837 passes. Workflow elapsed time is 1,895 seconds (31m35s, including native/platform jobs); the PR has 211 passing checks, none failed or pending, and 57 skipped. Per-file CI timings were not separately collected; the single-worker file costs are recorded above. ClawSweeper reports no actionable findings and sufficient boundary proof.

The missing protocol source alias exposed by tests and type checking was added to the shared Vitest and TypeScript resolvers. Reused Testbox checksum syncs timed out before execution and those leases were replaced. The default changed check compared against moving main and included unrelated changes; final validation pins the actual source base fd3914e0af3f76ae7545acd75f17d19408e7cd24 and the nine changed paths.

This is fixture and source-boundary evidence, not a live deployment result. No production Gateway was changed or restarted.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 gateway Gateway runtime size: M labels Sep 26, 2026
@steipete
steipete marked this pull request as ready for review September 26, 2026 09:18
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: b7a83010f6b4769091d632c0cc21486c74d86c67
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-methods.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@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 Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 5:25 AM ET / 09:25 UTC.

ClawSweeper review

What this changes

The branch makes the shared Gateway client wait and retry identity reads during suspension, and updates the protocol documentation, test configuration, and regression tests.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main and the latest release still settle suspended identity reads as errors, while this focused PR addresses the resulting request churn. Source review found no concrete introduced correctness or security defect.

Priority: P2
Reviewed head: b7a83010f6b4769091d632c0cc21486c74d86c67

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused owner-level code and baseline-to-after boundary evidence support a normal good PR rating.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The production shared protocol client is exercised through its request and frame handlers against an injected suspension in a synthetic Gateway socket. The reported after-fix result is 40 of 40 reads resolving on resume with at most one refusal each; no live deployment is claimed. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The production shared protocol client is exercised through its request and frame handlers against an injected suspension in a synthetic Gateway socket. The reported after-fix result is 40 of 40 reads resolving on resume with at most one refusal each; no live deployment is claimed. No stored-data contract changes.
Evidence reviewed 7 items Introduced client behavior: The PR keeps an identity read pending after a structured suspension refusal, then resends it on resume or the bounded timer while retaining its original deadline.
Current main still settles refusals: Current main removes a pending request and rejects its promise on a negative response; it has no suspension wait in this owner.
Control UI caller: A rejected identity read evicts its shared UI cache entry, making another render-driven read possible.
Findings None None.
Security None None.

How this fits together

The Gateway accepts authenticated requests over WebSocket and broadcasts suspension phases. A shared browser and Node client correlates those requests and supplies identity results to the Control UI and CLI.

flowchart LR
A[Control UI or CLI identity read] --> B[Shared Gateway client]
B --> C{Gateway suspended?}
C -- Yes --> D[Pending read]
G[Gateway resume event or retry timer] --> D
D --> E[Gateway identity request]
C -- No --> E
E --> F[Identity result or original deadline]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +89, Tests +220, Docs +8, Config +3. Total +320 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 95 6 +89
Tests 3 232 12 +220
Docs 1 8 0 +8
Config 1 3 0 +3
Generated 0 0 0 0
Other 0 0 0 0
Total 9 338 18 +320

Review metrics

Metric Value Why it matters
Runtime and test growth production +89 net lines, tests +210 net lines Runtime growth stays in the shared request owner and its suspension hint; the new tests cover the observed request storm and retirement paths.

Technical review

Best possible solution:

Keep suspension retry ownership in the shared client, with one pending identity read per caller, the original deadline, and unchanged dispatch for other methods.

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

Yes. Current-main response settlement and UI cache eviction explain repeated requests, and the PR reports a baseline 40-client run with 1,200 refusals; I did not execute it in this read-only review.

Is this the best way to solve the issue?

Yes. The shared pending-request client is the narrow owner for browser and Node behavior, and the change preserves deadlines, cancellation, and direct dispatch for other requests.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 75733458a9b7.

Labels

Label changes:

  • add P2: The PR addresses repeated identity requests during Gateway suspension, a bounded performance problem rather than a demonstrated outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The production shared protocol client is exercised through its request and frame handlers against an injected suspension in a synthetic Gateway socket. The reported after-fix result is 40 of 40 reads resolving on resume with at most one refusal each; no live deployment is claimed. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The production shared protocol client is exercised through its request and frame handlers against an injected suspension in a synthetic Gateway socket. The reported after-fix result is 40 of 40 reads resolving on resume with at most one refusal each; no live deployment is claimed. No stored-data contract changes.

Label justifications:

  • P2: The PR addresses repeated identity requests during Gateway suspension, a bounded performance problem rather than a demonstrated outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The production shared protocol client is exercised through its request and frame handlers against an injected suspension in a synthetic Gateway socket. The reported after-fix result is 40 of 40 reads resolving on resume with at most one refusal each; no live deployment is claimed. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The production shared protocol client is exercised through its request and frame handlers against an injected suspension in a synthetic Gateway socket. The reported after-fix result is 40 of 40 reads resolving on resume with at most one refusal each; no live deployment is claimed. No stored-data contract changes.

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)
  • Patrick Erichsen: 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.

@steipete
steipete merged commit 20a865c into main Sep 26, 2026
340 of 342 checks passed
@steipete
steipete deleted the steipete/perf-micro-suspension-request-storm-20260919 branch September 26, 2026 10:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
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 gateway Gateway runtime 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. security-sensitive-changed size: M 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