Skip to content

fix(githttp): refuse a ref at an object that no registered pack holds - #896

Merged
ThomasK33 merged 17 commits into
mainfrom
registry-checked-ref-targets
Nov 16, 2026
Merged

ThomasK33 merged 17 commits into
mainfrom
registry-checked-ref-targets

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Why

The node's cache repository can hold an object that no registered pack holds: a cache that was copied or edited out of band, or a registry that was rolled back. git reads such an object without complaint. Every other node, and this node after it loses its cache, hydrates from the registered packs alone and cannot write a ref at that object (update-ref ... trying to write ref ... with nonexistent object), so a ref at it wedges the repository: reads, clones and later writes answer 500.

A write-path audit of main found no product path that puts such an object into the cache (every writer registers its pack before the ref move), but three entry points trust the cache and not the registry, so one drifted cache is enough to store the wedging ref. I reproduced each on a live node and in tests by planting a loose commit in the cache directory:

  • POST /repos/branches/create resolves base_ref and preferred_base in the cache, and moves the ref without publishing a pack.
  • POST /repos/tags does the same for ref.
  • A push command with an empty pack that names the cache-only commit passes git's connectivity check, and the update hook moves the ref.

What changed

  • githttp.RegisteredPackView is a temporary object directory that links exactly the pack files that the registry lists (ListPacks) from the cache. A git child with GIT_OBJECT_DIRECTORY set to it, and no alternates, reads an object only when a registered pack holds it. gitread.RegisteredKinds asks the view for the type of each id.
  • A registered pack that the cache lacks (a fold replaced the packs since the cache was hydrated, or a concurrent push registered its pack in pre-receive and git has not yet moved it out of its quarantine) is downloaded first, and the listing is read again at most three times. A pack that the cache still lacks after that is left out of the view. An object that the view holds is held by a registered pack, so a found answer stands. A missing answer from such a view is an error (CheckAnswer, wrapping ErrViewIncomplete) and the request fails, because the object may be in the pack that the view lacks. A first version of this PR failed on any absent pack, and a verifier's stress run with 8 concurrent pushers refused 11 of 4,200 valid updates with it, so the check is now tolerant.
  • A missing answer also stands only when no pack was registered since the view was built. AskRegisteredPacks lists the registry again on a missing answer, builds a new view when a pack was added and asks again, at most three more times, so a pack that another node registers right after the listing never causes a refusal. The pre-receive check and gitread.RegisteredKinds both ask through it. A found answer never lists again.
  • POST /repos/branches/create (base_ref, base_branch, preferred_base) and POST /repos/tags write a ref only at a commit that a registered pack holds. A commit that only the cache holds answers 404 like one that does not exist, and a base that names no usable commit still falls back to preferred_base. The registry is read just before the compare-and-swap, after the ref policy and after the answers that write nothing (a tag that exists answers 409, a create with force or expected_target_sha at the branch's tip answers 200). So a request that the policy denies answers 403 even when its commit is only in the cache (it was 404 in the first version of this PR), and a denied request, a tag replay and a no-op branch create cost no registry read and no view. docs/reference/http-api.md says so.
  • A push is checked in pre-receive (denyUnregisteredTargets), before the atomic gate, any hold or any upload, and the whole push is refused: pre-receive: <ref> is at <sha>, which no pack of this repository's registry holds: only this node's cache has the object. Push the object again with its pack. The check runs there and not in the update hook because under --atomic an earlier update hook's compare-and-swap commits before a later command is refused, so a per-ref check would leave half of an atomic push stored. The check reads the new values that the main store already holds (one cat-file --batch-check that does not see this push's quarantine) and asks the registered packs, plus this push's quarantine (EnvForPush), only about those. A push that carries its objects has none of them in the main store, so a normal push pays that one git child and no registry read. A delete has no new value and is not checked. A push whose pack carries the commit heals the repository: the pack is registered before the ref moves.
  • Tests: TestRefWritesRefuseACommitThatOnlyTheCacheHolds (5 request shapes, pg and sqlite) and TestPreReceiveRefusesATargetThatNoRegisteredPackHolds (5 subtests, including the push whose pack carries the commit) and TestPreReceiveRefusesTheWholePushForATargetThatNoRegisteredPackHolds (atomic and not) fail on main. TestRegisteredKindsReadsTheRegisteredPacksOnly, the EnvForPush test and the heal-retry test cover the view.
  • The lane-schedule fingerprints are re-recorded, because preReceive and updateHook are covered functions (a new denyUnregisteredTargets and mainStoreKinds join the record). The model does not describe the check. The S3-WAL push census budget for a steady push stays at 21, because the check lists the registered packs only when the main store holds a new value.

