Repository navigation
improve(compaction): prepare large histories outside the Gateway thread - #200114
Conversation
Keep checkpoint selection and definition projection independent of host tool policy and executable wrappers. Preserve pinned-tool refusals and canonical schema comparison. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Move registry-owned authentication and request policy out of session assembly while preserving the SDK stream behavior and runtime binding. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Give native row framing and transcript decoding their internal data owners while preserving snapshot custody and acknowledged host consumption. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Move generic replay transforms and snapshot scanning into data owners while preserving host provider hooks, session effects and request bytes. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Share exact summary prompt and output policy with a single render-budget completion loop while preserving the existing public preparation API. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Prepare builtin summary facts and each actual render budget in the existing transcript reader while keeping provider effects, hooks and guarded writes on the host. Preserve the public four-argument preparation API. Native performance acceptance remains separate from this implementation. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Worked on by: - @RomneyDa - @vincentkoc - @jalehman Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: 2199d969-be5a-8b91-9cdf-517d3f575c0e
|
🦞👀 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: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
Merge current main without losing repeat-guard policy or announced compaction identities. Admit private preparation and render cohorts before payload decoding, preserving the complete acknowledged host stream above the optimization budget. Keep the existing worker heap and public SDK/configuration unchanged. Formal cold/warm performance acceptance remains separate. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Worked on by: - @RomneyDa - @vincentkoc - @jalehman Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: 32977ebc-3bc1-860d-9f5c-82a1cf284be6
Merge the current checkpoint replay identity contract into both moved compaction owners without changing transport authentication or the existing bounded preparation, preserving complete acknowledged host streaming above the optimization budget. Keep the existing worker heap and public SDK/configuration unchanged. Formal cold/warm performance acceptance remains separate. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Worked on by: - @RomneyDa - @vincentkoc - @jalehman Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: 9b1036d0-4f2a-8612-be3c-4305681d25ce
Keep worker data contracts independent of host implementation imports and remove unsafe replay casts without fabricating billing costs. Preserve the wrapper decoder inventory and scope diagnostic test transport state to each fixture. Keep the real long-history sender-policy proof and existing repeat guard intact. Shrink obsolete assertion/mock debt and record the existing-fixture regression allocation without adding a test file or changing execution limits. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Worked on by: - @RomneyDa - @vincentkoc - @jalehman Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: 1cbca64a-ec86-8663-854f-d575c59be846
Supply complete inert plugin ports to the shallow transport-host input type. Use SettingsManager directly after main retired the private compactionSettings test export, preserving its exact configuration and all existing assertions. Production inputs are unchanged; reuse their qualified build and native proof. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]>
Worked on by: - @RomneyDa - @vincentkoc - @jalehman Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: jalehman <[email protected]> OpenClaw-Publication: 473dfcfe-3e41-8b51-9488-61790dfb3aa0
Landed source and prospective performance proofPR #200114 is merged as 472cd0a after green exact-head CI. Its actual before-merge first parent is eba3bac. Contributor credit remains @RomneyDa, @vincentkoc and @jalehman. This evidence comment supersedes only the PR body's stale CI/landing status and draft prospective protocol. All earlier source-scoped qualifications, failures and adverse metrics remain evidence, not acceptance. No performance acceptance sample has started. Both actual-source builds and separate native eligibility qualifiers completed; those qualifiers are not part of this cohort. Rule SHA-256: Frozen post-merge comparison rule — cohort postmerge200114-paired1This is a prospective rule, not performance acceptance. No acceptance observations precede publication/readback of these exact bytes. Qualification captures are ineligible and remain separate. Flow: the real isolated OpenClaw Gateway/agent, actual new-config default safeguard post-reply maintenance, controlled local model HTTP, and unrelated-session RPCs. This does not establish live-provider semantic quality, natural pressure, exact effective SDK context, per-worker/JIT warmth, or global idle. Sources and artifacts:
Schedule and protocol: schedule-manifest SHA-256
Order and populations: five serial baseline/candidate process-cold pairs, then five separate process-warm pairs (n=5 per arm/population). Cold means a fresh Gateway process, not flushed OS/page caches. Each warm sample starts a fresh Gateway, imports both histories while stopped, and first durably settles maintenance in a distinct sacrificial physical session in that same PID before the measured-session ready/start barrier. Host load is recorded. No concurrent arms, outlier removal, pooled diagnostics, replacement tags, or replacement cohorts. Native/fidelity gate: every measured target, and both sacrificial/measured targets when warm, must have the exact native owner/incarnation/store identity, running/settled/write-release/removal/zero-owner facts, a healthy later observer sample, one durable boundary (18→19 for this fixture), the same degraded outcome class and four maintenance HTTP200 requests. Do not invent pre-run entry counters or treat degraded fallback as normal-quality success. Candidate private plan/render path counts and outcomes are reported explicitly; eligibility qualifiers must establish the actual private path, not merely dispatched labels. Native settlement does not establish global idleness. Slots and windows: keep all 300 scheduled slots and every valid/error/timeout/cancelled/suppressed outcome. Failed calls remain in latency statistics; suppressed slots have no fabricated latency. Fixed full-stream and broad pressure-release→native-settlement windows are both reported; no post-result window selection. Stream CPU uses immediate sample brackets with overhang recorded, no prorating. Full-capture startup/warmup and last-observed cumulative process CPU remain included; unsampled shutdown tails are unobserved. Process CPU already includes workers. Worker counters cover successful userland JSON strings ≥1024 UTF-16 units and overlapping tasks including overhang; host parsing is unobserved. Worker IDs are distinct observations, not simultaneous peaks. Comparable metrics (the workload's complete PERFORMANCE set):
Report all arm/population n=5 values, paired rows, medians, nearest-rank p95 and spread. A primary measurable responsiveness win requires at least a 20% reduction in BOTH population median and nearest-rank p95 of Hard stops: incomplete capture, original failed/started tag, native/source/outcome mismatch, missing expected comparable metric, or changed frozen plan/protocol/runtime inputs stops the original cohort with its completed prefix and failures retained. At each ten-observation population checkpoint, any comparable metric's median OR p95 worsening ≥20% (including a zero baseline increasing) stops before the next population. Smaller adverse changes are still adverse, not automatically accepted or dismissed as spread. A stopped cold population leaves warm unattempted; it is not replaced or reported as two-population acceptance. Partial work/path counters (all retained separately, not whole-workflow work totals):
Every counter increase is shown in counterAdverse, including intentional plan/render work moved into the worker. These partial counters do not stand in for total CPU/work or excuse worse user-facing cells. Model-request counts are scoped explicitly: the measured count includes its pressure request; maintenance counts remain independently four per phase. All raw slot/native/counter failures remain available; no filtering away adverse evidence. The controller never grants performance acceptance. Publication fields are evidence bookkeeping, not authority. Managed GitHub readback must record the actual merged state, PR head and merge commit separately, plus the full body and rule hashes, before plan creation/admission. Freeze complete plan/protocol/common scripts/runtime fingerprints before the first formal observation; revalidate the same original bindings at each effect. All captures remain private; only sanitized metadata/results, never transcript or model-request contents, may be published. |
Frozen cold comparison: stopped before warmNo performance acceptance. All five original cold pairs completed with 3,000/3,000 valid RPC slots and independently re-audited native/integrity proof. The controller exited 1 at the declared cold checkpoint: full-capture sampler-gap population p95 rose 562 → 833 ms (+48.221%), crossing the published 20% hard stop. All ten warm observations remain unattempted; no replacement cohort, discarded outlier, qualifier promotion or pooled diagnostic is used. Frozen rule, rule SHA-256 9809ca6950f80ce762c05b5b68e411b1e418ef80b7cbecc54488cbea9c3dba9c. Plan SHA-256 ec132e80caf6dc1de99ad098f2b43176983de08e897f5c7ee9a5c8b415427075. Baseline eba3bac (actual before-merge first parent); candidate 472cd0a (actual landed squash); common signed workload 99e9e235b2d801522cb71c80194c2277cb2df470. Exact qualified builds, image, fixture, protocol and original schedule remain bound as published. The worst-request responsiveness criterion is met for cold only: population median of stream maxima 258.306 → 77.758 ms (−69.897%); population p95 270.038 → 84.095 ms (−68.858%). This does not override adverse CPU, worker-heap, p95-latency or full-capture-pause cells, and warm is unmeasured. All comparable performance cellsEach cell aggregates five observations per arm. NN p95 is nearest-rank population p95 (the maximum at n=5), not a request-level percentile unless the metric itself says so. RSS/heaps are bytes, CPU is ms, RPC/sampler gaps are ms, worker IDs are distinct observed counts—not simultaneous peaks.
Every adverse performance cell
Paired original cold observations
Partial work/path counters — kept separateThese worker-only counters are not whole-workflow work totals. Every increase remains adverse accounting; smaller host transport is not permission to ignore CPU or heap costs. Model-request count includes the pressure request; independent maintenance count is four per sample.
All five original values per arm, in pair orderNo value is omitted; display is rounded to three decimals. Full-precision source/checkpoint and original receipts remain unchanged.
Native validity, scope and pause localizationEvery original capture verifies the same default safeguard flow: exact 47,184-row imported prefix, durable 18 → 19 compaction boundaries, degraded-quality fallback and four HTTP 200 maintenance requests; native settlement/write release/removal, unchanged source/build/frozen inputs, immutable artifact re-audit and task cleanup all pass. Each candidate records one actual prepared result and four rendered results; baseline records none. Native success is not normal-quality summarization, live-provider semantic quality, effective SDK-window proof, per-worker/JIT warmth or global idleness. The 833 ms maximum belongs to the first candidate’s setup/import process (PID 30), ending 48,564 ms before that sample’s measured phase begins. It is retained in full-capture accounting exactly as frozen, not removed or reclassified to rescue the run. Its source attribution is not established. The measured stream sampler is separately reported above; its improvement does not waive the full-capture hard stop. Stream CPU uses immediate bracketing samples with recorded overhang and no prorating. Full CPU includes startup/import and is last-observed cumulative CPU across Gateway PIDs; unsampled shutdown tails remain unobserved. Process CPU already includes workers. Worker JSON counts cover successful strings ≥1,024 UTF-16 units, overlapping tasks include overhang, and host parsing remains unobserved. Raw captures and complete paired metrics stay private; this comment contains sanitized metadata only. Disposition: cold responsiveness improved on this controlled workload, but the declared no-regression acceptance gate failed. Warm proof is blocked by that rule, not silently skipped or replaced. No rollback, further product change, threshold relaxation or repeat cohort is implied by this result. Contributor credit remains @RomneyDa, @vincentkoc and @jalehman. |
Related: #185111 (large-history preparation context; not a claim to resolve its Codex pre-turn workload).
What Problem This Solves
Preparing a large retained history for default safeguard compaction can block the Gateway thread and delay unrelated sessions.
User Impact
Eligible default compaction prepares and rerenders history in the existing transcript reader. Provider requests, authentication, hooks, custom providers, mutable SDK behavior and guarded writes remain host-owned. Oversized or unsupported windows retain complete acknowledged host hydration, not truncated context.
Paired performance acceptance remains pending. This is not a proven CPU/memory improvement or global no-blocking guarantee. No configuration, public SDK signature, schema or migration changes are required.
Why This Change Was Made
One internal preparation algorithm preserves row provenance and the public four-argument API. Canonical tool, replay, hydration and summary-budget owners serve worker and host consumers. No worker is held across inference, new cache, whole-history graph-transfer protocol or public read-only extension API.
The #194536 worker-memory fix is preserved: private plan/render cohorts are admitted before payload decoding, with a 16 MiB serialized-input ceiling and the unchanged 512 MiB worker heap. Larger windows retain complete streamed host hydration. This input ceiling is not a universal decoded-heap guarantee. Renders use the maintained filtered JSONL budget check in the same snapshot.
Current-main integration preserves repeat-guard metadata, announced compaction IDs and #200063's session/model-only checkpoint replay identity. Transport authentication is unchanged.
Scope, simplification and test cost
The signed series contains five coherent owner prerequisites and private producer/consumer adoption. Yield-only, exclusive-handoff and held-worker alternatives were rejected; duplicate materialization and eager replay work were deleted. Existing SQL position/retention bodies have one context-navigation owner, unchanged except exported-signature formatting, without a line-cap suppression.
The CI repair moves canonical worker data types out of host implementation modules and migrates every internal type caller. Sixteen moved casts are removed through real type narrowing; sparse legacy billing does not acquire fabricated zero-cost data. The wrapper inventory now includes its hydration decoder. Shared prepared-runtime fixtures supply their required catalog. Existing Gateway tests still make 40 real reads and assert over 64 transcript events, using distinct valid read limits rather than weakening the repeat guard. Diagnostic tests own a scoped transport host rather than inheriting another test's mocked provider callbacks.
Against main fcf29c4: 107 paths, +6,882/−2,665 lines, including mechanical moves. The runtime CI repair is 43 paths, +232/−206; its subsequent fixture-only follow-up changes two existing tests and their allocation. Test growth passes at 2,101 net lines = 400 allowance + 1,701 reviewed allocation: the earlier 93-line real-worker admission case plus 17 further net lines in existing CI fixtures. There is no new test case/file/cold shard, timeout change or raised shared threshold. Obsolete assertion and mock debt only shrinks; no unrelated UI allowance is added.
The changed 13-case hydration file costs 101.528 s cold wall / 174.598 local child CPU-seconds, including bootstrap; the new case takes 2.599 s in the affected batch. PostgreSQL conformance costs 79.568 s wall / 135.495 local child CPU-seconds. The diagnostic red reproduction costs 68.920 s wall, mostly transformation; its original lifecycle cases remain present. CI seconds are unobserved, and these different workloads are not speed comparisons.
Evidence
The runtime implementation is normal-hook signed 2557ac2, tree 68e73028926dae2bebb772f62519c683bd753963. Its exact sourcePerformance build passes with unchanged tracked source. The preceding whole-feature review retains its original scope; fresh P0–P2 review of the complete 43-path runtime CI repair is scoped-clean with 412,619 bytes of intact input.
The latest fixture-only follow-up is normal-hook signed a05d6ff, published tree 57ab8bd72361aba17d7eb8f90c22803d6b4fa71d. Production inputs are byte-unchanged from 2557, so its build, Gateway and native proofs are reused, not relabeled as new-source captures. A fresh three-file P0–P2 review is scoped-clean with 31,559 bytes of intact input.
SettingsManager.inMemorydirectly with the former fixture's exact settings after main retired an unused private helper export; no compatibility export is restored. Both failing owning graphs, agents-root and agents-sessions, now pass locally, as do matching strict type-aware lint, format and all nine fixture cases. Remote CI must still finish.Runtime Gateway qualification — source 2557, reused unchanged
defaultauto-landing3-warm-q1binds signed 2557ac2, its exact build and common workload 178e6b14eb40c725396b838c8114dd85ced6dcce. 300/300 probes are valid; warmup and measured phases share PID 1035. Each verifies one actual prepared plan, four rendered results, four HTTP 200 maintenance requests and durable boundaries 18 → 19. The outcome is degraded-quality fallback, not normal-quality summary success. Both original 47,184-row prefixes match their recorded bytes/SHA-256. All 71 raw files and two links are unchanged, inspection copies removed and cleanup valid.This is one source-bound qualification, not matched performance acceptance. All measured costs remain visible:
The stream brackets are immediate samples, 0 ms before and 60 ms after, without prorating. Full CPU includes startup/warmup and is last observed cumulative CPU per Gateway PID; unsampled shutdown tails remain unobserved. Process CPU already includes workers. Worker counters cover successful userland JSON strings of at least 1,024 UTF-16 units, not host parsing; overlapping tasks include overhang. Worker IDs are distinct observations, not simultaneous peaks. Full capture has two plans/eight renders including warmup; measured request count five includes its pressure request, not five maintenance requests.
Prior-source qualifications — retained separately, never pooled
defaultauto-landing2-warm-q1qualified signed 3ff / published 3f with 300 valid probes, same PID 1047, one plan/four renders/four maintenance requests and 18 → 19 degraded boundaries per phase. Both original prefixes matched; 69 raw files/two links were unchanged.Earlier exact-623 stream max 13.764 ms/full gap 407 ms and c58/77 max 71.683 ms/full gap 1,388 ms remain separate, each with 300 valid probes and the same degraded class/four maintenance requests. Every earlier CPU/RSS/parsing/failure cell, the 267/162 overlapping checks and all-19-file cost proof retain their original source scope. None is relabeled as current-source regression acceptance.
Open: exact-head CI/landing gates, formal paired cold/warm acceptance, live-provider follow-up, effective SDK window and per-worker/JIT warmth. No performance-win or no-regression conclusion is claimed.
Prospective acceptance protocol — draft, not an admitted cohort
Before acceptance, pin both production commits/build receipts, the signed controller, fixture, image and sampling manifests; freeze and read back the published rule. Previous diagnostics and qualifiers are ineligible.
Run five serial baseline/candidate cold pairs, then five separate process-warm pairs. Warm requires a distinct physical session to durably complete default maintenance in the same Gateway PID first; it does not establish per-worker/JIT warmth or global idle. Use unique immutable tags and stopped imports, auditing unchanged original prefixes, durable outcome class and maintenance request counts.
Keep all 300 scheduled slots and every error, timeout, suppression and cancellation. Retain full-stream and declared broad-window latency, sampler gaps, process/main CPU, RSS/heaps, parsing/transport and full-capture startup/warmup costs. No post-result window selection, outlier removal, replacement tags or diagnostic pooling.
Report n=5 per arm/population, median, nearest-rank p95, spread and paired rows. Incomplete capture or source/outcome mismatch stops the cohort with its prefix retained. A median/p95 metric worsening at least 20% stops before the next population. Every adverse cell remains visible; a worse user-facing metric needs explicit owner acceptance. Lower worst latency does not excuse higher CPU or memory.
No acceptance cohort has started under this draft. Qualification does not grant acceptance.
Contributor credit
Requested by @RomneyDa; publication authorized by @vincentkoc. Human contributor credit retained in the signed series: @RomneyDa, @vincentkoc and @jalehman.
Work sessions
Linked for team reference; these sessions aren’t public.
Worked on by