Skip to content

improve(gateway): reduce redundant startup work - #147165

Merged
steipete merged 2 commits into
mainfrom
codex/gateway-startup-waste
Sep 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/gateway-startup-waste

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway startup repeats Windows process-identity queries and reads historical worker placements whose result is no longer used.

User Impact

Startup avoids redundant native process launches and work proportional to retained placement history. At 10,000 historical placements, the worker-state loader's median time fell from 48.9 to 4.4 ms and temporary heap growth from 30.6 to 0.18 MiB. Overall readiness remained approximately 12.3 seconds, within measurement noise. No configuration changes or operator action are required.

Why This Change Was Made

Gateway locks now use the existing shared process-identity owner, which caches successful self reads while checking other processes freshly. The unused placement-presence projection and its full scan are removed; runtime recovery and reconciliation retain their existing reads.

Evidence

  • Windows x64, Node 26.8.2: one warmup plus three isolated Gateway launches per version; median readiness 12.346 → 12.283 seconds. This is not evidence of a reliable overall startup speedup.
  • Seven loader samples at each of 0, 1,000, and 10,000 synthetic historical placements. At 10,000 records, median 48.88 → 4.38 ms; all records remained intact. Imports, seeding, and pre-sample garbage collection were excluded.
  • The lock regression failed before the repair with four redundant native probes and passes after it. It checks both persisted lock identities across two real acquisition/release lifetimes. The final state-directory suite passes all four cases.
  • Affected and sibling tests: 86 distinct passes and one platform skip. Ten prepared-node workspace cases hit the same pre-change Windows Git Filename too long fixture failures; the eight relevant Gateway startup/cleanup cases pass.
  • Runtime build (pnpm build sourcePerformance), targeted lint, production typechecking, affected test typechecks, formatting, and diff checks pass. Independent review found no actionable issues; required autoreview is scoped-clean at its default P0 threshold.
  • Full build was already blocked on the unchanged baseline by declaration sealing reporting a changed dependency input. Aggregate changed-check hit a Windows URL-escaping failure in its test shard launcher; direct repository compiler-wrapper checks of the affected graphs passed.

The Gateway measurements use the repository's default isolated benchmark configuration and asynchronous health/readiness probes. Periodic synchronous PowerShell memory sampling was omitted from both versions because it blocked the stock benchmark's own HTTP probe deadlines on this host. No live Gateway state was changed.

Hosted CI exposed an existing Discord test synchronization race in checks-node-compact-small-33: preserves whole-utterance conversation across capture with empty CLI opening audio expected agent dispatch before it occurred. The test waited for recording, while dispatch runs on a separate conversation queue. The repair now awaits a deferred milestone resolved at the actual agent/control dispatch boundary. All six cases and their assertions remain intact, with no sleeps, polling, timeout changes, or production changes. All six repaired cases pass on Linux and Windows. Both Windows jobs passed in the initial hosted run, whose only failing test was this Discord case.

@clawsweeper

clawsweeper Bot commented Sep 13, 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 gateway Gateway runtime size: XS maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 15:58
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 12:35 PM ET / 16:35 UTC (Revision 3).

ClawSweeper review

What this changes

The PR reuses cached process identity for Gateway locks, removes an unused startup placement scan, and synchronizes Discord transcript tests with actual conversation dispatch.

Merge readiness

✅ Ready for maintainer review

Keep open as useful, bounded work: current main still performs both redundant operations, and no actionable defect was found in the introduced changes. The updated Discord test resolves the synchronization mismatch without weakening assertions.

Priority: P3
Reviewed head: 0cf334bcd15be71e516002657e914534d3192212

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused simplification with relevant Windows observations, meaningful regression coverage, and no actionable correctness findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports before/after isolated Windows Gateway launches and measurements of the changed worker loader with retained placements, showing reduced loader time and preserved records. Repeated real lock acquisitions provide supplemental identity coverage; the new Discord change only synchronizes tests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports before/after isolated Windows Gateway launches and measurements of the changed worker loader with retained placements, showing reduced loader time and preserved records. Repeated real lock acquisitions provide supplemental identity coverage; the new Discord change only synchronizes tests.
Evidence reviewed 8 items Introduced changes and current-main necessity: The host's complete merge-base-to-head patch identifies four introduced files. Comparing the two production files with fetched main confirms main retains the direct Windows lookup and unused placement-presence scan; this comparison establishes necessity, not ownership of unrelated base changes.
Identity caching preserves foreign-process freshness: The shared reader caches only successful reads of process.pid, retries failed reads, and queries foreign PIDs freshly. The Gateway still supplies its existing 1,000 ms Windows timeout and retains its liveness and stale-lock checks. Existing pid-alive tests cover failure retry and changing foreign identities.
Worker recovery remains independently owned: Every full Gateway initializes worker startup state, and runtime creation depends on that state being present rather than the removed flag. Recovery of interrupted tool operations, clearing previous local claims, and placement reconciliation remain intact. The removed listForReconcile call is a read-only projection, not a migration or recovery operation.
Findings None None.
Security None None.

How this fits together

Gateway startup acquires exclusive ownership of local state and initializes worker services from retained records. Process identity supports safe lock ownership checks, while worker recovery and reconciliation handle existing placements.

flowchart TD
  A[Gateway startup] --> B[Acquire state locks]
  B --> C[Shared process identity]
  C --> D[Cached self identity or fresh foreign lookup]
  A --> E[Load worker stores]
  E --> F[Initialize worker runtime]
  F --> G[Recover and reconcile placements]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -6, Tests +47. Total +41 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 1 7 -6
Tests 2 57 10 +47
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 58 17 +41

Review metrics

Metric Value Why it matters
Measured worker-loader improvement 48.88 → 4.38 ms at 10,000 retained placements The supplied Windows measurements demonstrate a local reduction in startup work without claiming an overall readiness speedup.

Technical review

Best possible solution:

Keep process identity with the shared reader and placement recovery with the worker runtime, eliminating startup work that has no consumer.

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

Not applicable as a user-facing bug report: source confirms redundant startup work, and the supplied Windows measurements quantify it; this read-only review did not execute the benchmark.

Is this the best way to solve the issue?

Yes. Reusing the existing identity cache and deleting an unconsumed query are narrow changes that preserve lock formats, process checks, configuration, and worker recovery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 149648a3d073.

Labels

Label justifications:

  • P3: This is a bounded startup-efficiency improvement and test synchronization repair with no demonstrated urgent user-facing failure.
  • 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 (live_output): The captured body reports before/after isolated Windows Gateway launches and measurements of the changed worker loader with retained placements, showing reduced loader time and preserved records. Repeated real lock acquisitions provide supplemental identity coverage; the new Discord change only synchronizes tests.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports before/after isolated Windows Gateway launches and measurements of the changed worker loader with retained placements, showing reduced loader time and preserved records. Repeated real lock acquisitions provide supplemental identity coverage; the new Discord change only synchronizes tests.

Evidence

What I checked:

  • Introduced changes and current-main necessity: The host's complete merge-base-to-head patch identifies four introduced files. Comparing the two production files with fetched main confirms main retains the direct Windows lookup and unused placement-presence scan; this comparison establishes necessity, not ownership of unrelated base changes. (src/infra/gateway-lock.ts:183, 0cf334bcd15b)
  • Identity caching preserves foreign-process freshness: The shared reader caches only successful reads of process.pid, retries failed reads, and queries foreign PIDs freshly. The Gateway still supplies its existing 1,000 ms Windows timeout and retains its liveness and stale-lock checks. Existing pid-alive tests cover failure retry and changing foreign identities. (src/shared/pid-alive.ts:115, 0cf334bcd15b)
  • Worker recovery remains independently owned: Every full Gateway initializes worker startup state, and runtime creation depends on that state being present rather than the removed flag. Recovery of interrupted tool operations, clearing previous local claims, and placement reconciliation remain intact. The removed listForReconcile call is a read-only projection, not a migration or recovery operation. (src/gateway/server-runtime-state-prepare.ts:94, 0cf334bcd15b)
  • Discord synchronization follows the actual dispatch boundary: voice-receive schedules conversation work on entry.conversations after recording finishes; entry.processingQueue belongs to recording. The new deferred resolves at agent/control invocation before the existing dispatch assertions. All six parameterized cases remain, including the oversized-input rejection assertions. (test/transcripts-discord-audio.integration.test.ts:208, 0cf334bcd15b)
  • Captured Windows behavior evidence: The complete supplied PR body, captured under sourceRevision 93f144efbe73c659968e73269b2059cf800effa880b8ac9f5271ecb9be9d60d4, reports real isolated Windows x64 Gateway launches on Node 26.8.2, loader measurements with retained synthetic placements, and preserved records. At 10,000 placements, median loader time decreased from 48.88 to 4.38 ms; overall readiness remained approximately 12.3 seconds. The body also reports the lock regression failing before and passing afterward, and all six repaired Discord cases passing on Linux and Windows. These are supplied observations, not reviewer-executed tests. (0cf334bcd15b)
  • Prior review continuity: The previous completed review retained no findings or published rank-up moves. Comparing its reviewed head with the current head shows only the Discord test synchronization change; the startup implementation is unchanged. (test/transcripts-discord-audio.integration.test.ts:105, 0cf334bcd15b)

Likely related people:

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

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-13T16:04:58.709Z sha 0f33732 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-13T16:16:08.157Z sha 0f33732 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit ec97feb into main Sep 13, 2026
186 of 187 checks passed
@steipete
steipete deleted the codex/gateway-startup-waste branch September 13, 2026 16:55
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
* improve(gateway): reduce redundant startup work

* test(discord): await transcript conversation dispatch
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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