Skip to content

fix(sessions): preserve retained history through provider replay hooks - #196023

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-replay-hook-clone-drops-prelude-marker-20260919
Nov 9, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-replay-hook-clone-drops-prelude-marker-20260919

Conversation

@steipete

@steipete steipete commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes retained history being cut after a reset when a provider replay hook runs before history limiting. With three newer user turns and historyLimit=1, the explicitly retained prelude must remain alongside the newest turn. Regression from #195961 (245cbaf915c2).

User Impact

Explicitly retained reset history survives provider replay sanitization and turn validation. No configuration, schema, migration, or provider API change.

Why This Change Was Made

cloneTranscriptView previously enumerated only string keys, dropping the non-enumerable prelude marker. A symbol-only pass now preserves own symbol data properties and their descriptors, recursively copying values using the existing cycle/alias map. The existing string-key loop is unchanged. The immutable-payload sharing fast path remains unchanged. Production change: +7/−0 lines, net +7; the extra lines preserve metadata without adding another owner or cache.

The marker audit also covers steering-message identity, attached steering runtime context, and memory reset-recall cutoff metadata. The latter two have object-valued payloads; tests verify detachment and cyclic/shared references. Non-enumerable string properties remain excluded.

Evidence

  • Exact parent 245cbaf9: all 3 replay-hook regression cases fail by losing the retained prelude; both clone-marker cases fail by losing descriptors. The fixed-source focused result is below.
  • Focused provider-replay-runtime, history, transcript-snapshot, sanitize-session-history, and prefix-stability suites: 103 passed across 6 files.
  • Chromium history-settlement browser test: 1 passed. Chat messaging UI E2E: 10 passed. No new browser imports; transcript-snapshot has no direct Control UI consumer.
  • Codex autoreview through P2: scoped-clean.
  • pnpm check:changed completed; all task-owned gates pass after repairing and rerunning the new fixture's typecheck. The changelog-attribution and dead-export failures reproduce on main and are detailed below.
  • Synthetic direct-owner benchmark, 15,000 messages: symbol-free detached clone wall 22.186 → 23.953 ms, CPU 24.451 → 27.374 ms, sampled allocation 20.293 → 21.990 MB. A/A changes: +0.6%, +1.1%, +1.8%. Immutable-root sharing remains about 0.185 µs per call and preserves source identity. This is the metadata-preservation cost at the writable boundary; the internal immutable-reader allocation benefit from improve(sessions): avoid copying transcript history for internal readers #195961 is unchanged. No database/workspace I/O is included.
  • Rejected a single Reflect.ownKeys pass because the same workload increased CPU 30.3% and allocation 83.6%.

The 108-line test allocation covers the requested retained-reset replay regression across all three hook routes and the independent clone descriptor/alias contract. Individual changed-file test durations: snapshot 0.47 s, provider replay 3.93 s including worker import/transform; actual test bodies are milliseconds. CI duration is pending.

The lead owns merge. No deployment was performed.

Unresolved main check failures requiring follow-up

Changelog attribution fails on exact parent 245cbaf915c21c6cc02ba2edbe3c62e2725a133e (20 credits), introduced by 266a7aa0fe69 / #194364. Dead exports: authorDisplayName introduced by 832bbf926fc5; isLaunchctlNotLoaded barrel orphaned by b4262689db5d / #130634; parseLaunchAgentEnabled and resolveLaunchAgentPlistPath barrels became production-unused at 3d707a9b963b / #121929. These are unresolved main defects, not passing checks. Both dead-export scans reproduce on the exact parent with an empty git diff 245cbaf9 --name-only; only the candidate files were temporarily removed/replaced for that run, then restored.

Preserve own symbol-keyed data descriptors in transcript clones so explicit reset-retained history survives provider sanitization and turn validation before history limiting. Keep the string-key copier and immutable sharing fast path unchanged. Fixes the regression introduced by #195961.

Tests cover all three replay hook routes and symbol descriptor, alias, cycle, and detached-value contracts. Allocate exactly 108 regression-test lines.
@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 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-09T14:14:34.660413Z fa2e2e7 PR opened
ℹ️ 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.

@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: 🦐 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves symbol-keyed transcript metadata when cloning messages for provider replay hooks.

Example: Retain “retained before reset,” then add “new turn 1” through “new turn 3” with historyLimit=1 and a replay hook.

  • Before: The clone loses the retention marker, leaving “new turn 2” and “new turn 3.”
  • After: History contains “retained before reset” and “new turn 3.”

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with useful regression coverage; confidence in exercised product behavior is limited to the reported in-process evidence.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence exercises the clone and replay composition in tests, while the reported browser scenarios do not demonstrate the changed replay behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Explicitly retained reset history disappears from model context after provider replay processing and history limiting.
Reason: This restores the existing retention contract with a narrow shared-owner fix, and the supplied maintainer-authored status establishes direction.

Regression provenance

Regression provenance — verified: source commit 245cbaf915c2 by Peter Steinberger; canonical PR #195961 (blame-to-merge-commit).

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs a source-confirmed retained-history regression still present on main; no actionable patch defect was found, and exact-head CI remains pending.

Priority: P2
Reviewed head: fa2e2e7f50040717e2b475003569dea95d9311f6

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied shipped-entry-point trace shows reset-retained history surviving a real provider replay hook and history limiting; parent-red/head-green regression results are reported in the body.
Agent review details

How this fits together

Session context construction marks explicitly retained messages; provider replay hooks receive detached clones before history limiting selects the model’s conversation window.

flowchart LR
  A[Session entries] --> B[Context construction]
  B --> C[Transcript clone]
  C --> D[Provider replay hooks]
  D --> E[History limiting]
  E --> F[Model context]
Loading

Technical review

Best possible solution:

Preserve symbol data descriptors and graph aliases in the existing transcript copier while retaining its immutable-sharing and opaque-value fallback behavior.

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

The current-main producer, clone boundary, and history-limit consumer establish the failing path, and the added integration fixture supplies concrete inputs; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch is the smallest complete repair using the existing owner: it preserves metadata at the point of loss without adding caller-specific retention policy, state, or another cloning path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4b077d31b914.

Provenance checked

  • Transcript container copying keeps the original intent (fed5b24: Avoid copying large payload strings while preserving detached mutable containers, aliases, cycles, and whole-graph fallback for opaque SDK values.)
  • Writable provider replay boundary keeps the original intent (245cbaf: Share immutable history internally while detaching messages before writable provider hooks and retaining in-place edits on nullish returns.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The pinned introduced diff adds symbol-data copying to the existing clone owner, two regression groups, and their test allocation; the verified test merge contains the same changes without removing base-only work. (src/config/sessions/transcript-snapshot.ts:101, fa2e2e7f5004)
  • Current-main failure boundary: All three replay-hook routes detach messages with shareImmutablePayloads=false, while the main-branch copier enumerates only string keys and therefore drops the retained-prelude symbol. (src/plugins/provider-replay-runtime.ts:22, 4b077d31b914)
  • Retention contract and consumer: Context construction attaches a non-enumerable sessionHistoryPrelude symbol to reset-retained messages, and limitHistoryTurns excludes those messages from the conversation start. (src/agents/embedded-agent-runner/history.ts:36, fa2e2e7f5004)
  • Verified regression provenance: improve(sessions): avoid copying transcript history for internal readers #195961 introduced detachReplayHookContext to preserve writable plugin boundaries; the reviewed commit adds the exact clone call responsible for losing the marker. (src/plugins/provider-replay-runtime.ts:22, 245cbaf915c2)
  • Proof and discussion inspected: The full body reports parent-red/head-green replay regressions, focused suites, browser tests, and a synthetic benchmark; comments supply no retained-reset replay demonstration through a shipped entry point. (fa2e2e7f5004)
  • Merge and CI state: GitHub reports mergeable=true; three PostgreSQL conformance jobs remain in progress and openclaw/ci-gate is pending, with no failing check observed across both check-run pages. (fa2e2e7f5004)

Likely related people:

  • Peter Steinberger: Raw commit f83539c adds src/config/sessions/transcript-snapshot.ts:63 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f83539c99800; files: src/config/sessions/transcript-snapshot.ts)
  • Shakker: Raw commit e2f6348 adds src/config/sessions/transcript-snapshot.ts:55 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e2f634809c8f; files: src/config/sessions/transcript-snapshot.ts)

PR surface

Source +7, Tests +108, Other +2. Total +117 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 7 0 +7
Tests 2 108 0 +108
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 4 117 0 +117

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
Production versus regression code Production +7; tests +108 The production addition repairs the shared copying boundary; tests cover three hook routes and the separate descriptor, detachment, cycle, and alias contract.

Labels

Label changes:

  • add P2: The regression suppresses explicitly retained model context when replay hooks and history limiting combine; affected released installations are not established.
  • 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: The regression suppresses explicitly retained model context when replay hooks and history limiting combine; affected released installations are not established.
  • 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.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • For stronger confidence, provide redacted Gateway output showing retained reset history and the newest turn after provider replay and history limiting.

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 9, 2026, 9:27 AM ET / 14:27 UTC.

@steipete

steipete commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Landing note (maintainer review): fixes a regression from #195961 (245cbaf, not yet deployed to Team). The provider replay hook detaches messages with cloneTranscriptView, which copied only Object.keys and so dropped the non-enumerable Symbol.for("openclaw.sessionHistoryPrelude") marker. History limiting could then cut retained-history prelude messages after a reset (ClawSweeper P2 on #195961). The clone now preserves own symbol-keyed data properties with their descriptors. Regressions fail on 245cbaf; exact-head CI green. Production +7 lines.

@steipete
steipete merged commit 6c1c19f into main Nov 9, 2026
146 checks passed
@steipete
steipete deleted the steipete/perf-micro-replay-hook-clone-drops-prelude-marker-20260919 branch November 9, 2026 14:43
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
openclaw#196023)

Preserve own symbol-keyed data descriptors in transcript clones so explicit reset-retained history survives provider sanitization and turn validation before history limiting. Keep the string-key copier and immutable sharing fast path unchanged. Fixes the regression introduced by openclaw#195961.

Tests cover all three replay hook routes and symbol descriptor, alias, cycle, and detached-value contracts. Allocate exactly 108 regression-test lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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