Skip to content

Restored-tab disk re-check can't loop or raise a false conflict; drop test-only editor-state guard - #31250

Merged
nwparker merged 5 commits into
mainfrom
nwparker/review-followups
Oct 20, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/review-followups

Conversation

@nwparker

@nwparker nwparker commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​134 $\color{#cf222e}{\Huge{\mathbf{−}}}$​64 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​70
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31 $\color{#cf222e}{\Huge{\mathbf{−}}}$​47 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16

ELI5

Three small leftovers from the review of the watcher and safe-save PRs (#31216): delete a check that only existed for tests, import a helper from where it lives, and stop a background file re-check from either looping forever or crying wolf.

What Changed

  • Restored-tab re-check no longer loops or raises a false conflict. When a reopened tab with unsaved edits is checked against disk, each newer check request used to restart the read, with no limit. On a slow SSH file under repeated reconnects, that could chase forever. Now a read that was overtaken by a newer request is discarded (it never decides anything), and further overlapping requests back off (2 s more each time, up to 15 s, one timer per tab) before a fresh read. The fresh read is judged normally: matches the version you loaded → cleared; differs → "changed on disk" banner. Only real read failures count toward giving up, as before.
  • isWholeEditorState removed. It guarded production code against partial stores that only tests passed. Callers now take the real AppState; seven test files build full states from createTestStore() (which also removed 24 as never casts).
  • getDiskBaselineSignature is imported from src/shared/disk-baseline-signature.ts directly; the re-export through diff-content-signature.ts is gone.

Why

The first version of the re-check fix capped overtaken reads and gave up at the cap. GPT's review caught that this turned an unchanged file into a false conflict and left autosave paused. Accepting the last read at the cap was also wrong, since that read may predate the newest request. Separating "overtaken" from "failed" is the smallest change that never infers a disk change from request churn and still can't loop.

Linked Issue

Follow-up to #31216.

Visual Proof

N/A: no layout change. The only behaviour change (no false banner, bounded re-reads) is covered by a regression test.

Testing

  • pnpm tc, pnpm run check:code-quality:changed, oxfmt --check pass.

  • Editor, hooks, lib, store and runtime tests pass (2048 files / 18,629 tests on the first commit; editor + hooks 556 files / 4,241 tests after the re-check fix).

  • New regression test: 45 overlapping checks (more than the 40-attempt cap) stay pending with no banner; the final fresh read clears when it matches and shows the banner when it differs. Existing test still covers giving up after repeated read failures.

  • remote-snapshot-alt-screen-host-chain.test.ts times out on this machine with or without this change.

  • Not manually tested in the app; macOS only.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

No wire or persisted-state change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

nwparker and others added 3 commits October 20, 2026 15:14
…xport; bound superseded restore re-reads

- Remove isWholeEditorState; its callers take the real AppState. Tests that
  mocked partial stores now build full states from createTestStore.
- Import getDiskBaselineSignature from shared/disk-baseline-signature
  directly and delete the re-export from diff-content-signature.ts.
- Restored-tab conflict scan: count superseded re-reads toward
  MAX_VERIFY_ATTEMPTS, so a read slower than the re-verify interval gives up
  with the conflict banner instead of looping forever. Adds a regression test.

Co-Authored-By: Claude <[email protected]>
… of giving up

A matching read at the cap cleared nothing and showed a false changed-on-disk
banner; it now resolves like any read. Only read failures give up.

Co-Authored-By: Claude <[email protected]>
…ng them

A superseded read may predate the newer check, so it never resolves the
verification, even at the attempt cap. Overlapping checks now delay the next
fresh read (bounded, one timer per tab) and keep verification pending; only
failed reads count toward giving up.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6fa85543-7811-48d5-8110-116dab17e6c1
📥 Commits

Reviewing files that changed from the base of the PR and between 1507ac9 and 6d28afa.

📒 Files selected for processing: 1
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.recheck.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

📝 Walkthrough

The editor now imports getDiskBaselineSignature from the shared module. Editor disk-change and reload checks no longer require the isWholeEditorState guard. Restored-tab verification delays retries for superseded reads, increases the delay up to a cap, and clears tracking after verification succeeds or gives up. Tests use complete test-store state and typed file fixtures.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 6d28a

Reopened tabs can incur an unnecessarily long disk-verification delay in a narrow retry scenario; this is bounded but should be tracked for follow-up.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 21 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the primary behavior fix and the related removal of the test-only editor-state guard.
Description check Passed The description covers the required change summary, rationale, testing, visual proof, scope, and checklist. It documents test limitations and references issue #31216, although the template requests a …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description covers the required change summary, rationale, testing, visual proof, scope, and checklist. It documents test limitations and references issue #31216, although the template requests a direct issue link.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f9fe3a7-476c-403e-a5a6-d8ef88b5d450
📥 Commits

Reviewing files that changed from the base of the PR and between f812c67 and 1507ac9.

📒 Files selected for processing: 23
  • src/renderer/src/components/editor/ExternalFileChangeBanner.test.tsx
  • src/renderer/src/components/editor/ExternalFileChangeBanner.tsx
  • src/renderer/src/components/editor/diff-content-signature.ts
  • src/renderer/src/components/editor/editor-changed-on-disk-mark.ts
  • src/renderer/src/components/editor/editor-clean-tab-disk-baseline.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.recheck.test.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.test.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/editor-stale-mount-guard.ts
  • src/renderer/src/components/editor/editor-untitled-dont-save-dialogs.test.tsx
  • src/renderer/src/components/editor/editor-untitled-save-lifecycle.test.ts
  • src/renderer/src/components/editor/use-monaco-editor-mount.cursor-owner.test.tsx
  • src/renderer/src/components/editor/useEditorPanelContentState.test.tsx
  • src/renderer/src/components/editor/useEditorPanelExternalContentEvents.ts
  • src/renderer/src/components/editor/useEditorPanelVisibilityContentState.test.tsx
  • src/renderer/src/hooks/editor-external-watch-disk-verification.ts
  • src/renderer/src/hooks/useEditorExternalWatch-self-move.test.ts
  • src/renderer/src/hooks/useEditorExternalWatch-switch-back.test.tsx
  • src/renderer/src/hooks/useEditorExternalWatch.test.ts
  • src/renderer/src/lib/execute-open-editor-path-move.test.ts
  • src/renderer/src/store/slices/editor/tabs/untitled-file-cleanup.ts
💤 Files with no reviewable changes: 2
  • src/renderer/src/components/editor/diff-content-signature.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

})
// Why back off, not cap: a superseded answer may predate the newer check, so it never resolves; churn only delays the fresh read.
const superseded = (supersededReadsByFileId.get(fileId) ?? 0) + 1
supersededReadsByFileId.set(fileId, superseded)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Clear superseded-read counts when a tab closes.

If a tab closes during a delayed retry, the timer can finish without removing its entry from supersededReadsByFileId. If the same file ID is reopened and another read is superseded, verification inherits the old count and can wait 15 seconds instead of starting with the initial retry delay. Clear the count on closure and other terminal paths that do not reach the accepted-read or give-up cleanup.

nwparker and others added 2 commits October 20, 2026 15:51
…ping-check tests

After #31196 a server's tab is no longer keyed by its path, so these tests
flagged a tab that does not exist and no read was ever issued.

Co-Authored-By: Claude <[email protected]>
@nwparker
nwparker merged commit b5f97ca into main Oct 20, 2026
33 checks passed
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