Limits

  • The check covers the object that a ref names. A commit that a push carries in its pack, but whose parent only the cache holds (a closure variant), still passes. Closing it needs a reachability walk over the registered packs for every push, which this PR does not take on.
  • A push that names a commit that the main store holds pays one registry read and one more git child, once for the whole push (not per ref).
  • A branch or tag create that writes pays one registry read, two symlinks for each registered pack and one git child, and it changes state. I added no cache and no admission limit for it. A repository whose repack runs lag has more registered packs and pays more for each such write.

Verification

  • The new route and push tests fail on main and pass here. At the head I ran the internal/api race lane without PostgreSQL (347 s), gofmt, golangci-lint 2.15.0 (0 issues), go vet, the doc-link gate and both fingerprint gates. At 3604afc I ran the full internal/githttp race lane (local backend, 851 s), internal/gitread, internal/gitlimit (lease audit) and the darwin test builds of githttp and api. After that commit the changes are in internal/api (the write routes), the docs, a merge of main (fix(api): refuse sync credentials that the run refuses, and cut quoted sync values #900, api only) and, at the end, one error sentinel, one test and a comment in githttp. A verifier ran the stress, the mutants and the request matrix at 9a39152. CI runs every lane at the head. The PostgreSQL and S3-WAL lanes run in CI (this host has no docker).
  • Concurrency: a verifier's stress run (8 pushers, 25 rounds each, one real push, one empty-pack raw push at a stored commit and one REST tag per round) refused 11 of 4,200 valid updates with the first version of this PR (update-hook check, strict view) and 0 of 4,200 on main. I ran the same script four times (2,400 operations) against 132e199, the head before main was merged in, and nothing was refused. I could not reproduce the refusal against the pre-receive version with the strict view either (four runs, 2,400 operations, none refused), so the tolerant view rests on its unit tests and on the reasoning above, not on a reproduced fix.
  • TestRefWritesReadTheRegistryOnlyBeforeAWrite counts the pack listings of a denied request, a tag replay and a no-op branch create (none) and of a write (some), and fails on the previous head. TestBranchCreateFallsBackToPreferredBaseWhenTheBaseIsOnlyInTheCache pins the fallback.
  • TestAskRegisteredPacksWhenAPackWasRegisteredSinceTheView covers the re-listing (a pack registered after the view, an unchanged listing, a found answer, the bound, an incomplete view). Dropping the change test or the bound fails it.
  • Four in-process pre-receive tests ran the hook from a work tree with a commit that no pack held, which the check now refuses. They run from the git dir and register the work repository's pack first, as a real node does.

Generated with xum • Model: anthropic:claude-sonnet-5-5 • Thinking: xhigh

The node's cache repository can hold an object that no registered pack
holds (a cache that was copied or edited out of band, or a registry that
was rolled back). git reads such an object, so three entry points stored
a ref at it: POST branches/create and POST tags resolved the base or the
target in the cache, and a push update with an empty pack passed git's
connectivity check. Every other node hydrates from the registered packs
alone, so each such ref wedged the repository. The two REST routes now
answer 404 for a commit that no registered pack holds, and the update hook
refuses the update, both by object state against a view of the cache that
links only the packs that the registry lists.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: Ia072c3e1bd28cbd9b2a4441250dae1d810a2d150
…arget check

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I89f3a475d656e81fd175b9b8f2c4c980c2409bfd
Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I868869117ec8447c2206cf6ffea5cfc051631500
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T21:41:35.115766Z 2625647 Manual request
🔒 Security Review ✅ Completed 2026-11-16T21:45:43.496595Z 2625647 Manual request

Security findings

Advisory findings (2)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c8007fd81

ℹ️ 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".

Comment thread internal/githttp/hook.go Resolved
Comment thread internal/githttp/hook.go Resolved
Comment thread internal/githttp/registryview.go Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 3c8007fd81

ℹ️ 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.

Comment thread internal/githttp/hook.go Resolved
…e push

The check moves from the update hook to pre-receive. Under --atomic an
earlier update hook's compare-and-swap commits before a later command is
refused, and each ref of a push paid a listing of the packs and a git
child. Pre-receive asks once for the whole push, and only about new values
that the main store already holds, so a push that adds objects pays one
batch of git. The registered packs and the quarantine of the push answer, so
a push that carries the object registers it and heals the node. The heal
of a missing pack lists again, within a bound.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I335225cf09bce68bf25f24062ced01472b9ce3b1
…registry check

The registry check moved from the update hook into pre-receive. The
sync commit line and the fingerprints of the touched functions move with it.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I3a6d84d330f4b4a55eca2421cbe7db795cc0e147
… is not in the cache yet

A push registers its pack in pre-receive, before git moves the pack out of
its quarantine into the cache. A second push that built the registered-pack
view in that window found a registered pack that the cache lacked, healed
once and failed when the next listing named another such pack. Under eight
concurrent pushers that refused valid updates (11 of 4200 operations, none
on main).

The view now keeps the packs that the cache lacks out, after a bounded number
of heal rounds, and CheckAnswer fails the request only when an object reads as
missing from such a view. An object that the view holds is held by a
registered pack, so a found answer stands.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I221deb6bf9fa5035f8aa12ac0b7112d69b2ec356
…istered-pack view

The pre-receive registry check now calls CheckAnswer. The sync commit line and
the fingerprint of denyUnregisteredTargets move with it.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I6332ca43f9d3d5f4041494a017e4e414120f64fe
A view that cannot fetch a pack no longer fails to build. It leaves the pack
out, and CheckAnswer fails a "missing" answer. The test pins both halves.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: Ie757e4a6674a1d295a0bb838eadb91be84f328bf
git runs hooks in the repository, and a stored commit is held by a registered
pack. Four in-process tests ran pre-receive from a work tree with a commit that
no pack held, which the registry check now refuses. They run from the git dir and
register the pack of the work repository first.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I1bb87a831c0ea795b3c7891ea4f987fb2cfdfcc2
Main added the git-refused probe next to the new registry check in hook.go,
and moved the lane-schedule sync commit line and fingerprints. This keeps both
functions, takes main's record files and re-records them in the next commit.

Change-Id: I22be103b4553bbf608f8891d403e7b05b41086e7
Signed-off-by: Thomas Kosiewski <tk@coder.com>
… its cache holds

The wire page lists what a push refuses. It now names the registry check, what
it covers and what it does not, and records the re-recorded lane-schedule
fingerprints after merging main.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I8264d9c38115a3a6dd1b35c2f66ba2c641cd6644
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7ceae2591

ℹ️ 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".

Comment thread internal/githttp/registryview.go Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: b7ceae2591

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ 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.

… view was built

Another node can register a pack that holds the object right after the view
listed the registry, and a complete-looking view then reads the object as
missing and refuses a push or a write that is healthy. AskRegisteredPacks now
lists the registry again when an answer reads missing and builds a new view
when a pack was added, at most three more times. Both callers, the
pre-receive check and gitread.RegisteredKinds, use it.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I0eb444bdcc565671a8c27a15dd293fd80c257411
…listing

The pre-receive registry check now asks through AskRegisteredPacks. The sync commit
line and the fingerprint of denyUnregisteredTargets move with it.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I01688599a82d940b852354ac2b710693d4cc74d9
Only the lane-schedule sync commit line conflicted. Main moved it, so this
takes main's line and the next commit re-records it.

Change-Id: I86e90d903c958024381dd32e71bc30a170d11e6c
Signed-off-by: Thomas Kosiewski <tk@coder.com>
Main moved the sync commit line in the same place. Only the line moves.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I0c4f01ffbb872d23bdaa64eb1c160c5549d7216f
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 262564715a

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 262564715a

ℹ️ 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.

Comment thread internal/githttp/registryview.go Resolved
…about to write

The registry check ran as soon as a branch base or tag target resolved, so a
request that the ref policy denies, a tag that exists and a branch that stays
where it is each built a view of the cache: one registry read, two symlinks for
each registered pack and a git child. A writer could repeat such a request to
spend that work without changing any state. The check now runs after the policy
and after the no-op and exists answers, just before the compare-and-swap.
A base that fails it still falls back to preferred_base.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I6e6f9285e9b4bf0682f1ca04dcf1f08d23507fdb
…he order of the check

The log for a view that lacks a pack said that the pack was missing from the blob
store, but only the node cache lacks it. CheckAnswer now wraps ErrViewIncomplete.
A new test pins that the pre-receive check runs before any upload or
registration: a refused push that carries a new commit stores no pack. The
http-api page now says that a create that leaves a branch at its tip, with force
or a guard, reads no registry either.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_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 -->

Change-Id: I6fcf7486de2b1e6aa44803748be3773f925b760e
@ThomasK33
ThomasK33 added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit be8cc18 Nov 16, 2026
16 checks passed
@ThomasK33
ThomasK33 deleted the registry-checked-ref-targets branch November 16, 2026 23:00
ThomasK33 added a commit that referenced this pull request Nov 16, 2026
Main gained #896 (githttp). The only conflict is the sync commit of the
lane-schedule model; the next commit re-records it on the merged tree.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: I366cda54751e41e91f387d4647f02b1a4dd3e3e1
Signed-off-by: Thomas Kosiewski <tk@coder.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant