Skip to content

fix: avoid repeated transcript copies during manual compaction - #199840

Merged
RomneyDa merged 2 commits into
mainfrom
openclaw/nimble-barnacle-5
Nov 15, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
openclaw/nimble-barnacle-5

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #199561

What Problem This Solves

Fixes unnecessary transcript copying when manual compaction prepares a session, adding work on the Gateway's main thread before summarization begins.

User Impact

Manual compaction preparation no longer requests writable copies of immutable transcript payloads merely to inspect them. Performance acceptance remains pending. This PR does not fix automatic warm-session compaction or all main-thread stalls. No configuration or migration is required.

Why This Change Was Made

Use the existing internal read-only branch accessor for synchronous manual preflight, instead of requesting writable copies immediately before context projection. Public SDK mutation isolation, model-context filtering, extension behavior, and writer/cancellation checks are unchanged; no worker or cache is added.

Requested and guided by @RomneyDa.

Work sessions

Linked for team reference; these sessions aren’t public.

Evidence

  • Real composition regression fails on exact base 9f0f89522a633826aa5c64483cca3bec3dacca34 at retained payload ownership and passes with this change. Delegate suite: 30/30 passed; unchanged codec siblings: 27/27 passed.
  • Targeted format, lint, agents-other test type graph and git diff --check pass. CI-only pinned-Bun parity was not run locally. Canonical local autoreview (Codex, P0–P2) found no actionable findings in the exact-base/final local snapshot. Published head 54617a8c765a8672c1459da190ad08567e38bb0e has the same tree as reviewed/tested signed commit 7bcfe0a3b7757a50ee0a759add452b620b54989a.
  • Exact baseline and published-head sourcePerformance builds pass. Workload f30da43971c6b210df2e89962d0af639bc04107e passed 17 isolated admission/control-flow contracts and fresh canonical local P0–P2 autoreview. All four separately tagged real-Gateway qualifiers passed and were audited: native compaction, physical-session 8192-byte continuity, matched two-request summary work, default limits, CPU brackets and cleanup.
  • ClawSweeper's review of the current head lists no code findings and requests the declared end-to-end performance evidence. That evidence is not yet complete.
  • The original frozen twenty-slot comparison was interrupted by a Gateway restart after six native-valid cold observations (three pairs). The seventh slot was interrupted before measured compaction; thirteen slots were unattempted. Original receipts and all outcomes are retained unchanged. This is not a completed five-pair population, a warm comparison, or performance acceptance. The interrupted task container is stopped. No failed tag was replayed and no observations were pooled or relabeled.
  • The earlier single profiled baseline remains exploratory only. Prior setup failures, the corrected invalid module-registry oracle and the receipt-shape admission refusal remain recorded separately.

Prospective performance rule — published before comparison timing

Real manual compaction through isolated built Gateways, the same private long-session fixture, native import and same-physical-session 8192-byte follow-up. Compare exact base 9f0f89522a633826aa5c64483cca3bec3dacca34 against exact published head 54617a8c765a8672c1459da190ad08567e38bb0e. Workload f30da43971c6b210df2e89962d0af639bc04107e preserves the five canonical rig/turn/mock/importer/observer files from 007777bbf9917bdc62a488b9e348990fc06c6a04. Successful exact builds, fixture/workload/protocol hashes, native admission and the complete order are frozen before accepted runs. Qualification timings are excluded.

Five serial interleaved baseline/candidate pairs cold, then five pairs process-warm, without profiling. Report every outcome, median, nearest-rank p95 (=maximum at n=5), min/max and spread for compaction/follow-up latency, whole-process and independently sampled main-thread CPU, RPC/lifecycle RSS and heap, and main-thread pulse gaps. Include bracket overhang and host load; all native integrity and cleanup checks must pass. No selective reruns, pooling or outlier removal.

A win requires copying reduction and measurable real-flow improvement without worse user-facing metrics. After each complete five-pair population, a 20% or greater adverse median or p95 in any measured cell stops before another population. Missing measurements block; zero-baseline/positive-candidate values stop. Smaller adverse cells remain visible and require explicit informed owner acceptance before landing. With no measurable gain, do not land as a performance improvement. Recovery must retain the interrupted original cohort and use separately declared fresh tags/bindings, never rewrite its receipts or silently combine populations.

Evidence reuse and measurement limits

The successful exact-base build is reused, not rebuilt. A separate audited schema supplement retains original install/build receipts and hashes. Whole-tree/dist fingerprints were observed at prior diagnostic admission/end and rechecked, not retroactively observed at build completion; that observation gap remains explicit. The candidate install/build binds the exact published head. Literal probe/install shell-child decoding preserves the actual recorded command without repeating the successful install.

The unchanged nominal 100 ms main-isolate sampler gives a coarse maximum adjacent gap over the inclusive RPC bracket, including overhang. It cannot resolve sub-100 ms blocking or replace other-session RPC latency. Process CPU/RSS include workers; worker-only zero counters do not mean zero main-thread parsing.

Process-warm manual compaction is not resident automatic compaction. Unrelated-session RPC probes occur after compaction, so concurrent responsiveness remains unproven. The fixture is one whole observed generation with fixed mock summaries, not a broad corpus or provider-quality test.

Worked on by

roboclaw-bot and others added 2 commits November 15, 2026 22:58
Use the existing internal read-only branch accessor for manual Gateway preflight. Preserve hydrated immutable payload ownership through preparation instead of requesting writable SDK copies.

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: 69c46a07-b290-85a3-adca-74cdf8832368
@clawsweeper

clawsweeper Bot commented Nov 15, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XS labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR uses the existing internal read-only transcript accessor during manual compaction preflight and extends the composition regression to check payload ownership.

Example: Manual compaction prepares the regression fixture with seven current messages, including 500,000-character assistant outputs.

  • Before: Read-only preflight requests writable message payloads, causing unnecessary deep copies before summarization.
  • After: Preflight retains the immutable payloads while making the same compaction decision.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch has no identified defect, but the declared real-flow performance proof is not yet supplied.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Manual compaction performs avoidable main-thread transcript copying before summarization starts.
Reason: The maintainer-authored direction removes source-verifiable waste using an existing contract and keeps the scope explicitly limited to manual preparation.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored draft open: the copying defect remains on main, and this focused patch addresses it without an identified correctness regression.

Priority: P2
Reviewed head: 54617a8c765a8672c1459da190ad08567e38bb0e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Publish the already-declared exact-base/head Gateway comparison showing reduced copying, successful compaction and follow-up, and the cold/warm acceptance results, with credentials and private endpoints redacted.
Agent review details

How this fits together

The Gateway sessions.compact handler prepares a session transcript under the lifecycle owner, checks whether compaction is useful, and passes the prepared session to the existing compactor.

flowchart TD
  A[Manual compaction request] --> B[Session lifecycle owner]
  B --> C[Prepare transcript]
  C --> D[Internal read-only branch]
  D --> E[Compaction preflight]
  E --> F[Existing compactor]
Loading

Technical review

Best possible solution:

Use the existing internal accessor for read-only preflight while preserving writable public access and the current compaction lifecycle.

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

Source inspection establishes the unnecessary detachment path on current main; the body reports an exact-base failing regression, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

This is the smallest complete fix for the stated preparation-stage defect: reuse the existing read-only accessor and extend the existing composition regression without adding state, workers, or parallel owners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7de99f0419bb.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b4fb043 adds src/gateway/server-methods/sessions-compaction-runner.ts:86 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b4fb0436986d; files: src/gateway/server-methods/sessions-compaction-runner.ts)
  • Sukhdeep: Raw commit c902f9a adds src/agents/embedded-agent-runner/compact.delegate.test.ts:794 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c902f9aa2f64; files: src/agents/embedded-agent-runner/compact.delegate.test.ts)
  • RoboClaw: Raw commit a4cc2ad adds src/agents/embedded-agent-runner/compact.delegate.test.ts:803 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: a4cc2adb5d1a; files: src/agents/embedded-agent-runner/compact.delegate.test.ts)

PR surface

Source +4, Tests +5. Total +9 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 9 5 +4
Tests 1 9 4 +5
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 18 9 +9

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Unnecessary main-thread copying affects manual compaction of large transcripts, without evidence of an urgent availability regression.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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: Unnecessary main-thread copying affects manual compaction of large transcripts, without evidence of an urgent availability regression.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 November 15, 2026, 6:24 PM ET / 23:24 UTC.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 15, 2026 23:33
@RomneyDa
RomneyDa merged commit 675297f into main Nov 15, 2026
226 checks passed
@RomneyDa
RomneyDa deleted the openclaw/nimble-barnacle-5 branch November 15, 2026 23:55
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Manual preflight copy fix: retained partial evidence

Incomplete: neither cohort reached five pairs; no warm acceptance observations were collected. Each table is a separate n=3-per-arm cold prefix. Nearest-rank p95 is the maximum of three, not the frozen n=5 acceptance result. No samples are pooled, corrected, discarded or replayed. Human merge is not performance acceptance.

Base: 9f0f895. Candidate: 54617a8. Workload: f30da43971c6b210df2e89962d0af639bc04107e.

Source regression is base-red/fix-green; 30 delegate and 27 unchanged codec checks pass. Both exact builds and four separately tagged real-Gateway qualifiers passed. Those facts do not make the incomplete performance comparison pass.

Original cohort

Gateway restart; seventh slot never reached measured compaction. Six native-valid cold observations, one interrupted/non-eligible slot and thirteen unattempted slots remain separate and unchanged.

Metric Base median / p95 / range Fix median / p95 / range Median / p95 change
rpcMs 1944.381 / 1950.492 / 1894.408–1950.492 2056.844 / 2134.200 / 1878.005–2134.200 +5.78% / +9.42%
cpuMs 4119.947 / 4205.640 / 4017.647–4205.640 4288.310 / 4751.837 / 4052.951–4751.837 +4.09% / +12.99%
mainThreadCpuMs 1046.921 / 1054.724 / 1044.577–1054.724 1024.779 / 1055.617 / 969.323–1055.617 -2.11% / +0.08%
rssMiB 1755.008 / 1776.559 / 1731.898–1776.559 1759.195 / 1771.383 / 1746.344–1771.383 +0.24% / -0.29%
mainHeapMiB 355.583 / 372.577 / 351.112–372.577 339.617 / 357.309 / 328.252–357.309 -4.49% / -4.10%
coldRssMiB 2008.883 / 2046.871 / 1993.082–2046.871 1963.688 / 2032.574 / 1958.219–2032.574 -2.25% / -0.70%
coldMainHeapMiB 416.669 / 457.296 / 412.237–457.296 406.171 / 437.189 / 405.044–437.189 -2.52% / -4.40%
workerObservedHeapMiB 43.190 / 43.366 / 43.170–43.366 43.294 / 43.997 / 42.782–43.997 +0.24% / +1.45%
primaryParsedBytes 15390507.000 / 15390507.000 / 15390507.000–15390507.000 15390454.000 / 15390454.000 / 15390454.000–15390454.000 -0.00% / -0.00%
primaryParseCount 3028.000 / 3028.000 / 3028.000–3028.000 3028.000 / 3028.000 / 3028.000–3028.000 +0.00% / +0.00%
primaryThreadCpuMs 265.951 / 285.432 / 257.373–285.432 277.943 / 279.298 / 268.755–279.298 +4.51% / -2.15%
hydrationTransferBytes 16243802.000 / 16243802.000 / 16243802.000–16243802.000 16243768.000 / 16243768.000 / 16243768.000–16243768.000 -0.00% / -0.00%
hydrationTransferEvents 4862.000 / 4862.000 / 4862.000–4862.000 4862.000 / 4862.000 / 4862.000–4862.000 +0.00% / +0.00%
workerThreadCount 1.000 / 1.000 / 1.000–1.000 1.000 / 1.000 / 1.000–1.000 +0.00% / +0.00%
followupMs 2336.000 / 2352.000 / 2330.000–2352.000 2164.000 / 2402.000 / 2151.000–2402.000 -7.36% / +2.13%
mainThreadPulseGapMaxMs 344.000 / 347.000 / 338.000–347.000 331.000 / 340.000 / 261.000–340.000 -3.78% / -2.02%

Whole-process CPU/RSS include workers. Main CPU is independently sampled with uncorrected RPC bracket overhang. Heap and RSS are sampled peaks; lifecycle peaks differ from the RPC window. Parsing/transfer/thread counters cover observed primary transcript-worker tasks, not main-thread parsing or all Gateway workers; worker count 1 does not mean only one worker existed in the process. The maximum adjacent gap from the nominal 100 ms main-isolate sampler includes bracket overhang and is neither exact blocking duration nor unrelated-session RPC latency. All adverse moves are retained above.

Recovery cohort 1

Awaited controller call aborted; seventh slot has measured compaction but no complete cleanup/native terminal receipt. Six native-valid cold observations, one interrupted/non-eligible slot and thirteen unattempted slots remain separate and unchanged.

Metric Base median / p95 / range Fix median / p95 / range Median / p95 change
rpcMs 1897.274 / 1987.948 / 1896.064–1987.948 1902.224 / 2104.187 / 1804.273–2104.187 +0.26% / +5.85%
cpuMs 4370.389 / 4546.119 / 4166.441–4546.119 4199.755 / 4667.113 / 3878.530–4667.113 -3.90% / +2.66%
mainThreadCpuMs 1096.308 / 1119.013 / 1037.661–1119.013 985.760 / 1022.518 / 911.252–1022.518 -10.08% / -8.62%
rssMiB 1758.066 / 1795.352 / 1738.629–1795.352 1779.258 / 1780.867 / 1760.949–1780.867 +1.21% / -0.81%
mainHeapMiB 350.384 / 378.273 / 335.692–378.273 357.529 / 396.401 / 340.228–396.401 +2.04% / +4.79%
coldRssMiB 1989.824 / 2062.008 / 1926.102–2062.008 1978.961 / 1992.273 / 1962.227–1992.273 -0.55% / -3.38%
coldMainHeapMiB 405.707 / 437.892 / 396.165–437.892 428.464 / 453.324 / 404.675–453.324 +5.61% / +3.52%
workerObservedHeapMiB 41.787 / 43.049 / 41.268–43.049 43.113 / 43.501 / 42.176–43.501 +3.17% / +1.05%
primaryParsedBytes 15390769.000 / 15390769.000 / 15390769.000–15390769.000 15390717.000 / 15390717.000 / 15390717.000–15390717.000 -0.00% / -0.00%
primaryParseCount 3028.000 / 3028.000 / 3028.000–3028.000 3028.000 / 3028.000 / 3028.000–3028.000 +0.00% / +0.00%
primaryThreadCpuMs 260.999 / 268.009 / 253.861–268.009 261.282 / 263.605 / 256.076–263.605 +0.11% / -1.64%
hydrationTransferBytes 16243972.000 / 16243972.000 / 16243972.000–16243972.000 16243938.000 / 16243938.000 / 16243938.000–16243938.000 -0.00% / -0.00%
hydrationTransferEvents 4862.000 / 4862.000 / 4862.000–4862.000 4862.000 / 4862.000 / 4862.000–4862.000 +0.00% / +0.00%
workerThreadCount 1.000 / 1.000 / 1.000–1.000 1.000 / 1.000 / 1.000–1.000 +0.00% / +0.00%
followupMs 2319.000 / 2333.000 / 2128.000–2333.000 2103.000 / 2403.000 / 2086.000–2403.000 -9.31% / +3.00%
mainThreadPulseGapMaxMs 356.000 / 357.000 / 339.000–357.000 323.000 / 338.000 / 317.000–338.000 -9.27% / -5.32%

Whole-process CPU/RSS include workers. Main CPU is independently sampled with uncorrected RPC bracket overhang. Heap and RSS are sampled peaks; lifecycle peaks differ from the RPC window. Parsing/transfer/thread counters cover observed primary transcript-worker tasks, not main-thread parsing or all Gateway workers; worker count 1 does not mean only one worker existed in the process. The maximum adjacent gap from the nominal 100 ms main-isolate sampler includes bracket overhang and is neither exact blocking duration nor unrelated-session RPC latency. All adverse moves are retained above.

Scope and remaining proof

This covers one real observed generation with synthetic fixed summaries and successful 8192-byte physical-session follow-ups for completed observations, not provider quality or a broad corpus. Neither prefix satisfies the declared cold/warm no-regression rule. Automatic compaction and during-window other-session responsiveness remain separate work.

Independent raw-metadata audit: 192 raw metric cells, 320 summary cells and all 32 table rows reconciled with zero discrepancies; 199 inspected metadata files remained unchanged. Original CPU/pulse bracket overhang was 10–85 ms before and 1–79 ms after; recovery was 9–99 ms before and 21–94 ms after. Neither interrupted slot is eligible, and the empty ineligible list in each explicit six-tag aggregate does not mean no interrupted slot existed.

RomneyDa added a commit that referenced this pull request Nov 16, 2026
Qualify the beta.4 equivalent of #199840 (canonical commit
675297f). Beta.4 delegates
getBranch directly to SessionEntryNavigation and does not have the
writable-copy boundary introduced by main-only #195961.

Assert payload identity across repeated manual-preparation branch reads.
Hydration creates private mutable containers once, so main's owned-payload
brand assertion does not apply; no product ownership change is needed.
Focused manual compaction regression, formatting and lint pass.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…law#199840)

* fix: avoid repeated transcript copies during manual compaction

Use the existing internal read-only branch accessor for manual Gateway preflight. Preserve hydrated immutable payload ownership through preparation instead of requesting writable SDK copies.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: jalehman <[email protected]>

* fix: avoid repeated transcript copies during manual compaction

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: 69c46a07-b290-85a3-adca-74cdf8832368

---------

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: jalehman <[email protected]>
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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS 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.

2 participants