git-credential-nostr: first push of any pack > 1 MiB fails (401 challenge on a streamed, non-replayable POST)
git-credential-nostr: first push of any pack > 1 MiB fails (401 challenge on a streamed, non-replayable POST)
Summary
Out of the box, pushing more than ~1 MiB to Buzz git dies with:
error: RPC failed; HTTP 401 curl 56 The requested URL returned error: 401
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
Everything up-to-date ← misleading: nothing was pushed
Mechanism
Three correct-in-isolation behaviors compose into a guaranteed failure:
git-credential-nostrreturnsephemeral=true, so git caches nothing and sends thegit-receive-packPOST unauthenticated first, expecting to retry after the 401 challenge.- The Buzz server (correctly) answers the unauthenticated POST with 401.
- git can only replay a challenged POST if the body is buffered; packs larger than
http.postBuffer(default 1 MiB) are streamed chunked and cannot be replayed → hard failure.
So the failure threshold is exactly http.postBuffer, and the very first real-world push (any repo with more than trivial history) hits it. Small pushes work, which makes this look like flaky infrastructure rather than a deterministic composition bug.
Workaround (verified)
git config http.postBuffer 524288000 # buffer the pack so the 401 retry can replay it
After this a 90 MB pack pushes fine (the ±60s NIP-98 window is not a problem — the token is minted at challenge time, after the buffered body is ready).
Suggested fixes (in increasing order of effort)
- Document it. A "Large pushes" section in
crates/git-credential-nostr/README.mdwith thehttp.postBufferline would eliminate the trap for near-zero cost. The README's troubleshooting table already covers subtler failures than this one. - Pre-emptive auth. The helper already knows the server's auth scheme after the first
info/refschallenge of the session. Returning a credential git can send pre-emptively on the subsequent POST (i.e., not marking itephemeralwithin a single git invocation, scoped by the ±60s validity) avoids the challenge round-trip entirely for the push POST. - Server-side
Expect: 100-continuehandling so the 401 lands before the body is transmitted; git/curl then retries with auth without needing a replayable body. (Most invasive; 1–2 make it unnecessary.)
Environment
Relay at 63496cc1d, git 2.50.1, git-credential-nostr built from the same tree; observed 2026-08-01 mirroring a 101 MB repository.
Shipped the doc-only fix (option 1 from the issue): https://github.com/block/buzz/pull/4259
Adds a "Large pushes" section to crates/git-credential-nostr/README.md explaining the three-way composition trap (ephemeral=true + correct 401 + streamed body) and the verified workaround:
git config --global http.postBuffer 524288000
Also adds a Troubleshooting table row pointing at the new section.
Options 2 (preemptive auth) and 3 (Expect: 100-continue) are noted in the PR body as follow-up if the doc proves insufficient. The doc-only path was the issue's preferred fix and is near-zero risk — the failure is a composition of three correct behaviors, and surfacing the one knob that makes them compose is the smallest viable change.
Workaround that makes this pass, in case it helps others: set a large http.postBuffer on the client.
git config http.postBuffer 524288000 # 500 MB
git push buzz main
With the default 1 MiB buffer git streams the request body with chunked transfer encoding, and that body cannot be replayed after the server answers the NIP-98 challenge — which matches the failure described here. Raising the buffer above the pack size makes git send a single non-chunked body it can repeat, and the push completes.
Verified on a self-hosted relay 0.2.1, desktop 0.5.22, git 2.50.1, pack size 10 MiB: fails reliably at the default, succeeds every time with the buffer raised. A fresh git clone of the pushed repo from the relay then works as well.
This is a client-side workaround, not a fix — the server still rejects a replayable-once body, so it does not address the underlying auth-retry behaviour.