Skip to main content

0014: Revision-safe asynchronous core

  • Status: Proposed (implemented in Phase 2, task 005)
  • Date: 2026-12-05

Context​

The UI thread read and wrote files, listed directories, compiled grammars, parsed on every keystroke (with a 6 ms budget and idle-frame catch-up) and started language-server processes. Go-to-definition results were matched only by a tag and permission epoch, so an answer could land after the text or caret had changed. Positions from servers were clamped, which can place a diagnostic on the wrong code.

Decision​

  • The UI owns documents; workers own slow work. A bounded file pool (fixed threads, jobs in flight and queued save bytes capped) runs open, reload, save, external-change probes and directory listings. One syntax worker owns every parser and tree. The language-server connection thread starts the process.
  • Snapshots, not copies. Workers receive rope snapshots (structure-sharing clones). Saves serialise on the worker.
  • Tickets on dispatch, checked on consumption. Requests record id, epoch, document id, revision, service generation, kind and caret. Results that no longer match are dropped and the request is cancelled.
  • Contiguous revisions only. The syntax worker applies edits only when they continue its tree exactly, otherwise it parses from scratch; newer text abandons a parse in progress; one result slot per document.
  • Strict positions. Only UTF-16 is offered; out-of-range positions are dropped. Unversioned diagnostics are never mapped onto newer text.
  • Synchronous entry points remain for headless callers and for close/quit saves.

Alternatives considered​

  • Keep the keystroke budget: still parses on the UI thread and needs idle frames to catch up.
  • An async runtime (Tokio): a large dependency for a handful of blocking file operations and one CPU-bound worker.
  • One thread per job: unbounded under bursts such as explorer expansion.

Consequences​

  • Typing cost no longer includes parsing; highlights can lag by one parse and are shifted meanwhile.
  • Every result path needs a staleness check; new request kinds must use tickets.
  • Synchronous APIs must not be used by the UI except for close and quit.

Validation​

See Phase 2 validation.