Skip to content

perf(sessions): reduce maintenance worker prewarm memory - #171697

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-worker-heap-retention-20260919
Oct 14, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-worker-heap-retention-20260919

Conversation

@steipete

@steipete steipete commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway startup prewarms its maintenance reader with the same chat presentation imports as its foreground history reader, retaining a second module graph in an isolate that does not serve chat pages.

User Impact

Less worker memory after startup while preserving foreground history prewarming and maintenance database admission. No schema, configuration, worker-count, or retention-policy changes.

Why This Change Was Made

The private prewarm request now identifies foreground history work. Maintenance still opens and retains the same admitted SQLite reader, but leaves chat presentation modules lazy. Existing worker lifetime, cancellation, rotation, and database cleanup remain the owners of those resources.

The +9 production LOC increase carries this distinction through the existing typed request, rather than creating another pool or prewarm implementation. Full foreground warmup is an existing startup-latency contract.

Evidence

Matched synthetic fixture: 5,000 sessions, 6,000 retained runs, 200 approvals, 100 disabled cron jobs, 12 real project worktrees, 1,500 MiB logical transcript text, 4,641,595,392-byte agent database. Six fresh maintenance workers per version on the same read-only fixture; Node 26.8.2, real owned task pool and transcript worker entry, source execution via the repository loader. Isolated benchmark sandbox, CPU 64–127, 64 GiB cap, nice 10 / idle I/O. No production data, service changes, or benchmark traffic to a live Gateway.

Metric (median, 6 fresh workers each) Before After
Cold allocation, MiB 823.88 525.41
Prewarm + 20 reads allocation, MiB 845.33 612.99
Retained heap after prewarm, MiB 64.33 42.96
Retained heap after 20 reads, MiB 66.56 51.60
Worker heap capacity after 20 reads, MiB 69.90 53.65
Process RSS after 20 reads, MiB 385.40 342.53
GC during prewarm + 20 reads, ms 340.97 273.27

Sampling interval: 32 KiB, including objects collected by both major and minor GC. Retained heap and process RSS are sampled after explicit GC; GC time includes that final collection. RSS covers the whole harness process, not a deployed Gateway. Source execution includes loader allocations, so exact production-bundle savings remain unmeasured.

This removes about 15 MiB of retained live heap (22.5%) and 16.25 MiB of worker heap capacity after real maintenance reads, with 27.5% fewer allocated bytes across prewarm plus the first 20 reads. Some loading shifts into the first maintenance read; the combined path still allocates less. A subsequent 20-read batch allocated a median 783,394 → 749,226 bytes/read (three runs each; neutral within sampling noise). Its median GC was 126 → 104 ms per batch. Combined prewarm/read GC ranges overlap (297–420 → 209–333 ms); no strong steady-state GC improvement is claimed.

Foreground eager-prewarm control retains 66.54 → 66.56 MiB after reads, effectively unchanged. Only the prewarmed maintenance isolate changes; these results must not be multiplied by every transcript worker. The rest of the worker fleet remains future investigation.

  • PR CI run 38509864174, attempt 1: success on 274f05d9253e44097b8bad052db07867b76d08eb (types, lint, selected test shards, boundaries, build, UI checks).
  • Changed-file oxfmt and scoped core/coreTests oxlint passed.
  • pnpm test src/config/sessions/session-history-read.imports.test.ts src/config/sessions/session-transcript-worker-lanes.test.ts src/config/sessions/session-transcript.worker.schema-freshness.test.ts --maxWorkers=1: 3 files, 35 tests passed.
  • Negative control: restoring unconditional imports fails the new test at the module-evaluation assertion. An initial negative-control attempt timed out during worker compilation; the completed repeat reached the expected assertion.
  • Review: independent subagent review (autoreview route unavailable), clean. The helper refused to start inference because its selected provider did not match the operator configuration; configuration was left unchanged.

Local validation follows the perf-lane policy: changed-file oxfmt/oxlint and three focused test files with one worker; broad gates belong to PR CI. No Testbox/Crabbox lease.

Read-only production inventory that selected this owner

One observation showed 41 tracked workers across 20 kinds: 1,982.6 MiB live worker heap, 2,378.5 MiB worker heap capacity, and 5,408.3 MiB process RSS. This is a census, not before/after deployment evidence.

Worker kind Count Live heap, MiB
session-transcript.worker.js 7 521.5
sqlite-store.worker.js 2 270.8
git-operation.worker.js 6 207.1
code-mode-node.worker.js 7 192.6
prepared-model-catalog.worker.js 1 152.4
openclaw-state-read.worker.js 2 105.8
memory-search.worker.js 1 79.2
session-accessor.sqlite-archive.worker.js 1 50.2
discovery.worker.js 1 48.7
file-tool-planning.worker.js 1 30.6
provider-prompt-state.worker.js 1 30.2
proxy.worker.js 1 27.1
attachment-processor.worker.js 1 25.8
identity-file.worker.js 1 24.8
fs-safe-copy.worker.js 1 23.8
image-processor.worker.js 1 23.7
identity-avatar-file.worker.js 1 22.4
worker-native-lifecycle.worker.js 1 21.4
openclaw-state-lease-heartbeat.worker.js 1 16.0
gateway-state-owner-heartbeat.worker.js 1 8.8

Keep foreground history prewarm eager while maintenance admits its SQLite reader without retaining unused chat presentation modules. Preserve existing reader admission, worker lifetime, and cancellation behavior.
@clawsweeper

clawsweeper Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-14T04:11:34.184172Z 274f05d PR opened
ℹ️ 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.

@chatgpt-codex-connector

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 🔄 Running since 2026-10-14T04:08:38.898345Z 274f05d PR opened
ℹ️ 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.

@steipete
steipete merged commit 893ba82 into main Oct 14, 2026
143 checks passed
@steipete
steipete deleted the steipete/perf-micro-worker-heap-retention-20260919 branch October 14, 2026 04:24
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…71697)

Keep foreground history prewarm eager while maintenance admits its SQLite reader without retaining unused chat presentation modules. Preserve existing reader admission, worker lifetime, and cancellation behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant