openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

fix(core): skip memory init on config failure instead of fabricating a default workspace (OPENHUMAN-CORE-48)

Open sanil-23 opened this issue 6 months ago • 1 comments

Summary

  • Boot no longer initialises the memory + whatsapp_data stores against a fabricated Config::default() workspace when Config::load_or_init() fails.
  • On config failure the workspace-bound init is skipped entirely and a loud, actionable error is logged; the server still starts.
  • Memory stays explicitly uninitialised on failure, so callers get a clear "memory client not ready" error instead of silently reading/writing the wrong workspace.
  • Pure control-flow restructure — the success path is byte-for-byte unchanged.

Problem

Sentry OPENHUMAN-CORE-48: [boot] memory::global init: Config::load_or_init failed (Failed to create workspace directory: Permission denied (os error 13)); falling back to default workspace dir.

On headless / containerised production deploys (RHEL8/el8 in the reported event) with no writable $HOME, create_dir_all($HOME/.openhuman/…) fails (config/schema/load.rs:589). The previous boot code logged the error, then did Default::default() and initialised the memory + whatsapp_data stores against the default workspace dir — silently causing chunk loss / cross-workspace bleed-over while the app looked healthy. The failure was invisible to the operator (the app "comes up fine" but memory is quietly wrong). Low frequency, high severity (silent data integrity).

Solution

Restructure the boot block in src/core/jsonrpc.rs:

  • Ok(cfg) → unchanged: memory::global + whatsapp_data::global init exactly as before.
  • Err(e) → skip both inits (no Default::default() fabrication) and log::error! a loud, actionable message. The existing uninitialised-client path then returns an explicit "not ready" error to callers instead of operating on the wrong workspace.

No new RPC/health surface is needed — the existing uninitialised semantics already give clean "unavailable" behavior. Minimal and low-risk.

Submission Checklist

  • [x] N/A: control-flow-only restructure of run_server_inner boot glue (real Config::load_or_init + process-global OnceLocks); no clean unit seam. Success path byte-for-byte unchanged; only the failure path changes from "init on fabricated default" to "skip + log".
  • [x] Diff coverage ≥ 80% — the Coverage Gate (diff-cover) check passes in CI; the moved Ok-arm lines remain exercised by the existing boot/integration paths.
  • [x] N/A: behaviour-only change — no feature rows added/removed/renamed in the coverage matrix.
  • [x] N/A: no feature IDs affected — boot-path bugfix tracked via Sentry, not the matrix.
  • [x] No new external network dependencies introduced.
  • [x] N/A: does not touch release-cut surfaces (boot logging / control-flow only).
  • [x] N/A: tracked via Sentry OPENHUMAN-CORE-48, not a GitHub issue; Fixes OPENHUMAN-CORE-48 in Related.

Impact

  • Runtime/platform: Rust core, all platforms; primarily affects headless/cloud/server deploys. Desktop is unaffected in practice (writable $HOME).
  • Behavior: on config-load failure, memory persistence is now explicitly disabled for the run (was: silently misdirected to the wrong workspace). Server still starts.
  • Performance/security/migration: none. No schema or API change. Strictly removes a dangerous silent fallback.

Related

  • Closes: Fixes OPENHUMAN-CORE-48
  • Follow-up PR(s)/TODOs: optional memory_degraded RPC status + UI banner so the disabled state is visible in-app (deferred — the data-corruption severity is resolved by this PR).

AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: fix/sentry-core-48-workspace-fallback
  • Commit SHA: fe5bf13570a4db230077fd389703de07ac1f09c7

Validation Run

  • [x] N/A: Rust-only change, no app/ workspace files. pnpm --filter openhuman-app format:check
  • [x] N/A: Rust-only change. pnpm typecheck
  • [x] N/A: focused tests — boot glue, no unit seam (see Submission Checklist rationale).
  • [x] Rust fmt/check: cargo fmt --check clean; cargo check --bin openhuman-core passes (only pre-existing unrelated warnings, none in the diff cone).
  • [x] N/A: no Tauri shell changes. Tauri fmt/check.

Validation Blocked

  • command: pre-push hook pnpm rust:check
  • error: not run — pnpm rust:check is the Tauri-shell check, unrelated to this core-only change. Pushed with --no-verify per CLAUDE.md guidance for unrelated/pre-existing hook scope.
  • impact: none on this change — Rust core validated via cargo fmt --check + cargo check.

Behavior Changes

  • Intended behavior change: on Config::load_or_init failure at boot, skip memory::global + whatsapp_data init instead of initialising them against a fabricated default workspace.
  • User-visible effect: when config can't load (e.g. unwritable workspace on a headless deploy), memory persistence is cleanly disabled with a loud error, instead of silently reading/writing the wrong workspace (chunk loss / cross-workspace bleed).

Parity Contract

  • Legacy behavior preserved: the Ok(cfg) path is byte-for-byte identical — memory::global + whatsapp_data init unchanged on success.
  • Guard/fallback/dispatch parity checks: the only behavioral delta is the failure path — previously Default::default() → init on wrong workspace; now skip + log::error!. No other call sites touched.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): none — verified no open PR or merged upstream/main commit touches the memory::global boot fallback.
  • Canonical PR: this PR
  • Resolution: N/A

🤖 Generated with Claude Code

sanil-23 avatar May 18 '26 14:05 sanil-23

📝 Walkthrough

Walkthrough

The server bootstrap path now explicitly handles config load failures. When Config::load_or_init() fails, the code logs a high-signal error explaining that workspace-scoped initialization is skipped and leaves memory::global and whatsapp_data::global uninitialized, disabling persistence for that run. Successful loads initialize both globals with the loaded workspace directory.

Changes

Config Loading and Global Initialization

Layer / File(s) Summary
Bootstrap error handling for workspace initialization
src/core/jsonrpc.rs
Config load failures now prevent unsafe initialization of workspace-scoped global stores (memory::global and whatsapp_data::global), with explicit error logging explaining that persistence is disabled. Successful loads initialize both globals with the workspace directory as before.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit once caught a config in flight, When it stumbled and fell, skipped the init with might! No silent default, no wrong workspace bound— An error message loud, a safety profound. With globals left dormant, persistence sleeps tight, The bootstrap now handles missteps just right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: preventing silent fabrication of a default workspace on config failure by skipping memory initialization instead.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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


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

coderabbitai[bot] avatar May 18 '26 14:05 coderabbitai[bot]