Skip to content

fix(take): a take's lazy baseline holds only the take before's final state, so a watched world's heap stops growing (#2585) - #2586

Merged
genekogan merged 2 commits into
mainfrom
agent/2585-take-baseline-chain
Nov 16, 2026
Merged

genekogan merged 2 commits into
mainfrom
agent/2585-take-baseline-chain

Conversation

@genekogan

@genekogan genekogan commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Problem

Since 0.129 a watched world's heap grows for as long as it has viewers. It is about 930 MB at 50 viewers, against 450 MB on 14 Nov code. At 200 viewers it reaches 3 to 6 GB, the clock collapses and every viewer reconnects. Closes #2585. Part of the scaling tranche (lane V, V0b).

The cause is in #2427's lazy take hashes.

  • Each take's baselineStateHash was read through () => body.finalStateHash of the take before.
  • That function held the earlier take's whole body. That body's own lazy baseline held the take before it, and so on.
  • So every take ever cut stayed reachable from the current recorder.
  • In a watched world each of those takes also kept its texts (TEXT, cached by copy identity).

Now finishLazy returns captureFinalState's own cached hash function, which holds only that take's final state. The body's field reads that same function, so every value is unchanged.

Acceptance

Proof

Tier: T3 (node tools/proof/tier.mjs: packages/engine-mars/src/take-retain.test.ts; the recorder is under mars/)

Reduced preview: souls-run-2585.mp4

  • images: none
  • playtest: the A3 runs, timed-run viewers --viewers 50,200 on souls-timed, 2 repeats per arm, main and candidate dispatched together. Own cores at start 0.3 to 0.8 % busy, machine 2 to 11 %; the world ran on two physical cores and the load on the rest.
  • reviewer pass: left for the coordinator's reviewer (T3).

Self-audit

Outside Touches

none

Time

09:19 to 09:50 UTC, about 31 min against the 3 h ceiling. About 20 min of that was waiting on the runs.

Changelog

changes/2585-take-baseline-chain.md

Risk

  • Risk: low in code. It is a 4-line change: the same hash function, so takes stay byte-identical, as take-recut.test.ts pins.
  • Who would notice: viewers, if a take's baseline were wrong. take-recut and the take golden test pin it.
  • Why the playtest covers it: the viewers bench is the path that regressed. It reads every take's hashes through the hub, at 50 and 200 viewers. The clip covers a viewer's live playback.
  • Rollback: revert the fix commit.

🤖 Generated with Claude Code

Coordinator sign-off (T3): the independent reviewer approved with no blocking findings (comment above). All of A1–A3 are met with the runs declared beforehand. It ships in 0.130: this leak is live in production on 0.129.

genekogan and others added 2 commits November 16, 2026 04:23
…, not its body, so dropped takes are collected (#2585)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@genekogan genekogan added the ci:run Open the CI window: run this ready PR's heavy CI jobs (docs/testing.md#ci-window) label Nov 16, 2026
@genekogan
genekogan marked this pull request as ready for review November 16, 2026 09:47
@genekogan genekogan added ci:run Open the CI window: run this ready PR's heavy CI jobs (docs/testing.md#ci-window) and removed ci:run Open the CI window: run this ready PR's heavy CI jobs (docs/testing.md#ci-window) labels Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Proof check: proof-ok passes

Tier T3 from packages/engine-mars/src/take-retain.test.ts (node tools/proof/tier.mjs).
Required at T3 (docs/process/PROOF-POLICY.yml): T2; scenario playtest with repeats_per_arm repeats per arm; reviewer agent pass; maintainer sign-off.

Check Status Detail
maintainer sign-off ok approved:maintainer added by @genekogan
problem statement ok present
linked issue ok #2585, #2427
acceptance ok 3/3 met
carried from the issue ok all 3 issue criteria present
self-audit ok checks, failed attempts, long tail and limits filled
clip ok 1 video link(s), 1 image(s)
proof.json ok valid and agrees with the checklist
playtest ok main 3d8da8a + #2583 (agent/v0b-main): 0/2, candidate: main + #2583 + this fix (agent/v0b-cand): 2/2
reviewer pass ok independent reviewer agent (coordinator dispatch): approve
Acceptance criteria
Criterion Status Evidence
[x] A1 Step 0, then a heap-only bisect. Step 0: reproduce the heap on main (o met #2585 (comment)
[x] A2 Fix the cause, or revert the offending change if a fix doesn't fit, wi met node --test packages/engine-mars/src/take-retain.test.ts -> fail before the fix, pass after
[x] A3 Re-run viewers --viewers 50,200, 2 repeats, main against the candida met #2585 (comment)

Proof links: 1 video, 1 image, proof.json linked.

Full-resolution videos — use the original clips and their proof metadata for motion/contact review. GIFs below are reduced previews.

souls-run-2585.mp4

Updated on every edit, push, label and review. How to fill it: .claude/skills/journal/SKILL.md. T3-T4 also need the maintainer's sign-off (tools/proof/gate.mjs). A maintainer can waive with the proof:waived label.

@genekogan

Copy link
Copy Markdown
Member Author

Independent reviewer pass (T3): approve, no blocking findings.

  • The retention chain is real, and the fix breaks it. finishLazy returned () => body.finalStateHash, and the body's baseline getter reached the previous take's closure. The fix returns captureFinalState's own cached hash, whose context reaches no take body or recorder.
    • A WeakRef probe (40 takes, 12 kept; watched, unwatched and with the baseline read) showed only the kept takes' final states live, plus one.
  • Hashes are identical in every path. It is the same function the body's getter called, cached internally, with the same order and the same held.mark updates. Recut, skip and setClock are pinned by take-recut.test.ts against pre-perf(take): a take's hashes are computed when first read, not in the tick that cuts it (#2422) #2427 ids and hashes. Restore from disk is unaffected. No clock, randomness or ordering change.
  • Tests. take-retain.test.ts fails on base (20/20 reachable) and passes on head. take-recut passes, as do the 10 take tests in mars/viewer (29 pass, 1 skipped). tsc is clean for packages/engine-mars and mars/viewer.
  • Non-blocking:
    • Each kept take also keeps its whole recorder, through (o) => o !== this in finishLazy's shared closure context. That is bounded at 13 and is not a leak, so it's a candidate follow-up.
    • The PR body's "until its own baseline is read" sentence was wrong; it is corrected below.

@genekogan genekogan added approved:maintainer Maintainer sign-off on a T3+ PR they authored (GitHub forbids self-approval) ci:run Open the CI window: run this ready PR's heavy CI jobs (docs/testing.md#ci-window) and removed ci:run Open the CI window: run this ready PR's heavy CI jobs (docs/testing.md#ci-window) labels Nov 16, 2026
@genekogan genekogan added merge:ready Hand the PR to the merge train (.github/workflows/merge-train.yml) ci:run Open the CI window: run this ready PR's heavy CI jobs (docs/testing.md#ci-window) and removed ci:run Open the CI window: run this ready PR's heavy CI jobs (docs/testing.md#ci-window) labels Nov 16, 2026
@genekogan
genekogan enabled auto-merge November 16, 2026 11:06
@genekogan
genekogan added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit e03e415 Nov 16, 2026
124 of 146 checks passed
@genekogan
genekogan deleted the agent/2585-take-baseline-chain branch November 16, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved:maintainer Maintainer sign-off on a T3+ PR they authored (GitHub forbids self-approval) ci:run Open the CI window: run this ready PR's heavy CI jobs (docs/testing.md#ci-window) merge:ready Hand the PR to the merge train (.github/workflows/merge-train.yml)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scaling V0b · The world's heap doubles under viewers since 16 Nov; 200 viewers restart a world

1 participant