Repository navigation
Description
Problem
LocalAgentServiceImpl::new turns a recoverable error into a panic:
// packages/daemon/src/services/local_agent_service.rs:208
let model_manager =
Arc::new(GgufModelManager::new().expect("GgufModelManager initialization failed"));It is called from build_database_services (packages/daemon/src/services/assembly.rs), which is the per-database open path — so this runs every time a database is opened, not once at startup.
Why it matters
Under ADR-053 one daemon serves N databases and opens them lazily, on demand: a request carrying x-ns-database-id for a database that is not currently open triggers get_or_open → build_database_services. A database can also be reopened after the idle reaper evicts it.
So this is not a startup-only risk. A single failing open panics the entire daemon, taking down every other database's session, the sync service, and the gRPC server with it — the daemon holds the database lock and is the only host for all business logic, so that is a full service outage triggered by one routed request.
The failure is reachable, not theoretical
GgufModelManager::new() (packages/agent/src/local_agent/model_manager.rs:350) fails on two ordinary environmental conditions:
$HOMEunset —default_models_dir()(line 1074) returnsModelError::Other("could not determine models directory: $HOME is unset"). Reachable when the daemon runs under a service manager / launchd job / container without a HOME in its environment.create_dir_all(~/.nodespace/models)fails (line 357) — read-only filesystem, a permissions problem, disk full, or a plain file already sitting at that path.
Neither is a programming error, which is the only thing expect is appropriate for.
Suggested fix
build_database_services already returns Result, so the error has somewhere to go. Either:
- make
LocalAgentServiceImpl::newreturnResultand propagate — the open fails, that one database reports an error, the daemon and every other database survive; or - degrade: keep the service constructed with no model manager, so local-agent features are unavailable for that database while the rest of it works. This matches how a missing NLP model is already handled —
has_model = falseskips the embedding wiring rather than failing the open.
The second is probably the better fit: an unusable models directory should not make a database unopenable, since nothing else about the database depends on it.
Notes
- Found by a sweep for panic paths reachable from request handling; this was the only
expecton a non-test daemon path that is reachable at runtime (the others are in#[cfg(test)]blocks inmain.rs). - Touches
packages/agent/local_agent, which is @malibio's area — filing rather than fixing.
Activity
mstomar125 commentedon Aug 19, 2026
Fixed in #2155.
`LocalAgentServiceImpl::new`'s `model_manager` field is now `Option<Arc>`. A failed `GgufModelManager::new()` now logs and degrades — the database still opens, with local GGUF model management (list/download/delete/load/unload/cancel/recommended) reporting `Status::unavailable` instead of failing the open, matching how a missing NLP model already disables only the embedding wiring rather than the database open. Chat turns and OpenAI-compatible models are unaffected.
Added regression tests: one proving the underlying `create_dir_all` failure is a real, non-panicking `Err` (via `GgufModelManager::with_dir` over a file-occupied path), one exercising the degraded `LocalAgentServiceImpl` end to end (all six model-management RPCs return `UNAVAILABLE`, not a panic), and one confirming an ai-chat turn still completes normally in degraded mode.