Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): discard stale highlights after file edits #9902

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/9902/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Editing a large source file can race an older syntax-highlight response. The response replaces the editor's updated line data, losing same-line edits in the rendered view or throwing FileRenderer.processFileResult: Line doesnt exist after new lines are added.

Cancel the file renderer's pending highlight request and evict its shared AST before updating editor tokens. This reuses Pierre's existing cancellation and eviction methods. Later highlights still run. The dependency stays at 1.3.0-beta.10; only its existing patch and lockfile patch hash change.

Related to #7907. This does not fix its separate wrapped-line scroll jump or establish a CachyOS/Electron retest. The issue should remain open for those remaining parts.

Verification

  • Real installed TextDocument, EditorTokenizer, FileRenderer and WASM worker, with only worker-message delivery controlled. No fabricated token results or browser geometry.
  • Baseline: five of the initial six tests fail, including the exact renderer error after one or sixty Enter edits, lost same-line text, and undo. The no-edit asynchronous control passes.
  • Candidate: seven editor-highlight controls pass, including fresh full-file highlighting, unchanged asynchronous output, same-line edits, Enter bursts, undo/redo, shared-cache eviction and reopening with the same key. Nineteen focused tests pass with the existing cache-identity and worker-lifecycle suites. The seven actual-worker tests passed again on the unchanged published head.
  • Web typecheck, targeted lint, patch reverse-application check and Node syntax check pass. Base refreshed to 2fb99a7a.
  • Current-head CI has no pending or failing jobs. Cursor Bugbot passed. Macroscope approved eligibility; its separate correctness check was skipped and its approval explicitly did not review code objects.

Actual browser before and after

Verified in Linux Chromium 152 with native pointer and keyboard input, word wrap enabled, and a 394px Files editor showing an owned copy of the public ChatView.tsx. No fabricated editor state, layout changes, provider turns or changes to shared installed packages were used.

Before, the main editor at 94cc8152 displayed the exact renderer exception after repeated Enter edits and returning to EOF. That editor implementation is unchanged at the current base. This native race is intermittent: a later fresh 60-Enter baseline attempt did not fail. The controlled real-worker tests above establish the stale-response failure and repair without depending on browser timing.

Before: the large-file editor displays the reported exception.

Before: FileRenderer.processFileResult reports Line doesnt exist in the narrow large-file editor

After, the exact d9e94bee package repair ran on main 2fb99a7a. All Pierre imports resolved to the same isolated package. The live FileRenderer.updateRenderCache contained both repair calls, and VirtualizedFile remained unpatched.

  • Starting at 8,255 lines, 60 native Enter presses persisted 8,315 lines and 317,716 bytes without a DOM renderer error.
  • Undo, redo and a typed marker worked. Disk contents confirmed the marker, and closing/reopening the file retained it.
  • After removing the marker, 61 further Enter presses reached 8,376 lines and 317,777 bytes, matching the large fixture size used for the earlier failure. Ctrl+End reached line 8,376 and the editor remained usable without the renderer exception.

After: the editor renders line 8,376 instead of the error.

After: the repaired editor remains usable at line 8376 following repeated Enter edits

After reopening: the saved marker remains present.

After reopening: the saved AUDIT-9902 marker is retained in the file editor

After recording: continued Enter editing and returning to EOF. The separate scroll jump is still visible; the renderer keeps working.

After video: repeated native editing in the large wrapped file without the renderer exception

These captures use the same narrow editor and owned large-file fixture. The sidebar filter differs, and unrelated audit integrations were present in both runs. This is web verification, not a retest on the reporter's CachyOS/Electron setup. Interrupted baseline recordings are not included.

Scope limit

The library's explicit primeFileHighlightCache API can retain a separately owned pending request for the same key. That unused-in-production T3 path is not changed here. Current T3 mounts one editable Files view per client, uses a separate prefix for read-only file caches, and does not call the priming API in production. Shared priming or concurrent same-key editor support needs a separate ownership decision. No new timer, loop, error suppression, save behavior or scroll policy is introduced.

GPT 6 Astra via Codex in T3 Code.


Note

Medium Risk Changes edit-time rendering and worker/cache lifecycle in a patched dependency; wrong cancellation could regress highlighting or performance, but scope is limited to the editable file update path.

Overview Fixes a race where a late syntax-highlight worker response could overwrite the editor after typing in large files—dropping same-line edits, showing wrong tokens, or throwing when line counts diverge.

The @pierre/diffs patch extends FileRenderer.updateRenderCache: before merging new tokenizer output, it cancels pending highlight tasks for that renderer and evicts the shared file cache for the file’s cacheKey, so stale AST/results cannot be applied while newer edits are in flight. Later highlights still run normally.

Adds fileEditorHighlight.test.ts, an integration suite that drives real TextDocument, EditorTokenizer, FileRenderer, and the WASM worker while deferring worker message delivery to assert stale responses are ignored, undo/redo stays correct, cache eviction behaves, and reopening with the same key is safe. Lockfile updates reflect the revised patch hash only.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit d9e94beec3a6cfaa1a6339bf6eb7f443f061aadd. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix FileRenderer to discard stale highlights after file edits

  • FileRenderer now cancels outstanding worker tasks and removes the edited file's keyed worker result cache before processing dirty rendered lines, so late async highlight responses no longer overwrite current edits.
  • Adds an integration test suite in fileEditorHighlight.test.ts covering stale responses after multiple edits, undo/redo ordering while a response is pending, shared-cache eviction, and reopening an edited file before pending responses complete.
  • Introduces a WorkerTransport adapter and helpers (applyChange, append, undo, renderContents) that let tests queue and release worker responses deterministically.
  • Risk: the patched FileRenderer cache-eviction path in pnpm-lock.yaml's @pierre/diffs patch runs on every dirty-line update; verify that cache eviction does not drop highlights for files that were edited but not yet saved when a concurrent render occurs.
Macroscope summarized d9e94be.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.5 KiB13.5 KiB+2 B (+0.0%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB−2 B (−0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.5 KiB+4 B (+0.1%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.0 KiB57.0 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages880 (0.0%)21✅
      ClaudeTotal thread wire13.6 KiB13.5 KiB−51 B (−0.4%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB−4 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.5 KiB−47 B (−0.7%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.9 KiB57.8 KiB−88 B (−0.1%)66.4 KiB✅
      ClaudeLive turn messages108−2 (−20.0%)21✅

      Baseline: 2fb99a7 · PR result: d9e94be · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 113.8 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. Approvability

      Verdict: Approved at d9e94be

      Macroscope's review found this PR approvable — This is a focused bug fix that invalidates stale highlight work and cache entries only when an editable file’s rendered tokens change. Its production footprint is small, and integration tests cover asynchronous responses, edits, undo/redo, cache eviction, and reopening.

      Notes:

      • No code objects were reviewed. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. juliusmarminge merged thisdf8e0eb

    5. juliusmarminge closed this

Sign in to join this conversation.