Repository navigation
app/: processing holds no long transaction and no blob locks; ProcessBuild timeout fits big builds - #118
Merged
Conversation
…Build timeout fits big builds
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.
Production evidence (3 Dec 2026, first day on app/)
The first real CI upload failed:
POST /api/v1/builds/…/snapshotsreturned 503 after 30 s. Postgres's lock log showed the request'sINSERT INTO blobs … ON CONFLICT (sha256) DO UPDATE(blobs::register) waiting 29.8 s on a ShareLock held by thebuilds.processjob. The job let go only when the worker killed it ("the job ran longer than its timeout of 1m").ProcessBuild::handleran all ofprocessing::processinside onedb::transactionwithpg_advisory_xact_lock. That covered storage verification, renders, downloading, decoding and diffing images incompare, diff overlays throughblobs::put, carry-forward, groups and the conclusion, so every blob row it wrote stayed locked for the whole run.What changed
processing::exclusive(build_id, wait, work): a per-build lock in the cache store (laravel::cache::lock, Postgres in production). It's held for at most 20 min and released whenworkends, fails or is dropped (Laravel'sLock::getreleases on drop). It is taken and released in statements of its own, soworkruns outside any transaction: storage requests, decoding and diffing hold no DB connection and no row locks. Blob writes (confirming uploads, the cached size and fingerprint, diff-overlay registration) and per-snapshot results each commit on their own straight away.processing::run(whatProcessBuild::handlenow calls) works in three steps:charge's own short transaction.stop_if_out_of_credits, outside any transaction as before.processunderexclusive.process. It takesprocessing::lock(the advisory lock, which reviews also take), re-checksstate == "processing", then charges, counts, runssource_unchanged, writes the warnings, concludes and records the auto-approval baselines, all or nothing.chargeis now its own short transaction under the advisory lock. An early comparison's charge and a run's charge can no longer interleave now that neither sits inside a long transaction. The conclusion calls the locked body directly.compare_now(POST …/compare) and the demo reset useexclusivetoo, with no surrounding transaction. If the early comparison waits more than 20 s for the build, it answers 409 "ask again" instead of hanging until a 503.ProcessBuildgetstimeout = 15.minutes(), inside the lock's 20 minutes.carry_forward: a rerun after a run killed part-way now compares a carried row that run inserted but leftpending. Before, it skipped the row because it already existed. That couldn't happen while everything rolled back together.Box::pin). Without that, a few debug-build tests overflowed the stack, because the sync test queue runs the job inside the request that dispatched it.docs/design-storage.mddescribes the new design.Why two workers can't collide
I picked a claim (option b), but it needs no migration because the claim lives in the cache store's lock table (
cache_locks). Option (a) would mean showing that every write is safe when two runs do it at the same time (page rows, diffs and carried rows written concurrently), not just when one run repeats them. That is harder to prove than keeping one run per build.exclusive.builds.process-again:<id>), then tries the lock once more. Either it gets the lock, or whoever holds it finds the note when it releases and queuesProcessBuildagain. So a render that finishes during a long run is never missed.compareoverwrites a snapshot's result;find_or_queueis keyed;ON CONFLICT DO NOTHING, plus the pending-row fix above;record_sourcesupserts;chargecharges only the difference from what was already charged.The one behaviour change: a run that fails part-way leaves its per-snapshot writes in place instead of rolling them back. The build is marked failed either way.
Test
an_upload_registering_a_blob_does_not_wait_for_a_build_processing_it(app/tests/processing.rs):processing::runagainst a blob store that accepts connections and never answers, so processing waits on the store atconfirm_uploads.blobs::registerof the same blob runs with a 2 s timeout, and the test asserts it finishes.registering the blob waited for processing: Elapsed(())). I checked this on a copy of main with aprocessing::runshim that is exactly the oldhandlebody.Results on agents-build-2:
cargo fmt --check,cargo clippy --locked --all-targets -D warningsandcargo test --locked --no-fail-fastall pass, with nothing failing. The known flakeinvite_member_checks_who_may_invite_and_its_limitspassed this time; it failed once in an earlier run, as #112 describes. The goldens are unchanged.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.