set a trap for the editor buffer corruption

Not a fix — I could not find the cause by reading, and shipping a guess dressed as
one is worse than saying so.

What reading DID settle, and it removes two of the three candidates:

- The end-of-turn refresh cannot be it. `reloadFile` sets `originalContent` and
  clears `isDirty`, so no refresh can produce the dirty dot in the screenshot.
- Nothing in the app types into the page: no `execCommand('insertText')`, no
  synthetic keyboard events, no clipboard writes anywhere near the editor.

That leaves Monaco's own change event, which means the model was edited the way a
paste or a programmatic `executeEdits` edits it. Neither is identifiable from a
screenshot taken afterwards, which is why this needs to be caught in the act.

`reportSuspiciousEdit` logs any insertion over 200 characters arriving while the
editor does NOT have focus, with an Error constructed at that moment so the stack
names the caller. A person cannot type 200 characters into an editor they are not
focused on; whatever does will be in that trace.

It prevents nothing and changes no behaviour. Delete it once the cause is known.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-16 11:15:33 +00:00
co-authored by Claude Opus 5
parent 23f2ecb950
commit fc8d02e8e1
2 changed files with 50 additions and 1 deletions
+11
View File
@@ -422,6 +422,17 @@ outside the example's new README:
only thing that writes a buffer without a keystroke, it runs exactly when a background job is
producing output, and it lands its result by path.
**Narrowed 2026-08-16, and a trap is now set.** `reloadFile` sets `originalContent` and clears
`isDirty`, so the end-of-turn refresh CANNOT produce the dirty dot in the screenshot — the refresh
path is out. Nothing in the app injects text into the page either: no `execCommand('insertText')`,
no synthetic keyboard events, no clipboard writes near the editor. That leaves Monaco's own change
event, which means it looks like a paste or a programmatic `executeEdits`.
`reportSuspiciousEdit` in CodeEditor.tsx logs any insertion over 200 characters that arrives while
the editor is NOT focused, with a stack trace taken at that moment. That is the missing evidence:
whoever calls it will be named in the trace. Delete it once the cause is known — it is a trap, not a
feature.
One thing to rule out first, because it is mine and it is recent: `2b70a570` gave `<Editor>` a real
`path`, so models are now keyed by file URI globally rather than being per-mount `inmemory://`. Two
panels open on the same file now share one model. That should be an improvement, but it is a change