Repository navigation
fix(sessions): reduce transcript reader memory and startup work - #177242
Open
vincentkoc wants to merge 3 commits into
Open
vincentkoc wants to merge 3 commits into
vincentkoc wants to merge 3 commits into
Conversation
Contributor
|
🦞👀 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. |
vincentkoc
force-pushed
the
fix/transcript-reader-imports-20261019
branch
from
October 19, 2026 10:27
76ef73e to
c180634
Compare
vincentkoc
marked this pull request as ready for review
October 19, 2026 10:27
Contributor
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
This was referenced Oct 22, 2026
This was referenced Oct 25, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Fixes unnecessary memory and startup work in session transcript readers. A model-context read imported writable agent/state database initialization and write execution, even when its worker only read an existing transcript.
Why This Change Was Made
Separate read observation from writable database acquisition. Readers observe the existing lifecycle owner without creating it; that owner continues to retain handles and refresh idle custody. Local admission, creation/deletion guards, committed-read companions, and owner inspection behavior remain intact.
Move write execution into the existing write-scope owner and transcript state reads into a read-only module. Update internal callers together. No config, schema-version, protocol, or public Plugin SDK contract changes.
User Impact
Lower per-reader module footprint without disabling session history or changing transcript contents. This is a targeted memory reduction, not a claim that the overall Gateway RSS problem is solved.
Release-note context: session transcript readers avoid loading writable database initialization and preserve existing handle lifecycle behavior. Release-owned changelog files are unchanged.
Evidence
Landing hold: the reader heap target passes, but the complete Gateway series does not satisfy the no-regression rule. Process CPU rose 6.48% (one plugin) / 4.88% (five plugins); additional regressions are listed below. No owner waiver has been requested or granted. Do not merge. Exact-head CI is pending after the wrapper inventory repair.
Completed diagnostic and development checks:
c180634279453642298f9ffce70fbe4412cd72c7.Acceptance rule, recorded before scored runs
Baseline:
357be061b3e1894b19410ffd9bf17c77819cbb9e. Candidate:c180634279453642298f9ffce70fbe4412cd72c7. Use the same runtime, dependencies, host, resource limits, and committed workload on both builds. Record actual build identity, harness hashes, host load, and all samples. Use a fresh task-owned temp root for every process and unset NODE_COMPILE_CACHE on both variants; the Gateway fixture also owns its worker bytecode cache.env -u NODE_COMPILE_CACHE node --import ./scripts/tsx.mjs scripts/bench-transcript-reader.ts --output <new-report.json>. Five serial interleaved baseline/candidate pairs. Each fresh process runs one cold plus 30 warm reads of an 80-message SQLite transcript, one bounded read, and heap samples at 2/5 seconds after drain. Require full output equality, exactly one reused worker, no pending tasks, and zero workers after cleanup. Target: at least 10% lower median worker heap at 5 seconds. Report cold and warm latency, CPU, process RSS, median, p95, and range separately; RSS is process-wide, never summed per worker.7d63c2fd41aaf978ecaff8a02cb347518cd2fb4b(scripts/bench-gateway-concurrency.ts,scripts/lib/gateway-bench-runtime.ts,scripts/lib/gateway-bench-probes.ts) applied identically to both source trees after building. Five serial AB pairs for each plugin count 1 and 5:node scripts/bench-gateway-concurrency.ts --entry dist/entry.js --gateway-runtime node --provider mock --plugin-count <1-or-5> --concurrency 1 --agent-warmup-turns 1 --turns-per-session 3 --runs 1 --warmup 0 --cadence-ms 100 --stream-chunk-delay-ms 1000 --json --output <new-report.json>.Leave session-count/history/profiling options unset. Require matching completed turns, inference payloads, activated plugins, and clean cleanup. Preparation workers retain their existing lifecycle on both sides.
The reader benchmark is committed here because the existing history benchmark measures source-host query execution and SQL tracing rather than a compiled model-context worker.
Scope accounting: runtime +604/-539 (net +65), tests/support +133/-113 (net +20), benchmark +234. The runtime increase supplies the read-only observation boundary without importing writer initialization; existing write operations and transcript-read implementations move to their canonical owner modules.
Conflict repair: newer main renamed the maintenance test import to runWrite. The rebased patch preserves that alias and redirects only its module path. No runtime patch changed. Both scored build identities were refreshed to the new base before any scored run; the earlier diagnostic comparison remains excluded.
Named follow-up: agent database workers still import the host SQLite broker through the synchronous deleteAgentProvenanceForAgent helper. Its existing kernel module is a possible owner; compiled loading and memory benefit still need measurement. This PR does not change that path.
Repeated reader results
All ten scored reader runs completed: five serial AB pairs, each with 31 full reads and one bounded read, exactly one reused transcript worker, and zero workers after cleanup. Every returned event and context version matched that run's synchronous canonical reader. The fixture hash is identical across all ten runs; whole-response hashes differ because each fresh transcript receives its own generation UUID. No sample was discarded.
Worker heap improved consistently by 7.83 MiB (21.85%). Cold read latency and CPU improved. Warm median latency moved +0.015 ms (+0.56%); process-wide source-host RSS moved +6.48 MiB (+1.17%), so this does not establish a total RSS gain. Gateway regression acceptance fails the stated no-regression rule; see the complete results below. With five samples, nearest-rank p95 is the observed maximum, not a stable population-tail estimate.
Build identities: baseline
357be061b3e1894b19410ffd9bf17c77819cbb9e, output SHA-256aa79db75ad766a7a21660418f6b6d1e0bfba5ce6bb07bc6cba8ad1804ad6a0d2; candidatec180634279453642298f9ffce70fbe4412cd72c7, output SHA-256d7db0fc166b3aaf9bd46f5119e0ea6ac4dc6a9db105b00add4a56106ef5e1b89. Both used the package build profile and the same dependency installation. Node 26.7.0, macOS arm64, 18 logical CPUs, 48 GiB physical memory.Complete Gateway regression results
All 20 runs are included: five serial AB pairs for each plugin count. Every run completed one verified warmup and three verified measured turns, activated every fixture plugin, and exited normally with code 0 after teardown. All readiness, session-list and Control UI probes succeeded. Worker counts were 26 (one plugin) / 30 (five plugins), including 1/5 retained preparation workers on both variants.
With five runs, p95 across runs is the observed maximum. Probe rows summarize each run's p95, not a pooled percentile. The 100 ms adaptive sampler produced 36-39 rounds; counts vary with measured duration. No sample is excluded and no regression is waived as noise.
Work completed is consistent across all runs: warmup sends 3 inference requests (2 recap, 1 turn); load sends 6 inference requests (3 recap, 3 turns) plus 2 embedding requests. Setup and post-load snapshots contain no additional requests; unknown payload bytes are zero. Baseline warmup/load request bytes are 81,076/245,174; candidate 81,116/245,294. The +40 bytes per turn are a remaining fixture-comparability limitation: candidate temp-root labels are five characters longer and fixture paths enter prompts, but raw payload equality was not retained, so this report does not assert byte-identical inference payloads. The stricter payload acceptance condition is therefore unproven.
Decision: hold. Reader heap improved by 7.83 MiB, but this is not a meaningful resolution of the 2.2-2.5 GiB Gateway footprint. Total CPU medians worsen on both Gateway cohorts; one-plugin probe medians and five-plugin startup/peak RSS also worsen. The prewritten rule requires explicit owner acceptance for any measured regression. No merge is authorized by these results.
CI repair at HEAD 480fc26: add the three new runtime module paths to the PR wrapper extraction inventory. The failed closure tests now pass locally under the default runtime and explicit pinned Bun (2 files, 22 tests each); the later current-head CI attribution is recorded below. This metadata-only change does not alter runtime source or compiled output, so scored runs retain candidate identity c180634; they are not relabeled as exact-head CI proof.
Additional sampled diagnostics (median of each per-run percentile):
The sampled five-plugin CPU-core-ratio median rises 39.66%, also exceeding the 20% stop threshold. The integrated process CPU measurements above remain the total-work measure; both are reported. One-minute host load before runs ranged 5.51-8.68 for p1 and 4.07-5.53 for p5. No score is discarded for host load.
CI repair and remaining attribution
Current head c7f91fb repairs the registry-listing spy in targets-dedupe.test.ts; all four focused tests pass. Runtime remains the measured c180634. The performance hold above is unchanged.
The failed CI run 39239246910 tested merge e0b66e08 (head 480fc26 into main b87a318), not the original performance baseline. Its Board test failure is inherited from that main parent: test and lifecycle blobs match, and main commit ae0ff9c fixes the assertion to match accepted reads draining before binding retirement (#177223).
The restored-requester final E2E failure remains unattributed: test/gateway-restored-requester-settle.e2e.test.ts:87 observed zero first provider requests after an agent-request timeout; other three cases passed. Unchanged test/deadline source alone does not prove inheritance. Named follow-up: compare the exact final case on CI main parent and merge candidate with matching builds, retaining the existing 2-second announcement budget. No production workaround or green claim.
Current-head CI attribution: c7f91
Run https://github.com/openclaw/openclaw/actions/runs/39284795736 tested integration 9deecef052ed66948ddf0c6f2aeebbdf322fa39d (c7f91fb into main parent 9acb9a7). Seven failed jobs contain eight failures. Four are inherited; four remain unattributed. No reader-source repair is justified by the evidence yet, and this is not an inherited-only landing claim.
Independent main failures come from https://github.com/openclaw/openclaw/actions/runs/39278710829 at af49c87, an ancestor of the integration main parent. Current main c8112c7 was checked for both completed assertion/mock repairs.
Named follow-up: run the four unknown cases serially on exact main parent9acb9a74 and integration9deecef0 with qualified matching dependencies, CI runtime, and matching built dist for E2E. Retain existing deadlines and collect original failure evidence; a passing isolated replay alone does not prove a fix. The performance hold and earlier unequal inference-byte evidence remain unchanged.