fix(language-server): re-render instead of recompiling on a schedule change (audit B7) #64

Merged
abiwab merged 1 commit from fix/audit-b7 into main 2026-09-30 18:14:15 +02:00
Owner

Audit B7 (read in the code, not reproduced by the audit). Changing gram.miseEnPlace called refresh(uri, state.text, state.version) for every open document: a full reload of the module graph, parse, compile and diagnostics, to change two render options.

Reproduced with a small LSP driver (a keystroke still waiting in the 150 ms debounce when the setting changes): the refresh runs with the cached text while the module graph reads the live buffer, so it produced an inconsistent state (state.text = old text, version 1, but compilation of the new text) and stored it with states.set. It was only replaced because the debounced refresh happened to finish after; a late one would have overwritten the correct state, leaving wrong diagnostic offsets and a stale preview until the next edit.

Fix: refresh()'s view-sending tail becomes renderViews(uri, state), a pure output of the cached state. A setting change calls it synchronously for each open document: nothing is parsed, compiled, or stored, so there is nothing to race with. The preview then shows the last compiled text at the new schedule, and the pending edit's refresh replaces it as before.

Checked with the driver (4 timings, final preview always the new text) and the audit's startup script (A3 still follows the setting). No unit test: server.ts wires a live connection; an end-to-end test is part of the missing tests in audit B11. No changeset: the setting and its refresh are new in 1.4.0.

Audit B7 (read in the code, not reproduced by the audit). Changing `gram.miseEnPlace` called `refresh(uri, state.text, state.version)` for every open document: a full reload of the module graph, parse, compile and diagnostics, to change two render options. Reproduced with a small LSP driver (a keystroke still waiting in the 150 ms debounce when the setting changes): the refresh runs with the *cached* text while the module graph reads the *live* buffer, so it produced an inconsistent state (`state.text` = old text, version 1, but compilation of the new text) and stored it with `states.set`. It was only replaced because the debounced refresh happened to finish after; a late one would have overwritten the correct state, leaving wrong diagnostic offsets and a stale preview until the next edit. Fix: `refresh()`'s view-sending tail becomes `renderViews(uri, state)`, a pure output of the cached state. A setting change calls it synchronously for each open document: nothing is parsed, compiled, or stored, so there is nothing to race with. The preview then shows the last compiled text at the new schedule, and the pending edit's refresh replaces it as before. Checked with the driver (4 timings, final preview always the new text) and the audit's startup script (A3 still follows the setting). No unit test: server.ts wires a live connection; an end-to-end test is part of the missing tests in audit B11. No changeset: the setting and its refresh are new in 1.4.0.
fix(language-server): re-render from the cached compilation when the schedule setting changes
All checks were successful
CI / Build, Test & Publish (pull_request) Successful in 2m23s
efb31fd4df
abiwab merged commit 4e18321d20 into main 2026-09-30 18:14:15 +02:00
abiwab deleted branch fix/audit-b7 2026-09-30 18:14:15 +02:00
Sign in to join this conversation.
No description provided.