Skip to content

fix(studio-server): history never drops an edit to make room for bytes it must keep - #9096

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/history-budget-replaced-bytes
Nov 29, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/history-budget-replaced-bytes

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A project's history no longer drops an old edit to make room for bytes that dropping it cannot free.

Why

When a save replaces a file's bytes, history keeps those bytes until it has taken the save in. They are in memory's list of things to keep, so a prune never removes them. They still counted against the history's size budget. Over budget, history prunes, sees it is still over, and drops its oldest edit, again and again, though none of that can free those bytes.

With the default 2 GB budget this needs a history already near its limit. It shows up in CI, where a test's budget is 16 bytes: firstCopy.test.ts "keeps the original an early save's receipt names through a prune before its late copy is filed" failed in a merge queue run (2026-11-29). When the 30 ms quiet timer commits the late copy before the follow-up sweep has run, 13 replaced bytes push the history over, the late copy's own change is dropped, and the project's start becomes the saved bytes instead of the original.

Related work

#8403 stopped counting the bytes held for a file's first copy, for the same reason. This covers the other list the prune keeps.

How

  • replacedHashes() lists both kinds of replaced bytes, and the prune and the budget both read it, so what is kept and what is counted cannot differ again.
  • Bytes named by a change not yet committed still count: they become history.
  • The replaced bytes of a file's unread saves are one chain per file and live as long as the open history; the next open prunes what nothing names.

Test plan

  • fails without the fix: projectHistory.saving.test.ts "stay kept, and never push an edit out of a history within its budget" (on main the history lists no edit at all). It depends on no timing.
  • It also pins that a prune keeps those bytes, which no test did: with the saves' bytes left out of the shared list, all 420 history tests that existed or came with this change passed until this assertion was added.
  • The CI failure, forced: with the follow-up sweep 120 ms late, firstCopy.test.ts fails on main with the same two hashes as CI and passes here. That delay is not in this change.
  • Each other part taken out fails at least two history tests: first-copy bytes out of the list, the list out of the prune, the list out of the budget.
  • All of Studio Server: 2,781 passed, 6 skipped. The history folder 3 runs in a row: 420 passed, 3 skipped. tsc --noEmit clean. All on Linux.
  • Not done: Windows and macOS runs, left to CI. The failure did not come back in 40 runs under CPU load; forcing the order is the evidence for the cause.

No visible change

History bookkeeping in Studio Server. No screen changes.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 273), smooth 73 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Quarantined, measured but not gated (0)

@miguel-heygen miguel-heygen added the needs-jerrai-review Request a review from Jerrai. Removed after the review posts; re-add to request another. label Nov 29, 2026

@jerry-heygen jerry-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at e48efe20. Pruning and history-budget accounting now use the same set of replaced bytes that must be kept. That prevents the budget from evicting an edit to make room for bytes the prune cannot free. The regression checks that both the edit and the protected bytes survive, while pending history entries still count toward the budget.

Exact-head regression and preview-regression workflows passed. The Studio Server test job was still running when checked; I did not run a live Studio save.

— Jerrai (pr-review)

@jerry-heygen jerry-heygen removed the needs-jerrai-review Request a review from Jerrai. Removed after the review posts; re-add to request another. label Nov 29, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 29, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit 3f0a20b Nov 29, 2026
88 checks passed
@miguel-heygen
miguel-heygen deleted the fix/history-budget-replaced-bytes branch November 29, 2026 16:30
@miguel-heygen miguel-heygen mentioned this pull request Nov 29, 2026
5 of 6 tasks
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.

2 participants