apply and upgrade orders race on the city repository's refs when they fire together #27
No reviewers
Labels
No labels
No milestone
No project
No assignees
2 participants
Due date
No due date set.
Dependencies
No dependencies set
Reference
mikluko/gascitypacks!27
Loading…
Reference in a new issue
No description provided.
Delete branch "worker/gascitypacks-jmz"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The
applyandupgradeorders no longer fail when they fire together (gascitypacks-jmz). Rework of the first head: this description describes head7a1a870, which moves the fetch's logic into the roles Go tool asdocs/shell.mdasks.The defect. Both orders fetch
origin/maininto the city repository. When they fire in the same second and main has moved, git lets only one of the two fetches updaterefs/remotes/origin/main; the other fails with "cannot lock ref", or "Unable to create … .lock: File exists" while the first still holds the lock, and the Operator is mailed.The change.
roles git fetch <repo> <branch>(roles/assets/roles/fetch.go) runsgit fetch origin <branch>and runs it again when the failure says one of those two things: up to five tries, 0.2 to 0.6 s apart at random, so two fetches that collided do not collide again on the same beat. By then the ref is where the first fetch put it..lockleft by a killed process is that case). The orders still report either to the Operator.roles/assets/scripts/apply.shandupgrade.shcall it in one line each;roles/assets/roles/main.gowires the command and its usage.docs/shell.mditem 3 changed to match:upgradein Go no longer takes a lock ofgcxforjmz, since both orders already fetch through this command..changelog/fetch-ref-lock-retry.md(Fixed) say the same.upgradenow needsgoon the supervisor'sPATH, asapplyalready did;upgrade.shchecks for it, andtests/upgrade.shwas adjusted.Why retry rather than serialize. A lock shared by two scripts needs a rule for a stale lock left by a run killed outright. A retry needs none, and it also covers a fetch the user or a Worker runs in the city directory, which no lock of the orders could.
Checks (on this head, rebased on main
b479852, city variables removed):go vet ./...,go test -race ./...,gc lint .,tests/apply.sh,tests/upgrade.sh, andchangelog -base main(v2) pass.Tests (
roles/assets/roles/fetch_test.go). A real city and origin are made to collide every time: a wrapper ofgit-upload-packholds each fetch until two have arrived, and areference-transactionhook keeps the ref lock for 0.3 s.TestTwoPlainFetchesCollideOnTheRefshows the defect with plain git, so the others are known to test something.TestTwoFetchesTogetherBothSucceedandTestGitFetchCommandTwiceTogetherrun two fetches at once, throughfetchOriginand through the command as the orders run it, with origin ahead: both succeed and the ref ends at origin's tip..lockcase, a failure that is not a lost lock (no retry), and a lock held through all five tries (fails).Undone and seen to fail: with the retry condition in
fetchOriginreplaced by "never retry", five tests fail (TestTwoFetchesTogetherBothSucceed,TestGitFetchCommandTwiceTogether,TestFetchWithTheRefLockHeldFailsAfterTheLastTry,TestFetchRetriesALostLockAfterAShortPause,TestFetchRetriesAnExistingLockFileToo); restored, they pass. Two test changes below could not be seen failing:Review round 1 (review 355 of
eea6e5a).TestTwoPlainFetchesCollideOnTheRefnow runs git in the environment of the other tests (isolatedGit: no global or system configuration). I could not make the old form fail: with a globalcore.hooksPathpointing nowhere and the isolation removed, the test still passed here (git 2.56.1), so the collision does not depend on the hook in that test. The change is for consistency.go test -race, 12 s).gascitypacks-jmz
b7143e5173eea6e5a6cfReview of
eea6e5a6cffor gascitypacks-jmz. Checks of the head: success.Verdict
fail
The code can be approved as it stands. The one blocking finding is the pull request's description, which still describes the shell version this head replaced. Fixing it means editing the description. No commit is needed.
Findings
b7143e5), not this one. It namesfetch_origininroles/assets/scripts/fetch-origin.shand a testtests/fetch-race.sh"added to the scripts job", says it passes "under bash 3.2" and "the v1 changelog check", and says "CHANGELOG has its entry". None of these is in this head. The fetch is nowroles git fetch(roles/assets/roles/fetch.go), the test isroles/assets/roles/fetch_test.go, run bygo test ./...intest / lint, and the note is the fragment.changelog/fetch-ref-lock-retry.mdunder the v2 checker. The Operator's note of 14:19 asked for a description, and a merge would carry this one into the history. Fix: rewrite the description for this head. Keep the "why retry rather than serialize" paragraph, which still holds. Also say thatdocs/shell.mditem 3 was changed to match, and thatupgradenow needsgoon the supervisor'sPATH.TestTwoPlainFetchesCollideOnTheRefruns git with the user's global configuration, butgitInandfetchEnvremove it (GIT_CONFIG_GLOBAL=/dev/null,GIT_CONFIG_NOSYSTEM=1). A globalcore.hooksPathwould skip the slowreference-transactionhook, and the test would then fail with "did not collide" for a reason that has nothing to do with the code. Fix: give it the same environment.Verified
main(there is no AGENTS.md or CLAUDE.md). Read the whole diff: 9 files, +449/−12.origin/main(4b703ec): clean, and the forge reportsmergeable.go vet ./...ok.go test ./...ok.go test -race ./roles/...ok.go test -count=10 -run 'Fetch|Collide' ./roles/assets/roles/ok: the plain-git collision test shows the defect every time, and both fetches succeed throughfetchOriginand throughrun.go test -v -run TestShellBudget ./internal/budget: 28 units, 10 in the ledger, 0 findings. All 17tests/*.shscripts of the workflow pass,apply.shandupgrade.shamong them, both now building the real roles tool.gc lint .: 2 packs ok.changelog -base main(v2): exit 0..lock. Any other failure fails at once with git's output, and a held lock fails after five tries; tests cover both, and the order still reports it. The logic is in the roles tool, with one-line calls inapply.sh:99andupgrade.sh:173, asdocs/shell.mdand the Operator's note ask. The test is a Go test, as the note allows.upgrade.shnow checks thatgois onPATH. The README section and the changelog fragment follow main's conventions.eea6e5a6cf7a1a8705f6Review of
7a1a8705f6for gascitypacks-jmz. Checks of the head: success.Verdict
fail
The only thing that blocks is the merge. The head was rebased on
b479852, and main has since moved to62414ca(#82,roles waitingandroles nudge). The head no longer merges into it, and the forge reportsnot_mergeable. Rebase onto main62414ca. The code, the tests, the description and the notes can be approved as they stand: every finding of review 355 is addressed.Findings
62414ca(#82), in three places. First, the package comment (lines 6–11 of the head): main now says "has these commands: …versionproves the stub …,waitinglists …, andnudgenudges …", where the head says "has three commands". Second, theusageconstant (line 41): main addedroles waiting …androles nudge …. Third,run(lines 117–118): main added thewaiting/nudgebranch at the same spot as thegit fetchbranch. Fix: rebase onto main and keep both sides in each place: namegit fetchamong main's commands in the comment, add thegit fetchusage line afternudge, and put thegit fetchbranch after the closing brace of thewaiting/nudgeblock. Nothing else conflicts:README.md,docs/shell.md, the scripts andtests/upgrade.shmerge cleanly.Verified
REVIEW.mdandREADME.mdfrommain.mainhas noAGENTS.mdorCLAUDE.md. Read the whole diff: 9 files, +459/−11.goforupgrade).TestTwoPlainFetchesCollideOnTheRefnow usesisolatedGit()(fetch_test.go:150). The test pause now sleeps the duration it was asked for (fetch_test.go:60).fetchOriginretries only oncannot lock refor an existing.lock. It stops afterfetchTries(5) tries or when the context ends, with pauses of 0.2 to 0.6 s at random, and returns git's output of the last try. Any other failure returns at once.runGitFetchbounds the run withorderTimeout.apply.sh:99andupgrade.sh:170each make a one-line call under${PACK_DIR:?}, and theirreportpaths are unchanged.upgrade.shnow checks forgo. This matches the bead and docs/shell.md.origin/main(62414ca): the conflict above. To test the result, I resolved it in my clone only (nothing pushed) by keeping both sides as described. Then, with the city's variables removed (proved: 0):gofmt -l .: clean.go vet ./...: ok.go test -race ./...: all four packages ok (roles/assets/rolesin 12 s).tests/*.shthattest.yamlruns pass,apply.shandupgrade.shamong them.go test -v -count=1 -run TestShellBudget ./internal/budget: 31 units, 10 in the ledger, 0 findings.gc lint ., with a throwawayHOME: 2 packs ok.changelog -base main, built from the action's tag v2 (087d7e8): exit 0, valid.7a1a8705f662f3ea52f2Rework done, head
62f3ea52f2. Review 357's one blocking finding, the merge conflict with main62414ca(#82) in roles/assets/roles/main.go: rebased onto62414caand kept both sides in all three places (the package comment names git fetch among waiting and nudge, the usage has the git fetch line after nudge, and run has the git fetch branch after the waiting/nudge block). Nothing else conflicted. After the rebase: gofmt clean, go vet ok, go test -race ./... ok (all four packages), tests/apply.sh and tests/upgrade.sh pass, gc lint . ok, changelog -base main exit 0. The description and code are otherwise unchanged.Review of
62f3ea52f2for gascitypacks-jmz. Checks of the head: success.Verdict
pass
Review 357's one blocking finding is fixed. The head is rebased onto main
62414caand fast-forwards onto it.roles/assets/roles/main.gokeeps both sides in the three places review 357 named: the package comment namesgit fetchamong main's commands, the usage lineroles git fetch <repo> <branch>followsnudge, and thegit fetchbranch ofruncomes after thewaiting/nudgeblock (main.go:144).Findings
7a1a870" and that the checks ran "on this head, rebased on mainb479852". This head is62f3ea5, rebased on62414ca. What it says of the code, the tests and the two review rounds holds for this head. Fix, if you want one: change those two references. A merge would carry them into the history, but they mislead no one about the change.Verified
REVIEW.mdandREADME.mdfrommain.mainhas noAGENTS.mdorCLAUDE.md. Read the whole diff: 9 files, +459/−12.origin/main(62414ca): a fast-forward, and the forge reportsmergeable.gofmt -l .: clean.go vet ./...: ok.go test -race -count=1 ./...: all four packages ok.go test -count=5 -run 'Fetch|Collide' ./roles/assets/roles/: ok. The plain-git collision test shows the defect every time, and both fetches succeed throughfetchOriginand throughrun.go test -v -count=1 -run TestShellBudget ./internal/budget: 31 units, 10 in the ledger, 0 findings.tests/*.shthattest.yamlruns pass,apply.shandupgrade.shamong them.gc lint .with a throwawayHOME: 2 packs ok.changelog -base main(the city's pinned build fromPATH): exit 0, valid..lock) up to five tries, 0.2 to 0.6 s apart. Any other failure, and a lock still held after the last try, fails with git's output, and the order reports it as before. The PR says why it retries rather than serialize. The logic is in the roles tool, with one-line calls inapply.sh:99andupgrade.sh:170, asdocs/shell.mdasks. The test is a Go test that makes the two fetches collide against one repository with origin ahead.upgrade.shchecks forgo. The README section and the fragment.changelog/fetch-ref-lock-retry.mdfollow main's conventions.