Skip to content

fix(studio): a drain settles inline edits opened while it waits - #8676

Draft
terencecho wants to merge 6 commits into
mainfrom
tai/studio-drain-settles-new-edits
Draft

terencecho wants to merge 6 commits into
mainfrom
tai/studio-drain-settles-new-edits

Conversation

@terencecho

@terencecho terencecho commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What

flushStudioPendingEdits now also saves edits that start while it is waiting on a slow write. That covers inline text edits that open, and debounced edits a flush listener queues (a nudge, a colour grade). Before, it looked for both once, at its start, so an edit started during the wait was never saved, yet the drain still reported clean.

Why

A caller that acts on clean (closing the view, switching away) assumes every open edit has been saved. An inline edit opened during the drain's wait broke that. It was left to save itself on unmount, after the caller had already acted, so a failure of that save could no longer be handled.

To reproduce:

  1. Register an open edit whose save is held.
  2. Start a drain.
  3. While it waits, open a second edit (settleOnDrain), then release the first save.

The drain reports clean, and the second edit's settle has run zero times.

Related work

None. Self-contained.

How

  • After each wait, the drain looks at the open edits again and settles each newly opened one exactly once, tracking the ones it has already settled.
  • It loops until a pass finds nothing new.
  • It fails only on edits that keep opening: after five rounds that each settled a newly opened edit, it reports failed ("Edits kept opening while the pending edits were saved.") rather than clean, so a caller that only proceeds on clean stays put. The result type is unchanged.
  • After each wait on a write other than the flush listeners' own saves, it asks the listeners again and waits for what they commit. A listener that answers every ask with a save is not asked again because of that save, so it cannot keep the drain from ending.
  • Listeners are asked again at most five times, and those rounds never fail the drain. A listener fed input on every ask (an arrow key held during an export) commits each time, and its write is tracked apart from its answer. After five re-asks (six asks in all) the drain stops asking and reports what its writes did, clean if none failed, as before this change.
  • A drain of only the current edits (onlyCurrent: true) never takes on newer ones, as before.

Known limit

An edit a listener queues while the drain waits only on listeners' own saves is not asked for again, so the drain can report clean with it still queued. Re-asking there would never end for a listener that answers every ask with a save. Running the drain again can meet the same sequence, so it does not close this.

Likewise, input still arriving after the fifth re-ask (the key still held) can stay queued when the drain reports clean, as it did before this change.

No visible change

The diff changes only studioPendingEdits.ts and its test: when a drain reports clean, and which edits it saves first. Nothing renders differently.

Test plan

  • Unit tests added/updated. src/utils/studioPendingEdits.test.ts, "an edit opened while a drain waits on a write":
    • "is settled before the drain reports clean": the reproduction above. The drain stays pending until the second edit's save lands.
    • "reports a failure, never clean, when edits keep opening".
    • "commits what a flush listener queued meanwhile before reporting clean".
    • "reports clean, not failed, while a listener is fed input on every ask": fails on the previous head (failed), passes now.
    • "reports a write that just failed, with no field focused", with and without onlyCurrent: the drain reads the writes in flight before any wait. These pass on main too; they guard this branch's earlier blur split.
    • "leaves a drain of only the current edits to them".
    • Fails without the fix: on main's studioPendingEdits.ts the first two fail, and the listener test fails on the first commit alone. 40/40 pass with the change.
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

— tai (drafted on Terence's behalf)

🤖 Generated with Claude Code

terencecho and others added 4 commits November 24, 2026 08:36
flushStudioPendingEdits read the open inline edits once, at its start. An edit
opened while it waited on a slow write was never settled, yet the drain reported
clean, so a caller that closes on clean closed with that edit still open.

The drain now looks again after each wait and settles each newly opened edit
once. If edits keep opening after five rounds it reports a failure, never clean.
A drain of only the current edits is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A flush listener (a nudge, a colour grade) that queued an edit while the
drain waited on another write was asked only once, at the drain's start,
so its edit stayed queued while the drain reported clean.

After each wait on a write other than the listeners' own saves, the drain
asks the listeners again and waits for what they commit. A listener that
answers every ask with a save is not asked again for it, so it cannot keep
the drain from ending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Splitting out the blur step made the drain wait a turn even with no field
focused. A tracked write that had just failed could drop out of the pending
set in that turn, and the drain reported clean. With no field focused the
drain again reads the writes in flight in the same turn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 57 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-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

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

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

Quarantined, measured but not gated (0)

Unstable (1)

  • seqplainkeys-none-px-r0-nested-z100: tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

The comment gate lets a file's comment share only go down. The drain's
added comments move into names and the PR description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review at 04562f3948 (draft, findings only).

What holds

  • Red-first, run one test at a time with main's studioPendingEdits.ts put back: "is settled before the drain reports clean" fails (second called 0 times), "reports a failure, never clean, when edits keep opening" fails (clean), and "commits what a flush listener queued meanwhile" fails ([]). All 39 tests pass at head.
  • The two "write that just failed, with no field focused" cases and "leaves a drain of only the current edits" also pass on main. That fits the body: they guard this branch's own earlier commit, and they don't fix anything on main. Main already read pendingEdits synchronously when nothing was focused.
  • The re-ask loop ends. I wrote a scratch probe with a listener that answers every ask with a save, plus one held write. It ended clean after 2 asks, because the listener's own save is excluded by promise identity. A write that never settles still keeps the drain waiting forever, the same as on main. The five-round cap doesn't change that.
  • The failure state doesn't stick. firstFailure is local to each drain. In a probe, a save that failed and then a successful save drained clean, and a failed drain followed by a second drain gave failed then clean.
  • Callers: none of the full-drain callers sets a timeout (export/render, share, clipboard, colour-grade scope, outside file changes, drawFileAgain). The onlyCurrent path (settlePendingEdits) behaves the same as before. A longer drain only waits longer, and there's a bound unless a write never settles.

Should-fix (small)

  • A listener is exempt from re-asking only if the write the drain waits on is the very promise the listener returned. A listener can also track a separate inner write, as the nudge does with its beginStudioPendingEdit promise. If that listener queues again on every ask, each round counts as "waited on other writes". My probe shows this: the listener's save tracks an inner trackStudioPendingEdit promise and returns inner.then(...). The drain re-asked 6 times and returned failed with "Edits kept opening while the pending edits were saved." No save failed. In the app this needs input that keeps arriving through the rounds, such as a held arrow key or a colour-grade drag during an export or an outside file change. Callers then show it as a save failure. On main the same case waited and then reported clean. Two options: report the cap as a distinct status, or count only rounds that settled a newly opened edit. Or, if this is intended, name it in the Known limit section.

Nits

  • In "is settled before the drain reports clean", stopSecond() and the second save's release sit outside finally. On main the first failure leaves that edit open and its write pending. Every later test in the file then times out at 5 s (6 failures in a whole-file run instead of 3), which hides which tests really fail.
  • The Known limit is real and narrower than before. A listener's queued edit is now picked up after any wait on a non-listener write, and it's missed only when the drain waits only on listener saves. Before, it was missed after any wait.

A listener fed input on every ask, such as a held arrow key during an
export, commits a nudge whose write is tracked apart from the listener's
answer. Each round then counted toward the five-round cap, and the drain
reported failed with no save failed, where it used to report clean.

Only rounds that settle a newly opened edit count toward the cap that
fails the drain. Listeners are asked again at most five times; after that
the drain reports what its writes did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Delta re-review at 8434dd32 (draft, findings only). The should-fix and the nit from my last review are resolved, and I have nothing new.

  • The cap now counts only rounds that settled a newly opened edit (opened && editsKeptOpening()). Listener re-asks have their own limit of 5, and reaching it never fails the drain. The loop still ends: a round with neither an opened edit nor a queued listener edit breaks, opened rounds fail at 5, and queued-only rounds stop after 5 re-asks. A re-ask always comes after a wait, and once the limit is hit the drain doesn't ask again, so it never leaves a freshly queued edit unwaited.
  • Red-first: with studioPendingEdits.ts from 04562f39 put back, the new test "reports clean, not failed, while a listener is fed input on every ask" fails (1 failed, 39 passed). At head the file passes 40/40, and that includes "reports a failure, never clean, when edits keep opening".
  • The cleanup in "is settled before the drain reports clean" is now in finally.

This branch has not been deployed

No deployments
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