git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/8] connect: send session-id with ls-refs and bundle-uri

From
Christian Couder <christian.couder@gmail.com>
Date
Nov 20, 2026, 16:48 UTC
Message-ID
<20261120164812.707946-12-christian.couder@gmail.com>
In-Reply-To
<20261120164812.707946-10-christian.couder@gmail.com>

1e905bbc00 (fetch-pack: advertise session ID in capabilities, 2020-11-11) only added session-id to fetch-pack and doesn't say why it was left out elsewhere. According to our "gitprotocol-v2.adoc" documentation, the goal of session IDs is to identify the process across multiple requests, so there is no reason to not send it with every request.

Let's then also send session-id in the `ls-refs` and `bundle-uri` requests which go through send_capabilities().

Note that this only changes behavior when `transfer.advertiseSID` is set, which is not the default.

Also note that over file:// and ssh:// one upload-pack process handles both `ls-refs` and `fetch`, so the server now logs the client's session-id twice per process, but this is harmless.

Let's add tests in t5705 to check that the server receives the client's session-id when only `ls-refs` is sent (with `git ls-remote`) and when only `bundle-uri` is sent (with `test-tool bundle-uri ls-remote`), as the existing tests there only use `fetch`, which already sent it.

Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
 connect.c                             |  6 ++++++
 t/t5705-session-id-in-capabilities.sh | 26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
diff --git a/connect.c b/connect.c
index 5f73fd9e7e..40cd279290 100644
--- a/connect.c
+++ b/connect.c
@@ -505,10 +505,16 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)
 {
 	const char *hash_name;
 	const char *promisor_remote_info;
+	int advertise_sid = 0;
+
+	repo_config_get_bool(the_repository, "transfer.advertisesid", &advertise_sid);
 
 	if (server_supports_v2("agent"))
 		packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized());
 
+	if (advertise_sid && server_supports_v2("session-id"))
+		packet_write_fmt(fd_out, "session-id=%s", trace2_session_id());
+
 	if (server_feature_v2("object-format", &hash_name)) {
 		int hash_algo = hash_algo_by_name(hash_name);
 		if (hash_algo == GIT_HASH_UNKNOWN)
diff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh
index ef0db57d1f..9b35c62629 100755
--- a/t/t5705-session-id-in-capabilities.sh
+++ b/t/t5705-session-id-in-capabilities.sh
@@ -84,4 +84,30 @@ do
 	'
 done
 
+test_expect_success 'session IDs advertised (ls-remote v2)' '
+	test_when_finished "rm -rf local tr2-server-events" &&
+	cp -r "$LOCAL_PRISTINE" local &&
+	git -c protocol.version=2 -C local ls-remote \
+		--upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \
+		origin &&
+	test_grep \"key\":\"client-sid\" tr2-server-events
+'
+
+test_expect_success 'session IDs advertised (bundle-uri v2)' '
+	test_when_finished "rm -f trace tr2-events" &&
+	test_config -C "$REPO" uploadpack.advertiseBundleURIs true &&
+	test_config_global transfer.advertiseSID true &&
+	test_config_global transfer.bundleURI true &&
+
+	# Only the server logs "client-sid", so the client and the
+	# server can share the same trace2 event file.
+	GIT_TRACE_PACKET="$(pwd)/trace" GIT_TRACE2_EVENT="$(pwd)/tr2-events" \
+	test-tool bundle-uri ls-remote "file://$REPO" &&
+
+	# Only the "bundle-uri" command is sent
+	test_grep "> command=bundle-uri" trace &&
+	test_grep ! "> command=ls-refs" trace &&
+	test_grep \"key\":\"client-sid\" tr2-events
+'
+
 test_done
-- 
2.56.0
Previous: Christian CouderNext: Christian Couder
Message 12 of 18 in “Fix promisor-remote reply missing from fetch”
  1. 0/3 Fix promisor-remote reply missing from fetchChristian Couder, Nov 12, 2026
  2. 1/3 connect: let write_command_and_capabilities() send a promisor-remote replyChristian Couder, Nov 12, 2026
  3. Junio C HamanoNov 12, 2026
  4. Junio C HamanoNov 12, 2026
  5. Christian CouderNov 13, 2026
  6. Junio C HamanoNov 13, 2026
  7. Christian CouderNov 20, 2026
  8. 2/3 fetch-pack: ensure fetch sends a promisor-remote replyChristian Couder, Nov 12, 2026
  9. 3/3 doc: gitprotocol-v2: send the promisor-remote reply with fetchChristian Couder, Nov 12, 2026
  10. 0/8 Fix promisor-remote reply missing from fetchChristian Couder, Nov 20, 2026
  11. 1/8 connect: pass capability lines to write_command_and_capabilities()Christian Couder, Nov 20, 2026
  12. 2/8 connect: send session-id with ls-refs and bundle-uriChristian Couder, Nov 20, 2026
  13. 3/8 connect: pass a reader to write_command_and_capabilities()Christian Couder, Nov 20, 2026
  14. 4/8 connect: buffer the ls-refs and bundle-uri requestsChristian Couder, Nov 20, 2026
  15. 5/8 connect: use write_command_and_capabilities() in get_remote_refs()Christian Couder, Nov 20, 2026
  16. 6/8 connect: use write_command_and_capabilities() in get_remote_bundle_uri()Christian Couder, Nov 20, 2026
  17. 7/8 fetch-pack: ensure fetch sends a promisor-remote replyChristian Couder, Nov 20, 2026
  18. 8/8 doc: gitprotocol-v2: send the promisor-remote reply with fetchChristian Couder, Nov 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.