Repository navigation
perf(execution): a warm call is admitted and released in 7 statements, not 16 - #778
Merged
Merged
Conversation
…ents A warm tier 2 call spent 16 platform statements on the fleet: a breaker upsert and read, a pool-wait limit read, a claim transaction, an admissibility check, the hold and protect, and a six-statement release, all before a mutation's reply. It now spends 6. - The breaker upsert returns the pause in the same statement. - ensure reads the company's active, admissible binding without the claim lock; protect still decides admission, and any miss takes the claim loop. - The pool-wait limit is read only when ensure has to claim or wait. - The release touches the binding and clears protection in one statement that holds the exclusive try-lock until it commits. - An admission's release is forked after the reply for every call kind. Part of #748 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e before the reply Review found two regressions in the first commit. - The one-statement breaker read the row as it stood before the upsert waited on it, so an admission could miss a trip committed during that wait, or be refused after a publish cleared the pause. The read is its own statement again, and two lock-wait tests race a trip and a publish reset against an admission. - A release forked from an owner's finalizer during shutdown escaped the closing scope, which disposed the activity session under it. Release timing is back to main's. Part of #748 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
A warm tier 2 call spent 16 platform statements, in two explicit transactions, getting admitted to its company's binding and releasing it (#748's counts):
Now it's 7 statements and no transactions.
What's in, and why authority holds
Warm read: 6 statements become 1. That's the claim transaction,
isAdmissibleTaskand theexecution.pool.waitread.ensurefirst reads the company'sactivebinding whose task is bound to a deployment that isn't retired. Only on a miss does it read the pool wait and run today's claim loop.protectis unchanged and still decides admission: the epoch,active, a bound task and a deployment that isn't retired. The warm read,protectandadoptnow share one SQL fragment for the task check.The claim lock serializes creating a binding, and it was released before
protect. It gave an existing active binding nothing thatprotectrelied on.Every case the claim loop handled differently still goes there:
claimingbinding, after adoption, replacement or a lost bind acknowledgement;deployment, as before.If something changes between the read and
protect,protectrefuses andacquire's existing loop reads again:stopping;The next read misses unless the binding is active and admissible, so it falls through to the claim loop.
binding_epochis unique and a binding's company never changes, soprotect's epoch check also pins the company.connect,ensureBindingand the limit-override rebind get the answer they got before: an active binding whose task could take admissions when it was read.Release: 6 statements become 2. The touch and the four-statement transaction become one statement:
UPDATE … WHERE (the company's admission binding) OR binding_id = <the call's binding>. ACASEclears that binding's protection only whenpg_try_advisory_xact_locksucceeds.protectsets protection again;BitmapOrover the admission partial index and the primary key, checked with 50k rows of binding history.Dropped after review
The one-statement breaker. I had used
WITH synced AS (upsert … RETURNING) SELECT COALESCE(synced, the row). When the upsert waits on a row lock and then writes nothing, the fallback read sees the row as it stood when the statement started, not after that wait. Two races follow:The read is its own statement again, with a comment saying why. Two new lock-wait tests cover both races, and both fail against the one-statement version.
Releasing after the reply. Forking the release from the owner's finalizer let it escape a closing host scope. The activity session and pool could then be disposed under it, which leaves protection in place through the crash window. Release timing is exactly as on main: quiet queries release after the reply, everything else before.
Main's existing quiet-query fork has a narrow version of the same gap, which I didn't touch here. If a quiet query's owner finishes its run exactly while the host scope is closing, the settlement fiber is forked into the closing scope and never starts. Its release is then skipped, with the same conservative result. An Effect probe confirms the ordering. It's a separate issue.
Not done: 3b,
Fleet.routereusing the bindingprotectreturned, is a follow-up.routestill readsexecution_bindingsbefore both bind and invoke, so it would save 2 more statements per call.Numbers
Local
brightlinewith tier 2 on the local task provider, which runs the same fleet controller as ECS. Each call is Allison on New Business.log_min_duration_statement = 0on the instance's own cluster, reset afterwards.deals.boarddeals.addNotedeals.boardPlatform statements before the reply, by statement order: the query went from 21 to 16 and the mutation from 35 to 26.
Every main window was identical: 5/5 query, 5/5 mutation, 6/6 re-run. On this branch:
The keepalive touch itself is unchanged.
The board renders and notes save. The board re-runs after every write and rename, and
pnpm dev shotreports no errors.Tests
Fleet.test.ts, over real Postgres:protectand the release, none of them in a transaction. On main it's 10 statements in 2 transactions.stoppingbinding and touches the company's fresh one, and housekeeping then stops the old task.deployment, and the call lands on a fresh task.patch_paused, and the call already admitted keeps running.The adoption and both breaker cases hold a real transaction open and wait until the call is blocked on its lock (
pg_stat_activity) before committing. Every case except the statement count also passes on main. The breaker test now uses a shared helper to publish versions.pnpm verifypasses: format, lint, typecheck, synth, test, postgres-concurrency, cli-smoke, tier2-smoke and browser.Part of #748
Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol.