Repository navigation
perf(runtime): a replace during a run keeps its work - #769
Merged
Merged
Conversation
A same-signature replace no longer bumps the subscription's epoch. The running read keeps its work and answers the replace only if the revisions it read still match a fence taken after the replace; otherwise it is discarded and the subscription runs again from the replace. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s slot Review round 1 on #769: a replace landing during each freshness check sent the run straight into another, so a document under repeated replaces could hold every company slot without answering or rotating. - A run takes at most one post-replace fence. A replace during it fails the final answerable check, so the run ends, runs again from the replace and its document rotates behind queued ones. - The analytics disposition entry now covers every replace discard, including one that overtakes the final authority check. - Tests: a queued document gets a slot while the noisy one replaces; a replace during the final authority check and during a revision-only up-to-date's check; an overlapped read failure and a failing freshness check send no error and run again at once; a key-aware fixture checks a replaced read against the dependencies it revealed and an absent resource. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 18, 2026
allisonmahmood
added a commit
that referenced
this pull request
Oct 19, 2026
…ng Reconnecting (#783) Release 14's What's new entry, written from \`7694bab\`. It covers everything merged since release 13's \`through\` (\`c9b8fc4\`), and sets the \`patchy\` release to \`0.14.0\` (\`packages/patchy/package.json\` and \`CURRENT_RELEASE\`). | Change | PRs | | --- | --- | | Improved: Tools with server code answer faster | #756, #764, #768, #769, #771, #772, #773, #775, #778 | | Improved: Your company's tools and pages open sooner | #759, #761, #766, #770 | | Fixed: Tools stop flashing Reconnecting while they load | #755, #776, #780 | | Improved: Publishing is quicker | #729 | | Improved: New tools start with a tidy layout | #763 | | Improved: Your usual is easier to scan | #721 | | Fixed: A page that isn't there says what to do | #762 | | Fixed: A logo Patchy can't read is refused, not a crash | #728 | | Behind the scenes: richer logs for live data | #758 | #720 is release 13's own entry, so it's left out. Made by Claude Opus 5.5 via Claude Code. Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a shell's
replacenamed a subscription that was already running with the same signature, the server bumped the subscription's epoch. The running read's result was thrown away, and the query ran again from the back of the queue. A tier 2 query that overlapped a slow-pathreplacecost a full extra run, and its panel waited twice as long.The work can't simply be kept, though. The run took its fence before it read. A
replacemay be recovering a committed write whose wake was lost. If the old read answered the new fence, reconciliation would finish on stale data and nothing would run the query again.Fix
A same-signature
replaceduring a run no longer bumpsepoch. The run keeps its work, but it answers the replace only once it proves that work fresh:replacewas admitted. If it equals the read's vector, the result is the answer: a snapshot, orup-to-dateif unchanged.up-to-datefrom the revision phase, answers only if no replace arrived after the run started. Otherwise it is dropped and the subscription runs again, as before.Design choice: a server-side check, not frames that name their sequence. The shell already counts the first answer after
admittedas answering the fence. So the server never sends an answer-bearing frame it can't prove fresh, and the wire contract, the shell anddocs/API.mdstay as they are. A tab running an older shell gets the same guarantee. Frames that name their sequence could also send a stale read as data-only, but an older shell would ignore the new field and count stale data as the answer. That would also need a wire bump. The only thing given up is early stale data in the rare case where a write lands during an overlapped run; that case costs the same rerun it does onmain.What stays:
up-to-date.epoch. A changed signature, an unsubscribe/re-add, or a document close or replacement still fails the presence check.duringRunwake intersection is unchanged.The runtime and analytics glossaries and ADR-0010 now say how a resync treats a read it overlaps.
Tests
New deterministic cases in
Subscriptions.test.ts, using gates on the read and on the revision fence:up-to-date, in three reads rather than four.up-to-date's check. Neither old answer is sent; a second run answers.-1) resource appearing, forces a rerun; nothing changed answers with one read.Against
main'sSubscriptions.ts, the cheap-path, missed-snapshot and coalesced-wait tests fail; the guarantee tests pass on both. With the freshness check removed, the lost-wake and overlapping-replace tests fail. Each later guard has its own test, which fails alone when the guard is removed: a looping freshness check, the final,up-to-dateand failure replace checks, and a fence over only the keys known before the read.Validation
I ran a local instance with a tier 2 patch whose
notes.slowquery reads a table and then waits 1.5 s. A script opened a document stream, subscribed withreplaceseq 0, and sent the same set asreplaceseq 1 500 ms later, while the query ran. Runs come from there-runwide events.main(3 runs)initial→discarded, thenreplace→deliveredinitial→deliveredA committed write during the run. A
notes.createmutation ran 300 ms into the read, before the replace. On both, the first run wasdiscarded, a second run (invalidation→delivered) followed, and the answer at about 3.0 s contained the new note.pnpm verifypasses locally: format, lint, typecheck, synth, test, postgres-concurrency, cli-smoke, tier2-smoke and browser. It ran before rebasing onto #766 and #768, which don't touch this code; the subscription suites passed again after the rebase.Closes #750
Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol.