Skip to content

🐛 fix(history): evict dead repos first, then the largest repo's oldest (#713) - #716

Merged
kbrdn1 merged 11 commits into
devfrom
fix/#713-undo-journal-eviction
Nov 12, 2026
Merged

kbrdn1 merged 11 commits into
devfrom
fix/#713-undo-journal-eviction

Conversation

@kbrdn1

@kbrdn1 kbrdn1 commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Description

The undo journal (history.toml) is capped at 100 entries across all repos and dropped the oldest one on overflow, whatever its repo. Entries that can never be undone (a consumer's test suite removing worktrees in temporary repos) pushed out real, older ones, and one busy repo could flush another repo's history. On overflow the journal now drops the oldest entry whose repo is confirmed gone, otherwise the oldest entry of the repo holding the most entries. The variables that keep a tool's tests off the user's state are documented for consumers.

Closes #713

Type of change

  • ✨ Feature (new functionality)
  • 🐛 Fix (bug fix)
  • 🚑️ Hotfix (critical production fix)
  • ♻️ Refactor (no behaviour change)
  • 📝 Docs
  • ✅ Tests
  • ⚡ Perf
  • 🔧 Chore / CI / build

Changes

  • src/history.rs: Journal::append picks the evicted entry through eviction_index: (1) the oldest entry whose repo_root is confirmed missing (try_exists() is Ok(false); a root that cannot be checked counts as present), (2) otherwise the oldest entry of the repo holding the most entries. Still one entry per append and only on overflow, so a repo on an unmounted disk keeps its entries until the room is needed. For a single-repo journal, (2) is plain oldest-first, as before.
  • tests/history_tests.rs: three tests, each red on origin/dev for its own assertion (gone entry evicted before an older live one; one gone entry per overflow, not all; a flooding repo pays before a quiet one). The rotation test now creates its repo dir so it still covers the all-live path.
  • docs/5.integrations/4.daemon-consumers.md (EN + FR): a section listing what isolates gwm when a consumer's tests run it: GWM_HISTORY_FILE, GWM_TRUST_LEDGER, GWM_NO_GLOBAL_CONFIG, XDG_CONFIG_HOME (the user's aliases.toml is read on every invocation and GWM_NO_GLOBAL_CONFIG does not cover it), GWM_AGENTS_HOME, plus GWM_ALLOW_BOOTSTRAP, GWM_GH / GWM_GLAB and the daemon's --socket.
  • docs/3.cli/1.reference.md (EN + FR): the gwm history paragraph states the new eviction order instead of "the oldest is dropped".
  • CHANGELOG.md: entry under [Unreleased] / Fixed.

Tests

  • cargo test passes locally (--no-fail-fast, 111 test result: ok, 0 failed)
  • cargo fmt --check passes
  • cargo clippy -- -D warnings passes (--all-targets)
  • New tests added under tests/ (TDD: a PR adding behaviour without tests is sent back)

Checklist

  • Branch follows <type>/#<issue>-<description>
  • Commits follow Gitmoji + Conventional Commits (see CONTRIBUTING.md)
  • CHANGELOG.md updated under ## [Unreleased]
  • README updated if CLI surface changed: no CLI surface change
  • examples/gwm.toml.example updated if config schema changed: no schema change
  • No unwrap() on user-facing paths (return GwmError instead)
  • No println! in TUI render code (status bar only)

Linked issues / docs

Notes for reviewers

  • Point 2 of [Bug]: undo journal evicts live entries before dead ones, and one repo can evict another's #713 (one repo evicting another's history) is handled by the "largest repo pays" rule rather than a per-repo cap: a per-repo cap would still let 30 repos overflow the global one, and a reserved floor needs a constant to pick. The rule is one HashMap count on overflow, and each of the two rules has its own red test.
  • Trade-off kept on purpose: under rule 2 a dormant repo keeps its old entries while the busy repo loses its oldest, even though an entry older than the gc prune window may already point at a pruned commit. Age is not a reliable proxy for that (gc may never have run), so the rule does not guess.
  • Out of scope: cleaning a journal that already holds dead entries. They go first now whenever room is needed, and gwm history --all shows them.
  • cargo audit is red on dev itself right now (RUSTSEC-2026-0459, RUSTSEC-2026-0486), independently of this diff; it is fixed in its own PR.

Three cases the oldest-first rule gets wrong: an entry whose repo is gone must go before an older live one, only one of them goes per overflow (a repo on an unmounted disk is missing, not gone), and a repo flooding the journal pays with its own entries before another repo loses its only one. The rotation test now creates its repo dir, so it keeps exercising the all-live path.
#713)

On overflow the journal dropped the oldest entry whatever its repo, so entries that can never be undone (temporary repos a consumer's tests removed worktrees in) pushed out real ones, and one busy repo could flush another's history. The evicted entry is now the oldest whose repo_root is confirmed missing (try_exists is Ok(false); an unreadable root counts as present), otherwise the oldest of the repo holding the most entries. Still one entry per append, nothing purged on write. A single-repo journal rotates exactly as before.
The daemon consumers page gains the variables a tool driving gwm from its test suite must set (GWM_HISTORY_FILE, GWM_TRUST_LEDGER, GWM_NO_GLOBAL_CONFIG, XDG_CONFIG_HOME for aliases.toml, GWM_AGENTS_HOME), in EN and FR. The gwm history reference states the new eviction order, and the changelog records the fix.
@kbrdn1 kbrdn1 added the fix Bug fix label Nov 12, 2026
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 53b8363e-c24e-4459-ba0b-ed51118f1adc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…he unverifiable root (#713)

Review of #716: the flooding test appended to the busy repo, which is also the largest, so a rule keyed on the appended entry's repo passed it. The quiet repo now overflows too and must cost the busy repo, not itself (killed that mutant). A unix-only test seals a repo's parent (mode 000) so try_exists errors: the entry must not be evicted as gone (killed a !exists() mutant). The module doc stops describing oldest-first rotation.
…e every one (#713)

A smaller repo that overflows takes from the largest until they are level; the rustdoc claimed a flooding repo pays before another loses anything, which only holds for the repo that is ahead.
…om, the parity limit (#713)

Review of #716. The default [worktree] base is {home}/cc-worktree/{repo}, which no GWM_* variable moves, so the recipe now gives the test repo a .gwm.toml that keeps worktrees in the scratch dir, as gwm's own suite does. A malformed aliases.toml prints a warning on every call rather than failing it. The global config.toml is written by the TUI's Settings and Keys panels, refused under GWM_NO_GLOBAL_CONFIG. The history reference and the changelog say repos end up with an even share at worst.
…r permission tests (#713)

Root ignores the mode bits, so the sealed root stays checkable and the precondition panicked. Same convention as tests/worktree_integration.rs: restore, print why, return.
…entry (#713)

Eviction runs from remove_verified_recording, inside gwm remove's point of no return; a journaled repo on a hung mount stalled it once per entry of that repo. The gone set is now computed over distinct repo roots.
The changelog links the consumers page by absolute URL (a repo-relative link 404s once the entry moves to changelogs/<version>.md). The history reference says a missing repo includes an unmounted disk. The isolation section no longer calls worktrees the only write no variable moves (the daemon socket is another, covered by --socket). The rustdoc's parity claim allows for a tie.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant