Skip to content

BUG: watch service can go stale while process stays alive (self-heal + heartbeat) #580

@phernandez

Description

@phernandez

Problem

bm watch can remain alive but stop indexing filesystem changes after long uptime (seen overnight on macOS).

This creates a silent failure mode for downstream tools: files exist on disk, but search/read by permalink and graph traversal lag indefinitely until manual watcher restart.

Related downstream issue: basicmachines-co/openclaw-basic-memory#15

Why this looks upstream

openclaw-basic-memory only spawns bm watch; it does not own file watching internals. The watch loop and restart behavior live in:

  • src/basic_memory/sync/watch_service.py
  • src/basic_memory/cli/commands/watch.py

Reproduction (observed)

  1. Run bm watch --project <name>.
  2. Leave running for several hours.
  3. Create/modify markdown files under project path.
  4. Process is still alive, but changes are not indexed until watcher is restarted.

Requested fix

Add explicit stale-watch self-healing and diagnostics in the watch service:

  1. Add a heartbeat timestamp in watch status (updated even when no file events occur).
  2. Detect stale cycles (watch loop alive but no event processing/heartbeat progress for configurable window).
  3. Force a clean watch cycle restart and emit a structured warning when staleness is detected.
  4. Expose staleness counters/last-restart reason in watch status JSON for monitoring.

Acceptance criteria

  • Long-running watcher recovers automatically from stale state without manual restart.
  • ~/.basic-memory/watch_status.json includes heartbeat + last restart reason.
  • A synthetic integration test reproduces stale cycle handling (or equivalent deterministic test harness around watch loop restart logic).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions