fix(web): open documents no longer reload after every agent command#32693

open9
main
fix/issue-32669
opened4d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 1d ago

Problem

An open Word, PowerPoint or other document/binary preview in the Files panel reloads and jumps back to its first page after every agent command and checkpoint, even when that file did not change. The document branch of FilePreviewPanel keyed AttachmentFilePreview on the thread-wide workspaceMutationId, which moves after every completed command, file change and checkpoint.

Reproduced on main @ 25bf84ab07 in the web app (fresh database, synthetic files): a 21-page report.docx scrolled to 2500px was torn down and reloaded at page 1 three times while the agent ran sleep 5; echo one and sleep 5; echo two (two commands plus the checkpoint), with the file untouched. A 400-row data.sqlite preview did the same on a single git status turn (scroll 966 → 0, twice).

Change

The document branch now goes through a small WorkspaceDocumentPreview that reads the server's fileRevision for the media-file asset with useAssetUrlState, the same way the video, audio, PDF and large-text previews already do, and remounts AttachmentFilePreview only when that revision (or the explicit refresh) changes.

  • An unchanged file stays mounted, keeping its page and scroll position.
  • A real edit gives a new revision, so the new bytes load.
  • While the revision is re-checked (including a reconnect, which reports Loading), the last revision is kept; the first open shows the loading state until the revision arrives, so the preview mounts once.
  • A failed mint (the file was deleted or moved) remounts so the preview shows its error.
  • Servers that report no fileRevision keep following workspaceMutationId as before. In a draft, recognized documents (served as draft-workspace-file) also keep following workspaceMutationId; draft unknown binaries are media-file assets and follow their file revision like any other.

Scope and approval

Fixes pingdotgg/t3code#32669

Triaged bug report; one-branch fix in apps/web/src/components/files/FilePreviewPanel.tsx plus its browser test. HTML, image and PDF previews are not touched.

Verification

Focused tests, apps/web/src/components/files/FilePreviewPanel.browser.test.tsx (workspace document previews):

  • keeps an unchanged document loaded when another workspace change lands: fails on main (an unchanged document re-minted its URL: expected "vi.fn()" to be called once, but got 2 times), passes here.
  • keeps an unchanged document mounted while its revision check reloads: guards the loading path.
  • reloads the document when its URL can no longer be minted: guards the deleted-file path.
  • loads the new bytes when the document itself changes: guards against never reloading.

At 359bba3d25 (main merged at d313b2aff3): vp run check:changed passes format, lint, knip, typecheck, tests and React Compiler. The server-without-fileRevision fallback and the draft transitions are checked by reading the code only; no test or capture drives them.

Evidence

Linux Chromium157; CSS1440×900,DPR2,font16px/100%,dark; Files maximized,explorer256px,preview1184px. R24:CSS900×900,light/dark,preview644px/900px. Synthetic fixtures,local isolated dev servers,free Replay invalidations; T3CODE_DEV_SEED=0. Before d313b2aff3; after 359bba3d25.

25/26 matrix rows have recordings; partial/unverified claims below prevent full-matrix sign-off. Logs sample every250ms. Log-clock times below are seconds after instrumentation; original video clocks differ. DiffT means channel delta>16, without normalization.

RowBefore
d313b2aff3
After
359bba3d25
Diff0DiffT
R02 ·1440×900 darkR02-before-a.png
R02-before.mp4
R02-before-log.json
R02-after-a.png
R02-after.mp4
R02-after-log.json
R02-diff0.pngR02-diff16.png
Word section20 → two unchanged-byte Replay turns/checkpoints. Video before0s→32.8s resets to section01; after0–36.2s stays20. Log before0.25→22.25s: identity1→6,scrollTop20368→0,checkpoints1→3; after0.26→30.75s: identity1→1,20368→20368,checkpoints1→3 (completions10.59/17.50s).
RowBefore
d313b2aff3
After
359bba3d25
Diff0DiffT
R03 ·1440×900 darkR03-before-a.png
R03-before.mp4
R03-before-log.json
R03-after-a.png
R03-after.mp4
R03-after-log.json
R03-diff0.pngR03-diff16.png
Slide2 → unchanged-byte Replay/checkpoint. Video before0s→9.1s resets to1; after0–45.8s stays2. Log before0.25→14.25s: identity1→5,scrollTop736→0,checkpoints5→6; after0.25→13.75s: identity1→1,736→736,checkpoints4→5. Supplemental R03-controls-after.mp4 / R03-controls-after-log.json: checkpoint then log47.6s Next3,49.8s Previous2; identity1 retained.
RowBefore
d313b2aff3
After
359bba3d25
Diff0DiffT
R04 ·1440×900 darkR04-recapture-before-a.png
R04-recapture-before.mp4
R04-recapture-before-log.json
R04-recapture-after-a.png
R04-recapture-after.mp4
R04-recapture-after-log.json
R04-recapture-diff0.pngR04-recapture-diff16.png
records400 rows101–150,scroll270/150 → unchanged-byte Replay/checkpoint. Before resets to categories by video~10s (remaining movie is a settled hold); after0–20.6s retains records. Log before0.25→229.25s: identity1→null,scroll270/150→null (one-row table has no sampled scroller),checkpoints6→7; after0.25→20.75s: identity1→1,270/150→270/150,checkpoints9→10. Original R04-before-log.json corroborates identity1→5 and270/150→0/0. Diff0 remains qualified by one unrelated chrome pixel.
RowWhat was shownRecording(s)Result
R01Uncached Word opens21pages,0–3.4sR01-after.mp4Partial: initial null-mutation boundary absent.
R05XLSX sheet2,F68,scroll1000/500,checkpoint18→19R05-readable-after.mp4Retained; action label O68 is incorrect; visible F68.
R06aRTF page2,125%,scrolled,checkpoint26→27R06a-scrolled-after.mp4Retained visually,iframeid1; numeric frame scroll unmeasured; rushed navigation unverified.
R06bOne-body ODT125%,scrolled,checkpoints11→13R06b-after.mp4Retained visually,iframeid1; numeric frame scroll unmeasured.
R07ODP slide2/focused frame,checkpoint13→14R07-after.mp4Retained,iframeid1.
R08EPUB chapter2/scroll,checkpoint14→15R08-after.mp4Retained visually,iframeid1.
R09ODS sheet2/vertical1000,checkpoint17→18R09-scrolled-after.mp4Retained; actual horizontal0 despite action label500.
R10Notebook25cells,cell24/scroll6310,saved text/image/HTMLR10-expanded-after.mp4Expanded state retained,checkpoint23→24,id1.
R11Archive nested text+image; log19–25.4s/26.6–32.7sR11-after.mp4Visual retention; Back/Parent usable; identity not sampled for image/root.
R12Scrolled font specimen,checkpoint22→23R12-after.mp4Retained,iframeid1; clipped first line excluded as typography proof.
R13Unknown binary,no-op then Save at log8.2sR13-after.mp4id1 retained; download360bytes matches synthetic SHA256(d7a0f51b…be7a9d).
R14Word A→B(~5s)→A(~57s); SQLite400→401(~32s)R14-word-after.mp4 R14-sqlite-after.mp4New/reverted bytes visible; Wordid1→2→3,SQLite1→3; Word still decoded from video.
R15Explicit Refresh: Word20→1; SQLite records/page101→categories; binary fallbackR15-word-after.mp4 R15-sqlite-after.mp4 R15-binary-after.mp4Recaptured with settled holds; Wordid1→2,scroll20368→0; binaryid1→2; original rushed clip rejected.
R16Local transport outage→reconnect; later editB→AR16-reconnect-after.mp4 R16-post-reconnect-edit-after.mp4Partial: starts/ends scroll0,id1→3; no remote/Loading/waiting retention proof.
R17Move open Word→unavailable error→restore/Try again(log24.6s)R17-after.mp4Real failure and recovery shown.
R18aCold missing file→mint error→recreate/Try againR18a-after.mp4Error/recovery shown; transient bands excluded from settled proof.
R18bAuthorized corrupt Office→renderer error→valid bytes/RefreshR18b-after.mp4Distinct error/recovery shown; transient bands excluded.
R19Legacy missing revision,null→m1→m2NoneUnverified: no compatibility harness/recording.
R20Real draft Word opens and Refresh resetsR20-real-draft-after.mp4Partial: same-draft mutations/first submission absent.
R21Real draft binary opens and Refresh remountsR21-real-draft-after.mp4Partial: exact mutations/edit/disposition not instrumented.
R22Draft same-basename A→B→A in different directoriesR22-file-identity-after.mp4Partial: second environment/thread/workspace/draft↔persisted absent.
R23NUL bad.txt remains honest text-fetch error through no-op/RefreshR23-after.mp4Partial: bad.csv and render/source controls absent.
R24900×900 light long-path error/ready; explorer toggle; dark→light Word; light fontR24-after.mp4 R24-theme-after.mp4Partial: theme retains Word20; resize visibly changes20→15; no font theme transition/splitter drag.

What else changed (every visible difference in the paired zero-threshold comparisons):

  • R02: section/page numbers01↔20 in heading and paragraphs; vertical content offset and preceding-page white strip. Header/explorer pixels match;165,135 changed pixels.
  • R03: counter1↔2,Previous disabled/enabled,title/bullet1↔2,and preceding-slide white strip/content position. Header/explorer match;66,638 changed pixels.
  • R04: table selector/categories↔records,page range/navigation state,1row/2columns↔400rows/16columns,headers/widths/cell text/borders/scroll positions/scrollbars,clipped edge cells,and populated↔empty viewport area. Original pair also changes Search caret/focus versus selector outline: not comparable. Recapture removes these rings but has one unrelated chrome pixel(2779,149),RGB31→30; Diff0 is still not a perfectly controlled comparison,2,004,614 changed pixels. Nothing was erased; DiffT suppresses that1-level pixel.

Unverified: R19; exact harness portions of R16/R20/R21; initial null boundaryR01; R06a navigation; remote/waiting/scroll retentionR16; full environment/thread/draft identityR22; CSV/controlsR23; resize reading-position retention and font theme transitionR24. R04 behavior is shown, but its strict zero-threshold comparison remains qualified. Scroll-boundary clipping, ellipsized paths, transient spinner/blank/stale frames and rejected originals are enumerated in capture-review.md. vp test run apps/web/src/components/files/FilePreviewPanel.browser.test.tsx:6/6 pass. The four revision tests cover unchanged/Loading/Failure/changed bytes; two cover Markdown tasks. These tests do not drive R19 legacy fallback or exact R16 waiting/R20–R21 draft transitions.

Drivers: instrument.js · preview-driver.js · export-log.js · capture-helpers.js · compare.py. Seeds: seed.py · extra-seed.py · mutate-fixture.py · identity-seed.py · long-odp.py · long-path.py · notebook-html.py · widen-sqlite.py · widen-xlsx.py. Method/fixtures: capture-protocol.md · catalog.json · synthetic-fixtures.zip. All recording logs/stills and verbatim ghdrop outputs: artifact-index.md. Both continuation servers stopped,own tab closed,before worktree removed,synthetic SQLite restored; after worktree clean. AI-assisted; verified with the tests and tools listed above.

Verification log
  • Review round 1 at 359bba3d25, two independent reviewers: no code defects found. One verdict MERGE; the other FIX_FIRST only for the then-missing recordings, now attached above.
  • Proof audit pass 2: retention, reload-on-edit, Refresh, error/recovery and first-open behaviour confirmed in the recordings, with every diff image recomputed. Open capture-quality notes: one rebuilt R02 frame differs from the delivered one inside the explorer-toggle icon (max 7/255); the R04 Diff0 retains one 1-level chrome pixel; several scrolled document stills clip text at the viewport edges.
  • Not checked: desktop (Electron) and mobile clients, a remote reconnect, a server without fileRevision.
  • CI green on 359bba3d25.

AI-assisted; verified with the tests and tools listed above.

🤖 Generated with Claude Code

Checks

21 successful · 23 skipped
All checks passed
359bba3

Added 7 commits

  • fix(web): a deleted open document shows its error instead of stale content45038ca
  • fix(web): open documents no longer reload after every workspace change7ea4edd
  • docs(web): correct the draft document preview comment86bd2e2
  • test(web): name the revision-check test for what it covers878f1a5
  • Merge remote-tracking branch 'origin/main' into fix/issue-32669c4f3486
  • fix(web): open documents stay loaded across a reconnectcdcc7bf
  • test(web): reproduce #32669 document preview remount on unrelated workspace changesdaca5a1
Synced from GitHub

Approvability

Verdict: Approved at c4f3486

Macroscope's review found this PR approvable — Document previews now use file revisions to avoid unnecessary reloads after unrelated agent commands, while retaining manual refresh and draft reload behavior. The change is limited to preview lifecycle and preserves existing asset access controls.

No code changes detected at 359bba3. Prior analysis still applies.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Document and binary-file previews now use asset revisions to determine when the preview remounts. Draft documents continue to use workspace mutation IDs. Browser tests cover preview retention, URL minting failures, and changed revisions.

Changes: Document preview revision handling

Layer / File(s)Summary
Revision-keyed document previews
apps/web/src/components/files/FilePreviewPanel.tsx, apps/web/src/components/files/FilePreviewPanel.browser.test.tsx
WorkspaceDocumentPreview selects an asset resource and keys the attachment preview by revision and refresh counter. It retains the last resolved revision while loading and uses a failure-specific key after URL errors. Tests cover unchanged revisions, failed URL minting, and changed revisions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • pingdotgg/t3code#25798: HTML previews still use workspace mutation IDs and can remount after unrelated commands.
  • pingdotgg/t3code#27681: HTML, PDF, and image previews remain outside the revision-based changes in this PR.

Possibly related PRs

Suggested reviewers: maria-rcks, only21mil, macroscopeapp

Merge Risk: External image Minimal · up to c4f34

The document-preview change is ready to merge after normal checks; no unresolved behavior has been established that requires a fix.

Pre-merge checks: Passed 4

Check nameStatusExplanation
Title checkPassedThe title "fix(web): open documents no longer reload after every agent command" follows conventional commit form and names the main change: open document previews stop reloading after unrelated agent …
Linked Issues checkPassedIssue #32669 requires that an open Word or PowerPoint preview keep its position when commands change no file, and that real file changes load. The diff in apps/web/src/components/files/FilePreviewPane…
Out of Scope Changes checkPassedThe whole-PR diff against the merge base changes the document branch of FilePreviewPanel.tsx and adds WorkspaceDocumentPreview, plus the browser test file named in the PR. The HTML, image and PDF bran…
Description checkPassedThe description covers the problem and reproduction, explains the change and scope, links the triaged issue, and provides focused test results and detailed before/after UI evidence. It also identifies…
Full details: Title check

Explanation

The title "fix(web): open documents no longer reload after every agent command" follows conventional commit form and names the main change: open document previews stop reloading after unrelated agent commands. The diff changes the document branch of FilePreviewPanel to key the preview on the server-reported fileRevision, which matches the title. The title is specific and short (10 words, 67 characters).

Full details: Linked Issues check

Explanation

Issue #32669 requires that an open Word or PowerPoint preview keep its position when commands change no file, and that real file changes load. The diff in apps/web/src/components/files/FilePreviewPanel.tsx replaces the document-branch key, which used workspaceMutationId, with WorkspaceDocumentPreview. For non-draft media-file resources, the new component calls useAssetUrlState and keys AttachmentFilePreview on the returned fileRevision. An unrelated workspace change therefore keeps the same key and the preview stays mounted. A changed fileRevision produces a new key, so new bytes load. The refreshRevision counter still remounts the preview on an explicit refresh. The shown state keeps the last revision during Loading, which covers a reconnect. A Failure produces a failure-specific key, so a deleted file shows its error. A Success without fileRevision falls back to workspaceMutationId, which keeps the previous behavior for servers that do not report a revision. The approach matches the existing WorkspaceVideoPreview pattern that the issue cites. The author reports browser tests for each path, including a test that fails on main and passes at the reviewed head. I did not run those tests. I did not inspect useAssetUrlState internals, so its re-mint behavior rests on the existing video-preview precedent and the reported tests.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes the document branch of FilePreviewPanel.tsx and adds WorkspaceDocumentPreview, plus the browser test file named in the PR. The HTML, image and PDF branches are not changed in the diff. The change serves the requested behavior in #32669 directly. Office, binary and document files all use the document branch, so their handling is an intended part of the fix and not an unrelated change. One edge case needs a note and is not a scope failure. A draft non-document binary uses a media-file resource with revision-based keying. The PR text says drafts keep following workspaceMutationId. That holds only when the server reports no fileRevision for that draft resource. I did not verify server behavior for drafts.

Full details: Description check

Explanation

The description covers the problem and reproduction, explains the change and scope, links the triaged issue, and provides focused test results and detailed before/after UI evidence. It also identifies unverified cases and limitations.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
External image Recent review info

External image Run configuration

External image Commits

Reviewing files that changed from the base of the PR and between a9e709f15f825cacac1b6d665fa1920c328d68b7 and c4f34869af90bb05befcae2fa7a73311a689694c.

External image Files selected for processing: 2

  • apps/web/src/components/files/FilePreviewPanel.browser.test.tsx
  • apps/web/src/components/files/FilePreviewPanel.tsx

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

Added 2 commits

  • Merge remote-tracking branch 'origin/main' into pr-32693c697a66
  • Merge remote-tracking branch 'origin/main' into pr-32693359bba3