Skip to content

Opening a database can panic the whole daemon: LocalAgentServiceImpl::new expects GgufModelManager to succeed #2043

Closed

Description

@mstomar125

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:

  1. $HOME unset — default_models_dir() (line 1074) returns ModelError::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.
  2. 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::new return Result and 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 = false skips 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 expect on a non-test daemon path that is reachable at runtime (the others are in #[cfg(test)] blocks in main.rs).
  • Touches packages/agent/local_agent, which is @malibio's area — filing rather than fixing.

Activity

  1. added
    bug
    on Aug 12, 2026
  2. self-assigned this
    on Aug 12, 2026
  3. mstomar125 commented on Aug 19, 2026

    @mstomar125
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendbughigh-priority

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions