From d880d7db020c59fd64a7c270b5d75422990948f4 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 16:40:23 +0000 Subject: [PATCH 01/10] fix(githttp): store no pack for a push command that git refuses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git refuses a push command before the update hook runs when its objects are incomplete (a missing tree, a missing parent, a random SHA, a tag at a missing target) or when it is a shallow update, but it still passes the command to pre-receive. The publication gate counted such a command as needing the pack, so the pack was uploaded and registered, no ref pointed into it, and every repack carried its objects forward. The gate now runs git's own connectivity check for the first command that has no stored target, and a command that fails it never justifies publication. A push whose commands git refuses and no other command needs the pack is refused before the upload, like a push that only policy-denied commands need. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I492f0a3b9407e77cfe4ac6464a467e3f43a97008 --- internal/githttp/hook.go | 38 +++++++- .../githttp/refused_push_pack_e2e_test.go | 97 +++++++++++++++++++ 2 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 internal/githttp/refused_push_pack_e2e_test.go diff --git a/internal/githttp/hook.go b/internal/githttp/hook.go index abf7e09c..197582db 100644 --- a/internal/githttp/hook.go +++ b/internal/githttp/hook.go @@ -1519,6 +1519,9 @@ func preReceivePolicyGate(commands []refCommand, verdicts []error, atomicPush bo assertf(len(verdicts) == len(commands), "preReceivePolicyGate: %d verdicts for %d commands", len(verdicts), len(commands)) var firstErr error needsPack := false + // The first command that git refuses before the update hook runs (see + // reachesUpdateHook): it can never land, so its pack is no reason to publish. + gitRefused := "" for i, c := range commands { // Verdicts are the caller's single shared policy evaluation // (Codex round-4 P2 on #173: re-evaluating here double-charged @@ -1535,12 +1538,21 @@ func preReceivePolicyGate(commands []refCommand, verdicts []error, atomicPush bo continue } if c.new != ref.ZeroSHA && !objectInMainStore(c.new) { - needsPack = true + switch { + case needsPack: + case reachesUpdateHook(c.new): + needsPack = true + case gitRefused == "": + gitRefused = c.ref + } } } - if firstErr == nil || needsPack { + if needsPack || (firstErr == nil && gitRefused == "") { return nil } + if firstErr == nil { + return fmt.Errorf("pre-receive: the quarantined pack is needed only by ref updates that git refuses (%s: its objects are incomplete, or the update is a shallow update), refusing pack publication", gitRefused) + } return fmt.Errorf("pre-receive: the quarantined pack is needed only by policy-denied ref updates, refusing pack publication (push the allowed updates separately): %w", firstErr) } @@ -2908,6 +2920,28 @@ func objectExists(sha string) bool { panic(fmt.Sprintf("githttp assertion failed: cat-file -e %s: %v", sha, err)) } +// reachesUpdateHook reports whether git's own connectivity check passes for sha, +// the check that receive-pack runs for each command before it runs the update +// hook (connected.c: rev-list --objects --stdin --not --all, with the hidden +// refs excluded, over the quarantine and the main store). git still runs +// pre-receive for a command that fails it ("missing necessary objects", or +// "shallow update not allowed"), but the update hook never runs for that +// command, so no ref can ever point into a pack that only it needs. A +// non-zero exit of git is the answer "no". A git that cannot start is a +// bug, which fails fast like objectExists. +func reachesUpdateHook(sha string) bool { + cmd := exec.Command("git", "rev-list", "--objects", "--stdin", "--not", "--exclude-hidden=receive", "--all", "--quiet", "--alternate-refs") + cmd.Stdin = strings.NewReader(sha + "\n") + err := cmd.Run() + if err == nil { + return true + } + if _, ok := errors.AsType[*exec.ExitError](err); ok { + return false + } + panic(fmt.Sprintf("githttp assertion failed: connectivity rev-list %s: %v", sha, err)) +} + // objectInMainStore reports whether sha is resolvable WITHOUT the // quarantine. git runs pre-receive with GIT_OBJECT_DIRECTORY pointed at the // quarantine and the main store as an alternate (githooks(5)); stripping diff --git a/internal/githttp/refused_push_pack_e2e_test.go b/internal/githttp/refused_push_pack_e2e_test.go new file mode 100644 index 00000000..9016f032 --- /dev/null +++ b/internal/githttp/refused_push_pack_e2e_test.go @@ -0,0 +1,97 @@ +package githttp + +// Regression for junk pack rows. git refuses some commands BEFORE the +// update hook (missing objects, shallow update not allowed) yet still hands +// them to pre-receive. Such a command can never land, so the publication +// gate (preReceivePolicyGate) must not store a pack that only it needs: a +// registered pack that no ref reaches is never swept, counts against the +// quota, and every repack carries it forward. + +import ( + "bytes" + "os/exec" + "path/filepath" + "strings" + "testing" + + "github.com/coder/openstorage/internal/ref" +) + +// refusedGit runs git in dir with stdin and returns its raw stdout. +func refusedGit(t *testing.T, dir, stdin string, args ...string) []byte { + t.Helper() + cmd := exec.Command("git", append(append([]string{}, gitIdentity...), args...)...) + cmd.Dir = dir + cmd.Stdin = strings.NewReader(stdin) + var stderr bytes.Buffer + cmd.Stderr = &stderr + out, err := cmd.Output() + if err != nil { + t.Fatalf("git %s: %v\n%s", strings.Join(args, " "), err, stderr.String()) + } + return out +} + +// assertOnlySetupPack fails unless repo holds exactly want packs, the ones +// its setup push stored, as rows and as blobs. +func assertOnlySetupPack(t *testing.T, repo string, want int) { + t.Helper() + if packs := pgPacks(t, repo); len(packs) != want { + t.Errorf("registered packs = %d, want %d: a push git refused registered its pack", len(packs), want) + } + if objs := s3Packs(t, repo); len(objs) != want { + t.Errorf("stored pack blobs = %d, want %d: a push git refused uploaded its pack", len(objs), want) + } +} + +func TestPackPublication_GitRefusedCommandStoresNothing(t *testing.T) { + t.Run("shallow push", func(t *testing.T) { + src := initWorkRepo(t) + commitFile(t, src, "b.txt", "two\n", "two", nil) + shallow := filepath.Join(t.TempDir(), "shallow") + mustGit(t, "", "clone", "-q", "--depth", "1", "file://"+src, shallow) + repo := registerRepo(t, "refused-shallow") + token := mintTestToken(t, repo, "git:read,git:write", "") + out, err := tryGit(shallow, "push", remoteURL(nodeA, repo, token), "HEAD:refs/heads/main") + if err == nil || !strings.Contains(out, "shallow update not allowed") { + t.Fatalf("want git's shallow refusal, got err=%v:\n%s", err, out) + } + assertOnlySetupPack(t, repo, 0) + }) + + for _, tc := range []struct { + name string + decoy bool // also create refs/heads/y at the stored commit + }{ + {"commit with a missing tree", false}, + {"beside a create at a stored commit", true}, + } { + t.Run(tc.name, func(t *testing.T) { + repo := registerRepo(t, "refused-raw") + work := initWorkRepo(t) + token := mintTestToken(t, repo, "git:read,git:write", "") + mustGit(t, work, "push", remoteURL(nodeA, repo, token), "HEAD:refs/heads/main") + stored := revParse(t, work, "HEAD") + junk := strings.TrimSpace(string(refusedGit(t, work, strings.Repeat("junk ", 500), "hash-object", "-w", "--stdin"))) + bad := strings.TrimSpace(string(refusedGit(t, work, "tree "+strings.Repeat("1", 40)+"\nparent "+stored+ + "\nauthor a 1700000000 +0000\ncommitter a 1700000000 +0000\n\nmissing tree\n", + "hash-object", "-t", "commit", "-w", "--literally", "--stdin"))) + pack := refusedGit(t, work, bad+"\n"+junk+"\n", "pack-objects", "--stdout", "-q") + + var body bytes.Buffer + caps := "\x00report-status" + if tc.decoy { + body.WriteString(pktLine(ref.ZeroSHA + " " + stored + " refs/heads/y" + caps + "\n")) + caps = "" + } + body.WriteString(pktLine(ref.ZeroSHA + " " + bad + " refs/heads/x" + caps + "\n")) + body.WriteString("0000") + body.Write(pack) + _, resp := postReceivePack(t, nodeA, repo, token, bytes.NewReader(body.Bytes()), false) + if !strings.Contains(resp, "ng refs/heads/x") { + t.Fatalf("git accepted refs/heads/x:\n%q", resp) + } + assertOnlySetupPack(t, repo, 1) + }) + } +} From 8faa6c5dbc30d6a36b7cc7187fb3a9bf7ce50f24 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 16:47:32 +0000 Subject: [PATCH 02/10] chore(verify): record lane-schedule fingerprints for the publication gate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I8e3d2e74dc284bef083f354e46edb0ba69ee47ef --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- .agents/skills/verify-lane-schedule/model/fingerprints.txt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index 6551defc..4711c7a7 100644 --- a/.agents/skills/verify-lane-schedule/SKILL.md +++ b/.agents/skills/verify-lane-schedule/SKILL.md @@ -226,7 +226,7 @@ With every fact TRUE in the code, setting each fact FALSE in the model alone fai ## Coverage record -Sync commit: `0f5979dd0589da6224230f74e9bc7d15143ef5d1` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `ee591ee81fff3eb78edac118d1ba860f6a77db71` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). Every declaration in these files is covered: diff --git a/.agents/skills/verify-lane-schedule/model/fingerprints.txt b/.agents/skills/verify-lane-schedule/model/fingerprints.txt index 42532cfb..eff01acb 100644 --- a/.agents/skills/verify-lane-schedule/model/fingerprints.txt +++ b/.agents/skills/verify-lane-schedule/model/fingerprints.txt @@ -228,11 +228,12 @@ internal/githttp/hook.go:parseRefTxCommitted 8471c50ec96eec8e6db39370335fbb30116 internal/githttp/hook.go:pauseAtUpdateBarrier a57f4482fb6742f6146ca93452fc9e003a70fd9bab1147a87bb4b32b465859c0 internal/githttp/hook.go:postReceiveHook 1f060af8c07a0c11ab59f6a26f444d7648ddfa9fac7bb506346e808a72311261 internal/githttp/hook.go:preReceive 472bccca1a374479cedb08f228f17893a2f20c1b971761085d5bdf0c60f35ba0 -internal/githttp/hook.go:preReceivePolicyGate c95e8f2792be33cb9ebf77a71d13662a6296dfe42edc4368bca10d8e466cdd60 +internal/githttp/hook.go:preReceivePolicyGate 9b61f53864eaa5b0de3f998639e2d7481dcd44ddeae4b04602c90ef85866a484 internal/githttp/hook.go:pushCommandUpdatable 7ff2f47180eec838d8c98da58a9836bc69a8b9ee1ac9d0f9270ee816594c04ba internal/githttp/hook.go:pushRefDeletable 33c0ee3ab6b1f4a8886faa66aa3db0a25efcb8407667c33d5c4fa1b3a5de3a94 internal/githttp/hook.go:pushRefPathTooLong 93ab890b939c3afe6a0e7d177327109d6aa988cb24a51bc8dff8d26546cfcbee internal/githttp/hook.go:pushRefUpdatable 4f8b9c8242b42701e22e8cbec49dd3e9e458d0cd1a2ba38393c3a38517da2fe9 +internal/githttp/hook.go:reachesUpdateHook 5ada70f14fc59bd03d5ace4954c4e835d329494fbd631c667b940a063c2024d3 internal/githttp/hook.go:referenceTransactionHook 50b0df140f1b52aed35700b5036f9a3d6513077107112e8275d801041fc63139 internal/githttp/hook.go:refuseSyncedImport 636fa8d40bbc1bfb508cdee46f3a80bffe7589f6b32494c1eddfede0850df0fe internal/githttp/hook.go:reservationVerdicts e149d8f3b071db14f7a96349dd982da8d48f07fd8384528b0a16cf4ec69573cf From f37f15b1374e343d6b2e8e725e02acd75f47cbe1 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 17:24:59 +0000 Subject: [PATCH 03/10] fix(githttp): refuse a git-refused push only on exit 128 and say why MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A connectivity check that cannot read an object exits 128. A git that does not know --exclude-hidden (before 2.39) exits 129, and a signal or an out-of-memory kill ends the check too. Those statuses say nothing about the command, so the gate publishes as it did before and no push that git accepts is refused. The refusal is a client-visible refusal, so the pusher reads why the push stored nothing. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I8df39e20ce78f02f8d03e2c24e588790dab5fc81 --- internal/githttp/hook.go | 14 +++++---- .../githttp/refused_push_pack_e2e_test.go | 30 ++++++++++++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/internal/githttp/hook.go b/internal/githttp/hook.go index 3dfb3117..efad5856 100644 --- a/internal/githttp/hook.go +++ b/internal/githttp/hook.go @@ -1553,7 +1553,7 @@ func preReceivePolicyGate(commands []refCommand, verdicts []error, atomicPush bo return nil } if firstErr == nil { - return fmt.Errorf("pre-receive: the quarantined pack is needed only by ref updates that git refuses (%s: its objects are incomplete, or the update is a shallow update), refusing pack publication", gitRefused) + return refusef("pre-receive: the quarantined pack is needed only by ref updates that git refuses (%s: its objects are incomplete, or the update is a shallow update), refusing pack publication", gitRefused) } return fmt.Errorf("pre-receive: the quarantined pack is needed only by policy-denied ref updates, refusing pack publication (push the allowed updates separately): %w", firstErr) } @@ -2936,8 +2936,12 @@ func objectExists(sha string) bool { // pre-receive for a command that fails it ("missing necessary objects", or // "shallow update not allowed"), but the update hook never runs for that // command, so no ref can ever point into a pack that only it needs. A -// non-zero exit of git is the answer "no". A git that cannot start is a -// bug, which fails fast like objectExists. +// exit of 128 is the answer "no": git cannot read the objects that the command +// needs. Any other status says nothing about the command (a git without +// --exclude-hidden, before 2.39, answers 129; a signal or an out-of-memory kill +// ends it too), so the answer is "yes" and the gate publishes as it did before: +// a wrong refusal of a push that git accepts is worse than one junk pack. A git +// that cannot start is a bug, which fails fast like objectExists. func reachesUpdateHook(sha string) bool { cmd := exec.Command("git", "rev-list", "--objects", "--stdin", "--not", "--exclude-hidden=receive", "--all", "--quiet", "--alternate-refs") cmd.Stdin = strings.NewReader(sha + "\n") @@ -2945,8 +2949,8 @@ func reachesUpdateHook(sha string) bool { if err == nil { return true } - if _, ok := errors.AsType[*exec.ExitError](err); ok { - return false + if ee, ok := errors.AsType[*exec.ExitError](err); ok { + return ee.ExitCode() != 128 } panic(fmt.Sprintf("githttp assertion failed: connectivity rev-list %s: %v", sha, err)) } diff --git a/internal/githttp/refused_push_pack_e2e_test.go b/internal/githttp/refused_push_pack_e2e_test.go index 9016f032..32f199e4 100644 --- a/internal/githttp/refused_push_pack_e2e_test.go +++ b/internal/githttp/refused_push_pack_e2e_test.go @@ -9,6 +9,7 @@ package githttp import ( "bytes" + "os" "os/exec" "path/filepath" "strings" @@ -79,7 +80,7 @@ func TestPackPublication_GitRefusedCommandStoresNothing(t *testing.T) { pack := refusedGit(t, work, bad+"\n"+junk+"\n", "pack-objects", "--stdout", "-q") var body bytes.Buffer - caps := "\x00report-status" + caps := "\x00report-status side-band-64k" if tc.decoy { body.WriteString(pktLine(ref.ZeroSHA + " " + stored + " refs/heads/y" + caps + "\n")) caps = "" @@ -91,7 +92,34 @@ func TestPackPublication_GitRefusedCommandStoresNothing(t *testing.T) { if !strings.Contains(resp, "ng refs/heads/x") { t.Fatalf("git accepted refs/heads/x:\n%q", resp) } + // The pusher reads why nothing was stored when the whole push is refused. + if !strings.Contains(resp, "needed only by ref updates that git refuses") { + t.Fatalf("the pusher does not read the refusal:\n%q", resp) + } assertOnlySetupPack(t, repo, 1) }) } } + +// reachesUpdateHook answers "no" only when git exits 128, the status of a +// connectivity check that cannot read an object. A git that does not know an +// option (129), a signal and an out-of-memory kill say nothing about the +// command, so the gate must not refuse a push on them. +func TestReachesUpdateHookRefusesOnlyOnExit128(t *testing.T) { + for _, tc := range []struct { + status string + want bool + }{{"0", true}, {"1", true}, {"128", false}, {"129", true}, {"137", true}} { + t.Run("exit "+tc.status, func(t *testing.T) { + bin := t.TempDir() + script := "#!/bin/sh\nexit " + tc.status + "\n" + if err := os.WriteFile(filepath.Join(bin, "git"), []byte(script), 0o755); err != nil { + t.Fatal(err) + } + t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH")) + if got := reachesUpdateHook(strings.Repeat("a", 40)); got != tc.want { + t.Fatalf("reachesUpdateHook with a git that exits %s = %v, want %v", tc.status, got, tc.want) + } + }) + } +} From 3c8d50ac9f0421a0acacf9e6e0ff37bd7daf7c6f Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 17:31:28 +0000 Subject: [PATCH 04/10] chore(verify): record lane-schedule fingerprints for the exit-128 rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I73ffc05cbf4b61525c02da34c08dbf54ea1c8f7c --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- .agents/skills/verify-lane-schedule/model/fingerprints.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index 4711c7a7..5844dd16 100644 --- a/.agents/skills/verify-lane-schedule/SKILL.md +++ b/.agents/skills/verify-lane-schedule/SKILL.md @@ -226,7 +226,7 @@ With every fact TRUE in the code, setting each fact FALSE in the model alone fai ## Coverage record -Sync commit: `ee591ee81fff3eb78edac118d1ba860f6a77db71` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `f37f15b1374e343d6b2e8e725e02acd75f47cbe1` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). Every declaration in these files is covered: diff --git a/.agents/skills/verify-lane-schedule/model/fingerprints.txt b/.agents/skills/verify-lane-schedule/model/fingerprints.txt index eff01acb..68d15c5d 100644 --- a/.agents/skills/verify-lane-schedule/model/fingerprints.txt +++ b/.agents/skills/verify-lane-schedule/model/fingerprints.txt @@ -228,12 +228,12 @@ internal/githttp/hook.go:parseRefTxCommitted 8471c50ec96eec8e6db39370335fbb30116 internal/githttp/hook.go:pauseAtUpdateBarrier a57f4482fb6742f6146ca93452fc9e003a70fd9bab1147a87bb4b32b465859c0 internal/githttp/hook.go:postReceiveHook 1f060af8c07a0c11ab59f6a26f444d7648ddfa9fac7bb506346e808a72311261 internal/githttp/hook.go:preReceive 472bccca1a374479cedb08f228f17893a2f20c1b971761085d5bdf0c60f35ba0 -internal/githttp/hook.go:preReceivePolicyGate 9b61f53864eaa5b0de3f998639e2d7481dcd44ddeae4b04602c90ef85866a484 +internal/githttp/hook.go:preReceivePolicyGate 022af08c29170fe53ffaa80864915cec62b2da1976c08239f620cefcb72bb4e1 internal/githttp/hook.go:pushCommandUpdatable 7ff2f47180eec838d8c98da58a9836bc69a8b9ee1ac9d0f9270ee816594c04ba internal/githttp/hook.go:pushRefDeletable 33c0ee3ab6b1f4a8886faa66aa3db0a25efcb8407667c33d5c4fa1b3a5de3a94 internal/githttp/hook.go:pushRefPathTooLong 93ab890b939c3afe6a0e7d177327109d6aa988cb24a51bc8dff8d26546cfcbee internal/githttp/hook.go:pushRefUpdatable 4f8b9c8242b42701e22e8cbec49dd3e9e458d0cd1a2ba38393c3a38517da2fe9 -internal/githttp/hook.go:reachesUpdateHook 5ada70f14fc59bd03d5ace4954c4e835d329494fbd631c667b940a063c2024d3 +internal/githttp/hook.go:reachesUpdateHook 5370101391a75e2e20512ffaf0e7573a93f20842b5eab67e936e576e47b74d7f internal/githttp/hook.go:referenceTransactionHook 50b0df140f1b52aed35700b5036f9a3d6513077107112e8275d801041fc63139 internal/githttp/hook.go:refuseSyncedImport 636fa8d40bbc1bfb508cdee46f3a80bffe7589f6b32494c1eddfede0850df0fe internal/githttp/hook.go:reservationVerdicts e149d8f3b071db14f7a96349dd982da8d48f07fd8384528b0a16cf4ec69573cf From 1512fa8adc47c07175d460c194e2c8ef998ba725 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 17:56:09 +0000 Subject: [PATCH 05/10] docs(githttp): say what git refuses before the update hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The gate comment says that a wholly allowed push is refused when only git-refused commands need the pack, and that receive-pack runs one combined check and then one check for each command. The wire compatibility page lists refs that git refuses among the refs that make the server decline a whole push. The no-replace test also covers the new check. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I405b02b6752efc97ef906d4eb3e13e8371983210 --- docs/explanation/wire-compatibility.md | 4 +++- internal/githttp/hook.go | 31 ++++++++++++++----------- internal/githttp/noreplace_hook_test.go | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/explanation/wire-compatibility.md b/docs/explanation/wire-compatibility.md index 76c5b3ed..5f39e9c8 100644 --- a/docs/explanation/wire-compatibility.md +++ b/docs/explanation/wire-compatibility.md @@ -125,7 +125,9 @@ Beyond the smart-HTTP wire format, the semantics clients depend on match git: fail independently, as in git, unless the server declines the whole push. It does so for its own limits, such as the pack quota, and in one case for refused refs. Refused refs are policy-denied refs, refs hidden on this remote, branches that the push sets to an - object that is not a commit, and names that a push cannot create + object that is not a commit, refs that git itself refuses before the update hook (the + push leaves their objects incomplete, or it is a shallow update that git does not + allow), and names that a push cannot create or update (for example, a name with only one level under `refs/`, such as `refs/funny` or `refs/heads`, another git-invalid name, a name with more than 32 `/`-separated parts, a part over 200 bytes, or a name over 900 bytes). When no other ref of the push needs diff --git a/internal/githttp/hook.go b/internal/githttp/hook.go index efad5856..cc562461 100644 --- a/internal/githttp/hook.go +++ b/internal/githttp/hook.go @@ -1474,11 +1474,13 @@ func atomicPushDFCheck(commands []refCommand) error { } // preReceivePolicyGate refuses pack publication unless it is justified: -// either the push is wholly policy-allowed (vestigial packs from creates at -// existing SHAs stay accepted, matching the no-pack path), or at least one -// policy-ALLOWED command needs quarantined objects (its target is not in -// the main object store yet). A push containing any denied command whose -// allowed commands all target already-stored objects is refused whole — +// either no command is refused (vestigial packs from creates at existing +// SHAs stay accepted, matching the no-pack path), or at least one command +// that policy allows and git lets reach the update hook needs quarantined +// objects (its target is not in the main object store yet). A push +// containing any denied command, or any command that git refuses before the +// update hook (reachesUpdateHook), whose other commands all target +// already-stored objects is refused whole — // its pack could only serve the denied refs (round-7 decoy) — with a // message telling the client to push the allowed updates separately. It // reuses the shared verdicts (enforceRefPolicy, plus the refusals of hidden @@ -2929,15 +2931,16 @@ func objectExists(sha string) bool { panic(fmt.Sprintf("githttp assertion failed: cat-file -e %s: %v", sha, err)) } -// reachesUpdateHook reports whether git's own connectivity check passes for sha, -// the check that receive-pack runs for each command before it runs the update -// hook (connected.c: rev-list --objects --stdin --not --all, with the hidden -// refs excluded, over the quarantine and the main store). git still runs -// pre-receive for a command that fails it ("missing necessary objects", or -// "shallow update not allowed"), but the update hook never runs for that -// command, so no ref can ever point into a pack that only it needs. A -// exit of 128 is the answer "no": git cannot read the objects that the command -// needs. Any other status says nothing about the command (a git without +// reachesUpdateHook reports whether git's own connectivity check passes for sha. +// receive-pack runs one such check over all commands before it runs any hook +// (rev-list --objects --stdin --not --all, with the hidden refs excluded, over +// the quarantine and the main store), and when it fails, it checks the commands +// one by one and refuses the ones that fail ("missing necessary objects"). A +// shallow update that git does not allow is skipped, and the pack that carries +// it lacks the parents of its commits, so this check fails for it as well. git +// still runs pre-receive for such a command, but the update hook never runs for +// it, so no ref can ever point into a pack that only it needs. An exit of 128 +// is the answer "no": git cannot read the objects that the command needs. Any other status says nothing about the command (a git without // --exclude-hidden, before 2.39, answers 129; a signal or an out-of-memory kill // ends it too), so the answer is "yes" and the gate publishes as it did before: // a wrong refusal of a push that git accepts is worse than one junk pack. A git diff --git a/internal/githttp/noreplace_hook_test.go b/internal/githttp/noreplace_hook_test.go index 5c421d55..f769ad3e 100644 --- a/internal/githttp/noreplace_hook_test.go +++ b/internal/githttp/noreplace_hook_test.go @@ -24,7 +24,7 @@ func TestHookObjectChecksKeepNoReplaceObjects(t *testing.T) { kinds, err := objectKinds([]string{id}) return err == nil && kinds[id] == "commit" } - for name, check := range map[string]func(string) bool{"objectExists": objectExists, "objectInMainStore": objectInMainStore, "objectKinds": objectIsCommit} { + for name, check := range map[string]func(string) bool{"objectExists": objectExists, "objectInMainStore": objectInMainStore, "objectKinds": objectIsCommit, "reachesUpdateHook": reachesUpdateHook} { _ = os.Remove(log) if !check(strings.Repeat("a", 40)) { t.Fatalf("%s = false for a git that exits 0", name) From 1c96fe3f2162074a3567275eac983caf559dfe68 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 18:27:27 +0000 Subject: [PATCH 06/10] chore(verify): re-record lane-schedule sync commit after merging main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Main moved the sync commit line in the same place. Only the line moves. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: If6d9dbcf7f01a570724e0c8a904801b6feb377be --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index 274274da..d4585ab6 100644 --- a/.agents/skills/verify-lane-schedule/SKILL.md +++ b/.agents/skills/verify-lane-schedule/SKILL.md @@ -226,7 +226,7 @@ With every fact TRUE in the code, setting each fact FALSE in the model alone fai ## Coverage record -Sync commit: `33c2441001bb13345d5304a891ca6f16ccf0b24b` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `9d39336125c017ad00adabc3dab174f2b4e754a6` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). Every declaration in these files is covered: From a8961d13f4d047b1130ca97dbd8ff07abe291f92 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 18:30:08 +0000 Subject: [PATCH 07/10] fix(githttp): bound the connectivity checks that one push spends on refused commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A writer could send a push with hundreds of commands that name incomplete histories. The publication gate then ran one git rev-list for each of them, and each walked the same objects. The gate now asks git once for each distinct target and stops asking after eight targets have failed. A push with more failing targets than that publishes its pack as it did before the check. git still refuses each of those refs. The same change rewraps a comment, corrects a comment that promised a message the git-refused refusal does not give, and adds a real signal to the exit-status test. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I5260045b374c817b034e832a6926a29c9ed00d5d --- internal/githttp/hook.go | 59 +++++++-- .../githttp/refused_push_pack_e2e_test.go | 121 +++++++++++++++++- 2 files changed, 170 insertions(+), 10 deletions(-) diff --git a/internal/githttp/hook.go b/internal/githttp/hook.go index cc562461..2dd3ebcc 100644 --- a/internal/githttp/hook.go +++ b/internal/githttp/hook.go @@ -1481,8 +1481,11 @@ func atomicPushDFCheck(commands []refCommand) error { // containing any denied command, or any command that git refuses before the // update hook (reachesUpdateHook), whose other commands all target // already-stored objects is refused whole — -// its pack could only serve the denied refs (round-7 decoy) — with a -// message telling the client to push the allowed updates separately. It +// its pack could only serve the denied refs (round-7 decoy) — and a policy +// denial's message tells the client to push the allowed updates separately. +// The checks of reachesUpdateHook are asked once for each distinct target and +// at most maxGitRefusedProbes times for targets that fail (gitRefusalProbe), so +// a push with many incomplete commands costs a bounded number of git children. It // reuses the shared verdicts (enforceRefPolicy, plus the refusals of hidden // refs and of names the server cannot store) — the quarantine is visible to // pre-receive via git's alternates, so is-ancestor and verify-sig checks @@ -1526,6 +1529,7 @@ func preReceivePolicyGate(commands []refCommand, verdicts []error, atomicPush bo // The first command that git refuses before the update hook runs (see // reachesUpdateHook): it can never land, so its pack is no reason to publish. gitRefused := "" + probe := newGitRefusalProbe(reachesUpdateHook) for i, c := range commands { // Verdicts are the caller's single shared policy evaluation // (Codex round-4 P2 on #173: re-evaluating here double-charged @@ -1544,7 +1548,7 @@ func preReceivePolicyGate(commands []refCommand, verdicts []error, atomicPush bo if c.new != ref.ZeroSHA && !objectInMainStore(c.new) { switch { case needsPack: - case reachesUpdateHook(c.new): + case probe.reaches(c.new): needsPack = true case gitRefused == "": gitRefused = c.ref @@ -2931,6 +2935,44 @@ func objectExists(sha string) bool { panic(fmt.Sprintf("githttp assertion failed: cat-file -e %s: %v", sha, err)) } +// maxGitRefusedProbes bounds the connectivity checks that one push may spend +// on commands that fail them. Each check walks the new objects of one command, +// and a writer can send a push with hundreds of commands that name incomplete +// histories. A push that has more distinct failing targets than this publishes +// its pack as it did before the check existed (see gitRefusalProbe). +const maxGitRefusedProbes = 8 + +// gitRefusalProbe asks reach once for each distinct target, and stops asking +// once maxGitRefusedProbes targets have failed. A target that it did not ask +// about reads as reaching the update hook: the gate then publishes, as it did +// before the check, because a quota-counted junk pack costs less than a wrong +// refusal of a push that git accepts. The gate stops asking at the first target +// that passes, so one push spends at most maxGitRefusedProbes+1 checks. +type gitRefusalProbe struct { + reach func(sha string) bool + known map[string]bool + refused int +} + +func newGitRefusalProbe(reach func(sha string) bool) *gitRefusalProbe { + return &gitRefusalProbe{reach: reach, known: map[string]bool{}} +} + +func (p *gitRefusalProbe) reaches(sha string) bool { + if r, ok := p.known[sha]; ok { + return r + } + if p.refused >= maxGitRefusedProbes { + return true + } + r := p.reach(sha) + p.known[sha] = r + if !r { + p.refused++ + } + return r +} + // reachesUpdateHook reports whether git's own connectivity check passes for sha. // receive-pack runs one such check over all commands before it runs any hook // (rev-list --objects --stdin --not --all, with the hidden refs excluded, over @@ -2940,11 +2982,12 @@ func objectExists(sha string) bool { // it lacks the parents of its commits, so this check fails for it as well. git // still runs pre-receive for such a command, but the update hook never runs for // it, so no ref can ever point into a pack that only it needs. An exit of 128 -// is the answer "no": git cannot read the objects that the command needs. Any other status says nothing about the command (a git without -// --exclude-hidden, before 2.39, answers 129; a signal or an out-of-memory kill -// ends it too), so the answer is "yes" and the gate publishes as it did before: -// a wrong refusal of a push that git accepts is worse than one junk pack. A git -// that cannot start is a bug, which fails fast like objectExists. +// is the answer "no": git cannot read the objects that the command needs. Any +// other status says nothing about the command (a git without --exclude-hidden, +// before 2.39, answers 129; a signal or an out-of-memory kill ends it too), so +// the answer is "yes" and the gate publishes as it did before: a wrong refusal +// of a push that git accepts is worse than one junk pack. A git that cannot +// start is a bug, which fails fast like objectExists. func reachesUpdateHook(sha string) bool { cmd := exec.Command("git", "rev-list", "--objects", "--stdin", "--not", "--exclude-hidden=receive", "--all", "--quiet", "--alternate-refs") cmd.Stdin = strings.NewReader(sha + "\n") diff --git a/internal/githttp/refused_push_pack_e2e_test.go b/internal/githttp/refused_push_pack_e2e_test.go index 32f199e4..a29537e6 100644 --- a/internal/githttp/refused_push_pack_e2e_test.go +++ b/internal/githttp/refused_push_pack_e2e_test.go @@ -12,6 +12,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "testing" @@ -60,6 +61,37 @@ func TestPackPublication_GitRefusedCommandStoresNothing(t *testing.T) { assertOnlySetupPack(t, repo, 0) }) + t.Run("many refs at one incomplete commit", func(t *testing.T) { + // A writer can name one incomplete commit with hundreds of refs. The + // gate asks git once for the commit, and refuses the push. + repo, work, token, stored := refusedRawSetup(t, "refused-many") + bad := refusedBadCommits(t, work, stored, 1) + resp := refusedRawPush(t, repo, token, work, bad, 200) + if !strings.Contains(resp, "needed only by ref updates that git refuses") { + t.Fatalf("the pusher does not read the refusal:\n%.600q", resp) + } + assertOnlySetupPack(t, repo, 1) + }) + + t.Run("more distinct incomplete commits than the probe budget", func(t *testing.T) { + // The gate spends at most maxGitRefusedProbes failing checks. Past that + // it publishes as it did before the check, and git still refuses each ref. + repo, work, token, stored := refusedRawSetup(t, "refused-distinct") + bad := refusedBadCommits(t, work, stored, maxGitRefusedProbes+1) + resp := refusedRawPush(t, repo, token, work, bad, 1) + if !strings.Contains(resp, "ng refs/heads/x0") || strings.Contains(resp, "ok refs/heads/x") { + t.Fatalf("git must refuse every ref:\n%.600q", resp) + } + assertOnlySetupPack(t, repo, 2) + }) + + t.Run("within the probe budget", func(t *testing.T) { + repo, work, token, stored := refusedRawSetup(t, "refused-budget") + bad := refusedBadCommits(t, work, stored, maxGitRefusedProbes) + refusedRawPush(t, repo, token, work, bad, 1) + assertOnlySetupPack(t, repo, 1) + }) + for _, tc := range []struct { name string decoy bool // also create refs/heads/y at the stored commit @@ -108,11 +140,17 @@ func TestPackPublication_GitRefusedCommandStoresNothing(t *testing.T) { func TestReachesUpdateHookRefusesOnlyOnExit128(t *testing.T) { for _, tc := range []struct { status string + script string // the body of the git stand-in want bool - }{{"0", true}, {"1", true}, {"128", false}, {"129", true}, {"137", true}} { + }{ + {"0", "exit 0", true}, {"1", "exit 1", true}, {"128", "exit 128", false}, + {"129", "exit 129", true}, {"137", "exit 137", true}, + // A real signal reaches Go as exit code -1, not 137. + {"signal", "kill -9 $$", true}, + } { t.Run("exit "+tc.status, func(t *testing.T) { bin := t.TempDir() - script := "#!/bin/sh\nexit " + tc.status + "\n" + script := "#!/bin/sh\n" + tc.script + "\n" if err := os.WriteFile(filepath.Join(bin, "git"), []byte(script), 0o755); err != nil { t.Fatal(err) } @@ -123,3 +161,82 @@ func TestReachesUpdateHookRefusesOnlyOnExit128(t *testing.T) { }) } } + +// refusedRawSetup stores one commit through a real push and returns the +// repository, the work tree, the token and the stored commit. +func refusedRawSetup(t *testing.T, name string) (repo, work, token, stored string) { + t.Helper() + repo = registerRepo(t, name) + work = initWorkRepo(t) + token = mintTestToken(t, repo, "git:read,git:write", "") + mustGit(t, work, "push", remoteURL(nodeA, repo, token), "HEAD:refs/heads/main") + return repo, work, token, revParse(t, work, "HEAD") +} + +// refusedBadCommits writes n distinct commits whose tree no store holds. +func refusedBadCommits(t *testing.T, work, parent string, n int) []string { + t.Helper() + var ids []string + for i := range n { + ids = append(ids, strings.TrimSpace(string(refusedGit(t, work, "tree "+strings.Repeat("1", 40)+"\nparent "+parent+ + "\nauthor a 1700000000 +0000\ncommitter a 1700000000 +0000\n\nmissing tree "+strconv.Itoa(i)+"\n", + "hash-object", "-t", "commit", "-w", "--literally", "--stdin")))) + } + return ids +} + +// refusedRawPush sends, in one raw receive-pack request, perCommit creates of +// refs/heads/x- at each commit in bad, with a pack that holds only those +// commits. It returns git's response. +func refusedRawPush(t *testing.T, repo, token, work string, bad []string, perCommit int) string { + t.Helper() + var body bytes.Buffer + caps := "\x00report-status side-band-64k" + for i, id := range bad { + for j := range perCommit { + name := "refs/heads/x" + strconv.Itoa(i) + if perCommit > 1 { + name += "-" + strconv.Itoa(j) + } + body.WriteString(pktLine(ref.ZeroSHA + " " + id + " " + name + caps + "\n")) + caps = "" + } + } + body.WriteString("0000") + body.Write(refusedGit(t, work, strings.Join(bad, "\n")+"\n", "pack-objects", "--stdout", "-q")) + _, resp := postReceivePack(t, nodeA, repo, token, bytes.NewReader(body.Bytes()), false) + return resp +} + +// The probe asks once for each distinct target and stops asking after +// maxGitRefusedProbes failures. +func TestGitRefusalProbeBoundsTheChecks(t *testing.T) { + var asked []string + probe := newGitRefusalProbe(func(sha string) bool { asked = append(asked, sha); return false }) + for range 1000 { + if probe.reaches("a") { + t.Fatal("a target that failed reads as reaching the update hook") + } + } + if len(asked) != 1 { + t.Fatalf("1000 commands at one target asked git %d times, want 1", len(asked)) + } + asked = nil + probe = newGitRefusalProbe(func(sha string) bool { asked = append(asked, sha); return false }) + var reached int + for i := range 1000 { + if probe.reaches(strconv.Itoa(i)) { + reached++ + } + } + if len(asked) != maxGitRefusedProbes || reached != 1000-maxGitRefusedProbes { + t.Fatalf("1000 distinct failing targets asked git %d times (%d read as reaching), want %d and %d", + len(asked), reached, maxGitRefusedProbes, 1000-maxGitRefusedProbes) + } + // A target that passes is remembered and never costs a failure. + asked = nil + probe = newGitRefusalProbe(func(sha string) bool { asked = append(asked, sha); return sha == "ok" }) + if !probe.reaches("ok") || !probe.reaches("ok") || len(asked) != 1 { + t.Fatalf("a passing target asked git %d times, want 1", len(asked)) + } +} From 89a0a08077c20fe6a00701bf555ac19e0dd29a90 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 18:36:52 +0000 Subject: [PATCH 08/10] chore(verify): record lane-schedule fingerprints for the bounded connectivity checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The publication gate now asks git through a probe. The sync commit line and the fingerprint of preReceivePolicyGate move with it, and the probe is covered. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I2623ed230422cc29d9a055365afa64b338e34899 --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- .agents/skills/verify-lane-schedule/model/fingerprints.txt | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index d4585ab6..03c5a74c 100644 --- a/.agents/skills/verify-lane-schedule/SKILL.md +++ b/.agents/skills/verify-lane-schedule/SKILL.md @@ -226,7 +226,7 @@ With every fact TRUE in the code, setting each fact FALSE in the model alone fai ## Coverage record -Sync commit: `9d39336125c017ad00adabc3dab174f2b4e754a6` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `a8961d13f4d047b1130ca97dbd8ff07abe291f92` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). Every declaration in these files is covered: diff --git a/.agents/skills/verify-lane-schedule/model/fingerprints.txt b/.agents/skills/verify-lane-schedule/model/fingerprints.txt index a977ae04..5236f5ef 100644 --- a/.agents/skills/verify-lane-schedule/model/fingerprints.txt +++ b/.agents/skills/verify-lane-schedule/model/fingerprints.txt @@ -173,6 +173,7 @@ internal/githttp/hook.go:const_EnvTestMode 0fb6278868ab64de8ed830c27d8012270084a internal/githttp/hook.go:const_EnvUpdateBarrier 6ff404753ce21cb0b7ae4bb9850b3c65c197d7aa44201a9dbbc89f076bd51e31 internal/githttp/hook.go:const_EnvUpdateBarrierEach 30d1db7c45c3f53685529b58faf0f2170bcb1fdd89f6cdecdbbafd8cdafe5387 internal/githttp/hook.go:const_importSyncedRefusal f9c4ddcfa5cfc3723957964e8931f1739395d817bb0d86e2791c9696c93dd41a +internal/githttp/hook.go:const_maxGitRefusedProbes 0b12df63e73be9ef62e9c210390ea316bf9fcc1b87211e7cf60fa3c514b523ce internal/githttp/hook.go:const_maxPushRefDepth 18915f2d5777fe14fc95965757f1cddd8bcaa074f25ddf971982ea6e7d1d9db4 internal/githttp/hook.go:const_maxPushRefNameBytes d0b62ce6ef4e41216d91b71f4a304234de19717a1ac7da561c62009d3a029854 internal/githttp/hook.go:const_maxPushRefSegmentBytes 84c00b544f5aed1b74877f054708eff1fcac2a8a24d221ffa9600854d60bfedb @@ -188,6 +189,7 @@ internal/githttp/hook.go:enforceRefPolicy 2cd2cf6aea243221e8fe27280a6333695d4455 internal/githttp/hook.go:enforceSyncClaimFence efb7b07e54bbb4008ac0cf53778c2ba690ad936051c103421aaf308b52e1cdf9 internal/githttp/hook.go:evalRefPolicy b232fd0a747ced157cec1bc4588e53bc13c54a39ff829f45108ae62c9601b5c8 internal/githttp/hook.go:gitRefSegmentValid be11ac7ba983b399f85ec59e9ac524d9d95329fe7c774f011934bf97b1b26cf7 +internal/githttp/hook.go:gitRefusalProbe.reaches 938ddcf9757e6b985bb3662f50b9fba53f51125d2d343ee8e0fff13ad530c065 internal/githttp/hook.go:hiddenOnRemote 91f396bdce763dd700bf642823435bfc3cec17f641d83f07af33f96ceacbe254 internal/githttp/hook.go:historyIntact b38332684e10b27880f57f3e4611858550bf615f33a5613fdb0af59c75b70770 internal/githttp/hook.go:import_"bufio" c8716a546ce61a4869563c666058adbec5f4783581ea4f74788f87ec1f0731f1 @@ -222,6 +224,7 @@ internal/githttp/hook.go:isBranchTip 4b841bc86abf0876e093b19da54ff7e1fda6011f3b3 internal/githttp/hook.go:loadRefPolicies e974fac4024c3534aaa1c55514851744f5b1999bf8a503573a7530130e140c63 internal/githttp/hook.go:looksLikeSSHPublicKey 0dfb41f2c68c29f7bd43dc0630624e292599c1da3b168d3ba9eade2349706e53 internal/githttp/hook.go:mustEnv f003f721f345a1dd8d73bf4b0c6f95e97157cab55714e6b922b10859e4c9c6b8 +internal/githttp/hook.go:newGitRefusalProbe 2c8f044c7fdb1d98ae3a941702951fab72596e708fff64397e85fd7a607ef21d internal/githttp/hook.go:newSigVerifier a555514bf11dbd3caaded84b9cca58ef7a8b7a83e39b24bfda507edcbb5a446a internal/githttp/hook.go:normalizeQuarantineKeep 08fe44518b58336b37472b2c027b85ee48b39b335a0f5d311bcf72e6e29675fb internal/githttp/hook.go:objectExists a9ba9ba7c3d15548a14c9ef9c56571831f9518ca386c0009ecd24b03373ab1b9 @@ -231,7 +234,7 @@ internal/githttp/hook.go:parseRefTxCommitted 8471c50ec96eec8e6db39370335fbb30116 internal/githttp/hook.go:pauseAtUpdateBarrier a57f4482fb6742f6146ca93452fc9e003a70fd9bab1147a87bb4b32b465859c0 internal/githttp/hook.go:postReceiveHook 1f060af8c07a0c11ab59f6a26f444d7648ddfa9fac7bb506346e808a72311261 internal/githttp/hook.go:preReceive 472bccca1a374479cedb08f228f17893a2f20c1b971761085d5bdf0c60f35ba0 -internal/githttp/hook.go:preReceivePolicyGate 022af08c29170fe53ffaa80864915cec62b2da1976c08239f620cefcb72bb4e1 +internal/githttp/hook.go:preReceivePolicyGate ca36486a30be47ace72b37aa7c77fec418a88d92a1a36951caf6d2a88a1ec4fd internal/githttp/hook.go:pushCommandUpdatable 7ff2f47180eec838d8c98da58a9836bc69a8b9ee1ac9d0f9270ee816594c04ba internal/githttp/hook.go:pushRefDeletable 33c0ee3ab6b1f4a8886faa66aa3db0a25efcb8407667c33d5c4fa1b3a5de3a94 internal/githttp/hook.go:pushRefPathTooLong 93ab890b939c3afe6a0e7d177327109d6aa988cb24a51bc8dff8d26546cfcbee @@ -246,6 +249,7 @@ internal/githttp/hook.go:sigVerifier.verifyCommit e169a962f642d67522cc48b9cd4916 internal/githttp/hook.go:testMode 9056ef1dbdfa8f6875d87e4272e7d18f29c722a37755a607dd4e3dae1c4f790e internal/githttp/hook.go:type_casDropStore 06047f65ba2b2821b24756ed0226f105f16bc6329d5146740837508a34f017dc internal/githttp/hook.go:type_dfConflictProber 04652c08a0fb8fe305ed46a44368d76b7ee70a2b034912ddacfc6db8d8acde8a +internal/githttp/hook.go:type_gitRefusalProbe 0f1622f30b1981f51d3eecbb1bf64f22b40a7e7ec0fbe637250a9bcfcfcb49a1 internal/githttp/hook.go:type_refCommand e037686129d2cb179e4c3a64f0ea09d26c1b12957eb5b3f7d0fcdf695832a1ef internal/githttp/hook.go:type_refPolicyMemo 7f1604056f494e4a6eaa2d453b94f924641594c8edd53a6daeec1f591b9ba04e internal/githttp/hook.go:type_refValuesProber 0389595e3fb341c7e67784d27674d922ddfcca2e3ae993cdba85ea0c8613a665 From 82141ff8804235db67b10a7e5ee53607c02e34f3 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 18:37:51 +0000 Subject: [PATCH 09/10] test(githttp): ask the probe test one question at a time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit staticcheck flagged the repeated call in one condition. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I4399c34c2fa711fc90100b764ac6c7aaaec05075 --- internal/githttp/refused_push_pack_e2e_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/githttp/refused_push_pack_e2e_test.go b/internal/githttp/refused_push_pack_e2e_test.go index a29537e6..3676724b 100644 --- a/internal/githttp/refused_push_pack_e2e_test.go +++ b/internal/githttp/refused_push_pack_e2e_test.go @@ -236,7 +236,8 @@ func TestGitRefusalProbeBoundsTheChecks(t *testing.T) { // A target that passes is remembered and never costs a failure. asked = nil probe = newGitRefusalProbe(func(sha string) bool { asked = append(asked, sha); return sha == "ok" }) - if !probe.reaches("ok") || !probe.reaches("ok") || len(asked) != 1 { - t.Fatalf("a passing target asked git %d times, want 1", len(asked)) + first, again := probe.reaches("ok"), probe.reaches("ok") + if !first || !again || len(asked) != 1 { + t.Fatalf("a passing target asked git %d times (answers %v, %v), want 1 and true, true", len(asked), first, again) } } From f371402456558627efcbc1bdda8a7bfc0c917869 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Mon, 16 Nov 2026 19:32:36 +0000 Subject: [PATCH 10/10] docs(githttp): state the limit of the git-refused check and pin it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The wire page said the server declines every push that only refused refs need. It does not past eight distinct refused targets, or with a git older than 2.39. The page now says so, a test pins the number that the page names, and a comment states the exact bound of the checks. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-sonnet-5-5` • Thinking: `xhigh`_ Change-Id: I438d281806df4ad2fad04b7be09e457cc1ac6094 --- docs/explanation/wire-compatibility.md | 3 +++ internal/githttp/hook.go | 2 +- internal/githttp/refused_push_pack_e2e_test.go | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/explanation/wire-compatibility.md b/docs/explanation/wire-compatibility.md index d77d618e..05b15002 100644 --- a/docs/explanation/wire-compatibility.md +++ b/docs/explanation/wire-compatibility.md @@ -133,6 +133,9 @@ Beyond the smart-HTTP wire format, the semantics clients depend on match git: a part over 200 bytes, or a name over 900 bytes). When no other ref of the push needs the objects that the push sends (only refused refs need them, or the other refs move to commits the server already has), the server declines the whole push and stores no pack. + The server asks git about at most eight distinct refused targets in one push. A push with + more than eight of them, or on a server whose git is older than 2.39, stores its pack as + before, and git still refuses each of those refs. A push that only deletes refs sends no objects and, within the server's own limits, keeps per-ref results. - **Documented deviation:** refs advance through per-ref compare-and-swap on the ref diff --git a/internal/githttp/hook.go b/internal/githttp/hook.go index 2dd3ebcc..20a1da04 100644 --- a/internal/githttp/hook.go +++ b/internal/githttp/hook.go @@ -2947,7 +2947,7 @@ const maxGitRefusedProbes = 8 // about reads as reaching the update hook: the gate then publishes, as it did // before the check, because a quota-counted junk pack costs less than a wrong // refusal of a push that git accepts. The gate stops asking at the first target -// that passes, so one push spends at most maxGitRefusedProbes+1 checks. +// that passes, so one push spends at most maxGitRefusedProbes checks. type gitRefusalProbe struct { reach func(sha string) bool known map[string]bool diff --git a/internal/githttp/refused_push_pack_e2e_test.go b/internal/githttp/refused_push_pack_e2e_test.go index 3676724b..9fa03225 100644 --- a/internal/githttp/refused_push_pack_e2e_test.go +++ b/internal/githttp/refused_push_pack_e2e_test.go @@ -211,6 +211,10 @@ func refusedRawPush(t *testing.T, repo, token, work string, bad []string, perCom // The probe asks once for each distinct target and stops asking after // maxGitRefusedProbes failures. func TestGitRefusalProbeBoundsTheChecks(t *testing.T) { + // The docs say eight, so the value is pinned here and in the docs together. + if maxGitRefusedProbes != 8 { + t.Fatalf("maxGitRefusedProbes = %d, want 8: docs/explanation/wire-compatibility.md says eight", maxGitRefusedProbes) + } var asked []string probe := newGitRefusalProbe(func(sha string) bool { asked = append(asked, sha); return false }) for range 1000 {