Skip to content

perf(gateway): shorten startup handoff and defer receipt persistence - #174159

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-startup-ready-1309
Oct 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-startup-ready-1309

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway ownership acquisition can remain asleep after a predecessor releases its lock, and plugin startup waits for advisory native-source receipt persistence after admission has completed.

User Impact

Ordinary ownership contention is checked every 250 ms instead of backing off to two seconds. Admitted plugins can finish startup while receipt persistence continues under the existing cache owner. Overall measured cold-start and stop/start time are neutral; this is a smaller critical path, not a claimed whole-startup speedup.

The five-minute acquisition deadline, single-instance checks, unknown-namespace heartbeat wait, config/auth validation, and recovery ordering remain unchanged. No configuration, schema, or upgrade migration is required.

Why This Change Was Made

Remove the extra backoff cap and the startup-only persistence join. Failed physical-lock probes stop before worker creation or SQLite reads; the tradeoff is at most four ordinary contention probes per second. Native bytes are already admitted, model workers receive the in-memory receipt overlay, and cache retirement still joins accepted writes before releasing captures.

Production LOC: 8 deleted, 0 added. The uncontended lock path still performs lease inspection/publication and heartbeat initialization; it has no fixed sleep. Environment selection still loads dotenv, validates/selects config, and pins state paths. Its later reread protects changed configuration/credentials after proxy teardown. Plugin registration remains serial with event-loop yields. Subagent recovery is unchanged.

Evidence

Local proof: 65 tests passed across src/infra/gateway-lock.test.ts, src/infra/gateway-lock.namespace.test.ts, and src/gateway/server-startup-plugins.test.ts, using pnpm test <those files> --maxWorkers=1. Total wrapper wall time: 65.03 s, including native worker preparation; Gateway file wall time 44.71 s, two infra files 7.22 s. The handoff regression took 124 ms and native receipt regression 983 ms. Changed-file formatting, scoped core lint, and git diff --check passed. Independent Codex review is scoped-clean at P0–P2, with no actionable findings.

Both regressions fail on original code: prolonged handoff exceeds the 250 ms bound (749 ms simulated lag), and plugin startup remains blocked behind the actual receipt publisher. The plugin regression also proves cache retirement waits for publication and reads the saved receipt afterward.

Measurement: isolated Linux/Node 26.8.1, three baseline pairs followed by three candidate pairs. Each pair restores the same maintained synthetic fixture: 5,000 sessions, 6,000 retained runs, 200 approvals, 100 disabled cron jobs, 12 project worktrees, a 4.64 GB agent database, and one installed no-network native-artifact plugin. Optional memory indexing is disabled equally in both arms. These are fresh-process starts, without purging OS page caches. Baseline 594e35ed589d1441bc3d4d1304c8aae9bd09a55f; candidate uses the two production-file changes from 3cfc7e47b78faad163eaf23be12023c0d9365c9a, with both runtime builds prepared separately.

Median metric Before After Difference
Cold first HTTP /readyz 200 39.598 s 39.511 s −0.087 s (neutral)
Restart first HTTP /readyz 200 17.389 s 17.360 s −0.029 s (neutral)
Stop → successor HTTP ready 22.135 s 22.279 s +0.144 s (neutral)
Cold plugin post-bind 116.5 ms 69.2 ms −47.3 ms
Controlled lock release → acquired 764 ms 28 ms −736 ms

Cold HTTP ranges: 39.491–39.705 s before, 39.251–40.001 s after. Stop-to-ready ranges: 22.112–39.004 s before, 21.530–22.795 s after. The restored cold fixture waits for an approximately 20 s full agent database integrity check (no-proof); one baseline restart also takes that fallback. Candidate /readyz bodies explicitly transition from startup-sidecars to agent-database:main / agent-database-inspection-pending, then become ready. Event-loop degradation is diagnostic, not the readiness blocker.

A fresh CLI successor started while its predecessor is alive is correctly refused at cli.bootstrap.admission.live-owner, before lock acquisition. The measured deployment sequence therefore uses stop → confirmed exit → fresh successor. Lock contention is a separate real holder/contender-process experiment with a fixed 5,001 ms hold after contention starts: before 757–781 ms, after 26–54 ms. This phase-dependent result is not a CLI deployment speedup claim; ordinary retry sleep is bounded at 250 ms plus probe/acquisition work.

Both arms begin with zero native receipts/artifacts/namespaces and finish with one of each. All measured Gateway processes exit successfully. No production state or services were used; benchmark state/processes were removed. No Testbox/Crabbox leases; PR CI owns broad validation.

Per-phase medians (milliseconds; overlapping/nested phases are not additive)
Phase Cold before → after (Δ) Restart before → after (Δ)
process.bootstrap 10,269.1 → 10,445.1 (+176.0) 6,690.2 → 6,649.5 (-40.7)
cli.bootstrap.gateway-lock 305.3 → 298.8 (-6.5) 333.2 → 334.5 (+1.3)
cli.main.gateway-run-select-environment 1,578.2 → 1,593.0 (+14.8) 1,580.6 → 1,599.4 (+18.8)
cli.main.gateway-run-pre-bootstrap 560.6 → 566.5 (+5.9) 569.3 → 568.1 (-1.2)
cli.main.gateway-run-bootstrap 5,006.3 → 5,135.0 (+128.7) 1,282.6 → 1,293.0 (+10.4)
cli.command.config-ready 5,002.1 → 5,130.6 (+128.5) 1,278.7 → 1,288.8 (+10.1)
cli.bootstrap.admission.state-snapshot 4,605.8 → 4,729.1 (+123.3) 976.1 → 981.7 (+5.6)
cli.bootstrap.admission.database-readiness 3,801.4 → 3,928.7 (+127.3) 22.9 → 22.5 (-0.4)
cli.bootstrap.admission.plugin-config 514.2 → 529.7 (+15.5) 906.7 → 935.8 (+29.1)
config.auth 215.4 → 207.4 (-8.0) 336.5 → 335.5 (-1.0)
plugins.runtime-post-bind 116.5 → 69.2 (-47.3) 238.6 → 244.7 (+6.1)
sessions.admission 523.1 → 539.0 (+15.9) 630.1 → 647.0 (+16.9)
sidecars.main-session-recovery 1,084.0 → 1,053.4 (-30.6) 2,122.7 → 2,119.5 (-3.2)
sidecars.model-runtime 1,099.7 → 1,120.1 (+20.4) 1,311.1 → 1,294.0 (-17.1)
sidecars.ready.total 17,672.7 → 17,743.5 (+70.8) 17,268.0 → 17,331.3 (+63.3)

The single-plugin fixture does not reproduce a large installed-plugin registry or establish a production-wide speedup. Neutral overall timing is the expected limitation of this net-deletion change.

Broad CI: exact-head run 38893093431; the complete selected CI checks and aggregate gate passed on the reviewed head. No CI retries or inherited-failure exception were needed.

@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review October 16, 2026 11:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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-10-16T11:22:50.243789Z 3cfc7e4 Draft marked ready
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 16, 2026
@steipete
steipete merged commit 8858de4 into main Oct 16, 2026
228 of 231 checks passed
@steipete
steipete deleted the steipete/perf-startup-ready-1309 branch October 16, 2026 11:35
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 gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant