Skip to content

[Bug]: Closing a file tab overwrites newer on-disk changes #8475

Description

@thomas-toh

Before submitting

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

Area

apps/web

Steps to reproduce

Setup: T3 Code desktop on device A (macOS laptop) connected to the T3 server running on device B (Windows desktop). Not sure if this is remote-specific, but I tested it on a remote environment.

  1. On device A, open a file in the files panel and type one character. Deleting it afterwards makes no difference (I typed a character, waited 5 s, deleted it).
  2. Change the file on disk from anywhere else. (In the reproduction: echo "APPENDED" >> file in a shell on device B. In the original incident: an agent turn rewriting the file.)
  3. On device A, without touching the editor, close the file tab or switch to another file.
  4. The file on device B is back to the device-A buffer; the appended line is gone.

Expected behavior

Closing a file tab should never write to disk unless the buffer holds changes newer than the file. If the file changed on disk after the last save from this tab, the tab's buffer is stale and must be discarded or reconciled, with a warning at most. In particular, a buffer with no net change (e.g., the reproduction method of typing and then deleting a character) should not write anything.

Actual behavior

On tab close, the editor writes its remembered buffer back to the server. The buffer was loaded before the on-disk change and never refreshed, so the write replaces the newer file with the old contents. The newer change is gone. Nothing in the UI or the orchestration event store records this. The only trace is a projects.writeFile span in server.trace.ndjson from the closing client's connection.

Impact

Major degradation or frequent failure

Version or commit

0.0.34

Environment

Windows 11 server, macOS desktop client connected remotely

Logs or stack traces

Source: ~/.t3/userdata/logs/server.trace.ndjson on the Windows server, spans filtered to
projects.readFile / projects.writeFile. Times local (UTC+1). conn = websocket connection id
of the macOS desktop client. No other connection or process touched the file in any window.

Original incident - spec/docs/30_tools.md
  01:57:05.602  ws.rpc.projects.writeFile  conn=96587f5d   <- small edit in the Mac file panel
  01:57:06.648  ws.rpc.projects.writeFile  conn=96587f5d
  02:01:16      (agent on the server rewrites the file: 108 -> 118 lines)
  02:02:43.885  ws.rpc.projects.readFile   conn=96587f5d
  02:02:43.906  ws.rpc.projects.writeFile  conn=96587f5d   <- file back to 108 lines, byte-identical to pre-rewrite
  No keystroke between 01:57:06 and 02:02:43.

Repro 1 - spec/scratch.md (3 lines)
  03:07:44.897  ws.rpc.projects.writeFile  conn=c37ddc71   <- [Mac] type one char
  03:07:49.335  ws.rpc.projects.writeFile  conn=c37ddc71   <- [Mac] delete it
  03:08:16      [PC] echo "APPENDED FROM PC" >> spec/scratch.md      (file = 4 lines)
  03:08:38.869  ws.rpc.projects.writeFile  conn=c37ddc71   <- [Mac] close the file tab, no keystroke
  03:08:40      [PC] file = 3 lines, appended line gone

Repro 2 - same file
  03:10:40.711  ws.rpc.projects.writeFile  conn=c37ddc71   <- [Mac] type one char
  03:10:45.089  ws.rpc.projects.writeFile  conn=c37ddc71   <- [Mac] delete it
  03:11:03      [PC] echo "ROUND 2 - APPENDED FROM PC" >> spec/scratch.md   (file = 4 lines)
  03:11:57.537  ws.rpc.projects.writeFile  conn=c37ddc71   <- [Mac] close the file tab, no keystroke
  03:12:00      [PC] file = 3 lines, appended line gone

Each Mac writeFile above was followed ~70 ms later by a projects.readFile on the same
connection (the editor's post-save confirm read); omitted for brevity.

Screenshots, recordings, or supporting files

No response

Workaround

Avoid editing the file using the remote tab viewer (use agent to edit or add comments). If not, wait for files written to disk on the server to sync back to the remote client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken or behaving incorrectly.needs-triageIssue needs maintainer review and initial categorization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions