t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Reopening the Changes panel shows a stale diff

Open nbrosei opened this issue 1 month ago • 1 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

Not sure

Steps to reproduce

  1. Open a thread and open the Changes panel. Wait for the diff to load.
  2. Close the panel.
  3. Without leaving the T3 Code window, change a file in the workspace, for example echo test >> README.md in the integrated terminal.
  4. Reopen the Changes panel within 5 minutes.

Expected behavior

Opening the panel refreshes the diff and shows the new change.

Actual behavior

The panel shows the diff from step 1 and does not show the new change. It updates only after the refresh button, or after the window loses and regains focus.

Likely cause (source inspection): the review.getDiffPreview query atom is kept alive by its idle TTL (5 minutes) after the panel closes. Atom.swr's mount revalidation only runs when the atom is rebuilt, so reopening within the TTL reuses the cached preview. While the panel is closed, DiffPanel's window-focus and workspace-mutation refreshes are not mounted, so nothing marks the preview as outdated. Calling refreshBranchDiffPreview() once when the panel mounts fixes it.

This doesn't look like a performance trade-off: the query is configured with a 5 s stale time and revalidateOnMount: true, and the panel already refreshes on every window focus. Reopening the panel should follow the same stale-while-revalidate rule.

Impact

Minor bug or occasional failure

Version or commit

main @ 7ac952c630

Environment

macOS 26.7.1 (arm64), desktop app 0.0.46-nightly.20261014.3105

Logs or stack traces


Screenshots, recordings, or supporting files

No response

Workaround

Click the refresh button in the diff panel, or switch to another window and back.

nbrosei avatar Oct 14 '26 18:10 nbrosei

[!NOTE] Grok responding on behalf of Julius.

Confirmed on main. This is a bug, not a caching trade-off.

  • review.diffPreview (packages/client-runtime/src/state/review.ts) sets staleTimeMs: 5_000. The shared query factory (runtime.ts) wraps it in Atom.swr({ revalidateOnMount: true }) plus Atom.setIdleTTL with a 5-minute default.
  • Atom.swr only checks staleness when the atom is built. If you reopen the panel inside the idle TTL, the atom is still alive, nothing rebuilds it, and the cached preview comes back with no revalidation, even though the 5 s stale time has long passed.
  • DiffPanel's window-focus listener and useWorkspaceMutationRefresh only run while the panel is mounted, so edits made while it's closed are never seen.

So the 5 s stale time and #8803 (keeping the right panel synced with edits) both say the panel should revalidate when it's reopened. Your suggested fix, calling refreshBranchDiffPreview() once on mount when canRefreshGitDiff is true, is a good scope. A small PR is welcome. Please check it against open #17886 so the refresh doesn't bring back the loading-skeleton flash. Related: #19530 (Changes row totals).

Workaround for now: the refresh button, or switch windows and come back.

juliusmarminge avatar Oct 14 '26 18:10 juliusmarminge