Skip to content

refactor(list): drop CommitDetailsTask and the per-SHA fallback - #2379

Merged
max-sixty merged 4 commits into
mainfrom
drop-commit-details-task
Apr 22, 2026
Merged

max-sixty merged 4 commits into
mainfrom
drop-commit-details-task

Conversation

@max-sixty

@max-sixty max-sixty commented Apr 22, 2026 •

Copy link
Copy Markdown
Owner

Now that the pre-skeleton commit_details_many batch fetches (timestamp, subject) for every item SHA (PR #2369), CommitDetailsTask has been a pure DashMap lookup wrapped in rayon spawn + channel send + drain match — pure overhead per item. Drop the task type and populate ListItem.commit from the batch map directly in the post-skeleton phase.

Scope

  • Remove CommitDetailsTask / TaskKind::CommitDetails / TaskResult::CommitDetails and their drain + dispatch + seeding plumbing.
  • Sort helpers (sort_by_timestamp_desc_with_cache, sort_worktrees_with_cache) now accept the full &HashMap<String, (i64, String)> — single canonical source.
  • Post-skeleton loop writes item.commit from the batch map directly. populate_item() (the statusline single-item entry point) also does its own one-SHA commit_details_many lookup so wt statusline --format=json keeps reporting real commit.message / commit.timestamp.
  • Drop the old silent fallback: on batch failure, the task used to fork git log -1 per-SHA via Repository::commit_details(). The collect() path now prints a loud warning on batch failure and renders placeholders for that run. populate_item() is silent on failure — the statusline has no UI for warnings.
  • Dead-code cleanup: Repository::commit_details() (singular), the RepoCache::commit_details DashMap field, the cache-priming side effect inside commit_details_many, and the circular commit_details_and_many_store_identical_cache_entries test.

What stays

  • Batch parser tests (spaces, multibyte UTF-8, duplicate SHAs, empty input, unknown-SHA error propagation) still cover commit_details_many directly.
  • Prunable worktrees are still skipped so Age/Message render · — preserves the old task-queue UX for items whose directory is missing from disk.

What's unchanged

  • Skeleton latency: no pre-skeleton additions.
  • wt list display: all snapshot tests pass.
  • batch_ahead_behind / ahead_behind() fallback: kept — that's version-compat for git < 2.36, not error-recovery.

Codecov

codecov/patch reports 90.90% — below the 96.63% target. The ~5 uncovered lines are the "fail loudly" batch-error warning path in collect() and the bail! for malformed git output in commit_details_many. Driving those from an integration test would require a pathological repo setup; the unit-test commit_details_many_fails_loudly_on_unknown_sha pins the contract the warning path depends on. Merging with explicit approval.

This was written by Claude Code on behalf of max-sixty

After PR #2369 the pre-skeleton `commit_details_many` batch fetches
`(timestamp, subject)` for every item SHA, so `CommitDetailsTask` was
a pure DashMap lookup wrapped in a rayon spawn + channel send + drain
match. Remove the task type entirely and populate `ListItem.commit`
from the batch map directly in the post-skeleton phase (after the
`rayon::scope` that runs `switch_previous` / `integration_target` /
fsmonitor starts, before the worker thread).

The old path also hid a silent fallback: on batch failure, the task
forked `git log -1` per-SHA via `Repository::commit_details()` — most
SHAs recovered, per-SHA errors landed in the "Some git operations
failed" warning. I dropped that path too: `commit_details_many` is
now the single canonical fetch, a failure is surfaced as a loud
warning, and Age/Message cells render placeholders for that run.
Self-heals next invocation.

Dead code cleanup follows: `Repository::commit_details()` (singular),
the `RepoCache::commit_details` DashMap field, the cache-priming side
effect inside `commit_details_many`, and the circular
`commit_details_and_many_store_identical_cache_entries` test are all
removed. The batch parser tests (spaces, multibyte UTF-8, duplicate
SHAs, empty input) stay — they cover the batch directly, not the
now-deleted cache path.

Skeleton latency is unchanged (no pre-skeleton additions). `wt list`
display is unchanged (snapshot tests pass). Prunable worktrees are
still skipped to preserve the old task-queue UX (`·` in Age/Message
for items whose directory is missing from disk).

> _This was written by Claude Code on behalf of max-sixty_

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One correctness concern: wt list statusline --format=json now returns commit.message = "" and commit.timestamp = 0 instead of the real values.

Reproduced against this PR vs main in a fresh single-commit repo:

# on main
"commit": {
  "sha": "4c5ae53...",
  "short_sha": "4c5ae53",
  "message": "Initial commit with a message",
  "timestamp": 1776825875
}

# on this PR (same repo, same commit)
"commit": {
  "sha": "4c5ae53...",
  "short_sha": "4c5ae53",
  "message": "",
  "timestamp": 0
}

Root cause: populate_item() in src/commands/list/collect/mod.rs (the statusline's entry point) previously relied on CommitDetailsTask — through work_items_for_worktree() — to populate item.commit. Removing the task drops that population for the single-item path: populate_item never calls commit_details_many, so item.commit stays None and JsonCommit in json_output.rs:258-263 falls through to "" / 0.

The main collect() path is fine because it calls commit_details_many directly and populates items from the map. The fix is symmetric — have populate_item() do a one-SHA commit_details_many(&[&item.head]) lookup (skipping null OIDs) and assign item.commit before / after the drain.

No existing test caught this because the statusline JSON tests (tests/integration_tests/statusline.rs around test_statusline_json_*) assert on commit.sha / short_sha but not message / timestamp. Worth adding an assertion on those two fields while fixing.

Comment thread src/commands/list/collect/mod.rs Resolved
`populate_item()` (the statusline JSON entry point) used to rely on the
removed `CommitDetailsTask` to fill `item.commit`. With the task gone,
`commit.message` and `commit.timestamp` fell through to `""` / `0` in
`wt list statusline --format=json`. The main `collect()` path is fine
because it batch-fetches and populates directly; only the single-item
path was orphaned.

Fetch the one SHA via `commit_details_many` in `populate_item()` before
spawning the other tasks, skipping null OIDs and prunable worktrees to
match `collect()`. Extend `test_statusline_json_basic` to assert on
`message` and `timestamp` so this regression is caught in the future.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Confirmed the regression and pushed 01bde4d.

populate_item() now fetches commit details for the single SHA via commit_details_many(&[&item.head]) before spawning the other tasks, skipping null OIDs and prunable worktrees to match collect(). test_statusline_json_basic now asserts on commit.message (non-empty) and commit.timestamp (> 0) so future regressions on this path get caught.

Collapse the post-skeleton batch-error handling in `collect()` from a
match to an `unwrap_or_else` closure, and drop the match-based Err arm
in `populate_item()` — statusline has no UI for warnings, so silent
fall-through to placeholder cells is the right behavior.

Add a unit test that forces `commit_details_many` to fail with an
unknown SHA, pinning the error-propagation contract the main `collect()`
path depends on.

> _This was written by Claude Code on behalf of max-sixty_

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes Apr 22, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov/patch shows 90.90% of the diff covered (target 96.63%). The uncovered lines are most likely the new unwrap_or_else error closure in collect():

let commit_details_map = repo.commit_details_many(&all_shas).unwrap_or_else(|err| {
    eprintln!(
        "{}",
        warning_message(cformat!("Failed to batch-fetch commit details: {err}"))
    );
    std::collections::HashMap::new()
});

On main, this call uses .unwrap_or_default(), so the warning-emitting closure is entirely new code from codecov's perspective. The new commit_details_many_fails_loudly_on_unknown_sha test only pins the Err return from commit_details_many itself — it doesn't exercise the collect()-level handler that emits the user-facing warning.

Options:

  • Add an integration test that runs wt list against a repo whose refs point to an unreachable SHA (e.g., a worktree whose HEAD has been garbage-collected) and asserts the Failed to batch-fetch commit details warning reaches stderr.
  • Fall back to .unwrap_or_default() and document the silent fallback, matching the pre-PR behavior.

Happy to push either fix. Dismissing the approval until the coverage gap is closed.

@worktrunk-bot
worktrunk-bot dismissed their stale review April 22, 2026 03:29

CI failed — codecov/patch coverage below target (90.90% vs 96.63%); see follow-up comment

The collect()-level unwrap_or_else closure that emits the
"Failed to batch-fetch commit details" warning had no test — codecov
flagged the four lines as uncovered. Drive it end-to-end: corrupt a
detached worktree's HEAD file to a non-null unresolvable SHA (the
batch filters out NULL_OID, so a non-null invalid SHA is needed to
reach commit_details_many and fail the whole batch), drop the
dangling branch so for-each-ref refs/heads/ still succeeds, then
assert on the wt list snapshot.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Closed the coverage gap in 24f95d4. Added test_list_warns_when_commit_details_batch_fails — corrupts a detached worktree's HEAD file to a non-null invalid SHA (non-null is required because collect() filters NULL_OID out of the batch), drops the dangling branch so for-each-ref refs/heads/ still succeeds, then snapshots the wt list output. The snapshot pins the Failed to batch-fetch commit details: fatal: bad object 0000000000000000000000000000000000000001 warning on stderr, which covers the four lines codecov flagged.

@max-sixty
max-sixty merged commit 390b025 into main Apr 22, 2026
25 checks passed
@max-sixty
max-sixty deleted the drop-commit-details-task branch April 22, 2026 14:58
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.

2 participants