Repository navigation
Commit 4bdc91e
fix(web): file saves no longer overwrite newer disk changes (#1869)
## Problem
An open workspace file panel saves its buffer over disk changes it never saw.
An agent or terminal edits the file, the user types, and autosave silently drops the newer disk contents.
## Change
Each save names the disk version its draft started from; a stale save is refused, and the user is asked.
1. Panel loads the file; client keeps its revision
2. Save sends `expectedRevision` with the contents
3. Server re-reads the file and compares
- one write per real file at a time
4. Changed or deleted: refused as `contents_changed`
5. Editor shows a persistent toast:
- **Overwrite:** saves the draft without the check
- **Reload:** drops draft, shows disk version
- **Old drafts:** dropped or superseded, never saved
**Revision:** length plus FNV-1a over the decoded text; synchronous, since `crypto.subtle` is missing on plain-HTTP remote origins.
**Read failure:** stays `operation_failed`, never a conflict.
**Unchanged:** saves with no loaded revision (new files, older clients) write as before.
### Layout
```text
packages/contracts/src/
├── projectFileRevision.fork.ts shared revision hash
└── project.ts hooks: expectedRevision, contents_changed
apps/server/src/
├── workspace/WorkspaceFileSystem.fork.ts compare before write, write lock
├── workspace/WorkspaceFileSystem.ts hook: call the check
├── server.ts hook: add the write lock
└── ws.ts hook: map the error
apps/web/src/components/files/
├── fileSaveBase.fork.ts per-file loaded revision
├── fileSaveConflict.fork.ts guarded write + toast
├── fileSaveCoordinator.ts hook: discard()
├── projectFilesQueryState.ts hooks: capture, forget
└── useFileSaveCoordinator.ts hook: wrap the write
```
### Surfaces
- **Web editors:** plain, rendered, rich markdown
- **Shared:** `useFileSaveCoordinator` saves all
- **Desktop:** wraps web
- **Mobile:** no workspace file editor
- **Server:** `WorkspaceFileSystem.writeFile` only
### Retirement notes
- **Hash:** duplicates upstream's private one
- lives in `fileContentRevision.ts`
- **Cherry-pick:** touches fork-only files
- does not apply to upstream `main` as is
- **Upstream:** fixed only the tab-close case
- `pingdotgg#8630`
- closed `pingdotgg#8475`
## Scope and approval
Closes #1761
Human decision from the housekeeping walk: fix in the fork, ask on conflict.
- [ ] **Disk change:** never lost to a stale buffer
## Verification
Real Chrome, dev build of this branch, scratch project:
1. Panel loads `README.md`
2. Disk gains a line; user types in panel
3. Toast appears; disk keeps the new line ✅
4. **Reload:** panel shows disk; toast closes ✅
5. Disk changes again; user types; toast appears ✅
6. **Overwrite:** disk holds the panel text ✅
https://github.com/user-attachments/assets/c1b44fba-f2c2-44f5-ae2e-9d2964570901
| Span | Real | Clip |
| --- | --- | --- |
| load and edit | 11s | 3x |
| prompt and reload | 7s | kept |
| idle | 85s | cut |
| edit, prompt, overwrite | 13s | kept |
**Tests:** each case fails without its fix and passes with it.
- [x] Web: stale save asks, then overwrites
- [x] Web: Reload drops the draft unwritten
- [x] Web: Reload covers a reopened panel
- [x] Web: Reload covers a closed panel's in-flight save
- [x] Web: a save landing after Reload stays dropped
- [x] Web: a fresh edit after Reload keeps it dropped
- [x] Web: a saved draft is never resent unchecked
- [x] Server: stale write refused
- [x] Server: matching base saved
- [x] Server: deleted file refused
- [x] Server: file turned FIFO refused as not a file
- [x] Server: racing saves via any link: one wins
- [x] Server: unreadable file fails as a read
- [x] Server: outside paths refused, never followed
**Checks:**
- [x] `vp run fork:ci` → exit 0
- [x] `apps/web` `vp run build` → exit 0
- [x] `apps/server` `vp run build` → exit 0
- [ ] `vp run check:changed` → exit 1
- all failures in files this PR does not touch
- format: 3 mobile and server files
- lint: `serviceLauncher.fork.test.ts`
- test: `GitManager.test.ts` CLAUDE.md case
Claude Opus 5.5, Claude Code in T3 Code.
## Fork trailers
Fork-Domain: upstream-fixes
Fork-Tier: bugfix
Fork-Upstreamable: yes
Co-authored-by: donjor <[email protected]>1 parent 41476b4 commit 4bdc91e
15 files changed
Lines changed: 795 additions & 0 deletions
File tree
- apps
- server/src
- workspace
- web/src/components/files
- packages/contracts/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
493 | 494 | | |
494 | 495 | | |
495 | 496 | | |
| 497 | + | |
496 | 498 | | |
497 | 499 | | |
498 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| |||
81 | 86 | | |
82 | 87 | | |
83 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
84 | 288 | | |
0 commit comments