Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(picker): skip disk cache write when `git log` fails (#2651)

Worktrunk Bot777070fc7ccb
diff --git a/src/commands/picker/items.rs b/src/commands/picker/items.rs
index 216345a73..c6c75a160 100644
--- a/src/commands/picker/items.rs
+++ b/src/commands/picker/items.rs
@@ -444,11 +444,12 @@ impl WorktreeSkimItem {
/// key out of `main`'s SHA — a `git fetch` advancing `origin/main`
/// doesn't invalidate any entry — while preserving correctness as
/// `main` and wall-clock advance.
- /// Render the Log preview and report whether the disk cache was hit.
- /// The orchestrator uses the flag to schedule a background refresh —
- /// see [`Self::refresh_log_preview`] and the `LogCacheEntry`
- /// docstring for why decorations baked into `raw_log` need
- /// refreshing even though the cache key is correct.
+ ///
+ /// Returns the rendered preview and a flag for whether the disk cache
+ /// was hit. The orchestrator uses the flag to schedule a background
+ /// refresh — see [`Self::refresh_log_preview`] and the `LogCacheEntry`
+ /// docstring for why decorations baked into `raw_log` need refreshing
+ /// even though the cache key is correct.
pub(super) fn compute_log_preview(
repo: &Repository,
item: &ListItem,
@@ -544,16 +545,19 @@ impl WorktreeSkimItem {
preview_cache::read_log(repo, head, width, height)
};
let was_disk_hit = cached.is_some();
- // On `git log` failure (effectively unreachable here — merge-base
- // already validated `head` upstream), fall back to a default
- // entry. `process_log_with_dimming` + `format_log_output` handle
- // the empty `raw_log` gracefully and produce empty output, the
- // same effective behavior as the prior explicit early return.
+ // On `git log` failure (effectively unreachable — merge-base
+ // already validated `head`), `unwrap_or_default()` yields an
+ // empty entry which `process_log_with_dimming` + `format_log_output`
+ // render as empty output below. We deliberately skip the disk
+ // write in that case: persisting an empty `LogCacheEntry` would
+ // poison the SHA-keyed cache so a single transient failure
+ // suppresses the preview indefinitely.
let entry = cached.unwrap_or_else(|| {
- let fresh = Self::compute_log_raw_and_stats(repo, head, log_limit, show_timestamps)
- .unwrap_or_default();
- preview_cache::write_log(repo, head, width, height, &fresh);
- fresh
+ let fresh = Self::compute_log_raw_and_stats(repo, head, log_limit, show_timestamps);
+ if let Some(ref f) = fresh {
+ preview_cache::write_log(repo, head, width, height, f);
+ }
+ fresh.unwrap_or_default()
});
let (processed, _hashes) =