Skip to content

improve: prepare long conversation context without rechecking sealed history - #203040

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-sealed-transcript-initial-context-20260919
Nov 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-sealed-transcript-initial-context-20260919

Conversation

@steipete

@steipete steipete commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Preparing model context from a long conversation can re-inspect an entire already-sealed transcript message, including tool evidence that the projection immediately removes. The transcript owner retains the immutability fact after the generic freezer memo rotates, but the projection helper did not consume it.

Related: #202547, #202136, #200888, #199480.

User Impact

Less CPU and allocation during initial-context preparation. Model-context bytes, hydration isolation, writable SDK behavior, and persistence remain unchanged. No configuration, schema, migration, or new cache.

Why This Change Was Made

The existing pure-projection helper now checks transcript ownership before generic deep inspection. Mutable and opaque SDK graphs keep their existing validation and detachment, and projected results still receive normal freezing. Hydration sealing and the publication clone remain necessary; this removes the redundant source inspection at its owner.

Production delta is +1 line: an existing-owner import and a condition substitution. The regression extends the existing memo-rotation fixture. The existing compaction benchmark gains an initial-context-only arm and verifies that baseline source replacement actually loaded before measurement.

Evidence

The regression fails on exact parent 4c7701017b653fec558f078ed1878059ebe5de39 at the unwanted inspection of sealed history, and passes with this change. It checks identical projected output, shared mutation rejection, and retained-context isolation after writable SDK edits. 248 focused source tests pass, plus one Chromium transcript-entry test and ten mocked-Gateway chat messaging E2E tests. Isolated Codex autoreview through P2 is clean.

All 400 measured outputs have the same complete context hash. Initial-context thread CPU improves 89.4%, sampled allocation 95.9%, and pooled p95 wall time 88.6%. No sample was discarded and no tail exception was needed.

Per initial-context build A/A arm 1 A/A arm 2 Before After
Mean thread CPU (ms) 60.999 60.177 58.981 6.225
Median wall (ms) 59.959 60.556 58.736 6.072
Pooled p95 wall (ms) 66.423 64.219 62.413 7.087
Mean sampled allocation (MB) 140.672 140.057 140.192 5.688

Each cell pools 50 operations across five processes; allocation runs are separate from timing. Before/after wall ranges are 56.060–64.288 / 4.886–7.616 ms. Process-mean CPU ranges are 58.074–59.467 / 6.084–6.398 ms. A/A CPU differs 1.35% and allocation 0.44%. Node 26.12.1, macOS arm64, 32 physical cores, 512 GiB RAM. Local test/typecheck/dead-export work finished before this campaign; light Git/publication/native PR workflow activity overlapped. Host load is recorded per process.

Acceptance declared before measurement: persisted synthetic 1,700-message / 21,158,679-byte fixture; one warmup and ten operations per process; five counterbalanced A/A and five A/B process pairs for timing, with separate collected-inclusive allocation sampling. Require identical complete context bytes, lower initial-context thread CPU and allocation, and no >20% pooled p95 wall regression. Report all samples and spread. This measures the initial-context owner after real hydration, excluding SQL, transport, provider inference, and workspace discovery.

node --expose-gc --import ./scripts/tsx.mjs scripts/perf/compaction-transcript-clone-measure.ts --initial-context --operations 10 --scratch /isolated/proof --output /isolated/result.json

Baseline adds --owner-file /isolated/base-immutable-data.ts, extracted from the exact parent. Allocation runs add --allocation.

pnpm check:changed completed with two test-only narrowing errors, subsequently corrected and verified by the affected typecheck/regression, plus an inherited dead-export failure. All other stages passed. The same three unused exports reproduce on the clean exact parent with the same frozen dependency graph: exposeGlobalPackageThroughRelease, resolveGitReleaseCheckout, and writeGitUpdateResultFixture. Introducing commit b229b2664537d / #200578 added the first two exports and removed the final consumers of the third. This is an attributed main regression, not a passing full-check claim; no updater repair is bundled. Final benchmark script typecheck, lint, format, and baseline-loaded smoke pass. The focused source run took 132.68 s including compilation; two additional SDK consumer tests took 61.46 s including compilation. The changed regression itself is subsecond.

Avoid repeating deep immutability inspection of admitted transcript payloads after generic memo rotation. Preserve writable SDK detachment and hydration sealing; extend the owner regression and initial-context benchmark.
@clawsweeper

clawsweeper Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: XS labels Nov 21, 2026
@steipete
steipete marked this pull request as ready for review November 21, 2026 10:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T10:08:25.782677Z 1f38919 Draft marked ready
ℹ️ 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.

@steipete

Copy link
Copy Markdown
Contributor Author

The final performance evidence is now in the PR body: all 400 measured contexts match; initial-context thread CPU falls 89.4%, sampled allocation 95.9%, and pooled p95 wall time 88.6%. Focused mutation-isolation, SDK, browser, and prompt-prefix proof passes. The unchanged head is 1f3891920973bdc08bc0442f66c87ecdb4ed67f0.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. 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 Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses transcript ownership when preparing immutable context projections and extends the existing regression and benchmark.

Example: Prepare context from a hydrated 1,700-message conversation containing tool-result evidence.

  • Before: The reported benchmark spends 58.981 ms of thread CPU per build rechecking sealed history.
  • After: The reported benchmark uses 6.225 ms per build, with identical complete context bytes.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, correct optimization with useful owner-boundary measurements and passing exact-head CI; performance confidence is limited to the measured in-process workload.
Proof confidence 🦐 gold shrimp (3/6) This behavior-preserving internal optimization has production-owner benchmark evidence after real hydration, with identical context outputs; it makes no whole-Gateway or live-provider performance claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Preparing long conversations spends avoidable CPU and allocation inspecting sealed tool evidence that model context immediately excludes.
Reason: The maintainer-authored direction removes measured redundant work through existing owners without changing model-context content or runtime configuration.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR removes redundant inspection through the existing ownership boundary, preserves mutation isolation, and has no actionable findings; the exact-head CI gate passes.

Priority: P2
Reviewed head: 1f3891920973bdc08bc0442f66c87ecdb4ed67f0

Before merge

None.

Findings

None.

Agent review details

How this fits together

Session hydration seals transcript payloads; model-context preparation removes storage-only metadata, publishes isolated context, and retains writable SDK detachment.

flowchart LR
  A[Persisted transcript] --> B[Hydration and sealing]
  B --> C[Owned payload roots]
  C --> D[Pure context projection]
  D --> E[Frozen model context]
  B --> F[Writable SDK detachment]
Loading

Technical review

Best possible solution:

Consume the existing sealed-payload guarantee at the shared projection owner while retaining publication freezing and writable SDK detachment.

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

Source shows that memo rotation makes the existing projection helper traverse sealed tool evidence before discarding it; the PR reports an exact-parent failing regression, but no target code was executed during this review.

Is this the best way to solve the issue?

This is the smallest complete fix: reuse the existing ownership fact in the shared helper, extend the existing regression, and preserve the established cloning and opaque-input boundaries.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 103e91ab0d51.

Provenance checked

  • Immutable projection eligibility keeps the original intent (037ad05: Reuse pure projections only for immutable sources while leaving mutable and opaque graphs uncached.)
  • Memo-rotation regression keeps the original intent (51bed3b: Ensure owner-sealed history avoids repeated inspection after generic memo rotation while preserving caller isolation.)
  • Compaction benchmark and context publication keeps the original intent (018e2fb: Measure real hydrated rewrite ownership while retaining the initial-context clone required for SDK isolation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 037ad05 adds src/shared/immutable-data.ts:130 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 037ad0565c8f; files: src/shared/immutable-data.ts)
  • Vincent Koc: Raw commit 9bf980e adds src/agents/sessions/session-manager-codec.test.ts:48 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 9bf980ed4a1b; files: src/agents/sessions/session-manager-codec.test.ts)

PR surface

Source +1, Tests +12, Other +19. Total +32 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 15 3 +12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 23 4 +19
Total 3 40 8 +32

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.

Review metrics

Metric Value Why it matters
Benchmark-only flag 1 new flag: --initial-context Selects isolated context measurement without adding a runtime configuration setting.

Labels

Label changes:

  • add P2: Reduces synchronous preparation work for long conversations without evidence of an urgent availability regression.
  • 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: Reduces synchronous preparation work for long conversations without evidence of an urgent availability regression.
  • 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.

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 21, 2026, 5:22 AM ET / 10:22 UTC.

@steipete
steipete merged commit 04382b7 into main Nov 21, 2026
225 of 228 checks passed
@steipete
steipete deleted the steipete/perf-micro-sealed-transcript-initial-context-20260919 branch November 21, 2026 10:26
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Nov 21, 2026
Preserve the initial-context benchmark added in #203040 alongside endpoint rewrite measurement. The endpoint production fix is unchanged. Integrated maintenance and codec tests pass; Codex autoreview has no actionable P0-P2 findings.
vincentkoc added a commit that referenced this pull request Nov 21, 2026
…3044

* origin/main:
  fix(ci): decouple boundary fixture from timing inventory (#203026)
  fix(ci): shard capable compatibility UI targets (#203042)
  perf(agents): restore selected subagent payloads once (#203039)
  fix: keep standalone context from completing QA tool steps
  perf(sessions): reuse sealed ownership for context projections (#203040)
  refactor(hooks): separate event predicates from hook registry (#203017)
  fix(ci): align update export audits with their consumers (#203030)
  fix: keep cold baseline checks within the existing heap limit
vincentkoc added a commit that referenced this pull request Nov 21, 2026
* feat: open shared sessions in their source Control UI

* feat: open shared sessions in their source Control UI

OpenClaw-Publication: a3826b6b-5899-8ff2-a1b5-84961c64219f

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  fix(ci): decouple boundary fixture from timing inventory (#203026)
  fix(ci): shard capable compatibility UI targets (#203042)
  perf(agents): restore selected subagent payloads once (#203039)
  fix: keep standalone context from completing QA tool steps
  perf(sessions): reuse sealed ownership for context projections (#203040)
  refactor(hooks): separate event predicates from hook registry (#203017)
  fix(ci): align update export audits with their consumers (#203030)
  fix: keep cold baseline checks within the existing heap limit

* fix(session-share): accept the runtime config snapshot in the source link resolver

The stored-session link resolver took a mutable config, so the plugin's readonly
runtime snapshot failed production and test typechecks. Accept the snapshot type.

Document the real Open original setup: allow the link command on the receiver
Gateway, set the source Control UI origin, reinstall the source node with all
three commands, then approve the widened surface. Move the section ahead of
Security boundary and add a troubleshooting entry.

Assert through the Gateway catalog list that a provider-supplied link survives
streamed and final rows, and drop the menu unit test the browser fixture covers.

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  refactor(test): remove duplicate token startup wait case (#203087)
  fix: keep Plugin SDK declarations within the build limit
  fix(ci): remove unused hook type exports (#203074)
  fix(test): exercise the sign-in callback path guard (#203075)
  refactor(tts): separate caption eligibility from text helpers (#203068)
  test: reuse worker preload options (#203058)
  refactor(test): share Bun native-policy test launcher (#203064)
  fix(cron): a chat-created automation's failure notice reaches that chat (#203056)
  refactor(test): remove duplicate claw origin rejection case (#203067)
  refactor(channels): move chunk-mode lookup to streaming readers (#203047)
  refactor: separate skill queries from workspace discovery (#203045)
  fix: resume new chat turns in retained tasks after a restart
  refactor: separate usage pricing preparation from formatting (#203043)
  fix: avoid repeated filesystem probes before agent turns (#203057)
  perf(agents): preserve sealed history during endpoint compaction (#203037)
  fix(test): give deferred identity fixtures read scope (#203053)
  refactor(test): remove redundant channel catalog facade (#203052)
  refactor(cli): isolate daemon port presentation (#203020)
  refactor(cron): isolate CLI input parsing (#203031)

* chore(plugin-sdk): record the approved session-discussion surface growth

Open original adds two exports to openclaw/plugin-sdk/session-discussion: the
stored-session Control UI path resolver and the session path parser. Raise the
public export and callable budgets by two for them.

Use neutral fixtures for the rejected-origin and rejected-query URL tests so the
fixtures do not resemble credentials; the same rejections are covered.

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

Avoid repeating deep immutability inspection of admitted transcript payloads after generic memo rotation. Preserve writable SDK detachment and hydration sealing; extend the owner regression and initial-context benchmark.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
* feat: open shared sessions in their source Control UI

* feat: open shared sessions in their source Control UI

OpenClaw-Publication: a3826b6b-5899-8ff2-a1b5-84961c64219f

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  fix(ci): decouple boundary fixture from timing inventory (openclaw#203026)
  fix(ci): shard capable compatibility UI targets (openclaw#203042)
  perf(agents): restore selected subagent payloads once (openclaw#203039)
  fix: keep standalone context from completing QA tool steps
  perf(sessions): reuse sealed ownership for context projections (openclaw#203040)
  refactor(hooks): separate event predicates from hook registry (openclaw#203017)
  fix(ci): align update export audits with their consumers (openclaw#203030)
  fix: keep cold baseline checks within the existing heap limit

* fix(session-share): accept the runtime config snapshot in the source link resolver

The stored-session link resolver took a mutable config, so the plugin's readonly
runtime snapshot failed production and test typechecks. Accept the snapshot type.

Document the real Open original setup: allow the link command on the receiver
Gateway, set the source Control UI origin, reinstall the source node with all
three commands, then approve the widened surface. Move the section ahead of
Security boundary and add a troubleshooting entry.

Assert through the Gateway catalog list that a provider-supplied link survives
streamed and final rows, and drop the menu unit test the browser fixture covers.

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  refactor(test): remove duplicate token startup wait case (openclaw#203087)
  fix: keep Plugin SDK declarations within the build limit
  fix(ci): remove unused hook type exports (openclaw#203074)
  fix(test): exercise the sign-in callback path guard (openclaw#203075)
  refactor(tts): separate caption eligibility from text helpers (openclaw#203068)
  test: reuse worker preload options (openclaw#203058)
  refactor(test): share Bun native-policy test launcher (openclaw#203064)
  fix(cron): a chat-created automation's failure notice reaches that chat (openclaw#203056)
  refactor(test): remove duplicate claw origin rejection case (openclaw#203067)
  refactor(channels): move chunk-mode lookup to streaming readers (openclaw#203047)
  refactor: separate skill queries from workspace discovery (openclaw#203045)
  fix: resume new chat turns in retained tasks after a restart
  refactor: separate usage pricing preparation from formatting (openclaw#203043)
  fix: avoid repeated filesystem probes before agent turns (openclaw#203057)
  perf(agents): preserve sealed history during endpoint compaction (openclaw#203037)
  fix(test): give deferred identity fixtures read scope (openclaw#203053)
  refactor(test): remove redundant channel catalog facade (openclaw#203052)
  refactor(cli): isolate daemon port presentation (openclaw#203020)
  refactor(cron): isolate CLI input parsing (openclaw#203031)

* chore(plugin-sdk): record the approved session-discussion surface growth

Open original adds two exports to openclaw/plugin-sdk/session-discussion: the
stored-session Control UI path resolver and the session path parser. Raise the
public export and callable budgets by two for them.

Use neutral fixtures for the rejected-origin and rejected-query URL tests so the
fixtures do not resemble credentials; the same rejections are covered.

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: vincentkoc <[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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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.

1 participant