Skip to content

fix(state): state read worker loads the whole Gateway graph (+486 MB RSS) - #161003

Merged
steipete merged 2 commits into
mainfrom
fix/state-read-worker-graph-main
Sep 29, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/state-read-worker-graph-main

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: every Gateway and CLI process that starts a state-read worker loads a 52 MB worker bundle, after #160592 made that worker import the update write graph. That raised Kova Gateway peak RSS by about 486 MB and pushed the packed worker over the npm 6 MiB limit.

User Impact

Gateway and CLI memory return to pre-#160592 levels, and the npm package check passes again. Update-run reconciliation reads and writes behave exactly as before.

Why This Change Was Made

stateRead is a standalone runtime-process entry built with codeSplitting: false, so every static and dynamic import in its graph is inlined. The worker's new import of update-run-reconciliation.worker pulled in update-run-write. That leads through the failure facts to a lazy flows/doctor-health-contributions import, and from there to the whole Gateway, doctor and wizard graph.

  • The two read-only functions move unchanged into update-run-reconciliation.read.ts; the read worker imports only that module.
  • A new guard checks all nine standalone runtime-process entries and fails if their esbuild graph reaches the Gateway server, flows, wizard, in-process Gateway, update-run-write or failure-fact modules.

This back-ports the release/2026.9.7 fix (7c4cae3) and adds the guard.

Evidence

  • Built dist/state/openclaw-state-read.worker.js: 52,186,708 → 3,491,598 bytes; esbuild inputs 9,768 → 1,025.
  • Kova bisect: parent 4ddd0e3 measured gateway-performance 1,146 MB; fix: keep update history responsive during reconciliation #160592 (5ff5fb2) measured 1,632 MB.
  • Strict release Kova on the fix: 15/15 PASS, gateway-performance 1,011 MB (run 36524439509).
  • The guard passes all nine entries in 3.7 s (--maxWorkers=1) and fails on 682 forbidden inputs with the pre-fix import restored.
  • 95 focused tests pass; full build passes; oxfmt, oxlint and review are clean.

Move reconciliation inspection and candidate selection into a read-only
module shared by the state reader and reconciliation writer. The standalone
reader disables code splitting, so its former write-side import also
bundled dynamic failure-fact/Doctor imports and the Gateway runtime.

At release tip 56fb887, the built worker was 52,186,708 bytes with
9,768 esbuild inputs. After this split it is 3,491,598 bytes with 1,025
inputs, measured with packages external for both input graphs.

Keep the read queries, eligibility checks, and transactional reconciliation
bodies unchanged. The full build and 95 focused tests pass.
Bundle each standalone entry with esbuild and reject transitive Gateway server, flow, wizard, in-process dispatch, and update-write inputs. Restoring the release-tip reader import and writer exports fails only the state reader with 682 forbidden inputs; the fixed graph passes all nine entries.

Validation: pnpm test test/scripts/runtime-process-build-graph.test.ts --maxWorkers=1 (3.67s wall, 0.678s Vitest); negative control 3.732s wall. oxfmt, oxlint, and independent review pass.
@clawsweeper

clawsweeper Bot commented Sep 29, 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.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 1:58 AM ET / 05:58 UTC.

ClawSweeper review

What this changes

The branch separates update-run reconciliation reads from writes and adds a build-graph test to keep standalone workers from bundling Gateway code.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Current main still carries the reported worker import path. The proposed repair matches the documented read and write boundaries, and source review found no introduced correctness defect.

Priority: P1
Reviewed head: 0a2a42998d91bf4eccbd1a17ed8ae4969a1cbb42

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and preserves the reconciliation contract, with useful build and runtime evidence whose selected benchmark revision remains a reviewer visibility limit.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The production read-worker split matches the release-branch fix's four file blobs; the PR reports before/after built-worker sizes and improved Gateway RSS from a linked successful Kova run. The run permits a separately selected target ref, but its exact selection could not be independently read through the available artifact-log path. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The production read-worker split matches the release-branch fix's four file blobs; the PR reports before/after built-worker sizes and improved Gateway RSS from a linked successful Kova run. The run permits a separately selected target ref, but its exact selection could not be independently read through the available artifact-log path. No stored-data contract changes.
Evidence reviewed 8 items Current main retains the dependency: The pinned main revision imports reconciliation reads from the write-side worker, which itself imports update-run-write.
Reader is isolated by the introduced patch: The read worker now imports the read-only module. The moved selection and inspection functions retain their queries and eligibility checks, while the writer still rereads candidates inside its transaction.
Build boundary and regression guard: The production build disables code splitting for standalone entries; the new test inspects all nine entries for forbidden Gateway and update-write inputs. The PR reports a passing negative control against the former import.
Findings None None.
Security None None.

