Skip to content

fix(gix-protocol): send all V1 want lines before shallow and deepen lines. (#3247) - #3248

Open
sagi-qryptonite wants to merge 1 commit into
GitoxideLabs:mainfrom
sagi-qryptonite:fix-v1-want-order
Open

sagi-qryptonite wants to merge 1 commit into
GitoxideLabs:mainfrom
sagi-qryptonite:fix-v1-want-order

Conversation

@sagi-qryptonite

@sagi-qryptonite sagi-qryptonite commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #3247.

This PR was written by Claude, an AI agent, through sagi-qryptonite's account. Everything below is my own account of the work.

Motivation

The fix is for a repository scanner built on gix that fetches repositories with Shallow::DepthAtRemote(1). Shallow fetches from Azure DevOps Services fail, so it currently has to fall back to full fetches for those hosts.

Root cause

fetch() adds the shallow/deepen* arguments before the wants. For protocol V0/V1, Arguments::send() then swapped only the first want to the front. With more than one want, the deepen line ended up between want lines. A clone always has at least two wants (HEAD and the branch it points to, even if they are the same id).

git upload-pack accepts lines in any order, so GitHub and git http-backend didn't notice. Azure DevOps follows the grammar in gitprotocol-pack, want-list *shallow-line *1depth-request [filter-request] flush-pkt, and answers with HTTP 400.

It isn't the unadvertised deepen-* capabilities suspected in the issue. gix 0.91 sends only what the server advertised.

Packet traces

Shallow clone (depth 1) of an Azure DevOps Services repository, captured with gitoxide.tracePacket=true:

Before (HTTP 400):

>> want af56d96fdbd7c26e9fc94336b6f50dcc6ceff484 thin-pack side-band-64k shallow multi_ack_detailed allow-tip-sha1-in-want no-done filter agent=git/oxide-0.91.0
>> deepen 1
>> want af56d96fdbd7c26e9fc94336b6f50dcc6ceff484
>> FLUSH
>> done

After:

>> want af56d96fdbd7c26e9fc94336b6f50dcc6ceff484 thin-pack side-band-64k shallow multi_ack_detailed allow-tip-sha1-in-want no-done filter agent=git/oxide-0.91.0
>> want af56d96fdbd7c26e9fc94336b6f50dcc6ceff484
>> deepen 1
>> FLUSH
>> done
<< shallow af56d96fdbd7c26e9fc94336b6f50dcc6ceff484
<< FLUSH
<< NAK
<< (sideband) Azure Repos
<< (sideband) Found 7 objects to send. (0 ms)
<< (pack)

The order of the lines is the only difference between the two requests.

Change

prepare_v1() now sorts the arguments stably in grammar order: all wants (the first one still carries the capabilities), then shallow lines, then the deepen* lines in the order they were added, then filter. Stateless transports resend the retained arguments in each round, so every round uses this order.

The expectation in response::v1::arguments::all changes because it encoded the old behaviour, where the swap moved the shallow line behind the deepen* lines. The new order (shallow before deepen) is the order git uses.

Tests

  • The existing fetch::arguments::v1::haves_and_wants_for_clone and haves_and_wants_for_fetch_stateless now add deepen (and filter) before two wants, as fetch() does, and check the exact request bytes of both stateless rounds. Both fail without the fix, and the stateless one also fails if filter isn't ranked after the deepen* lines.

  • cargo test -p gix-protocol passes with blocking-client and with async-client. cargo fmt --check passes. cargo clippy reports nothing new; the existing drop_non_drop warning at fetch/function.rs:154 is also on main.

  • cargo test -p gix --features blocking-network-client --test gix -- remote:: clone passes, including all shallow clone and fetch tests. On macOS, fetch_and_checkout_honors_shared_repository_permissions also fails on main, so that failure is unrelated.

  • Against live servers with a small gix::clone::PrepareFetch program:

    Remote depth 0 depth 1 depth 3
    Azure DevOps Services (public repository) ok ok (HTTP 400 before) ok
    github.com/octocat/Hello-World ok ok ok

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Contributor
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-25T13:27:06.925212Z 7b3170d PR opened
ℹ️ About Codex in GitHub

Your 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.

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

Copy link
Copy Markdown
Contributor

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: 7b3170decb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread gix-protocol/src/fetch/arguments/mod.rs Resolved
@sagi-qryptonite
sagi-qryptonite force-pushed the fix-v1-want-order branch 2 times, most recently from 359b3f2 to 2e07615 Compare November 25, 2026 13:37
…pen` lines. (GitoxideLabs#3247)

`fetch()` adds `shallow` and `deepen*` arguments before the wants, and
`Arguments::send()` then only swapped the *first* `want` to the front for
protocol V0/V1. With more than one want, which a clone always has
(`HEAD` and the branch it points to), the request became

```
want <id> <capabilities>
deepen 1
want <id>
0000
done
```

The V1 grammar is `want-list *shallow-line *1depth-request [filter-request] flush-pkt`
(see `gitprotocol-pack`), which is also the order `git` uses.
`git upload-pack` accepts lines in any order, so this went unnoticed with
GitHub and `git http-backend`, but Azure DevOps Services rejects such a request
with HTTP 400, which made every shallow clone from it fail.

Now the arguments are sorted stably before sending, in grammar order:
all wants (the first one still carrying the capabilities), `shallow` lines,
the `deepen*` lines in the order they were added, and `filter` last.
As stateless transports resend the retained arguments in each round,
every round uses this order.

`haves_and_wants_for_clone` and `haves_and_wants_for_fetch_stateless` now add
`deepen` (and `filter`) before multiple wants, like `fetch()` does.

The expectation of `response::v1::arguments::all` changes as it encoded
the previous behaviour, where the swap moved the `shallow` line behind
the `deepen*` lines.
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.

Shallow clone (depth 1) from Azure DevOps over HTTPS fails with HTTP 400 from git-upload-pack

1 participant