Skip to content

Preserve session diff availability across refreshes and forks#237

Merged
andagaev merged 1 commit into
mainfrom
preserve-diff
Jul 24, 2026
Merged

Preserve session diff availability across refreshes and forks#237
andagaev merged 1 commit into
mainfrom
preserve-diff

Conversation

@andagaev

@andagaev andagaev commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator
  • Persist explicit empty, present, and unknown states while retaining known line totals when refreshes fail.
  • Reset source-derived diff metadata on forks and refresh the new worktree state.
  • Keep binary-only, metadata-only, and diagnostic diffs available through chat shortcuts and documentation.

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces a three-state SessionDiffState enum (Unknown, Empty, Present) to preserve diff availability across session refreshes and forks, replacing the previous binary has/doesn't-have model.

  • Persistence layer: Adds has_diff INTEGER column (NULL=Unknown, 0=Empty, 1=Present) via migration 061, with conservative backfill that leaves zero-line legacy rows as NULL (Unknown) to preserve access to binary/rename-only diffs. Fork reset and new session creation both initialize to NULL; mark_session_diff_unknown uses a no-op guard (AND has_diff IS NOT NULL) to avoid unnecessary WAL writes.
  • In-memory state & UI: should_show_diff() returns true for both Unknown and Present, so the d: Diff shortcut remains visible when diff status is uncertain. Failed refreshes retain stale line totals but flip diff_state to Unknown, and all response-parser SessionStats constructions correctly supply diff_state: SessionDiffState::Unknown for token-only contexts.

Confidence Score: 5/5

Safe to merge — the three-state diff model is correctly implemented end-to-end with no blocking issues.

No P0 or P1 findings. The Unknown/Empty/Present model is consistently applied across the SQLite schema, fork SQL, DB read/write helpers, in-memory state, and UI visibility logic. Migration 061 conservatively handles binary/metadata-only diffs by leaving zero-line legacy rows as NULL rather than 0. The optimistic WHERE clause in update_session_diff_stats correctly uses SQLite's null-safe IS NOT operator, and mark_session_diff_unknown is a no-op when the state is already Unknown. Fork and new-session initialization both start at Unknown so the diff shortcut remains accessible until the first real refresh.

No files require special attention.

Reviews (12): Last reviewed commit: "Preserve session diff availability acros..." | Re-trigger Greptile

Comment thread crates/agentty/migrations/062_backfill_session_diff_presence.sql Outdated
@andagaev
andagaev force-pushed the preserve-diff branch 2 times, most recently from 210aa87 to 016adde Compare July 21, 2026 15:11
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@andagaev
andagaev force-pushed the preserve-diff branch 6 times, most recently from 9219acb to cd2fa4d Compare July 23, 2026 07:15
@andagaev andagaev changed the title Preserve session diff availability across refreshes Preserve session diff availability across refreshes and forks Jul 23, 2026
@andagaev
andagaev force-pushed the preserve-diff branch 2 times, most recently from fc16796 to 99f4f55 Compare July 23, 2026 07:51
- Track explicit empty, present, and unknown states while retaining known line totals when refreshes fail.
- Reset source-derived diff metadata on forks and refresh the new worktree state.
- Keep binary-only, metadata-only, and diagnostic diffs available through chat shortcuts and documentation.
@sonarqubecloud

Copy link
Copy Markdown

@andagaev
andagaev marked this pull request as ready for review July 24, 2026 05:25
@andagaev
andagaev requested a review from minev-dev as a code owner July 24, 2026 05:25
@andagaev
andagaev merged commit f430bfa into main Jul 24, 2026
20 checks passed
@andagaev
andagaev deleted the preserve-diff branch July 24, 2026 05:26
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.

1 participant