Repository navigation
fix: reduce transcript allocation when preparing native context seeds - #194545
Conversation
Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: 294c8539-9e0b-4d17-aef7-76eb33f15e8b
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR selects bounded native context inside transcript readers before hydrating discarded message payloads. Example: Preparing a 4,096-byte native seed from a long synthetic session.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a concrete allocation defect still present on main, and the earlier import-boundary finding is resolved; no new actionable defect was identified. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherNative harness seed requests enter the host, which reads durable or memory-backed transcript context and returns selected messages plus omission and admission facts. flowchart TD
A[Native harness] --> B[Host seed preparation]
B --> C[Session context reader]
C --> D[SQLite snapshot]
C --> E[Memory session actor]
D --> F[Shared bounded selection]
E --> F
F --> G[Selected messages and facts]
G --> B
Technical reviewBest possible solution: Keep bounded acquisition inside the existing transcript snapshot, with shared pure selection and accounting that preserve context and reader isolation. Do we have a high-confidence way to reproduce the issue? Current-main source shows full-context materialization before bounding, and the supplied regression records excess hydration; no target code was executed during this read-only review. Is this the best way to solve the issue? Selecting before hydration repairs the acquisition boundary using existing snapshot and projection owners, while the follow-up preserves lightweight imports and unchanged selection formulas. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f01b0aae3cfc. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +255, Tests +158, Other +4. Total +417 across 24 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed November 8, 2026, 2:19 AM ET / 07:19 UTC (Revision 2). |
Move shared selection and token accounting into existing pure leaf owners without loading compaction transports or the agent runtime. Preserve the transcript-reader isolation introduced by #162609 and package only the required leaf closure. Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: 09aca01f-b368-487f-97eb-dbb64b0b376f
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Preserve exceptional JSON and canonical last-member admission facts while retaining upstream compaction progress and wrapper inventory. Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: 9793f742-04ad-4d1a-b977-7ebd074e7f63
Build last-member JSON lookup with typed Kysely. Keep deterministic hydration assertions without repeated timing samples and allocate exactly the remaining 250 regression-test lines. Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: beebe320-4be9-4844-bf45-651370b69c83
Keep current main compaction behavior while resolving estimator imports through the lightweight context-token-pressure owner. Include the merged recorder-owned worker-context repair. Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: d07a04d5-f480-4414-994f-c5feed6be860
Align the native hook relay middleware expectation with the compact payload serializer introduced by #196756. Retain exact result content and details assertions. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: 63a451db-f5c9-453b-96f0-72ed26ba3893
Backport the complete native seed read, projection, selection, token-accounting, and JSON scalar parity stack to the 2026.11.5-beta.4 release baseline. Preserve beta reset retention and token estimation; migrate its additional SAFETY_MARGIN consumer. Exclude unrelated newer-main runtime APIs and Codex serializer expectations. Source: fb83d65 (#194545) (cherry picked from commit fb83d65) Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit ffbb4049517f052fb42c129bdc667897b9359356)
Related: #191847
Current integration and green CI — November 12, 2026
Published head
c0720ff44c13bda3ea24603e390b4905e8cc4785is green: exact-head CI run43135788063completed successfully, and the watcher reportedgithub_rollup=SUCCESS, zero pending checks, andGREEN. The PR remains open and mergeable; no merge or release was performed.The preceding integration head
539ee820ccfb25a99cc9ec04e5125731eb167a9ehas the same source tree as reviewed local candidatec6f93f9dad0d861c9f5cc6d533ca73b4d8857ffb. It integrates main27af644cbfeebc86118b6abc8ebbbabdcec44499additively, preserving ancestry and including upstream repair #196487. Conflict resolution preserves main's compaction behavior and redirects request-budget'sSAFETY_MARGINimport to the existing lightweight owner.Preparation reported 165 passing tests and 11 PostgreSQL skips across 11 files, including the four formerly failing suites, native seed, portability, host seed, import boundary, and compaction coverage. Full core typecheck, lint, formatting, and diff checks passed. Independent inspection of the remerge delta and affected owner modules found no actionable issue.
Integration CI run
43132256022completed with one failing test shard (checks-node-changed-extensions-config-15-1, job130899544492) plus the aggregate gate; all four PostgreSQL jobs passed. The remaining failure was a stale pretty-printed JSON expectation inrun-attempt.native-hook-relay.test.ts, following upstream compact-result change #196756 (3d6699cb9d95). It reproduced locally: 1 failed / 11 passed. A one-line fixture correction retains the exact content and details assertions and changes no production behavior, guards, baseline, or test allocation. The corrected suite passed all 12 tests (18.16s suite duration, 20.85s wrapper wall time); targeted lint, formatting, and diff checks passed. Local repair186f6f2309b8and published headc0720ff44c13bda3ea24603e390b4905e8cc4785have the same source tree. The new exact-head run is green; the older red runs below are historical evidence only.Problem and user impact
Native harness seed preparation previously materialized full transcript context before applying its byte/token allowance. This change selects the canonical bounded suffix inside the existing transcript snapshot before transferring historical payloads. Memory sessions share the same selector. Public full-context reads and cloud recovery are unchanged; there are no configuration, schema, migration, cache, or durability changes.
Tool pairing, summaries, admitted-input accounting, media handling, and the native host's compaction policy are preserved. Lightweight readers use pure selection/accounting owners rather than importing compaction transports or the agent runtime facade. Existing consumers moved together; no import guard was weakened.
This is separate from #194536. The native path did not exist in 2026.11.1; the original reported OOM root cause remains unproven.
Allocation evidence
e235339a0fb7b4f01269e03fccf9507c8a853545, the real host caller received 9 messages / 131,524 bytes for a 4,096-byte allowance, then selected 2 messages / 299 bytes.Main integration and review repairs
Integrated main
c74d7a70ae1249ccb9fe18d256560e2e223f195c, retaining both wrapper-inventory parents and upstream host compaction-progress behavior. Seed scalar reads retain upstream exceptional-JSON handling: native decoding is guarded, and exceptional payloads use canonical hydration within the same snapshot.Independent reviews identified two related last-member defects. Both were reproduced and fixed: duplicate summary fields could cause a seed hydration disagreement; duplicate keys, roles, or outer message fields could lose the admitted user. Seed scalar lookup now uses JSON.parse-compatible last-member semantics, including the admitted role, without transferring ordinary historical bodies. SQLite regressions compare against the full-fidelity reader. No parallel parser, new state owner, or compatibility layer was added.
Prior integrated validation
Reviewed local merge candidate:
12088df64e319eb25f16a0b3404f5ee9837439cb.clearsTurnScopedSystemUpdates, whose default is false. The final review confirmed that policy; expiration-aware context-engine lifecycle behavior was not enabled here.CI ratchet repair
The failed baseline-ratchet job in run
42670719885was reproduced against the CI merge of head27460c380ed94dbfa5a57cca6b96aa482c5edaddand base51833f164e4570235ccc87a86c8075960a73c1ae. SQLite mechanical SQL grew 2 → 3, and test lines grew by 271 (265 above the ceiling).bounded-context-seed.txtallocation covers exactly those 250 lines under the documented test-cost policy; the shared scalar is unchanged. On the reproduced CI tree the test-line guard passes with its original 6-line slack.8bfde30da02b, 11 tests passed across the seed and transcript-portability suites; 11 PostgreSQL cases skipped. Seed suite wall time was 4.78 seconds; portability suite 5.96 seconds; combined wrapper wall time including compilation was 69.27 seconds. Targeted owner typecheck, two-file lint, formatting, and diff checks passed. Preliminary compiler invocations used an incorrect broad root or omitted canonical ambient declarations; the corrected owner-scoped configuration passed.openai/gpt-6.1-sol; it lacks helper-owned isolation and structured validation. The reviewed local repair and published head24a1f06bbfd7d0976bb6dee9961a2b6b25e005b8have the same source changes.Exact-head CI outcome and inherited failures
Run
42762761521completed with failure for head24a1f06bbfd7d0976bb6dee9961a2b6b25e005b8. The repairedchecks-fast-baseline-ratchetsjob passed, as didbuild-artifacts, production/test typechecks, lint, and all three PostgreSQL conformance shards. The four remaining test jobs (129652615457,129652615461,129652615615,129652615639) and aggregateopenclaw/ci-gatefailed.The job checkout log identifies the actual tested merge as
3d540291985662065af19741db70083ca0c9f110, combining this PR head with main75c494e697e7aef8b0db23840bf84d6eb3f6dc4e. The older integrated base is not adequate attribution evidence: all 93 tests in the four affected suites pass both on that original basec74d7a70ae1249ccb9fe18d256560e2e223f195cand on the PR head alone.Independent execution on the actual CI base
75c494e697e7aef8b0db23840bf84d6eb3f6dc4e, without this PR, reproduced all 10 CI failures (83 passed). Lead execution on the exact CI merge reproduced the same 10 failures (83 passed):worker-turn-detached-context.test.tsworker-turn-transcript-footprint.test.tssessions-rewind.storage.test.tsSESSION_PARTICIPATION_REQUIREDinstead ofSESSION_MUTATION_AUTHORIZATION_CHANGED.server.sessions.create-worktree-spawn.test.tsCommand:
node scripts/run-vitest.mjswith those four suite paths,--maxWorkers=1, isolated filesystem module caches, and continue-on-failure for the failing trees. Wrapper wall times were 235.40s on the PR head, 227.08s on the original base, 233.89s on the actual CI base, and 236.05s on the exact CI merge. The actual-base and merge runs both exited 1 with identical signatures. This is concrete inherited-failure evidence, not a passing replay or a green CI claim. No tests, guards, or baselines were weakened; no unrelated repair, extra push, CI rerun, or merge was performed.Limits and unqualified checks
Navigation scans remain linear; the first overflowing row is hydrated. One huge row and nondiscardable admitted input remain separate bounds. No heap caps were lowered. No live Gateway/model or local PostgreSQL qualification was run; no credentials were copied. All three PostgreSQL conformance shards passed in the exact-head remote run above.
Full wrapper build checks on the integrated checkout could not qualify locally because frozen dependency preparation failed (
ERR_PNPM_FROZEN_LOCKFILE_WITH_OUTDATED_LOCKFILE, with installed tsdown 0.23.3 versus required 0.23.4). This remains a local qualification gap; exact-head remotebuild-artifactspassed, but does not establish every full-package/declaration requirement. The earlier UI preflight also lacked Chromium. The historical CI run remained red solely on the independently reproduced inherited failures above; see the current integration section for the new head.Planned native-seed latency measurement (before timing)
Compare exact head
24a1f06bbfd7d0976bb6dee9961a2b6b25e005b8against its integrated pre-change basec74d7a70ae1249ccb9fe18d256560e2e223f195c, not today's main. Use committed synthetic short (all history fits) and long (many 16-KiB payloads exceed 4,096 bytes / 1,024 tokens) workloads, including an admitted user key and a summary case. Count SQL and decoded payload bytes separately before timing; separately verify identical final context. Measure the canonical host bounded-seed preparation with actual SQLite worker transfer if feasible, explicitly labeling any narrower boundary. Exclude fixture creation, module compilation, and instrumentation from timing. Run serial ABAB with at least 20 samples per version and workload; report median, p95, min/max spread, host load, and separate worker-cold versus warm observations. OS caches are not flushed. A latency reduction with unchanged context is a win; any median or p95 regression of 20% or more is a stop flag, not noise. Smaller changes overlapping spread are inconclusive. Full Gateway/model-turn latency is unqualified unless explicitly measured.Measured native-seed latency — November 10, 2026
The committed synthetic benchmark
scripts/bench-native-seed.mjswas run on those exact sources in isolated copies:TSX_DISABLE_CACHE=1 node --import tsx/esm scripts/bench-native-seed.mjs .openclaw/tmp/seed-latency/base 100. Benchmark source snapshot:d9822bc9815c73f4813916ab2d70a5b6410f9904; report and raw samples are committed on the separate scratch branch at3cc977fe9086inscripts/perf/native-seed-latency-2026-11-10.{md,json}. No production-code changes or push to this PR were made for measurement.Warm timing encloses the real host
bindBoundedSeed().prepareBoundedSeed()path, including durable SQLite worker dispatch, SQL, worker result transfer, and final host selection. Fixture creation, imports, source verification, and instrumentation are outside the warm window. Each workload has 100 serial baseline/candidate pairs after five untimed warmups, a 4,096-byte / 1,024-token budget, and an admitted user key. Short has four 64-byte old payloads; long has 256 × 16-KiB old payloads; summary adds a retained compaction summary. Full final contexts match, with explicit assertions for recent-question retention, admitted-user exclusion, omission notice, and summary presence.Separate snapshot-kernel counts: short SQL calls 9 → 10, marked payload parses 4 → 4, decoded bytes 981 → 981; long SQL 261 → 7, parses 256 → 1, bytes 4,242,499 → 16,574; summary SQL 262 → 8, parses 256 → 1, bytes 4,242,510 → 16,574. These are kernel counts, not all host/worker SQL, total wire bytes, or heap measurements.
This is a real tradeoff: long histories are faster, but short histories are slightly slower, not proven unchanged. No 20% median/p95 threshold was crossed. The largest short sample doubled (6.052 → 12.083 ms); that tail observation is flagged rather than discarded or presented as universal improvement.
Environment: Node v26.12.1, Linux x64, AMD EPYC 4585PX, 32 logical CPUs; load averages 3.96/2.84/2.09 → 3.87/2.91/2.13. Independent CI work continued on the host. Source checks verified 43,873 baseline and 43,875 candidate files against Git blobs. The benchmark uses compaction disabled, no media/continuation/refresh, and no live admission receipt (the admitted key is present). It does not measure Gateway transport, native harness RPC, model startup, model compaction, or complete user-turn latency. One first short read was 2,343.638 / 2,487.400 ms including lazy source-worker startup/compilation; it is separate diagnostic data, not a qualified cold-production benchmark. Syntax, formatting, diff checks, complete workload assertions, and owned-child cleanup passed; the repository lint wrapper was blocked by externally linked dependency containment. Review corrections added source verification, bounded cleanup, and fixture assertions; exploratory numbers from an invalid summary fixture were discarded before this final run.