Skip to content

fix(protocols): bound opaque replay string memory - #506

Merged
Menci merged 1 commit into
mainfrom
fix/opaque-replay-memory
Sep 6, 2026
Merged

fix(protocols): bound opaque replay string memory#506
Menci merged 1 commit into
mainfrom
fix/opaque-replay-memory

Conversation

@Menci

@Menci Menci commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Summary

Recover raw opaque UTF-16 strings in bounded, compact chunks so long reasoning-replay histories do not retain a V8 rope node for every code unit. Preserve the existing carrier bytes, every UTF-16 code unit, BOMs, and lone surrogates.

The regression coverage exercises the full code-unit range, chunk boundaries, large values, nonzero-offset views, empty input, and incomplete code units. A separate retained-heap fixture protects the memory behavior, and the development documentation explains how it runs through standard verification.

Memory behavior

Affinity analysis retains decoded opaque values while subsequent history blocks are processed. Per-character concatenation retained approximately 12 MiB for a bounded fixture of 64 strings containing 393,216 ASCII code units; chunked recovery retains approximately 0.35 MiB for the same output.

The fixture launches an isolated Node.js process with explicit GC, warms the production helper, and measures heap usage while all decoded strings remain reachable. It compares their contents after sampling because comparisons can flatten ropes and hide the defect. These figures measure retained Node.js heap, not peak production Worker memory. The wire format and persisted data remain unchanged.

Test Plan

  • Preserve the raw carrier contract across all UTF-16 code units, BOMs, lone surrogates, chunk boundaries, offset views, empty input, and odd-length rejection.
  • Verify that the retained-heap regression fails for per-character recovery and passes for chunked recovery, with identical decoded output.
  • Run the complete pnpm run verify chain: 548 test files and 5,733 tests passed; local installer verification passed 106 cases with four environment-dependent skips; lint, typecheck, repository checks, and web-build assertions passed.
  • Pass all eight PR CI checks. CI installer verification passed 109 cases and covered the three absent-CLI scenarios skipped locally.
  • Review the recorded production trial: the affected session resumed real tool-use cycles at approximately 861k–874k input/cache tokens without a new compaction, and live logs captured repeated successful requests around 15 MiB without observed resource-limit outcomes.
  • Run the real pinned Codex 0.144.5 app-server smoke test. That exact CLI version is absent from both local and CI environments; this is the sole remaining CI installer skip.

The client version also changed during the production trial, so recovery is not a single-variable experiment. The isolated before/after heap regression independently establishes the implementation's memory improvement.

Recover raw UTF-16 carriers in bounded flat chunks so long replay histories do not retain a V8 rope node per code unit. Preserve every code unit and the existing wire format.

Cover the full UTF-16 range, BOMs, surrogate and chunk boundaries, offset views, and isolated retained-heap growth. The bounded Node fixture drops retained heap from about 12 MiB to 0.35 MiB. Document how this regression runs through the standard verification workflow.
@Menci
Menci merged commit be4b176 into main Sep 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant