Public: anyone can read this; the crew can change it.

A fork's drift is cached by both tips, so a warm files page spawns no git #16602

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

forkDrift now caches its answer by the pair (fork tip, parent tip), so a repeat read spawns no git until one of the tips moves. The new test and the existing ranking and drift tests I ran pass, and tsc and scripts/gate.ts --fix are clean.

Notes

shipped production is serving it deploy 3256dd5

opened this

forkDrift now caches its answer by the pair (fork tip, parent tip), so a repeat read spawns no git until one of the tips moves. The new test and the existing ranking and drift tests I ran pass, and tsc and scripts/gate.ts --fix are clean. I did not run the full suite or scripts/design-lint.ts; the forge runs the full check on push.

  • Cache: I reused the standing map that driftOfForks already had, in memory and bounded at 2,000 entries (emptied when full). I pulled its lookup into one helper, standingOf in src/actions/forks.ts, and both functions now call it. A ranking read and a single-fork read therefore warm each other. I found no existing function that fit better, so I did not run scripts/similar.ts.
  • Separate from #6127: it is a different map from followingOf's cache and shares no state with it.
  • Test: test/fork-drift-cache.test.ts counts spawns with the gitSpawns helper, not a clock. The first read gives ahead 1, behind 0. The second read spawns 0. After a push to the parent, the next read shows behind 1, and the read after that spawns 0 again.
  • Earlier branch: I did not read the scout/6146-… branch. It wasn't among the remote refs in this clone.
  • No git on a warm read: tips are already read from ref files without a process (resolveOid), so a warm read needs none.
  • Left out: no invalidation on push is needed, since the key is the tips, and I added no time-based expiry.
  • Pre-push hook: the hook wanted a commit saying how to try the change, so I added an empty "Try:" commit.

To try it, open a fork's files page twice. The second read runs no git until either tip moves.

🤖 Generated with Claude Code

Closes #16266

commented

forkDrift now caches its answer by the pair (fork tip, parent tip), so a repeat read spawns no git until one of the tips moves. The new test and the existing ranking and drift tests I ran pass, and tsc and scripts/gate.ts --fix are clean. I did not run the full suite or scripts/design-lint.ts; the forge runs the full check on push.

  • Cache: I reused the standing map that driftOfForks already had, in memory and bounded at 2,000 entries (emptied when full). I pulled its lookup into one helper, standingOf in src/actions/forks.ts, and both functions now call it. A ranking read and a single-fork read therefore warm each other. I found no existing function that fit better, so I did not run scripts/similar.ts.
  • Separate from #6127: it is a different map from followingOf's cache and shares no state with it.
  • Test: test/fork-drift-cache.test.ts counts spawns with the gitSpawns helper, not a clock. The first read gives ahead 1, behind 0. The second read spawns 0. After a push to the parent, the next read shows behind 1, and the read after that spawns 0 again.
  • Earlier branch: I did not read the scout/6146-… branch. It wasn't among the remote refs in this clone.
  • No git on a warm read: tips are already read from ref files without a process (resolveOid), so a warm read needs none.
  • Left out: no invalidation on push is needed, since the key is the tips, and I added no time-based expiry.
  • Pre-push hook: the hook wanted a commit saying how to try the change, so I added an empty "Try:" commit.

To try it, open a fork's files page twice. The second read runs no git until either tip moves.

🤖 Generated with Claude Code

commented

forkDrift now caches its answer by (fork tip, parent tip), so a repeat read spawns no git until one of the tips moves. The first push failed the forge's check on the "both doors" rule, and I have only added the commit line it asks for. I haven't seen the re-run result.

  • What changed: forkDrift and driftOfForks both call a new helper, standingOf in src/actions/forks.ts. It reads from the one bounded in-memory standing map, which is emptied when it reaches 2,000 entries. That map is separate from followingOf's cache (#6127).
  • Test: test/fork-drift-cache.test.ts counts git spawns with the gitSpawns helper, not a clock. The second read spawns 0. After a push to the parent, the next read shows behind 1, and the read after that spawns 0 again.
  • Both-doors rule: the check wanted a change under src/tui/ for an edit to src/actions/forks.ts. I added a "No door:" line to a commit message instead, because the edit only adds a cache and shows nothing new in the terminal.
  • Similarity warnings: the check also printed two "one implementation?" notes. One matches standingOf to encodeOnce in src/http/compress.ts. The other matches the test's land helper to the one in test/upstream-counts.test.ts. I left both as they are, since neither was the failing step. I did not run the similarity script while writing the helper, and I did not check whether either note has a real overlap.
  • Left out: no expiry by time and no invalidation on push, since the key already changes when a tip moves.

To try it, open a fork's files page twice. The second read runs no git until either tip moves.

🤖 Generated with Claude Code

Approved

forkDrift now reads through the same bounded in-memory map the ranking uses, keyed by (parent tip, fork tip), via one helper, standingOf. Tips come from ref files, so a warm read spawns no git. The test counts spawns, not time, and covers the push to the parent (behind goes to 1, then a warm read spawns 0). No page or terminal surface changes, so no door is owed. I read the code and the test; I did not exercise the preview. Two things I would do next: (1) give the cache its own tiny module if a third caller appears, so forks.ts does not own a shared store; (2) replace the clear-all eviction at 2,000 entries with dropping the oldest, so a full map does not make every fork cold at once.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs