Skip to content

perf(gateway): keep publication recovery off the readiness path - #180128

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-boot-critical-path-r181-20260919
Oct 22, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-boot-critical-path-r181-20260919

Conversation

@steipete

@steipete steipete commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Pending GitHub publication recovery can delay Gateway readiness and agent dispatch while local Git commands or GitHub requests wait. Three observed boots reached ready in 21.63, 96.51, and 36.54 seconds; publication recovery accounted for 6.38, 81.38, and 21.17 seconds respectively.

User Impact

The Gateway can become ready and admit agent dispatch while pending publication recovery continues. Required placement authority recovery and personal-publication confirmation invalidation still finish before dispatch opens. Publication effects retain their existing authority, durable recovery, and shutdown-drain contracts. No configuration, schema, or migration changes are required.

Why This Change Was Made

Publication retries now run in the existing tracked background reconciliation operation after session retirement, instead of blocking placement-runtime startup. A retirement failure postpones the initial retry to the existing scheduled recovery sweep. Runtime production code has no net line growth (6 added, 6 removed); no cache, owner, or parallel implementation is introduced.

The startup benchmark can seed a real pending publication and delay one read-only local Git command. It records that both builds actually reach and complete this boundary, and retains missing requester authority so the synthetic request cannot publish externally.

Evidence

The regression fails on the original code because startup remains pending during held publication recovery; it passes with the fix and also verifies that shutdown drains the held recovery. All 191 focused tests pass: 48 across startup, startup cleanup, startup maintenance, recovery events, and publication runtime; 43 startup-benchmark tests; and 100 credential-writer-guard tests. The runtime regression fails on base; the fixture-guard regression also fails before its repair. Changed-file formatting and lint pass. Independent review is clean through P2 on the full final patch. Broad validation belongs to PR CI.

CI caught two fixture writer edges that needed explicit review. The historical fixture is created in a new exclusive root before Gateway launch. The guard now permits only its private helper to insert one shared publication and execute one exact SQL literal removing requester authority from that synthetic request. Other callers, duplicate writes, changed predicates/values, and appended SQL remain rejected. No production authority bypass was introduced.

Paired measurements

Three concurrent groups, five fresh boots per side per group (15 per build). Group 2 swaps the interleaved CPU placement; group 3 resolves the two mixed-sign metrics under v5.2. Every boot passed ready/RPC, exact plugin inventory, delayed-publication completion, common post-ready completion milestones, and clean shutdown without a forced kill.

Workload: eight agents, 4,096 sessions, 128 MiB inert payload, and 44 loaded plugins (17 bundled plus 27 synthetic). A pending publication waits 10 seconds at a real read-only local Git boundary. Separate network namespaces and missing historical requester authority prevent external publication. Fresh process/state roots use a warm host filesystem cache.

Group (n=5/side) Metric Baseline mean Candidate mean Absolute Δ Relative Δ
1 Ready 23.788 s 13.012 s -10.776 s -45.30%
1 First sessions.list RPC 23.901 s 13.102 s -10.798 s -45.18%
1 Sampled process-tree CPU 37.000 s 34.400 s -2.600 s -7.03%
1 Peak RSS 3518.664 MiB 3545.242 MiB +26.578 MiB +0.76%
1 Common startup work complete 43.826 s 33.428 s -10.398 s -23.73%
1 Shutdown 0.980 s 1.015 s +0.036 s +3.65%
2 Ready 24.258 s 13.511 s -10.747 s -44.30%
2 First sessions.list RPC 24.353 s 13.617 s -10.736 s -44.09%
2 Sampled process-tree CPU 35.600 s 34.200 s -1.400 s -3.93%
2 Peak RSS 3531.422 MiB 3490.075 MiB -41.347 MiB -1.17%
2 Common startup work complete 42.320 s 33.397 s -8.924 s -21.09%
2 Shutdown 0.772 s 0.662 s -0.111 s -14.35%
3 Ready 23.005 s 12.350 s -10.655 s -46.31%
3 First sessions.list RPC 23.088 s 12.434 s -10.654 s -46.15%
3 Sampled process-tree CPU 35.800 s 32.400 s -3.400 s -9.50%
3 Peak RSS 3542.532 MiB 3570.477 MiB +27.945 MiB +0.79%
3 Common startup work complete 42.060 s 31.623 s -10.437 s -24.81%
3 Shutdown 0.852 s 1.421 s +0.569 s +66.81%

The original swapped groups improve ready by 10.762 seconds (44.80%) and first RPC by 10.767 seconds (44.63%) on the mean paired delta; sampled CPU improves 5.48%. RSS (+26.58, −41.35 MiB) and shutdown (+35.77, −110.81 ms) initially had opposite signs and were treated as inconclusive, not adverse.

After the required third group, the absolute mean across all three groups is:

  • Peak RSS: +4.392 MiB (+0.12% of the pooled baseline; 3530.873 → 3535.265 MiB).
  • Shutdown: +0.165 s (+18.97% of the pooled baseline; 0.868 → 1.032 s).

