Repository navigation
daemon: stop model-manager init failure from panicking the whole process - #2155
Conversation
…nager init failure GgufModelManager::new() failing (e.g. $HOME unset, an unwritable or file-occupied models directory) used to be an unwrap-via-expect in LocalAgentServiceImpl::new. build_database_services runs on every per-database open under ADR-053 (databases open lazily on demand and can reopen after idle eviction), so that panic took down the whole daemon process — every other open database, the sync service, and the gRPC server — over a single database's model-manager failure. model_manager is now Option<Arc<GgufModelManager>>: a failed init logs and degrades this database's local GGUF model management (list/download/ delete/load/unload/cancel/recommended report UNAVAILABLE) instead of failing the open, mirroring how a missing NLP model already disables only the embedding wiring (SharedContext::has_model) rather than the database open. Chat turns and OpenAI-compatible models are unaffected since neither depends on the GGUF model manager. Adds a shared from_model_manager construction path (used by both new() and tests) and regression tests: one proving GgufModelManager::with_dir fails cleanly (not a panic) when its directory path is occupied by a file, and two exercising the degraded LocalAgentServiceImpl end to end — the six model-management RPCs return Status::unavailable, and an ai-chat turn still completes normally. Co-Authored-By: Claude <[email protected]>
…s real failure path The three original regression tests all constructed the degraded shape via from_model_manager(..., None) directly, so none of them actually drove GgufModelManager::new() to fail inside LocalAgentServiceImpl::new itself — the exact match arm that replaced the original .expect(...). A revert of that arm back to a panic would have passed all three tests unnoticed. Adds local_agent_service_new_survives_a_real_model_manager_init_failure, which points $HOME at a tempdir whose .nodespace/models path is occupied by a file and calls the real constructor, asserting it degrades (model_manager: None) rather than panicking. The $HOME mutation is bounded to new()'s synchronous body (no .await in between) and a repo-wide grep confirms no other test in this crate's unit-test binary reads $HOME, so it does not race any other test. Also corrects a doc comment that said degraded mode persists "until the daemon is restarted" — ADR-053's idle-reaper eviction-then-reopen also re-runs build_database_services and gets a fresh chance to succeed, without a full restart. Co-Authored-By: Claude <[email protected]>
|
Self-approving (mstomar125) — GitHub blocks self-approval via the formal review API for the PR author, so recording it here per repo convention. Adversarial review sub-agent pass completed: independently checked out the branch, diffed against origin/main, compiled, and re-ran the test suite; verified every One real gap flagged: none of the original three tests drove Final independent re-verification on the pushed HEAD: |
Summary
LocalAgentServiceImpl::newusedGgufModelManager::new().expect(...), turning a recoverable environmental failure ($HOMEunset, an unwritable or file-occupied models directory) into a panic.LocalAgentServiceImpl::newis called frombuild_database_services, the per-database open path — under ADR-053 a daemon serves many databases, opened lazily on demand (and reopened after idle eviction), so this panic ran on every open, not just at startup. A single failing open took down the whole daemon process: every other open database, the sync service, and the gRPC server along with it.Fix
model_manageris nowOption<Arc<GgufModelManager>>. A failed init logs the error and degrades — the database still opens, with local GGUF model management (list/download/delete/load/unload/cancel/recommended) reportingStatus::unavailableinstead of failing the open. This mirrors the existing convention inassembly.rs/local_agent_service.rsfor an optional per-database capability whose init failure shouldn't block the open: a missing NLP model already disables only the embedding wiring (SharedContext::has_model), not the database open. Chat turns and OpenAI-compatible models are unaffected — neither depends on the GGUF model manager.Concretely:
list_modelscontributes an empty local catalog instead of failing outright (OpenAI-compat discovery is independent and still works).download_model/delete_model/load_model/unload_model/cancel_model_download/recommended_modelreturnStatus::unavailablewith a clear message.load_model_and_collect_eventsemits anerrorprogress event instead of panicking.LocalAgentServiceImpl::from_model_manager, a shared construction path used by bothnew()and tests, so the degraded shape can be exercised without touching$HOMEor the real models directory.Testing
gguf_model_manager_new_fails_cleanly_when_models_dir_path_is_a_file— proves the underlying failure (create_dir_allover an occupied path) is a real, non-panickingErr, using the existingGgufModelManager::with_dirtest constructor.model_management_rpcs_degrade_when_model_manager_init_failed— builds aLocalAgentServiceImplwith the model manager forced absent and asserts all six model-management RPCs returnStatus::unavailable(not a panic), andlist_modelsstill succeeds with an empty local catalog.ai_chat_turn_still_works_when_model_manager_init_failed— proves the rest of the service (an ai-chat turn end to end) is unaffected in degraded mode.cargo test -p nodespace-daemon: 151 unit tests + all integration suites pass.cargo clippy -p nodespace-daemon --all-targets: clean (had to move a helper fromResult<_, Status>toOptionto satisfyclippy::result_large_err—Statusis ~176 bytes and my helper's naturalOkside is a bare pointer, unlike the gRPC handlers themselves whoseResponse<T>Okside keeps them under the lint's threshold).cargo clippy --all-targetsis blocked by a pre-existing, unrelatednodespace-appbuild failure (missingresources/skill/**/*glob target) — reproduced identically onorigin/mainwith no changes, confirmed out of scope for this fix.Closes #2043