Skip to content

serve: missed watcher events on macOS leave an open model stale #918

Done

Description

@bpowers

On macOS, simlin-serve can miss an external edit to a model file, and a model that is already open then keeps serving the old content with no error or log line.
A later browser save merges against that stale copy and can overwrite the external edit.
The server should notice a file changed on disk even when no watcher event arrives.

Example

Measured on a macOS host with fseventsd and Spotlight under heavy load:

  • watch() took 3.5 s to return, and the first event arrived about 1.5 s after that.
  • A write made 2 s after watch() returned was never reported in most runs (from 3 of 4 up to 6 of 6).
  • A stream idle for about 2 s dropped the next event; this reproduced with raw notify, without the debouncer.

FSEvents finishes registering a stream asynchronously after watch() returns, and changes made before registration completes are never delivered.

Why it matters

Seen only on a developer machine while chasing flaky watcher tests (#916), not in a user report.
The startup window is less important than it looks: models are read from disk lazily on first open, so a missed edit to a model nobody has opened yet is harmless.
The dropped-event-when-idle case can happen at any time to an open model.
Linux (inotify) has not shown this.

Fix

Do not trust the watcher to be lossless.
Before serving or saving an open model, stat the file and compare mtime and size (or the content hash) with what the registry last recorded; if they differ, run the same merge the watcher would have run.
Alternative: a periodic rescan of the tree, which costs a stat walk proportional to tree size.

Pointers

  • src/simlin-serve/src/watcher.rs (spawn_watcher, handle_model_change)
  • src/simlin-serve/src/registry.rs (get_or_init_doc, last_disk_hash)
  • src/simlin-serve/src/main.rs (scan, then start the watcher)
  • docs/tech-debt.md entry 37: a separate, deterministic macOS rename/unlink gap

Activity

  1. changed the title [-]serve: external edits made during watcher startup are silently and permanently lost[/-] [+]serve: missed watcher events on macOS leave an open model stale[/+] on Oct 12, 2026
  2. added
    backend
    bug
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions