openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Feature Request: Bidirectional Obsidian Vault Sync via File Watcher

Open rsnobles opened this issue 6 months ago • 3 comments

Summary

The memory tree pipeline successfully writes summary .md files to <workspace>/memory_tree/content/wiki/, and a symlink can expose these in the user's Obsidian vault. However, there is no mechanism to watch the vault for user-created or edited notes and ingest them back into the memory tree. This completes the bidirectional sync loop described in the architecture docs.

Background

Karpathy's LLM Wiki model treats the wiki as read-only raw data (written by the LLM) with the human browsing in Obsidian. OpenHuman's architecture goes further — the vault is meant to be bidirectional: the agent writes summaries, the user writes notes, and both sides stay in sync.

Currently:

  • Left side (services → memory tree) is fully built via the Composio periodic sync pipeline
  • Right side (memory tree ↔ Obsidian vault) is missing the reverse direction

Proposed Implementation

1. Add notify crate dependency

Add the notify crate (or notify-debouncer-mini) to Cargo.toml for cross-platform filesystem event watching (FSEvents on macOS, inotify on Linux, ReadDirectoryChanges on Windows).

2. Create memory_sync/workspace/folder/ module

The memory_sync/workspace/ scaffold already exists but is empty. Implement a SyncPipeline for folder watching that:

  • Watches the vault's wiki/notes/ directory (or a configurable path) for Create, Modify, and Remove events
  • On Create/Modify: reads the file, calls ingest_document_with_scope() to push through the canonicalize → chunk → score → persist pipeline
  • On Remove: marks the document as deleted in the memory tree

3. Handle the dedup issue

ingest_document_with_scope() deduplicates by source_id. A re-ingest of an edited file with the same source_id is a no-op. The watcher needs to either:

  • Append a content hash or mtime to the source_id so edits produce a new id
  • Or add a force_reingest parameter to bypass the dedup gate

4. Track file modification times

Maintain an in-memory or SQLite-backed map of path → last_mtime so the watcher can detect actual changes and avoid re-ingesting unchanged files on startup.

5. Register in the startup path

Follow the Composio periodic sync pattern (start_periodic_sync() in composio/periodic.rs):

  • Singleton OnceLock guard
  • tokio::spawn the watcher loop
  • Respect the scheduler gate policy (pause when memory tree is disabled)
  • Log and swallow errors so the loop never panics

Alternatives Considered

  • Symlink only: Works for agent → user direction but not user → agent. User edits in Obsidian are invisible to the memory tree.
  • Polling-based sync: The existing Folder source kind globs all files on every tick. Inefficient for a vault that may have thousands of files. File watching is O(events) instead of O(files).
  • Separate CLI command: A manual openhuman vault sync command would work but requires user action. A watcher is automatic.

Acceptance Criteria

  • [ ] User creates or edits a .md file in the vault's wiki/notes/ directory
  • [ ] The change is detected within a reasonable window (≤30 seconds)
  • [ ] The content is ingested into the memory tree and appears in query results
  • [ ] User deletes a file from the vault and it's marked as deleted in the memory tree
  • [ ] The watcher respects the memory tree disabled/signed-out states
  • [ ] The watcher survives restarts (state persisted in SQLite)

Related Code

  • src/openhuman/memory_sync/composio/periodic.rs — pattern to follow for the watcher loop
  • src/openhuman/memory_sync/workspace/mod.rs — scaffold where the module should live
  • src/openhuman/memory_sources/readers/folder.rs — existing FolderReader for reference
  • src/openhuman/memory_sources/sync.rs — sync_items_individually() and ingest_document_with_scope() call site
  • src/openhuman/memory/ingest_pipeline.rs — ingest_document_with_scope() definition and dedup logic

rsnobles avatar Jun 01 '26 21:06 rsnobles

this is a great idea. recently we pushed a new feature that lets you specific a source for workspace files. so let me explore if that will meet this req.

senamakel avatar Jun 02 '26 00:06 senamakel

Status / parity check — watcher merged but not active yet (~40%)

#3183 added a vault file-system watcher implementation (notify-debouncer based, with mtime-suffixed source-id dedup, create/modify/remove handling, and scheduler-gate awareness).

The catch: as it currently sits in the tree the watcher isn't wired in and doesn't appear to build as part of the crate:

  1. The module isn't declared by its parent (pub mod watcher; is missing), so it's orphaned.
  2. It references a state submodule that doesn't exist.
  3. notify / notify-debouncer-mini aren't in Cargo.toml.
  4. start_vault_watcher() is never called from any startup path, so the "detected within ≤30s" AC can't be met.

What's remaining: declare + register the module, add the crate deps, call the watcher from startup, and add an integration test proving the ingest→query round-trip. The logic is written; it just isn't connected. Keeping open until it's active end-to-end.

oxoxDev avatar Jun 05 '26 12:06 oxoxDev

hye hey thanks for this. i had a look. so basically modifying the wiki actually get quite expensive to handle and resync all the updates. one of the key properties of the memory tree is that documents are considered to be immutable. this lets us assume a lot of other things that we can use to speed up memory processing.

the best way to work on this is to add a custom folder that the memory tree can watch bascailly and this should be it.

senamakel avatar Jun 12 '26 07:06 senamakel