openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

feat(memory-tree): status panel + on/off toggle (#1856 Part 1)

Open YOMXXX opened this issue 6 months ago • 2 comments

Summary

  • Adds the Memory Tree status panel (4 tiles + auto-sync toggle) inside MemoryWorkspace, surfacing it in both /intelligence and Settings → Memory data with a single mount point.
  • Wires up two new RPCs — memory_tree_pipeline_status (read-side aggregate) and memory_tree_set_enabled (toggle that flips scheduler_gate.mode between auto and off).
  • Drops the half-baked useConsciousItems + useMemoryIngestionStatus-driven status pill from Intelligence.tsx; the new panel supersedes it.

Problem

#1856 calls for a real Memory Tree status surface that exposes pipeline health and lets the user pause auto-ingest without restarting the core. The existing header pill was sourced from the legacy actionable-items pipeline and showed counts that no longer matched anything visible.

Solution

Rust (src/openhuman/memory_tree/tree/rpc.rs, src/openhuman/memory/schema.rs):

  • pipeline_status_rpc aggregates mem_tree_chunks (COUNT + MAX(timestamp_ms) in a single query) + per-state mem_tree_jobs counters + a walkdir-driven recursive size of memory_tree_content_root(). All blocking I/O runs on spawn_blocking. A pure derive_pipeline_status helper locks the precedence rules (paused > error > syncing > running > idle).
  • set_enabled_rpc flips config.scheduler_gate.mode = SchedulerGateMode::{Auto, Off}, persists with config.save(), and hot-reloads via scheduler_gate::gate::update_config(...) so live workers observe the new policy at their next wait_for_capacity() await. Idempotent (changed=false for no-ops).
  • Schema entries match the existing RegisteredController pattern; all_controller_schemas_and_registered_controllers_stay_in_sync continues to pass.

Frontend (app/src/):

  • MemoryTreeStatusPanel.tsx renders the four-tile dashboard plus an inline toggle row whose markup mirrors AIPanel's ToggleRow. Adaptive polling — 1.5s while syncing/active jobs, 4s otherwise — mirrors useMemoryIngestionStatus. Error banner with retry button covers the fetch failure path; toggle errors surface via the existing onToast channel.
  • memoryTreePipelineStatus() / memoryTreeSetEnabled() wrappers in tauriCommands/memoryTree.ts keep the snake_case-on-the-wire convention used by the sibling helpers.
  • Mounted above <MemorySources> in MemoryWorkspace (one place, two surfaces).
  • Intelligence header cleanup: removed useConsciousItems + useMemoryIngestionStatus + useIntelligenceStats imports + the systemStatus* derivation block + the two pill JSX blocks. The hooks themselves stay — they have their own tests and may serve future consumers.

i18n: new memoryTree.status.* keys in en.ts + the English chunk + all 12 non-English chunk-1 files. pnpm i18n:check reports missing: 0, extra: 0, drifted: 0 across every locale.

Notes / tradeoffs:

  • The 20-min Composio fetch loop is intentionally NOT paused by this toggle yet — that requires a Notify signal on the periodic timer and is queued for #1856 Part 2.
  • Schema does not yet record original-source sizes, so compression_ratio is deferred until that is plumbed.

Submission Checklist

  • [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy — 5 new Rust tests in memory_tree::tree::rpc::tests (precedence rules, idle/paused/ingested branches, toggle round-trip incl. no-op); 6 new Vitest cases covering tiles, skeleton, toggle round-trip, paused branch, fetch error + retry, and toast on toggle error.
  • [x] Diff coverage ≥ 80% — every new branch in pipeline_status_rpc, derive_pipeline_status, set_enabled_rpc, the React panel, and the hook is exercised. Local pnpm debug unit MemoryTreeStatusPanel and cargo test --lib memory_tree::tree::rpc::tests pass with all 6 + 15 cases green.
  • [x] N/A: Coverage matrix updated — no feature-row add/remove/rename, only a new status surface within an existing one.
  • [x] N/A: All affected feature IDs listed in ## Related — no matrix-row change.
  • [x] No new external network dependencies introduced — only walkdir (already in Cargo.toml).
  • [x] N/A: Manual smoke checklist — not a release-cut surface.
  • [x] Linked issue referenced via Refs #1856 (intentionally NOT Closes — Part 2 / Part 3 of the issue stay open).

Impact

  • Desktop: users get an immediate, color-coded view of Memory Tree health (Status / Last sync / Total chunks / Wiki size) and a 1-click pause/resume control. Paused state survives core restart (persisted in config.toml).
  • Pause semantics: flipping the toggle off sets scheduler_gate.mode = off, which the existing memory queue worker (memory_queue/worker.rs) cooperatively respects via wait_for_capacity(). The 20-min Composio fetch loop is unaffected (queued for Part 2).
  • Performance: the status RPC is two SQL counters (one aggregate, one per-job-state) plus a walkdir of the memory_tree content root — cheap enough to poll at 1.5–4s. Logged at debug level with [memory-tree][rpc] and [ui-flow][memory-tree-status] prefixes for trace grepping.
  • Compatibility: no schema migration, no config-shape change beyond toggling an existing enum value.

Related

Refs #1856 (Part 1 only — Part 2 = pause 20-min Composio fetch loop + team siloing; Part 3 = integration health list).

Follow-up work:

  • Pause the 20-min Composio fetch loop on toggle (memory_sync/composio/periodic.rs needs a Notify signal).
  • Add compression_ratio once original source sizes land in the chunks schema.
  • Integration health list (#1856 Part 3).
  • Team-level knowledge siloing (#1856 Part 2).

Summary by CodeRabbit

  • New Features
    • Memory Tree Status Panel: 4-tile dashboard (status, last sync, total chunks, storage) with skeletons and live polling.
    • Auto-sync toggle with busy/disabled states, retry flow, and toast notifications on toggle failures.
    • Panel integrated into the Memory workspace, replacing legacy header status pills.
  • Localization
    • Added translations for the status panel across many languages.
  • Tests
    • UI tests for display states, loading, error/retry, and toggle interactions.

Review Change Stack

YOMXXX avatar May 27 '26 00:05 YOMXXX

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 06aeb045-0dea-4713-b28f-06712718163d

📥 Commits

Reviewing files that changed from the base of the PR and between 9e07bdc7c00f32676d63eba933e1e3704cf4f83f and cd4e94fce19ca53ff644630bdf7d64792900fbdf.

📒 Files selected for processing (3)
  • app/src/pages/Intelligence.tsx
  • app/src/utils/tauriCommands/memoryTree.ts
  • src/openhuman/memory/schema.rs
💤 Files with no reviewable changes (1)
  • app/src/pages/Intelligence.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/src/utils/tauriCommands/memoryTree.ts
  • src/openhuman/memory/schema.rs

📝 Walkthrough

Walkthrough

Adds backend RPCs (pipeline_status, set_enabled) with handlers/tests, TypeScript tauri wrappers, an adaptive polling hook and MemoryTreeStatusPanel UI (four tiles + auto-sync toggle), i18n keys across languages, component tests, and integrates the panel into MemoryWorkspace while removing legacy header pills.

Changes

Memory Tree Status Panel Feature

Layer / File(s) Summary
Backend RPC handlers & tests
src/openhuman/memory_tree/tree/rpc.rs
New RPC types and implementations: pipeline status aggregation (chunks, jobs, wiki size), compute_dir_size_bytes, derive_pipeline_status precedence, set_enabled persistence/hot-update, and unit/async tests covering status derivation and toggle persistence.
Controller schema and handlers
src/openhuman/memory/schema.rs
Registers memory_tree controller schemas and adds handlers that load config and delegate to RPC functions.
Frontend RPC Command Wrappers
app/src/utils/tauriCommands/memoryTree.ts
Typed wrappers memoryTreePipelineStatus() and memoryTreeSetEnabled() that invoke core RPC, unwrap envelopes, and return typed responses.
UI Polling Hook & Component
app/src/components/intelligence/MemoryTreeStatusPanel.tsx
useMemoryTreeStatus adaptive polling hook (fast/slow cadence, cancel on unmount) and MemoryTreeStatusPanel rendering four tiles (status, last sync, total chunks, wiki size), skeletons, error banner+retry, and auto-sync toggle with toast error reporting; hook re-exported.
Component Test Suite
app/src/components/intelligence/MemoryTreeStatusPanel.test.tsx
Vitest tests mocking tauri commands: resolved tile rendering, loading skeletons, toggle round-trip and paused UI, error+retry flow, and toggle failure toasts.
Localization
app/src/lib/i18n/chunks/*, app/src/lib/i18n/en.ts
Adds memoryTree.status.* keys (labels, state strings, error/retry/toggle messages, relative time buckets) across language chunks and central English map.
Integration & Cleanup
app/src/components/intelligence/MemoryWorkspace.tsx, app/src/pages/Intelligence.tsx
Mounts MemoryTreeStatusPanel inside MemoryWorkspace (wires onToast) and removes legacy Intelligence header pills, replacing with placeholder comments.

Sequence Diagram(s)

sequenceDiagram
  participant MemoryWorkspace
  participant StatusPanel as MemoryTreeStatusPanel
  participant Hook as useMemoryTreeStatus
  participant TauriCmd as Tauri Commands
  participant Backend as Backend RPC
  participant Toast as onToast Callback

  MemoryWorkspace->>StatusPanel: mount (onToast)
  StatusPanel->>Hook: start polling
  Hook->>TauriCmd: memoryTreePipelineStatus()
  TauriCmd->>Backend: openhuman.memory_tree_pipeline_status
  Backend-->>TauriCmd: PipelineStatusResponse
  TauriCmd-->>Hook: typed status
  Hook-->>StatusPanel: status (loading=false)
  StatusPanel->>StatusPanel: render tiles + toggle

  User->>StatusPanel: toggle auto-sync
  StatusPanel->>TauriCmd: memoryTreeSetEnabled(false)
  TauriCmd->>Backend: openhuman.memory_tree_set_enabled
  alt toggle succeeds
    Backend-->>TauriCmd: SetEnabledResponse
    TauriCmd-->>StatusPanel: response
    StatusPanel->>Hook: refresh()
    Hook->>TauriCmd: memoryTreePipelineStatus()
    Backend-->>StatusPanel: updated paused status
    StatusPanel->>StatusPanel: re-render paused state
  else toggle fails
    Backend-->>TauriCmd: Error
    TauriCmd-->>StatusPanel: Error
    StatusPanel->>Toast: onToast({ message })
  end

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • tinyhumansai/openhuman#1856 — Implements the Memory Tree status panel and scheduler toggle described in the issue (RPCs, UI, and wiring).

Suggested reviewers

  • graycyrus
  • M3gA-Mind

Poem

I munched the bytes and watched the sync,
Four shining tiles — click and blink.
I paused the flow, then nudged it free,
The tree breathed calm and hummed to me.
Hooray — small bytes, big joy. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a Memory Tree status panel UI component with an on/off toggle functionality, which is the primary focus across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 27 '26 00:05 coderabbitai[bot]

Pushed 4 commits addressing all 5 CodeRabbit actionables on top of feat/1856-memory-tree-status-panel:

  • Actionable 1 (memoryTree.ts wrappers must use core_rpc_relay) — fixed in 1785ac28. Both memoryTreePipelineStatus and memoryTreeSetEnabled now route through invoke('core_rpc_relay', { request: { method, params } }). The status panel mounts during boot and starts polling before the realtime socket has connected, which is exactly the case AGENTS.md / .claude/memory.md flag as a callCoreRpc foot-gun (raw fetch() fallback → CORS preflight). Kept the rest of the file on callCoreRpc since other wrappers are user-initiated and not part of this PR.
  • Actionable 2 (formatRelativeMs must go through i18n) — fixed in d8c5a802. Helper now takes the t translator and pulls every bucket (justNow, secondsAgo, minuteAgo/minutesAgo, hourAgo/hoursAgo, dayAgo/daysAgo) out of the memoryTree.status.* namespace. The runtime t() does not interpolate, so {count} placeholders are substituted client-side via .replace('{count}', String(n)), matching the established devices.lastSeenMinutes / team.memberCount pattern. Added 8 new keys to en.ts plus all 13 chunk-1 files (en + 12 locale chunks, non-English entries seeded with the English copy). pnpm i18n:check reports missing: 0 / extra: 0 for every locale.
  • Actionable 3 (fake timers in MemoryTreeStatusPanel test) — fixed in 072f7d90. beforeEach now pins vi.useFakeTimers({ shouldAdvanceTime: true }) + vi.setSystemTime(FIXED_NOW_MS), payload() derives last_sync_ms from the same constant, and afterEach restores real timers and mocks. shouldAdvanceTime: true is necessary so RTL's waitFor and the panel's polling loop keep making progress without per-test advanceTimersByTime calls; setSystemTime still freezes the wall clock for formatRelativeMs. All 6 existing tests pass.
  • Actionable 4 (wiki_size_bytes only walk wiki/) — fixed in 65526ce1. Picked Option A (scope walk to content_root.join("wiki")) so the wire field stays wiki_size_bytes, matching the UI tile label "Wiki size". Missing wiki/ short-circuits to 0, so fresh installs are unaffected. Updated the rustdoc on PipelineStatusResponse.wiki_size_bytes to document the new scope.
  • Actionable 5 (redact walk-error path) — fixed in 65526ce1. Verified walkdir::Error's Display impl writes "IO error for operation on <abs-path>: ...", so {err} was a second path-leak vector beyond err.path(). Switched the log to has_path={} kind={:?} — boolean + io::ErrorKind only.

Validation (all from the worktree, against upstream/main):

  • cargo fmt --manifest-path Cargo.toml --check — clean.
  • GGML_NATIVE=OFF cargo check --manifest-path Cargo.toml --lib — pass (pre-existing warnings only).
  • GGML_NATIVE=OFF cargo test --lib memory_tree::tree::rpc::tests — 15/15 pass (5 new + 10 existing).
  • pnpm exec prettier --check over the changed TS files — clean.
  • pnpm exec eslint --max-warnings 0 over the changed TS files — clean.
  • pnpm typecheck — clean.
  • pnpm i18n:check — missing: 0 / extra: 0 for all 12 non-English locales.
  • pnpm debug unit MemoryTreeStatusPanel — 6/6 pass.

Tip is 65526ce1. Force-with-lease push, no new PR.

YOMXXX avatar May 27 '26 01:05 YOMXXX

thanks, looks good merging this now

graycyrus avatar May 27 '26 14:05 graycyrus