Skip to content

fix(bench): stop deleting packed-refs in invalidate_caches_auto - #2697

Merged
max-sixty merged 1 commit into
mainfrom
fix/bench-packed-refs-invalidation
May 11, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/bench-packed-refs-invalidation

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

create_repo_at ends with an explicit git gc (added in #2683 to fix the list-bench fixture race). gc packs every loose ref into .git/packed-refs and prunes the loose copies, so post-gc packed-refs is the only on-disk record of refs/heads/main. `invalidate_caches_auto` then deleted that file as part of its cold-cache reset — taking the only copy of the branch ref with it.

The fallout surfaced one bench later: `wt stub`'s body has no template vars, so it survived; `wt with_vars` resolved `{{ commit }}` via `rev-parse main`, got an `Err` back, and Criterion panicked at warm-up of `dispatch/with_vars/warm/1`. The nightly `benchmarks` job has been red since the #2683 merge for this reason (failed run, reported as #2693).

`packed-refs` is git's primary ref storage post-gc, not a cache — there's no cold-cache equivalent to simulate by deleting it (the kernel page-cache isn't invalidated by `unlink` anyway). Drop the deletion, document why, and add a regression test.

Test plan

  • New `invalidate_preserves_refs_after_gc` unit test in `wt-perf` — fails on `main` (`rev-parse main` returns 128), passes here.
  • Full `cargo bench --bench alias` — all 8 variants complete (stub + with_vars × warm/cold × 1/100). Before the fix, `dispatch/with_vars/warm/1` panicked.
  • `cargo clippy -p wt-perf --all-targets -- -D warnings`, `cargo fmt --all`.

Fixes #2693.

🤖 Generated with Claude Code

`create_repo_at` ends with an explicit `git gc` (added in #2683 to fix the
list-bench fixture race). gc packs every loose ref into `.git/packed-refs`
and prunes the loose copies, so `packed-refs` becomes the only on-disk record
of `refs/heads/main`. `invalidate_caches_auto` then deleted that file as part
of its cold-cache reset — taking the only copy of the branch ref with it.

The fallout surfaced one bench later: `wt stub`'s body has no template vars,
so it survived; `wt with_vars` resolved `{{ commit }}` via `rev-parse main`,
got an Err back, and Criterion panicked at warm-up of
`dispatch/with_vars/warm/1`. The nightly benchmarks job has been red since
the #2683 merge for this reason.

`packed-refs` is git's primary ref storage post-gc, not a cache — there's
no cold-cache equivalent to simulate by deleting it (the kernel page-cache
isn't invalidated by `unlink` anyway). Drop the deletion, document why, and
add a regression test that asserts `rev-parse main` still resolves after
`invalidate_caches_auto`.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@worktrunk-bot worktrunk-bot added the automated-fix Automated CI fix label May 11, 2026
This was referenced May 11, 2026
@max-sixty
max-sixty merged commit de3ef90 into main May 11, 2026
31 of 39 checks passed
@max-sixty
max-sixty deleted the fix/bench-packed-refs-invalidation branch May 11, 2026 09:47
max-sixty added a commit that referenced this pull request May 11, 2026
## Summary

- Adds `picker_preview` benchmark group measuring "process spawn → all
preview tasks drained" for `wt switch`'s interactive picker.
- Introduces `WORKTRUNK_PREVIEW_BENCH=1`, an early-exit gate inside
`handle_picker` that runs the full prelude (collect, speculative spawn,
skeleton, initial + deferred precompute, `orchestrator.wait_for_idle()`)
and returns before skim launches or any JSON / stderr I/O. Shares the
dry-run path; behavior with the env var unset is unchanged.
- Closes the coverage gap behind #2662 / #2683 / #2685 / #2704, which
were tuned against `wt list` as a proxy because no direct picker
measurement existed.

## Why this measurement

Picker submits one preview-compute task per row to the global rayon
pool. The user-visible quantity to optimize is the responsiveness window
between picker launch and "all previews ready" (j/k navigation hits
cached content). Option 1 from the task — headless wall clock to drain —
is the cleanest measurable proxy and avoids the PTY route, which hits
the documented nextest/SIGTTOU pain on `shell-integration-tests`.
PTY-driven first-interactive-ready can be a follow-up.

## Variants

- `picker_preview/warm/typical-8`
- `picker_preview/cold/typical-8`

Cold uses `BatchSize::PerIteration` (not `SmallInput`): `SmallInput`
calls `setup` for an entire batch up front and then runs timed routines
back-to-back, so only the first iter in each batch is genuinely cold —
the rest hit a freshly populated `.git/wt/cache/`. `PerIteration`
invalidates immediately before every measured iteration; setup is far
cheaper than `wt switch`, so per-iter `Instant::now` doesn't dominate.

`sample_size(10)` + `measurement_time(35s)` per #2685's lead — slow
benches don't benefit from the default 30 samples.

`cfg(unix)`-gated with a no-op `main` on Windows; the picker is
Unix-only and `wt switch` (no args) hits the unavailable path before the
env var is consulted.

## Sample run

```
picker_preview/warm/typical-8   time:   [185.62 ms 191.72 ms 200.77 ms]
picker_preview/cold/typical-8   time:   [209.34 ms 226.23 ms 239.29 ms]
```

## Test plan

- [x] `cargo bench --bench picker_preview` runs cleanly on both variants
- [x] `cargo run -- hook pre-merge --yes` — 3667 tests pass
- [x] New `test_picker_preview_bench_produces_no_output` asserts
`WORKTRUNK_PREVIEW_BENCH=1` keeps stdout/stderr empty (covers the
env-gated branch, locks the no-I/O contract)
- [x] Smoke test: `wt switch` with `WORKTRUNK_PREVIEW_BENCH` unset still
hits the TTY error path (user-visible behavior unchanged)
- [x] Smoke test: `WORKTRUNK_PICKER_DRY_RUN=1` still emits the cache
JSON dump (regression check)
- [x] `/review-codex` pass clean after iterating on three findings
(packed-refs fix already on `main` via #2697 once branch was rebased;
`BatchSize::PerIteration` for true per-iter invalidation; `cfg(unix)`
gate for Windows)

> _This was written by Claude Code on behalf of Maximilian Roos_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nightly tests failed

2 participants