emdash icon indicating copy to clipboard operation
emdash copied to clipboard

[bug]: Workspace deactivation leaks durable file-search roots until fs-watch exhaustion breaks Cmd+K and @ mentions

Open jschwxrz opened this issue 3 months ago • 0 comments

Bug Description

On a remote Linux workspace server, file-search root registrations accumulate as workspaces are activated because normal workspace deactivation does not unregister them. Registrations are durable, so every previously registered root is restored and watched again when the workspace server starts, including inactive workspaces and worktrees that no longer exist.

Eventually the shared fs-watch worker becomes saturated. File-search watcher attachments time out, active roots fail to publish an index generation, and both Cmd+K file search and @ file mentions return no workspace files. Other consumers of the same watcher worker, including files, Git, and the workspace registry, also begin logging watcher timeouts.

This was observed on workspace server 0.1.3. At incident time, the persisted file-search catalog contained:

  • 11 registered roots
  • 43,562 indexed paths
  • 2 roots whose directories no longer existed
  • several roots belonging to inactive or suspended workspaces

One currently active root was still registered but had current_generation = NULL and zero indexed paths.

The lifecycle appears unbalanced in apps/emdash-desktop/src/core/features/workspaces/api/node/lifecycle-participants.ts: the file-search participant registers during activate, while deactivate only stops preview servers. In packages/core/src/runtimes/file-search/node/root/root-registry.ts, every persisted catalog row is restored at startup.

Steps to Reproduce

  1. Connect Emdash to a Linux workspace server.
  2. Activate a workspace so its root is registered with file search.
  3. Deactivate, suspend, or close the workspace without deleting it.
  4. Repeat with multiple tasks/worktrees; optionally remove some old worktree directories from disk.
  5. Restart the workspace server.
  6. Observe that all historical file-search catalog rows are restored and watcher attachment is attempted for each root, including inactive and missing roots.
  7. Continue until watcher startup begins timing out, then open Cmd+K or type an @ file mention in an active workspace.

Actual vs Expected Behavior

Actual:

  • Inactive and missing roots remain durably registered.
  • Startup restores all accumulated roots and attempts to watch them.
  • Logs contain errors such as:
    • File-search root does not exist
    • File-search watcher could not attach to the root
    • Operation timed out after 10000ms
    • Unable to remove watcher: Invalid argument
    • worker process exited for fs-watch
  • An active root can remain registered with no current generation and no indexed paths.
  • Cmd+K and @ file lookup return no files.
  • Filesystem watcher failures spill into files, Git, and workspace-registry services.

Expected:

  • File-search registration has balanced ownership: normal deactivation/disconnection releases the caller's interest, while another active client/session can keep the same root alive.
  • Persisted search indexes may be retained as cold caches, but inactive catalog rows must not imply permanent active watchers.
  • Missing roots are pruned during restoration instead of retried on every startup.
  • Watcher failure does not permanently prevent an active root from publishing an initial searchable generation.
  • Failed active roots retry with bounded backoff or use a polling/on-demand reconciliation fallback.
  • Restoration and watcher startup are concurrency-limited so historical roots cannot starve the active working set.

emdash Version

Workspace server 0.1.3

Operating System

Remote Linux workspace server (exact distribution not recorded)

Additional Context

The incident was recovered without restarting the server by:

  1. Preserving the three roots currently marked active in Emdash session-intent state.
  2. Unregistering eight inactive or stale roots through the live API.
  3. Cycling the three active registrations through unregister/register.
  4. Allowing their indexes to rebuild.

After recovery:

  • 3 roots remained registered
  • 18,286 paths were indexed
  • all three roots had a published generation
  • SQLite integrity check returned ok
  • no new watcher or file-search errors appeared after rebuilding

No repositories, worktrees, conversations, or workspace contents were deleted.

Related: #3084 reaches the same shared watcher-exhaustion failure domain through large recursive local project-root watches. This issue has a different initiating defect: leaked durable file-search registrations and eager restoration on the remote workspace server.

Suggested regression coverage:

  • repeated activate/deactivate cycles do not grow the active/durable root set;
  • multiple clients sharing a root are reference-counted or leased safely;
  • disconnected clients lose their leases;
  • missing persisted roots are pruned on startup;
  • active search publishes an initial generation when watcher attachment fails;
  • failed watcher attachment can recover without manual unregister/register;
  • restoration startup is bounded and prioritizes active roots.

jschwxrz avatar Sep 01 '26 18:09 jschwxrz