Skip to content

Commit 879e0f9

Browse files
committed
fixup! Add an AGENTS.md file to help with AI-assisted debugging/development
AGENTS: document learnings from split-index + fsmonitor investigation While investigating a CI failure in the `linux-TEST-vars` job caused by the interaction between the `pt/fsmonitor-linux` and `hn/git-checkout-m-with-stash` topics in `seen`, several debugging techniques proved essential and were not previously documented. The investigation required bisecting the first-parent history of `seen` while temporarily merging the fsmonitor topic at each step. This revealed that `GIT_TEST_SPLIT_INDEX=yes` corrupts the bisect machinery's own index operations unless it is unset before cleanup checkouts. It also revealed that `fprintf(stderr, ...)` instrumentation in Git's C code is swallowed by the test framework, making Trace2 the correct instrumentation approach. A key insight was that the bug appeared Linux-specific only because `linux-TEST-vars` is the sole CI job setting `GIT_TEST_SPLIT_INDEX=yes`; there is no macOS or Windows equivalent. The actual root cause (the `index.skipHash=true` + split-index interaction producing a null `base_oid` in the shared index) is platform-independent. Add four documentation sections capturing these learnings: bisecting `seen` interactions, reproducing with exact CI variables, verifying CI platform coverage before concluding platform-specificity, and using Trace2 for instrumentation inside the test framework. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent ef8d1d2 commit 879e0f9

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,30 @@ Enable tracing to see command execution patterns:
230230
GIT_TRACE2_EVENT=/path/to/trace.txt git <command>
231231
```
232232

233+
### Instrumenting Git Internals During Tests
234+
235+
When adding debug output to Git's C code during test investigation,
236+
`fprintf(stderr, ...)` from git subprocesses spawned by the test framework
237+
is typically swallowed (redirected or discarded by the test harness). Use
238+
Trace2 instead:
239+
240+
```c
241+
trace2_data_intmax("index", NULL, "my_debug/cache_nr", istate->cache_nr);
242+
trace2_data_string("index", NULL, "my_debug/state", some_string);
243+
```
244+
245+
Then run the test with `GIT_TRACE2_EVENT` or `GIT_TRACE2_PERF` pointing to
246+
a file, and grep the output. This integrates with Git's existing tracing
247+
infrastructure and survives the test framework's output management.
248+
249+
As a last resort (e.g. when Trace2 is not initialized yet at the point you
250+
need to instrument), write to a fixed file path:
251+
252+
```c
253+
FILE *f = fopen("/tmp/debug.log", "a");
254+
if (f) { fprintf(f, "state: %u\n", value); fclose(f); }
255+
```
256+
233257
### Comparing Branches After Rebase
234258

235259
```bash
@@ -264,6 +288,32 @@ away from the original branch point the commit is cherry-picked to, so it
264288
often makes sense to squash both old and new downstream changes, and then
265289
to "interpolate" between them when encountering merge conflicts).
266290

291+
### Bisecting Failures in `seen`
292+
293+
When a topic passes on its own but fails after being merged to `seen`, the
294+
failure is caused by interaction with another in-flight topic. To identify
295+
the culprit:
296+
297+
1. Fetch the exact `seen` commit from the failing CI run (get the SHA from
298+
the workflow run metadata via the GitHub API).
299+
2. Use a worktree checked out at that `seen` commit.
300+
3. Bisect the first-parent history between `upstream/master` and `seen~1`
301+
(excluding the topic's own merge). At each bisection step, merge the
302+
topic in temporarily, build, run the test, then undo the merge.
303+
4. Write a `git bisect run` script that automates this. Key pitfalls:
304+
- The script must `unset` test environment variables (especially
305+
`GIT_TEST_SPLIT_INDEX`) before cleanup operations like
306+
`git checkout -f`, otherwise the worktree's own index can get
307+
corrupted.
308+
- Use `git checkout -f "$ORIG"` (not `git reset --hard`) to undo the
309+
temporary merge, since `reset --hard` under split-index can corrupt.
310+
- Save the current commit OID at the start (`ORIG=$(git rev-parse HEAD)`)
311+
because `ORIG_HEAD` is unreliable during bisect.
312+
- On merge conflict, return 125 (skip) and `git merge --abort`.
313+
5. Store the alias for running with the full set of CI test variables as a
314+
repository-local alias (to avoid repeating the long export list and to
315+
allow the user to approve the tool call once).
316+
267317
### CI/Workflow Failure Investigation
268318

269319
When a CI workflow fails, the debugging process has a high cost per iteration.
@@ -295,6 +345,23 @@ locally with faster turnaround:
295345
- For build failures: replicate the build environment and commands.
296346
- For macOS issues: if you lack a Mac, at least trace the Makefile logic
297347
to understand what flags should be set and why.
348+
- For test failures that only appear in specific CI jobs (like
349+
`linux-TEST-vars`): reproduce with the _exact_ set of environment
350+
variables that job sets. Check `ci/run-build-and-tests.sh` for the
351+
job's variable block. Do not assume a single variable (e.g.
352+
`GIT_TEST_SPLIT_INDEX`) is sufficient; other variables may contribute
353+
to the failure path.
354+
- When a test fails in `seen` but not on the topic branch alone, check
355+
out the exact `seen` commit from the failing CI run (get the SHA from
356+
the workflow run metadata) and reproduce against that. The interaction
357+
with other in-flight topics is the likely cause.
358+
359+
**5. Do not assume CI coverage from platform support.** When asking "why
360+
does platform X not see this bug?", verify whether CI actually tests that
361+
combination on that platform. For example, `GIT_TEST_SPLIT_INDEX=yes` is
362+
only set by `linux-TEST-vars`; there is no equivalent `osx-TEST-vars` or
363+
`windows-TEST-vars` job. A bug that only manifests under split-index
364+
testing may be present on all platforms but only caught on Linux.
298365

299366
**5. Add comprehensive diagnostics on first attempt.** If you must push to
300367
CI to test, make that push count:

0 commit comments

Comments
 (0)