Shutdown is the measured tradeoff: the final absolute mean rises 164.65 ms, or 18.97% of the pooled baseline, below the 20% rejection threshold; the original swapped groups were +3.65% and −14.35%, so they also do not meet the both-groups rejection rule. One candidate shutdown took 3.762 seconds versus 0.537 seconds on its paired baseline; its trace attributes 3.316 seconds to plugin-metadata closure. That sample remains included. The v5.2 decision uses the absolute mean rather than the mean of relative deltas.

All gating metrics pass. The third group is decided on absolute means; no metric was rejected on a tiny-baseline relative mean. Completion time is additional context. The rejection rule is a ≥20% adverse paired mean or ≥10% adverse in both swapped groups, with mixed signs or >5× baseline differences requiring the third group.

Latency spread and low-sample tails

Each cell has n=5. Values are median [minimum, maximum] in seconds. The maximum is also the nearest-rank p95 at n=5; these tails are context only, below the 200-sample p95 gate minimum. No p99 gate is inferred.

Group Metric Baseline median [min, p95/max], n=5 Candidate median [min, p95/max], n=5
1 Ready 23.441 [22.588, 24.868] 12.829 [11.711, 14.350]
1 First RPC 23.561 [22.696, 24.960] 12.917 [11.811, 14.432]
2 Ready 22.975 [21.865, 27.699] 12.822 [11.364, 15.777]
2 First RPC 23.044 [21.939, 27.893] 12.912 [11.449, 15.933]
3 Ready 23.245 [21.730, 24.032] 12.793 [10.879, 13.329]
3 First RPC 23.366 [21.820, 24.122] 12.887 [10.947, 13.426]

The runtime removes the readiness dependency without abandoning work: representative pair 1-7 reduced worker-environment startup from 10.579 seconds to 11.5 ms while publication recovery still took 10.806 seconds and completed after ready. Required placement authority remains ahead of dispatch, and shutdown still joins publication recovery.

Protocol and limits: the shared guard is unchanged (2,500 ms production loop maximum, load 60, dirty pages 2 GiB); all measured pairs use slot B with baseline on even CPUs 64–94 and candidate on odd CPUs 65–95, reversed for group 2. Group 1 acquired the lock per boot; groups 2 and 3 held it across their five boots. No accepted measurement was interrupted by the guard. Preparation and fixtures were sequential under the prescribed low-priority CPU/IO limits.

CPU/RSS cover equal completed work: delayed Git read, initial post-ready database maintenance, and final handler prewarm must all finish before teardown. The initial ready/publication-only window permitted unequal background initialization, so its resource samples were excluded before this campaign. Setup failures (missing fixture identity/launcher, bypassed delay wrapper, and wrong plugin count) and the canceled preliminary run are also excluded. Accepted cohorts are group 1 indices 7–11, and groups 2/3 indices 1–5. Sampled process-tree CPU has whole-second resolution; RSS is sampled every 100 ms. No cold production page-cache experiment, real GitHub latency experiment, or per-collection GC measurement was performed.

The builds compare pinned base a928225b43b17e78661a3bf9ef3a12d959724387 with this runtime patch. Later rebases and the final current-main check did not change the affected startup/publication owners; current-head CI supplies broad validation. Production behavior awaits the next approved deployment/boot.

Reproduction uses the committed benchmark with fresh roots, identical plugin JSON, a common start epoch, separate baseline/candidate entries and the CPU/guard/lock arrangement above:

node --import ./scripts/tsx.mjs scripts/bench-gateway-startup.ts --case teamBoot --fixture-root <fresh-root> --bundled-plugin-fixture <44-plugin-json> --publication-git-delay-ms 10000 --entry <build>/dist/entry.js --runs 1 --warmup 0 --timeout-ms 120000 --start-at <common-epoch-ms>

Exact-head CI run 39708232280 passed all 38 executed jobs. Same-second duplicate 39708232491 was canceled immediately. The separate security-review aggregate selects the highest run ID, skipping only wholly skipped runs, and therefore projects that canceled duplicate as a CI failure. The exact publisher source at 5c5be9edb3855812a302c9807b1edfbb4e180154 confirms that selection. Its security workflow succeeded; no CI rerun or branch update was requested to chase this unrelated aggregate status.

Live signal after an approved deployment: readiness should precede completion of sidecars.worker-environments.publications; placement authority recovery must still precede dispatch, and agent RPCs should not return the startup-unavailable error after ready. Publication recovery and its warnings may finish later. No production Gateway was changed or restarted.

@clawsweeper

clawsweeper Bot commented Oct 22, 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.

@steipete
steipete marked this pull request as ready for review October 22, 2026 01:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-22T01:57:18.011404Z 2f357f1 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: M labels Oct 22, 2026
@steipete
steipete force-pushed the steipete/perf-micro-boot-critical-path-r181-20260919 branch from c74384e to 5783db6 Compare October 22, 2026 01:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c74384e154

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@steipete
steipete force-pushed the steipete/perf-micro-boot-critical-path-r181-20260919 branch from 5783db6 to 2e3cc89 Compare October 22, 2026 01:44
Run publication retries in the existing tracked background reconciliation operation. Preserve startup placement authority recovery and shutdown drainage while making Gateway readiness independent of Git/network recovery delays.
@steipete
steipete force-pushed the steipete/perf-micro-boot-critical-path-r181-20260919 branch 2 times, most recently from 2e3cc89 to 2f357f1 Compare October 22, 2026 01:52
@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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Moves pending GitHub publication recovery into tracked background reconciliation so it no longer blocks Gateway readiness.

Example: A pending publication waits on a local Git read delayed by 10 seconds.

  • Before: Gateway startup waits for publication recovery before returning.
  • After: Startup can finish while recovery continues, and shutdown still joins the recovery operation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and has useful lifecycle coverage, but the required performance evidence has not yet been supplied.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Gateway readiness and agent dispatch wait for optional publication recovery when Git or GitHub is slow.
Reason: Observed startup delays and the current awaited call establish user value, and the maintainer-authored direction preserves mandatory recovery and explicitly accepts existing maintenance serialization.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a verified startup dependency with a focused change, and no actionable introduced defect was found.

Priority: P2
Reviewed head: 2f357f1d64a7861cc00f0c852e42898da5f525d3

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The recorded paired campaign must show real Gateway readiness and seeded-session access during delayed publication recovery, with comparable completed-work CPU/RSS results and clean shutdown.
Agent review details

How this fits together

The Gateway placement sidecar restores placement authority during startup, then maintains placements and retries durable GitHub publications through lifecycle-tracked operations.

flowchart TD
  A[Gateway startup] --> B[Publication confirmation invalidation]
  B --> C[Workspace and placement recovery]
  C --> D[Gateway readiness]
  C --> E[Tracked retirement and publication recovery]
  E --> F[Existing Git and GitHub publication owners]
  E --> G[Shutdown drain]
Loading

Technical review

Best possible solution:

Retain the existing reconciliation owner and shutdown drain while confirming the readiness improvement against the recorded performance acceptance rule.

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

Current main directly awaits publication recovery during startup, and the supplied regression reports a base failure at that boundary; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The runtime change is the smallest complete repair: it relocates the existing recovery call into an already tracked operation without adding ownership, caches, or a parallel publication path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 902a9a0af238.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 593176c adds src/gateway/server-worker-placement-startup.ts:628 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 593176caf551; files: src/gateway/server-worker-placement-startup.ts)

PR surface

Source 0, Tests +90, Docs +26, Other +236. Total +352 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 6 6 0
Tests 2 91 1 +90
Docs 2 28 2 +26
Config 0 0 0 0
Generated 0 0 0 0
Other 2 248 12 +236
Total 7 373 21 +352

Review metrics

Metric Value Why it matters
Benchmark option 1 new benchmark-only flag --publication-git-delay-ms injects a bounded 1–30000 ms local Git delay for teamBoot; it adds no Gateway configuration setting.

Labels

Label changes:

  • add P2: Pending publication recovery can substantially delay startup on affected installations, with a focused improvement and limited blast radius.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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: Pending publication recovery can substantially delay startup on affected installations, with a focused improvement and limited blast radius.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide the paired benchmark results for the reviewed head, including readiness, first session RPC, comparable completed-work CPU/RSS, and shutdown outcomes.

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 October 21, 2026, 10:07 PM ET / October 22, 2026, 02:07 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

The paired campaign is complete: three groups with five fresh boots per side (15 per build), including the v5.2 third group for mixed-sign RSS and shutdown results. The body now contains all group means, absolute/relative deltas, sample counts, latency spread, equal-work completion checks, exclusions, and limitations.

Across all three groups, ready improved 23.684 → 12.958 seconds and first sessions.list RPC improved 23.780 → 13.051 seconds. Sampled process-tree CPU fell 6.83%; peak RSS rose 4.39 MiB (0.12%). Shutdown rose 164.65 ms (18.97% of the pooled baseline), below the declared rejection threshold. The 3.762-second plugin-metadata shutdown sample remains included; v5.2 uses the absolute mean. Every accepted boot completed recovery and exited cleanly without forced termination.

Exact-head CI run 39708232280 passed all 38 executed jobs, including its CI gate. Duplicate same-head run 39708232491 was canceled immediately. The separate aggregate selects that higher-numbered canceled run, which explains its red CI-only projection; dependency and security-sensitive review statuses both passed. This is an unrelated aggregate-status defect, not a failing test. The successful run and canceled duplicate are both linked in the body; no CI rerun is needed. Landing is under the standing authorization for identified unrelated CI status failures.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 24ce722 into main Oct 22, 2026
167 of 202 checks passed
@steipete
steipete deleted the steipete/perf-micro-boot-critical-path-r181-20260919 branch October 22, 2026 02:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…claw#180128)

* perf(gateway): keep publication recovery off the readiness path

Run publication retries in the existing tracked background reconciliation operation. Preserve startup placement authority recovery and shutdown drainage while making Gateway readiness independent of Git/network recovery delays.

* fix(perf): seed a valid publication identity profile

* test(perf): audit offline startup publication fixture writes

* test(perf): compare completed startup work in publication benchmark
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 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: 👀 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