Repository navigation
perf(memory): bound derived worker snapshot and pricing retention - #174067
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR limits retained transcript snapshots to an aggregate 8 MiB source-byte budget and replaces serialized pricing fingerprints with SHA-256 digests. Example: One transcript worker indexes sixteen sessions whose snapshots each account for 4 MiB of source data.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR provides a focused memory reduction that current main does not contain, with no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe transcript worker derives memory-indexing entries from authoritative session data, while pricing contexts supply model rates and cache-invalidation fingerprints to usage accounting. flowchart TD
A[Session database] --> B[Transcript worker]
B --> C[Bounded snapshot cache]
B --> D[Memory indexing entries]
E[Catalog and pricing policies] --> F[Pricing context]
F --> G[Usage estimates and fingerprints]
Technical reviewBest possible solution: Use the existing LRU byte budget and compact pricing digest while preserving transcript reconstruction and normal estimate-cache invalidation. Do we have a high-confidence way to reproduce the issue? Current-main source retains up to sixteen 4 MiB snapshots and the complete serialized pricing fingerprint; these retention paths are directly identifiable without executing target code. Is this the best way to solve the issue? The change addresses both retained representations at their existing owners, removes manual eviction code, and preserves pricing inputs and transcript validity checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 51042e8c1a27. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests +6. Total +7 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 16, 2026, 5:45 AM ET / 09:45 UTC. |
* commit 'ac03ca0b6d26a7dc55d0d262e40d2549631b1ea7': (25 commits) fix: apply shared plugin model policy to decisions (#156621) perf: shortlist transcript relevance scores before metadata reads (#174058) fix: strip standalone trailing NO_REPLY from replies (#171990) fix(ci): avoid repeated discovery during changed-test planning (#174069) fix(sqlite): preserve transaction outcomes when warnings throw (#157151) fix(ai): native video handoff to chat-completions providers + preflight video cost (#170920) fix(litellm): image generation fails when the backend returns image URLs (#173508) test(memory,gateway,infra,subagents): remove low-value tests (batch d152) (#174034) perf(memory): bound derived worker snapshot and pricing retention (#174067) fix(test): reduce eager imports during test startup (#174056) refactor(codex): share lifecycle preflight fixtures (#174062) test(gateway,matrix,agents,ui): remove low-value tests (batch d150) (#174025) perf(infra): batch usage refresh maintenance (#174050) fix(gateway): revert cold session list worker regression (#174052) refactor(config): consolidate browser meeting configuration (#173947) fix(cron): keep global-session deliveries on the selected agent (#173855) test(compaction): assert structured stale-writer failure (#174064) fix(cli): local terminal chat sends model requests without the configured proxy (#173530) test(ui): restore bootstrap preference locale after each case (#174065) fix: download session files through the development proxy (#173973) ...
What Problem This Solves
Memory indexing can retain up to 64 MiB of transcript snapshot payloads in one worker, and model pricing contexts retain full serialized pricing tables as their fingerprints. Both are reconstructible derived data.
User Impact
Reduces memory retained after indexing and pricing work without changing transcript output or pricing decisions. Existing persisted estimate fingerprints change once and are recomputed normally; no schema or configuration change is required. Revisiting an evicted transcript can require another database read.
Why This Change Was Made
The transcript export cache now uses the existing LRU owner with an 8 MiB aggregate source-byte budget, preserving its 16-entry and 4 MiB per-entry limits and generation-based append/rewrite checks. Pricing contexts retain a SHA-256 digest of the same deterministic serialization instead of the serialization itself.
Production delta is +1 line (8 added, 7 removed): the manual count-eviction loop is deleted, the existing cache supplies aggregate byte eviction, and the pricing digest requires its crypto import. No new cache framework, worker owner, configuration, or compatibility path is introduced.
Measurement
Compared base
08dd80a42558with head8925281ab99b6a240a060bd07f49c75a2f935fb9in an isolated checkout on a Linux benchmark host using Node 26.10.0 and synthetic state only. The fixture contains 5,016 sessions, 6,000 retained runs, 200 startup approval records, 100 disabled cron jobs, and 12 synthetic Git projects. Its original agent database is 4,641,595,392 bytes, with 1,500 MiB of generated transcript text; sixteen approximately 3 MiB export sessions were then added. No production state was copied or exercised.Three fresh-process rounds per revision, through the real
buildSessionEntries()export worker and pricing owners:All sixteen export content hashes matched across all six runs, including rebuilding the evicted first session. The byte budget saves 42.3 MiB of live worker heap in this workload; the extra cold reread is the intended tradeoff. Timing is indicative because the benchmark host had concurrent workload. These are synthetic workload results, not a production-wide RSS prediction.
The matched built-Gateway list workload was neutral: RSS before explicit GC was 1,554.0 → 1,540.1 MiB; at the post-GC checkpoint it was 1,497.7 → 1,505.4 MiB (+0.5%). Both revisions used an offline-restored copy of the same fixture, 100 real
sessions.listRPCs, and a 45-second settling interval. Mean RPC latency was 19.45 → 19.51 ms; p99 was 55.72 → 58.32 ms, with identical response sizes and session counts. These small differences are consistent with shared-host/allocator variation. This list-only workload does not exercise the export cache or large pricing tables, so no overall Gateway saving is claimed. Heap snapshots were taken after the measurement checkpoint.Post-GC heap census, grouped by script. Both revisions had 14 live workers; used/capacity values are MiB, not per-worker RSS.
worker-native-lifecycle.worker.jsopenclaw-state-read.worker.jsgateway-state-owner-heartbeat.worker.jsopenclaw-state-lease-heartbeat.worker.jssqlite-store.worker.jssession-transcript.worker.jsdiscovery.worker.jsprepared-model-catalog.worker.jssession-list.worker.jsMain-thread live heap was 330.8 → 329.4 MiB, with 341.4 MiB capacity on both revisions. The fixture deliberately disables live integrations; workers absent from this census are not covered by these measurements.
Worker Audit
Ten empty Node workers added about 8.1 MiB RSS each on this host. RSS is process-wide; per-worker
process.memoryUsage().rssis not a valid isolate attribution. The census records each isolate's used heap and capacity separately.The filesystem ownership heartbeat must remain isolated from SQLite lease heartbeats: SQL admission can block synchronously while filesystem renewal must stay live. Both heartbeat families already coalesce compatible work. The transcript label aggregates several worker pools rather than identifying one isolate. Recent-history pages and usage-rollup caches already have effective byte bounds; SQLite writer state is lifecycle-owned actor/context state, not an accumulated result cache.
Catalog workspace contexts remain resident because evicting them would recreate native module graphs that cannot unload. A synthetic catalog-worker heap snapshot contains 35.6 MiB of strings, 18.1 MiB of code, and 2,517 module jobs; it does not reproduce the larger production workload. Shared configured catalog facts are consumed by runtime-generation reuse and cannot simply be deleted. Existing 512 MiB old-generation limits for catalog, transcript, and SQLite writer workers remain unchanged; this PR does not claim that lower limits are safe.
Proof
src/model-catalog/pricing.test.ts,packages/memory-host-sdk/src/host/session-files-reset-revision.test.ts, andsrc/infra/lru-cache.test.ts. The strengthened pricing retention regression fails on the original implementation.