How this fits together

Gateway and CLI update requests read history through a shared SQLite read worker. Reconciliation candidates then reach a write worker, which rechecks them before changing update history; the standalone reader’s import graph also determines its bundle size.

flowchart LR
A[Gateway or CLI update request] --> B[State read worker]
B --> C[Read-only reconciliation scan]
C --> D[Candidate records]
D --> E[Write worker recheck]
E --> F[Update history result]
B --> G[Standalone worker build]
G --> H[Bundle size and memory]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +36. Total +37 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 54 53 +1
Tests 2 40 4 +36
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 94 57 +37

Review metrics

None.

Technical review

Best possible solution:

Keep the read-only import boundary and its standalone build-graph guard when this repair lands on main.

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

Yes. The pinned main import and standalone build configuration give a direct graph and bundle-size comparison path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Splitting the unchanged read functions at their existing worker boundary removes the heavy import without altering the transactional writer, and the graph test guards the regression.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 239bbdd56d8f.

Labels

Label changes:

  • add P1: The current-main worker graph has a reported roughly 486 MB Gateway RSS regression and exceeds the stated npm worker-size limit.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The production read-worker split matches the release-branch fix's four file blobs; the PR reports before/after built-worker sizes and improved Gateway RSS from a linked successful Kova run. The run permits a separately selected target ref, but its exact selection could not be independently read through the available artifact-log path. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The production read-worker split matches the release-branch fix's four file blobs; the PR reports before/after built-worker sizes and improved Gateway RSS from a linked successful Kova run. The run permits a separately selected target ref, but its exact selection could not be independently read through the available artifact-log path. No stored-data contract changes.

Label justifications:

  • P1: The current-main worker graph has a reported roughly 486 MB Gateway RSS regression and exceeds the stated npm worker-size limit.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The production read-worker split matches the release-branch fix's four file blobs; the PR reports before/after built-worker sizes and improved Gateway RSS from a linked successful Kova run. The run permits a separately selected target ref, but its exact selection could not be independently read through the available artifact-log path. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The production read-worker split matches the release-branch fix's four file blobs; the PR reports before/after built-worker sizes and improved Gateway RSS from a linked successful Kova run. The run permits a separately selected target ref, but its exact selection could not be independently read through the available artifact-log path. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 5ff5fb2 adds src/infra/update-run-reconciliation.ts:96 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5ff5fb278348; files: src/infra/update-run-reconciliation.ts)
  • Jason (Json): 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 f2715ed into main Sep 29, 2026
142 checks passed
@steipete
steipete deleted the fix/state-read-worker-graph-main branch September 29, 2026 07:10
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 29, 2026
## What Problem This Solves

Fixes Control UI authentication timeouts and severely delayed Gateway state reads when running on Bun.

On a Bun-hosted production Gateway, browser connects authenticated and then hit `handshake timeout ... phase=auth_validated`; the same connections logged `Gateway profile acquisition authority expired` seconds later because profile resolution finished after the socket closed. `sessions.list` took up to 184 s while the host was ~90% idle. Thread sampling showed ~28 new shared-state read worker threads per 10 s (~0.7 s each) through the two-slot pool, i.e. roughly 3 reads/s of total capacity, so reconnect storms kept the queue saturated and the login gate reported the Gateway as unreachable.

## User Impact

Successful shared-state reads reuse warm workers and SQLite readers. Native cleanup still waits for worker exit when a reader closes. No configuration, schema, stored-data retention, or migration changes are required.

## Why This Change Was Made

Node has reused successful read workers since #151929. Bun was retiring a worker after every read and bypassing retained readers, so worker startup saturated the two-worker pool. This change keeps healthy Bun reads warm while routing host resource closes through existing pool rotation. The existing native SQLite disposal callback records task-internal closes, including identity replacement, snapshots, and quarantine admission; the existing cleanup reply makes the host join worker exit. Bun reader idle cleanup belongs to the pool’s existing 30-minute timeout.

Transcript discovery remains unchanged: its native readers must close before captured aliases are released, so Bun still needs worker exit there. Ordinary transcript reads already reuse workers. Related: #161003 reduces the worker bundle separately; #160946 overlaps the shared-state transport file. This PR makes no bundling changes.

Known remaining Bun cost (follow-up, not a regression): a cold read without a warm main-thread borrow runs fresh admission, which opens and closes the quarantine store per read when that store exists, so such reads still retire their worker on Bun. The warm Gateway RPC path below does not hit it.

The second commit keeps schema-fact tracking installed before the Bun disposal hook. Installing the statement-invalidation wrapper first let schema tracking overwrite it, so a cached version read survived a dynamic authorizer denial (caught by the Bun unit shard in CI on the first head).

## Evidence

- Bun 1.4.2 with selected SQLite 3.53.4: Kysely sync insert/select followed by close left the same database, WAL, and shared-memory descriptors open in lsof. Thread exit remains required.
- Real Bun Gateway (isolated state, signed CLI device auth): authenticated connect plus 20 `sessions.list` and 20 `sessions.catalog.list` calls issued 28 shared-state reads, **0 fresh admissions, 2 read workers total, no retirements**; `sessions.list` median 1.1 ms, `sessions.catalog.list` median 0.9 ms.
- Real Bun pool, 50 successful reads: **50 worker starts before → 1 after**; **29.527 seconds → 0.837 seconds** on a synthetic database. Canonical path-close returned with zero live workers and one confirmed native exit.
- Exact original-source negative control: all three new regressions failed for the intended reasons. The real Bun test covers repeated-read worker counts, host-close settlement, successful task-internal close, and quarantine admission close; the Node runtime seam covers idle retention and successful identity replacement.
- Changed-file costs (`pnpm test <file> --maxWorkers=1`): `openclaw-state-db-read-connection.cache.test.ts` **10 passed, 74.09 s wall** (includes cold worker compilation); `openclaw-state-read-worker.test.ts` **32 passed, 29.24 s wall**; `openclaw-state-read-worker.bun.test.ts` **1 passed, 7.07 s wall** (2.1 s actual test time). The child starts real Bun once to prove native worker exit; these timings include repository test startup, and no sleeps/polling were added.
- `pnpm tsgo` passed (**22.54 s**); the state-logging test type lane passed (**12.36 s**). Installed `oxfmt --check`, type-aware `oxlint` on all changed TypeScript, and `git diff --check` passed.
- Focused sibling tests: **172 passed across nine files**, 65.44 s wall, covering read connection errors, settlement, authority, worker command replies, quarantine cleanup, native SQLite/Kysely behavior, pool reuse/FIFO/rotation, and resource cleanup. Independent Codex review: scoped-clean, no actionable P0–P2 findings.
- CI fix (second commit): `src/infra/sqlite-schema-facts.test.ts` under `OPENCLAW_VITEST_RUNTIME=bun` failed on the first head, passed on main, and passes on the fixed head (Bun subset 32 passed; Node focused 129 passed).
- Production: **+33/-35 (net -2)**. Tests and test support: **+154/-11 (net +143)**. Docs: **+1/-0**. CI timing is not yet available; no CI dispatch or rerun requested.

Proof is local on macOS with synthetic data. No production Gateway was restarted or deployed; this does not claim a full reconnect-storm load test. The real-Bun regression skips when Bun 1.4+ is unavailable.

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…RSS) (openclaw#161003)

* fix(state): keep the state read worker out of the update write graph

Move reconciliation inspection and candidate selection into a read-only
module shared by the state reader and reconciliation writer. The standalone
reader disables code splitting, so its former write-side import also
bundled dynamic failure-fact/Doctor imports and the Gateway runtime.

At release tip 56fb887, the built worker was 52,186,708 bytes with
9,768 esbuild inputs. After this split it is 3,491,598 bytes with 1,025
inputs, measured with packages external for both input graphs.

Keep the read queries, eligibility checks, and transactional reconciliation
bodies unchanged. The full build and 95 focused tests pass.

* test(state): keep standalone workers out of the Gateway server graph

Bundle each standalone entry with esbuild and reject transitive Gateway server, flow, wizard, in-process dispatch, and update-write inputs. Restoring the release-tip reader import and writer exports fails only the state reader with 682 forbidden inputs; the fixed graph passes all nine entries.

Validation: pnpm test test/scripts/runtime-process-build-graph.test.ts --maxWorkers=1 (3.67s wall, 0.678s Vitest); negative control 3.732s wall. oxfmt, oxlint, and independent review pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
## What Problem This Solves

Fixes Control UI authentication timeouts and severely delayed Gateway state reads when running on Bun.

On a Bun-hosted production Gateway, browser connects authenticated and then hit `handshake timeout ... phase=auth_validated`; the same connections logged `Gateway profile acquisition authority expired` seconds later because profile resolution finished after the socket closed. `sessions.list` took up to 184 s while the host was ~90% idle. Thread sampling showed ~28 new shared-state read worker threads per 10 s (~0.7 s each) through the two-slot pool, i.e. roughly 3 reads/s of total capacity, so reconnect storms kept the queue saturated and the login gate reported the Gateway as unreachable.

## User Impact

Successful shared-state reads reuse warm workers and SQLite readers. Native cleanup still waits for worker exit when a reader closes. No configuration, schema, stored-data retention, or migration changes are required.

## Why This Change Was Made

Node has reused successful read workers since openclaw#151929. Bun was retiring a worker after every read and bypassing retained readers, so worker startup saturated the two-worker pool. This change keeps healthy Bun reads warm while routing host resource closes through existing pool rotation. The existing native SQLite disposal callback records task-internal closes, including identity replacement, snapshots, and quarantine admission; the existing cleanup reply makes the host join worker exit. Bun reader idle cleanup belongs to the pool’s existing 30-minute timeout.

Transcript discovery remains unchanged: its native readers must close before captured aliases are released, so Bun still needs worker exit there. Ordinary transcript reads already reuse workers. Related: openclaw#161003 reduces the worker bundle separately; openclaw#160946 overlaps the shared-state transport file. This PR makes no bundling changes.

Known remaining Bun cost (follow-up, not a regression): a cold read without a warm main-thread borrow runs fresh admission, which opens and closes the quarantine store per read when that store exists, so such reads still retire their worker on Bun. The warm Gateway RPC path below does not hit it.

The second commit keeps schema-fact tracking installed before the Bun disposal hook. Installing the statement-invalidation wrapper first let schema tracking overwrite it, so a cached version read survived a dynamic authorizer denial (caught by the Bun unit shard in CI on the first head).

## Evidence

- Bun 1.4.2 with selected SQLite 3.53.4: Kysely sync insert/select followed by close left the same database, WAL, and shared-memory descriptors open in lsof. Thread exit remains required.
- Real Bun Gateway (isolated state, signed CLI device auth): authenticated connect plus 20 `sessions.list` and 20 `sessions.catalog.list` calls issued 28 shared-state reads, **0 fresh admissions, 2 read workers total, no retirements**; `sessions.list` median 1.1 ms, `sessions.catalog.list` median 0.9 ms.
- Real Bun pool, 50 successful reads: **50 worker starts before → 1 after**; **29.527 seconds → 0.837 seconds** on a synthetic database. Canonical path-close returned with zero live workers and one confirmed native exit.
- Exact original-source negative control: all three new regressions failed for the intended reasons. The real Bun test covers repeated-read worker counts, host-close settlement, successful task-internal close, and quarantine admission close; the Node runtime seam covers idle retention and successful identity replacement.
- Changed-file costs (`pnpm test <file> --maxWorkers=1`): `openclaw-state-db-read-connection.cache.test.ts` **10 passed, 74.09 s wall** (includes cold worker compilation); `openclaw-state-read-worker.test.ts` **32 passed, 29.24 s wall**; `openclaw-state-read-worker.bun.test.ts` **1 passed, 7.07 s wall** (2.1 s actual test time). The child starts real Bun once to prove native worker exit; these timings include repository test startup, and no sleeps/polling were added.
- `pnpm tsgo` passed (**22.54 s**); the state-logging test type lane passed (**12.36 s**). Installed `oxfmt --check`, type-aware `oxlint` on all changed TypeScript, and `git diff --check` passed.
- Focused sibling tests: **172 passed across nine files**, 65.44 s wall, covering read connection errors, settlement, authority, worker command replies, quarantine cleanup, native SQLite/Kysely behavior, pool reuse/FIFO/rotation, and resource cleanup. Independent Codex review: scoped-clean, no actionable P0–P2 findings.
- CI fix (second commit): `src/infra/sqlite-schema-facts.test.ts` under `OPENCLAW_VITEST_RUNTIME=bun` failed on the first head, passed on main, and passes on the fixed head (Bun subset 32 passed; Node focused 129 passed).
- Production: **+33/-35 (net -2)**. Tests and test support: **+154/-11 (net +143)**. Docs: **+1/-0**. CI timing is not yet available; no CI dispatch or rerun requested.

Proof is local on macOS with synthetic data. No production Gateway was restarted or deployed; this does not claim a full reconnect-storm load test. The real-Bun regression skips when Bun 1.4+ is unavailable.

Co-authored-by: Peter Steinberger <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 2, 2026
* fix(state): state read worker loads the whole Gateway graph (+486 MB RSS) (#161003)

* fix(state): keep the state read worker out of the update write graph

Move reconciliation inspection and candidate selection into a read-only
module shared by the state reader and reconciliation writer. The standalone
reader disables code splitting, so its former write-side import also
bundled dynamic failure-fact/Doctor imports and the Gateway runtime.

At release tip 56fb887, the built worker was 52,186,708 bytes with
9,768 esbuild inputs. After this split it is 3,491,598 bytes with 1,025
inputs, measured with packages external for both input graphs.

Keep the read queries, eligibility checks, and transactional reconciliation
bodies unchanged. The full build and 95 focused tests pass.

* test(state): keep standalone workers out of the Gateway server graph

Bundle each standalone entry with esbuild and reject transitive Gateway server, flow, wizard, in-process dispatch, and update-write inputs. Restoring the release-tip reader import and writer exports fails only the state reader with 682 forbidden inputs; the fixed graph passes all nine entries.

Validation: pnpm test test/scripts/runtime-process-build-graph.test.ts --maxWorkers=1 (3.67s wall, 0.678s Vitest); negative control 3.732s wall. oxfmt, oxlint, and independent review pass.
(cherry picked from commit f2715ed)

* fix: retain SQLite workers through package replacement (#162076)

Resolve read-only worker launches through the running updater's retained
generation. Keep session reuse generation-aware and join child work before
retiring its runtime files. This protects future self-updates; an already
loaded 2026.9.6 driver retains its first-hop limitation.

Refs #161865

(cherry picked from commit f59e979)

* fix(update): retry the Windows backup rename on transient locks (#162231)

On Windows the managed update swap renamed the live package tree to its backup location once; a transient EPERM/EBUSY/EACCES from an antivirus, indexer, or Scheduled Task handle failed the swap and rolled the update back. The filesystem owner of the swap now retries those codes with bounded backoff (16 attempts), records each retry, re-checks package identity and update authority between attempts, and reports a named failure after the bound. POSIX behavior is unchanged.

Refs #162027

(cherry picked from commit b5555b0)

* fix: avoid duplicate SQLite copies during update rehearsal (#162403)

* fix: avoid duplicating SQLite snapshots during update rehearsal

* test: target final snapshot publication in race hooks

* test: exercise staging cleanup after snapshot transfer

* docs: describe row-preserving update rehearsals

(cherry picked from commit c77a055)

* perf(update): allow native Git runtime directory copies (#162387)

Co-authored-by: Peter Steinberger <[email protected]>
(cherry picked from commit 1129326)

* fix: prevent slow Gateway shutdown during memory sync (#162616)

* fix(state): retain publication leases while Gateway drains

* perf(state): preserve normal publication close scheduling

(cherry picked from commit defb7cf)

* perf(gateway): reduce session publication allocations and repeated redaction scans (#162810)

Reduce repeated session-publication allocations and redaction prefilter scans at their lifecycle owners, preserving live recipient authority and byte-identical redaction.

Validated with Node 24 and fork Bun tests, authority negative controls, fixture differential checks, pinned AWS kernel and three-round load benchmarks, a clean post-rebase spot quartet, and green exact-head CI.

(cherry picked from commit 4e4e315)

* fix(agents): bound the shell snapshot cache (#162967)

snapshotCache in src/agents/shell-snapshot.ts was a process-wide Map that retained one entry per distinct cwd/environment key for the Gateway's lifetime, so long-running Gateways with many sessions grew without bound. The owner now reuses the existing LRU cache with a documented 128-entry limit; the active key stays cached and a miss recomputes. At 201k synthetic keys RSS fell from 265 MiB to 232 MiB and live heap from 74 MiB to 6 MiB.

Closes #162582

(cherry picked from commit 24baf01)

* improve: deliver sessions_send replies once

(cherry picked from commit 84c6eb8)

* fix: prevent delegated work from stopping silently

(cherry picked from commit 4f0541e)

* fix(update): canonicalize package activation paths

* test(update): fix the Windows backup-rename regression on native Windows

Inject the platform only into the backup-rename policy. Leave native filesystem staging, verification, and cleanup on the host platform so the Linux policy case reaches its injected EPERM on Windows. Preserve all existing failure, retry, rollback, and content assertions. Refs #162027.

* fix(sessions): keep announce skip token private

* test(sessions): avoid awaiting detached reply flow

* test(ci): include infra in shared Windows partitions (#162310)

* test(release): align backport companion expectations

* test(sqlite): verify snapshot content receipts

* test(subagents): align retired reply token expectations

* test(release): align completion cutover integrations

* test(release): recognize direct peer replies

* test(release): align requester yield guidance

* test(release): align direct session reply fixtures

* fix(release): preserve session continuation authority

* fix(codex): avoid startup app-server bursts for idle agents (#163129)

Closes #163026

## What Problem This Solves

Fixes a burst of Codex app-server processes when a Gateway starts with many configured agents and explicit Codex homes. Thanks to @609NFT for reporting the remaining startup pressure after #162912.

## User Impact

Idle agents no longer start catalog-only app-servers at Gateway activation. Explicit homes hydrate when an authorized catalog request first needs them, using the existing progressive loading behavior. Native turns remain available without prior catalog hydration.

## Why This Change Was Made

A concurrency limit on initialization alone would still accumulate retained shared clients. Removing eager fleet hydration avoids both startup fanout and catalog-only retention without changing shared-client pooling, active-turn ownership, stored data, or cache schemas. The service still captures its background execution scope; on-demand catalog hydration and refresh keep their existing owner.

No overlap with Pash/Sarah changes: their history on the touched documentation concerns output projection, scheduled app authority, Computer Use, and managed binary selection, not catalog activation.

## Evidence

Real Gateway and packaged native Codex app-servers in an isolated Linux arm64/Node 24.21 container, with 739 synthetic agents and seven additional explicit homes:

| Startup measurement | Main baseline | Candidate |
| --- | --- | --- |
| App-server processes spawned / peak live | 16 / 16 (8 wrapper/native pairs) | 0 / 0 |
| Peak aggregate process RSS, 180-second window | 3,315,548 KiB | 1,744,276 KiB; repeat 2,247,344 KiB |
| Gateway readiness | 77.84 seconds (earlier sample 78.42) | 78.78 seconds; repeat 80.97 |

Readiness remains approximately 80 seconds; this does not claim a latency improvement. The synthetic profile demonstrates elimination of activation-driven native processes, not reproduction of the reporter's host OOM or blocked-egress timeout count.

- On-demand catalog RPCs returned the exact three seeded session IDs for agents `agent000`, `agent001`, and `agent738`, including the normal cold `catalog_pending` transition.
- Exact-head live gate: zero app-server processes before the request, then agent `agent738` completed a real `openai/gpt-5.4-mini` turn through the **codex** harness in 4.65 seconds with the expected reply. Utility-model jobs, heartbeat, cron, and model discovery were disabled; one inference turn.
- Regression fails on the baseline because activation starts resident work; passes on the candidate and verifies that subsequent demand initializes the home. The stop, request-lifetime, homes, backoff, and listing-cache files pass: **41 tests**, 34.39 seconds wall total; the changed stop file's three tests took 136 ms.
- `git diff --check` passes.
- Inspected Codex app-server lifecycle at `codex-rs/app-server/src/lib.rs:244–307`: shutdown drains admitted turns. This fix does not alter that lifecycle or retire a sibling turn's shared connection.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 01d479d)

* test(release): make session describe drain bound structural

* fix(release): complete session and drain backports

* test(release): cover cron send cutover

* test(release): align completion prompt expectations

* refactor(gateway): satisfy line caps

* test(gateway): remove stale fixture import

* test(gateway): isolate heartbeat lifecycle cases

* test(gateway): start lazy catalog hydration

* test(ui): tolerate sub-pixel sidebar roster layout (#161068)

(cherry picked from commit 4d638fd)

* test(ui): stabilize model refresh tooltip hover

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Jason (Json) <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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