Repository navigation
fix(api): refuse a branch or tag at a commit whose history the packs cannot walk - #929
Conversation
…cannot walk POST /repos/branches/create and POST /repos/tags wrote a ref at any commit that a registered pack holds. A push can leave a commit in a registered pack whose parent, tree or blob no pack holds, because receive-pack checks the commits that a push's refs reach and no other commit of its pack. A ref at such a commit hydrates, and every clone, fetch and archive that walks the history then fails, on every node. A ref write now asks the registered packs for the commit's whole history, as receive-pack does for the new tips of a push: git rev-list --objects --not --all over a view of the registered packs, with --missing=print so that the answer is the set of objects that git cannot read and never git's error text. The view has no commit-graph, because a commit-graph can describe a commit that no registered pack holds. A commit that a ref reaches ends the walk at once, and the oldest commit of 500,000 linear commits costs about two seconds. A walk of more than 30 seconds answers 503. A commit whose history the packs cannot walk answers 404, like a commit that does not exist, falls back to preferred_base, and writes an operator line to the API log. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ <!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->
…heck Change-Id: I385c10692ae3758f14033a04370349cacc32a51c Signed-off-by: Thomas Kosiewski <tk@coder.com>
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31eb87aabe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
🛡️ Codex Security Review
Here are some automated security review suggestions for this pull request.
Reviewed commit: 31eb87aabe
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
Review of the first head found that the walk had no admission slot, no heap cap and no request budget of its own, that git 2.43 dies on a missing start object, that a plain create of an existing branch paid for a walk before it lost its swap, and that a merge with an expected_source_sha could store a commit that no registered pack holds. - The walk runs under the slots, the 30-second budget and the 256 MiB heap cap of the git:read routes (503 with Retry-After, 503, 422). - A cat-file asks for the start object first, and exit status 128 of the walk reads as a history that cannot be walked, so git 2.39 and 2.43 answer as git 2.55 does. - A plain create of a branch that exists answers 409 before the walk. - POST /repos/merge checks an expected_source_sha that is not the tip of the source branch like a base. - Tests pin the log line, the default budget and the merge pin. Docs state the measured cost, the dependence on commit dates and the git version note. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ <!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->
…heck Change-Id: I212e06e70df3fa1336b6885e6606bbde84efc37c Signed-off-by: Thomas Kosiewski <tk@coder.com>
|
@codex review |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e3a7f7950
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…ory walk as measured The second review of the walk found that exit status 128 also covers a damaged cache (a corrupt pack), that a separate unreferenced history of 100,000 commits already answers 422 under the heap cap, and that a merge answering a busy pool as 500 would not fail a test. - The log line, the monitoring row and http-api.md name both causes of exit status 128 (a missing object on older git, a damaged cache) and say that the answer is 404 for both, as the ancestry check of a push does. - The cost paragraph gives the measured heap threshold of a separate history (50,000 commits fit, 100,000 do not) and that a create with a refused base_ref walks preferred_base under a budget of its own. - A merge with an expected_source_sha answers 503 with Retry-After when no slot is free and frees its slot (test: no free slot). --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ <!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->
A branch create with a refused base_ref walks preferred_base next, and each walk made a budget of its own, so one request could take two slots in turn and two time budgets. The handler now makes one budget for the request and both walks draw on it, and the slot is freed before the ref is written. TestBranchCreateWalksBothBasesUnderOneBudget runs a fake git that takes a second for each walk under a budget of 1.6 s: the request answers 503 and frees its slot, and with a budget for each walk it answers 404. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ <!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->
…heck Change-Id: I8042408c6a59b5e02027065d8707c6cc84da70fa Signed-off-by: Thomas Kosiewski <tk@coder.com>
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…it is free at the write The third review found that the tag handler and the merge pin check closed their budget after the walk without a defer, so a panic between the first git child and the close (what the recovery middleware is for) kept the slot until restart, and that nothing pinned that a branch create frees its slot before the ref is written. - wrefUsableCommitAlone owns its budget and frees it with a defer. The tag handler and the merge pin check use it. - TestRefWritesFreeTheirSlotAfterAPanic and the merge subtest panic at the registry read that follows a "missing" answer and check that no slot is held. - TestRefWritesFreeTheirSlotBeforeTheRefIsWritten records the slots in use at each ref write of a tag, a branch, an allocated name and a fallback. - The http-api.md and PR wording of the damaged cache and of the two walks of a create are made exact. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ <!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->
|
@codex review |
|
@codex security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 184c0ca31c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…e repository The walk stops at a commit that a ref reaches (rev-list --not --all) and reads no tree or blob below it. A ref that a push left at a commit whose history the packs cannot walk therefore lets a branch or tag at the same commit, or at one that it reaches, pass. A walk without the boundary reads the whole history with its trees for every request, which a repository of 500,000 commits does not fit under the heap cap. http-api.md now states the limit and its reason. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ <!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->
…heck Change-Id: Iee1d37e907c03ce3813d6c99dfc91df206a84dd6 Signed-off-by: Thomas Kosiewski <tk@coder.com>
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…ets through The walk does read trees below the commits that a ref reaches (git marks their trees as uninteresting and skips a missing one without reporting it), so the paragraph now says that it reports no missing object below them. A complete commit built on a ref that sits at a broken history also passes, which the paragraph left out. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ <!-- xum-attribution: model=anthropic:claude-sonnet-5-5 thinking=xhigh -->
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Why
POST /repos/branches/createandPOST /repos/tagswrite a ref at a commit that a registered pack holds (#896). That check holds the commit itself and nothing that it names.receive-packchecks the commits that a push's refs reach and no other commit of the pack, so a push can leave a commit in a registered pack whose parent, tree or blob no pack holds. #896 listed this as a limit (a "closure variant": a pack carries a commit whose parent only the cache holds) and did not take on the walk that closes it.A ref created at such a commit hydrates, because
update-refneeds only the commit object, and then every clone, fetch and archive that walks the history fails (Failed to traverse parents of commit ... possible repository corruption), on every node. A verifier of #918 found it: a raw push whose pack also carries a commit with a missing parent, thenPOST /repos/branches/create {"base_ref": "<that commit>"}answers200. I reproduced it in the tests below: on main, a missing parent, a missing grandparent, a missing tree and a missing blob each give200and a ref.What changed
gitread.RegisteredClosureanswers whether the registered packs hold the commit and what git needs to read its history. It runs git's own connectivity check, the one thatreceive-packruns for the new tips of a push, over a view of the registered packs (githttp.RegisteredPackView, built by fix(githttp): refuse a ref at an object that no registered pack holds #896):git rev-list --objects --missing=print --quiet <sha> --not --all.--missing=printmakes git print the id of each object that it cannot read (?<id>) and exit 0, so the answer is the set of objects that git cannot read. git's error text decides nothing.ErrViewIncomplete, as forRegisteredKinds).cat-file --batch-checkof the commit runs first, because git before 2.45 dies on a start object that it cannot read. Exit status 128 of the walk then means that git could not walk the history (git 2.39 on a missing parent commit, git 2.43 on a ref at a missing object), which is the same answer, as it is for the ancestry check of a push (isAncestorUncached, which also logs both causes). The status is git's answer to any fatal failure, so a corrupt pack in the cache reads the same way and answers404(round 1 of this PR answered500there). The log line names both causes. Any other exit of git is an error. The API history tests pass with git 2.39.5, 2.43.0 and 2.55.0.gitReads). With no free slot a create answers503withRetry-After, a walk past its budget answers503, and a walk that needs more memory answers422. The walks of one request (base_ref, thenpreferred_base) share one slot and one time budget, and the slot is freed before the ref is written.POST /repos/branches/createanswers a plain create of a branch that exists (409) before it reads the registry or starts a walk, as it already did for a tag that exists. A request that cannot win does not cost a walk.wrefUsableCommit(it replaceswrefHeldCommit). A commit whose history the packs cannot walk answers404, like a commit that does not exist, falls back topreferred_base, and writes a WARN line to the API log (repo,sha).POST /repos/mergewith anexpected_source_shathat is not the tip of the source branch asks the same question about the pin. The source branch can reach a commit that no registered pack holds (a push can leave one behind a tip, while the cache holds it), and a fast-forward would store it in the target ref. A pin that the packs cannot walk answers the409ref_guard_failedthat a pin outside the source branch answers. The tip needs no check, because a ref is at it.http-api.mdsays what a base, a tag target and a merge pin must be and what the check costs. The monitoring table and the metrics mapping indeploy-production.mdlist the log line.Cost
500,000 linear commits (each with a new blob and three new trees, 2.5 million objects), git 2.55, no commit-graph in the view, on a host at load 12 to 37, so the times are upper bounds. Median of 3:
main(a ref reaches it)main~1000main~100000main~250000422after about 3 to 4 s (out of memory)422The walk goes from the commits that the refs reach down to the base, so the cost is the distance between the two and also depends on the commit dates that a pusher chooses: 1,000 new commits dated after the tip of
maintake 14 ms, and the same commits dated 1970 take 1.7 s, because git also walks the history of the refs down to the date of the commit. A separate history costs more than the history that the refs reach, because git also holds its trees. The root of the 500,000-commit history fits under the 256 MiB cap (I ran it underulimit -d 262144), a separate history of 50,000 commits fits, and one of 100,000 commits does not.The check that #896 added (
cat-file --batch-checkof the base) costs 4 ms, andrev-list --quiet <tip>without a boundary costs 1.78 s. A commit-graph in the cache would answer the root in 0.28 s, but a graph cannot tell this check anything that it can trust. So a typical request (a base that a ref reaches, near its tip) costs milliseconds, and a hostile one costs at most the 30-second budget and the heap cap, under the slots that every git read shares.The cheaper check that I did not take is
cat-file --batch-checkof the base's parents and tree: 4 ms, and it refuses a commit whose parent is missing. It leaves out a missing grandparent (a pack can carry a chain of planted commits), a missing tree below the first level and a missing blob, which are the cases that the tests below pin. A walk that costs milliseconds for an honest request and is bounded by budget and slots for a hostile one closes all of them, so I took it.Tests
TestRefWritesRefuseACommitWhoseHistoryThePacksLack: for a registered pack that carries a commit with a missing parent, a missing grandparent, a missing tree or a missing blob, each of the five request shapes (base_ref, thepreferred_basefallback,force, an ephemeral branch and a tag) answers404, leaves the refs, writes the WARN line withrepoandsha, and still accepts a complete commit. It is red on main: every shape answers200and creates the ref.TestRefWritesAcceptACommitWhoseHistoryThePacksHold: a commit that no ref reaches but whose pack holds everything, the root and the tip are accepted, and a fresh node walks the whole repository.TestRefWritesWalkUnderTheGitAdmissionSlots: with every slot of the repository taken, each shape answers503withRetry-Afterand writes nothing, and the walk frees its slot. The merge test has the same subtest (no free slot).TestRefWritesReadTheRegistryOnlyBeforeAWrite(existing, extended): a plain create of a branch that exists answers409with no registry read.TestMergeExpectedSourceSHARefusesAPinThatThePacksLack: a source branch whose tip is a child of a cache-only commit, pinned at that commit, answers409withff_onlyandmergeand changes no ref. It is red without the merge check (200, the target ref at the pin). The tip as a pin still merges.TestBranchCreateWalksBothBasesUnderOneBudget: a fake git makes each walk take a second and the budget lasts 1.6 s, so a create with two refused bases answers503and frees its slot. With a budget for each walk the same request answers404.TestRefWritesFreeTheirSlotBeforeTheRefIsWritten(a tag, a branch, an allocated name, a fallback after a refusedbase_ref: no git read slot is held at the ref write, because a ref write can wait ten seconds for a push's hold) andTestRefWritesFreeTheirSlotAfterAPanic(a panic in the walk, in every request shape and in the merge pin check, leaves no slot held).TestRegisteredClosure...(internal/gitread): the answer rests on?lines and on exit status 128 alone, the command line and environment are the connectivity check over the view without alternates, the start-object check, exit 129 and a kill are errors, a walk past its budget (or its request budget) isErrTimeBudgetwhile a caller that gave up gets its own error, and the default budget is 30 s.--not --all, no--objects, no--missing=print, the commit-graph switch removed, a missing object ignored, other output accepted, always usable, the timeout not reported, no budget, no 409 pre-read, no start-object check, no exit-128 reading, no merge pin check, merge limit errors answered as500, a budget for each walk, a budget that is not freed on a panic (tag, merge and branch), the slot kept through the ref write, no WARN line, and a 300-second default.gofmt,go vet, golangci-lint 2.15.0,go test -race ./internal/gitread,go test -race ./internal/api(local backend), the darwin test builds, the doc-link gate and both fingerprint gates. The PostgreSQL lane runs in CI.Limits
--not --alltrusts every ref: a branch or tag at that commit, at a commit that it reaches, or at a complete commit built on top of it, passes (my verifier showed each case for a missing tree, blob and parent). The check cannot tell that ref from a healthy one without walking the whole history with its trees for every request, and a walk with trees and no boundary does not fit the heap cap from about 250,000 linear commits (underulimit -d 262144, 100,000 commits fit and 250,000 do not: peak RSS 255 MB and 392 MB, a figure that also counts mapped pack files). A walk of the commits alone fits at 500,000 commits, but it costs about 1.7 s for every request and misses a missing tree or blob. Closing it at the source is the check of the new tips in pre-receive.404and logs the line with both causes.404, git 2.43: also404through exit status 128), and each refused request logs the line. Such a repository is wedged already (update-refrefuses the ref), andrepair-refslists the ref.base_refis refused andpreferred_baseis walked too): milliseconds for a base near a tip, at most about two seconds for the root of a 500,000-commit history, and up to the 30-second budget for a commit that no ref reaches (one budget for the whole request). Peak memory is capped at 256 MiB per walk on Linux (the cap of every git read).Generated with
xum• Model:anthropic:claude-sonnet-5-5• Thinking:xhigh