Skip to content

fix(diff,review): track DiffDocState revisions in plugin deps and harden row bounds - #2570

Merged
Hona merged 1 commit into
devfrom
fix/2562-diff-file-bar-oob-panic
Dec 6, 2026
Merged

Hona merged 1 commit into
devfrom
fix/2562-diff-file-bar-oob-panic

Conversation

@Hona

@Hona Hona commented Dec 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Root cause: Clicking a diff file header bar (DiffViewer::file_header) calls DiffDocState::set_collapsed, which rebuilds rows/keys (shrinking single-file preview or 1-file diffs from N rows to 1 row, [DiffRow::File(f)]) and bumps rev/keys_rev without bumping SessionReview::stamp. Because native::diff::version (Dep::Diff) omitted diffs.keys_rev() and diffs.rev(), both side-region's region_with and surfaces::render_opt_lazy's memo_with_hash returned the cached El tree with the stale virtual_rows count and virtual_rows_version. Rune's virtualizer then invoked Inner::row(s, 1) against the 1-element st.rows slice, panicking at crates/opencode-code-view/src/diff/view.rs:370:24 (index out of bounds: the len is 1 but the index is 1).
  • Sibling gaps fixed: The same stale-dependency pattern affected fold-separator reveals (DiffDocState::reveal), scroll_to_line auto-expand, offline text_failed, plugin custom diffs (native::custom_diff::version / watched_stamp for Dep::CustomDiff), and unwrapped narrow review diffs (native::diff::narrow_version for Dep::NarrowReview, now also zero-alloc).
  • State invariants & bounds safety: Clamped visible_rows to 0..rows.len() in rebuild and set_visible_rows, cleared sticky() for collapsed or off-preview files, skipped off-preview file_rows entries in scroll_to_file (which can equal rows.len()), guarded st.files().get(f) in number_cell drag and code_cell touch-tap handlers, and used .get(i) in row_keys / Inner::row (matching native::tree).

Changes

  • crates/opencode-code-view/src/diff/state.rs: expose rev() / keys_rev(); clamp visible_rows in rebuild and set_visible_rows; use .get() for self.nav; guard sticky() against collapsed, off-preview, or past-end state.
  • crates/opencode-code-view/src/diff/nav.rs: guard scroll_to_file against off-preview files and file_rows[file] >= rows.len().
  • crates/opencode-code-view/src/diff/view.rs: use .get(i) in row_keys and Inner::row with stale-key / empty-El fallbacks.
  • crates/opencode-code-view/src/diff/chrome.rs: use st.files().get(f) in number_cell::on_drag and code_cell::on_background_press_tx.
  • features/review/src/mobile.rs: expose NarrowReview::open_diffs.
  • apps/desktop/src/plugin_host/native/diff.rs: include diffs.keys_rev() and diffs.rev() in DiffVersion / version (keeping .0 as sr.stamp for Diff.Changed); hash sr.stamp and each open narrow diff's (path, keys_rev, rev) in narrow_version.
  • apps/desktop/src/plugin_host/native/custom_diff.rs: include diffs.keys_rev() and diffs.rev() in version and watched_stamp.

Verification

  • pwsh -NoProfile -File scripts/guardrails.ps1 passed 12/12 (92/94 effective App fields, all touched files <= 800 lines).
  • Full cross-platform build checks delegated to PR CI (no automated tests per repo rule).

Fixes #2562
Reported by @RUBisco0211

@Hona
Hona merged commit 47d073d into dev Dec 6, 2026
8 checks passed
@Hona
Hona deleted the fix/2562-diff-file-bar-oob-panic branch December 6, 2026 06:34
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.

diff: clicking the file bar panics with index out of bounds and quits Rune

1 participant