Skip to content

perf(agents): keep transcript readers out of catalog workers - #183196

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-buf24-catalogidle-20261025
Oct 25, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-buf24-catalogidle-20261025

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Catalog workers retain the transcript reader/actor import graph merely to detach background session work from its initiating transcript context.

User Impact

Reduces retained heap in the synthetic source-worker benchmark by 4.97 MiB (3.48%). Catalog contents and transcript-write authority are unchanged. No config, persistence, or worker restart policy changes.

Why This Change Was Made

Move the existing transcript AsyncContext and synchronous detachment function into one lightweight module. Writer producers and detached callers share the same context; all callers migrate, and the old export is removed. This removes 221 loaded scripts from the measured worker without adding a cache or retained prepared state. Production LOC: +127/-119 (net +8); tests: +20/-21. The eight additional lines are explicit type imports required to keep the context contract acyclic; runtime logic and retained state do not grow. The new module is included in the PR wrapper extraction inventory.

Idle retirement is deliberately deferred: catalog generations retain plugin source publication custody, and restarting a worker can recapture changed source. The existing worker-exit integration contract requires republishing borrowers. Avoiding that lifecycle change keeps this repair small and preserves ownership.

Evidence

Node 26.12.1, actual CatalogWorkerTaskPool, synthetic runtime plugin with 500 discovered models, 5,000 remote rows, five workspaces, two remote revisions, ten catalog requests per worker. Five alternating independent baseline/candidate launches; forced GC outside request timing. Baseline owner source: 27e08fc724c7ca8d01f3cf83066f0f45e7289977; final confirmation shares checkout base 8ae44f9249540b4d377fb6b80f25f004a5d959e1. The five-pair confirmation below includes the acyclic type-layout repair.

Pair Baseline retained MiB Candidate retained MiB Delta MiB
1 142.570 137.608 -4.962
2 142.589 137.596 -4.993
3 142.553 137.607 -4.946
4 142.564 137.589 -4.974
5 142.563 137.610 -4.953
Mean (n=5 each) 142.568 137.602 -4.966 (-3.48%)

All 100 responses contain the same 501 entries and identical full-snapshot SHA-256 (18a0b546b9b6d84f504fad0bcc67535689d0dfc9416a9562563bc65b9959578c). Heap after one request: 135.798 → 130.818 MiB; after five workspaces: 139.635 → 134.677 MiB (n=5 each).

An exploratory baseline worker already retained 121.98 MiB before its first task. Worker heap snapshots analyzed with scripts/heap-snapshot-diff.mjs show loaded scripts 4,565 → 4,344 and code-tree retained bytes 59,875,544 → 57,291,464 (one snapshot per side). Retained subtree sizes overlap and are not added together.

Timing is context only on this shared, compute-constrained host: first request mean 19,113 → 18,069 ms (n=5 each); subsequent requests mean 141.8 → 118.3 ms (n=45 each, ranges 66.7–273.2 / 55.6–252.1 ms). The earlier five-pair pass showed 142.570 → 137.597 MiB but warm latency went the other direction (171.2 → 192.5 ms, n=45 each), reinforcing that these uncontrolled timing figures are context only. No tail-percentile, allocation, CPU, promotion, or GC-time claim. Source-mode TypeScript-loader retention and host contention prevent projecting these heap/latency numbers to packaged Gateway RSS or restart cost. This removes a measurable import cost; most of the idle worker footprint remains.

Reproduce with scripts/perf/catalog-worker-retention-measure.ts --output <new-dir> --workspaces 5 --models 5000 --runtime-plugin through the repository TS loader; the header documents baseline source substitution and optional worker snapshots.

Validation:

  • Focused transcript-write-context, CLI history-boundary, and session-manager-model-context-snapshot tests: 79 passed (19 + 29 + 31).
  • Changed-file formatting/lint, core typecheck, and export-name collision guard passed.
  • PR wrapper source closure: 3 passed. Eager-import closure: 17 passed initially; its 2 failures identified the missing new-module inventory entry, then both passed after the fix. Owner-continuation: 9 passed.
  • Independent subagent review (autoreview route unavailable): clean, including the wrapper inventory addition; configured review provider mismatch was not worked around by changing configuration.
  • Rebased onto current main; the only conflict was an import block in CLI history tests. Preserved the newly added upstream tests; all 29 tests in that file passed on the rebased head.
  • Initial PR CI found a type-only import cycle and the obsolete deleted-mock baseline entry. Both were repaired: the canonical Madge guard reports zero cycles, and the mock ratchet passes after canonical --prune removes exactly one entry. Independent review is clean; normalized emitted JavaScript is identical across all nine TypeScript repair files.
  • A later CI shard exposed a lifecycle-test synchronization error: client WebSocket closure does not join detached ws:preauth connect work. The test now immediately verifies zero session mutations, then requires the existing Gateway drain to report idle/no blockers within five seconds. It does not clear or cancel work. Independent review is clean; all 14 tests in server.sessions.create.lifecycle.test.ts pass locally, bringing focused behavior proof to 102 tests. This failure was repaired, not labeled inherited.
  • Broad validation: CI run 40160250786 on exact head e72a24426fd506b7439c08c7607dc322892d1155. Completed successfully: 102 jobs passed and 23 were intentionally skipped, including all three PostgreSQL conformance shards and all repaired checks.

After deployment, compare the catalog worker's idle heap at comparable generation/workspace counts; catalog contents, worker count/restarts, and request errors should remain stable. No production profiling is needed for this change.

@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T04:48:12.513914Z cc63c4a 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 gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: S labels Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@steipete
steipete force-pushed the steipete/perf-buf24-catalogidle-20261025 branch from ec08d22 to 121cbce Compare October 25, 2026 03:41
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR moves transcript context storage and detachment into a lightweight module so catalog workers avoid loading transcript readers.

Example: Synthetic catalog worker with five workspaces, 5,000 remote rows, and a runtime plugin discovering 500 models.

  • Before: Reported mean retained heap was 142.568 MiB.
  • After: Reported mean retained heap was 137.602 MiB, with identical catalog snapshot hashes.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The extraction is coherent and preserves existing contracts; evidence supports the focused worker-memory claim, while broad CI validation remains unresolved.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal extraction is outside the ordinary contributor proof gate; supplied measurements exercise the actual CatalogWorkerTaskPool with a synthetic runtime plugin on Node 26.12.1 and report unchanged catalog hashes, without establishing packaged Gateway savings.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Catalog workers retain unnecessary transcript implementation code for background-work detachment.
Reason: The maintainer-approved direction removes measured import overhead through a small behavior-preserving extraction without adding caches, settings, or lifecycle machinery.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: the focused extraction preserves existing behavior and has measurable performance value, with no actionable patch defect found; CI remains unresolved.

Priority: P2
Reviewed head: 121cbce3e747f20822d4fcf887ba9f2d88b65994

Before merge

None.

Findings

None.

Agent review details

How this fits together

Catalog workers load provider plugins to produce model snapshots; background-work detachment now imports the shared context store without pulling in transcript readers and actors.

flowchart LR
  A[Catalog request] --> B[Catalog worker]
  B --> C[Plugin runtime]
  C --> D[Background work detachment]
  D --> E[Lightweight context store]
  F[Transcript writer guards] --> E
  B --> G[Model snapshot]
Loading

Technical review

Best possible solution:

Land the lightweight extraction with the existing writer guards and catalog lifecycle intact once the CI failure is resolved or shown to be inherited.

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

Current-main imports establish the unnecessary reader coupling, and the supplied benchmark exercises the actual catalog worker; no target code was executed during this review.

Is this the best way to solve the issue?

The smallest complete fix is to relocate the existing context and detachment operation, migrate consumers, and preserve writer enforcement; this diff follows that approach.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5181de212c10.

Provenance checked

  • Shared transcript context keeps the original intent (a8aee07: perf(infra): consolidate per-turn async context stores #181780 consolidated per-turn context carriers while preserving each owner's nesting and detached-work semantics.)
  • CLI-history detachment keeps the original intent (e20b56c: Detach background work from the parent's account-bound CLI-history capability during recovery.)
  • Catalog worker measurement and lifecycle keeps the original intent (138f9f6: Measure retained remote-catalog duplication while preserving workspace registrations and captured plugin source ownership.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e998107 adds src/config/sessions/transcript-write-context.ts:441 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e9981073bdd2; files: src/config/sessions/transcript-write-context.ts)

PR surface

Source +8, Tests -9, Other +55. Total +54 across 34 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 23 127 119 +8
Tests 8 10 19 -9
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 69 14 +55
Total 34 206 152 +54

Review metrics

Metric Value Why it matters
Production versus tests Production +127/-119; tests +10/-19 The eight-line production increase supplies acyclic type imports; runtime state and detachment logic are relocated rather than expanded.

Labels

Label changes:

  • add P2: A bounded catalog-worker memory optimization with demonstrated synthetic savings and no intended user-facing behavior change.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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: A bounded catalog-worker memory optimization with demonstrated synthetic savings and no intended user-facing behavior change.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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.

  • Determine whether the exact-head session-creation CI failure is inherited or repair its demonstrated cause.

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 24, 2026, 11:57 PM ET / October 25, 2026, 03:57 UTC.

@steipete
steipete force-pushed the steipete/perf-buf24-catalogidle-20261025 branch from 121cbce to e72a244 Compare October 25, 2026 03:59
Move the existing transcript context and detachment operation to a lightweight owner and migrate all consumers. Catalog workers no longer import the transcript reader graph through the plugin runtime.

Five alternating synthetic source-worker pairs retained 142.570 to 137.597 MiB after forced GC, with identical catalog hashes. Production LOC is neutral. Preserve plugin source custody and worker lifecycle; no idle retirement or cache added.
Keep context types with the lightweight context owner and migrate all direct type consumers. This preserves the runtime implementation while satisfying the architecture guard. Prune the baseline entry for the removed transcript detachment mock.
Client socket closure does not join the Gateway generation\x27s detached preauth tasks. Keep the immediate session-mutation settlement assertion and use the existing active-work drain to verify that all remaining work settles without masking persistent leaks.
@steipete
steipete force-pushed the steipete/perf-buf24-catalogidle-20261025 branch from e72a244 to cc63c4a Compare October 25, 2026 04:46
@steipete
steipete merged commit 9dfeeca into main Oct 25, 2026
177 checks passed
@steipete
steipete deleted the steipete/perf-buf24-catalogidle-20261025 branch October 25, 2026 05:19
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…w#183196)

* perf(agents): keep transcript readers out of catalog workers

Move the existing transcript context and detachment operation to a lightweight owner and migrate all consumers. Catalog workers no longer import the transcript reader graph through the plugin runtime.

Five alternating synthetic source-worker pairs retained 142.570 to 137.597 MiB after forced GC, with identical catalog hashes. Production LOC is neutral. Preserve plugin source custody and worker lifecycle; no idle retirement or cache added.

* fix(agents): keep transcript context contracts acyclic

Keep context types with the lightweight context owner and migrate all direct type consumers. This preserves the runtime implementation while satisfying the architecture guard. Prune the baseline entry for the removed transcript detachment mock.

* test(gateway): await detached connect work before asserting idle

Client socket closure does not join the Gateway generation\x27s detached preauth tasks. Keep the immediate session-mutation settlement assertion and use the existing active-work drain to verify that all remaining work settles without masking persistent leaks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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