Skip to content

Resolve the GGUF models directory through the daemon's NodeSpace home (closes #3761) - #3762

Merged
malibio merged 2 commits into
mainfrom
issue-3761-models-dir-home
Oct 12, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3761-models-dir-home

Conversation

@malibio

@malibio malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

On Windows the daemon logged could not determine models directory: $HOME is unset at startup and ran with local GGUF model management disabled, because GgufModelManager::new() read only HOME. Windows defines USERPROFILE, not HOME.

  • Add models_dir() beside nodespace_dir() in the daemon: the models/ directory under the NodeSpace home, which follows NODESPACE_HOME and otherwise asks the platform for the user's home.
  • Use it for both the embedding model lookup (resolve_model_path) and the GGUF model manager, so the two share one resolution instead of two parallel ones.
  • Delete GgufModelManager::new() and default_models_dir(). The daemon passes the directory to with_dir(), so the rule has one copy.
  • Three live agent tests that located the user's real models now say so explicitly with dirs::home_dir().

Test plan

  • shared_local_agent_new_opens_the_model_manager_when_home_is_unset (new): with HOME unset the manager opens and creates the models directory under the NodeSpace home
  • shared_local_agent_new_survives_a_real_model_manager_init_failure: now redirects through NODESPACE_HOME; a file occupying the models path still degrades cleanly
  • Both fail against the previous HOME-only code (reverted the fix locally and watched them fail)
  • bun run test:changed (scripts, types, node-types, Rust workspace via nextest) and bun run quality:fix pass

Not covered: a real Windows run of the fixed daemon. The failure was observed on the v0.3.5 installer in a Windows 11 ARM VM; the fix is verified by the tests above, not by relaunching it there.

Closes #3761

🤖 Generated with Claude Code

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic code review: initial review

Verdict: REQUEST CHANGES (posted as a comment; GitHub blocks requesting changes on one's own PR). The production fix is clean and minimal; one test-support regression needs fixing first.

Requirements check (#3761)

  • With HOME unset the model manager initializes (open_model_manager -> models_dir() -> nodespace_dir() -> dirs::home_dir())
  • The models directory follows NODESPACE_HOME
  • One resolution shared by the embedding model and the GGUF manager; default_models_dir and GgufModelManager::new deleted with no shim
  • Degraded-mode test kept, now redirecting through NODESPACE_HOME
  • [~] A test covers HOME unset. It also sets NODESPACE_HOME, so it proves the manager no longer reads HOME but does not exercise the dirs::home_dir() fallback. That fallback is shared code the database path already uses, so acceptable.
  • No remaining doc or comment says the models path honours $HOME (repo and nodespace-docs searched)

Findings

Critical: daemon-spawning app-lib tests now look in the wrong directory
packages/desktop-app/app-lib/test-support/src/lib.rs:112 and :372-387 (model_file_available)
SpawnedDaemon::spawn_with_socket sets NODESPACE_HOME=<tmp_dir>. Before this PR the daemon's GgufModelManager::new() read the real $HOME/.nodespace/models, so the guard and the daemon agreed. After it, the daemon looks in <tmp>/.nodespace/models (empty) while model_file_available still checks the real $HOME. The guard passes, then the daemon finds no model: the download test starts the live multi-gigabyte fetch its own comment warns about, or the ai-chat test fails. Verified by reading spawn_with_socket.
Principle: a skip guard must test the same resolution as the code under test.

Important: model_file_available doc comment is badly rewrapped and misleading (same file, :372-376).

Important: with_env is not panic-safe (local_agent_service.rs, test module). Harmless under nextest; a Drop guard makes it correct on any runner.

Nit: packages/agent/src/golden/runner.rs:35 still reads HOME only (dev-tool default); the same one-liner this PR already uses fixes it.

Nit: bundled_model.rs:114 and nlp-engine/src/config.rs:325 build the models path by hand. Neither regresses; the first is pinned by a test, the second only runs for standalone callers with no explicit path.

Answers to the author's questions

  • Non-test source with HOME-only reads: only the golden/runner.rs nit.
  • with_env under nextest: safe (process per test, one synchronous call).
  • Behaviour lost by dropping GgufModelManager::new(): none; directory creation stays in with_dir, error text unchanged.
  • Windows paths in models_dir(): correct (dirs::home_dir() uses the platform API; empty NODESPACE_HOME is treated as unset).

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment; GitHub blocks requesting changes on one's own PR). Full findings in the review comment above.

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Review feedback addressed (75f11f4)

Addressed (4)

  • 🔴 Spawned test daemons looked in the wrong directory. Confirmed by reading spawn_with_socket (it sets NODESPACE_HOME=<tmp>), and again by experiment: with the link removed, download_of_an_already_present_model_reaches_ready_with_no_error started the live HuggingFace download instead of failing fast. Replaced model_file_available with SpawnedDaemon::spawn_with_user_model(filename): it returns None (skip) when the user lacks the model, and otherwise links that one file into the daemon's isolated models directory. The check and the link are one operation, so they cannot disagree. Only the file is linked, never the directory, so the embedding model stays invisible to isolated daemons (the isolation assembly.rs documents).
  • 🟡 Mangled model_file_available doc comment. Gone with the helper; the new doc states the contract and why one file is linked.
  • 🟡 with_env not panic-safe. Now restores through a Drop guard.
  • 🟢 golden/runner.rs read HOME only. Uses dirs::home_dir().

Skipped (2)

  • bundled_model.rs:114 builds the models path by hand: it is pinned by the existing the_target_is_the_daemons_model_path test, so drift is caught.
  • nlp-engine/src/config.rs:325 fallback: only reached by standalone callers with no explicit path; the daemon always passes one. Revisit if nlp-engine can start depending on the daemon's resolver.

Verification

  • On a machine with the 5 GB model, all five ai_chat_send_to_idle_test / model_download_terminal_state_test tests pass through the link (the load and ai-chat tests genuinely load it, ~3 min each).
  • bun run quality:fix and bun run test:changed (scripts, types, node-types, Rust workspace) pass.

Re-review decision

RE-REVIEW NEEDED. The critical finding was a behavioural fix with new test-support API and three edited test files, not a cosmetic change. Run /pragmatic-code-review again; it should review only 75f11f4.

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic code review: re-review of 75f11f4

Verdict: APPROVE (posted as a comment; GitHub blocks approving one's own PR). Verification was by reading the diff and the code it touches; tests were not re-run by the reviewer (the author's runs are in the previous comment).

Previous feedback

4 recommendations: 4 addressed, 0 not addressed, 0 new blocking issues, 2 nits. The 2 author skips are acceptable.

  • 🔴 Spawned daemons looking in the wrong directory: fixed. The daemon's models dir is nodespace_dir()/models = <NODESPACE_HOME>/.nodespace/models; spawn_with_user_model builds exactly <tmp>/.nodespace/models, and the check and the link are one operation. Only one file is linked, so the embedding model stays invisible. The link is created before spawn_with_socket, so the daemon never starts without it. The daemon_with_model_or_skip! macro type-checks in the unit-returning tokio tests.
  • 🟡 Mangled doc comment: fixed (helper deleted; no model_file_available reference remains in the repo or nodespace-docs).
  • 🟡 with_env panic safety: fixed. RestoreEnv is constructed before any mutation; repeated keys restore idempotently.
  • 🟢 golden/runner.rs HOME-only default: fixed (dirs::home_dir(); dirs is already an agent dependency).

Risk checks

  • Could a test damage the user's real model through the link? No path found. delete_model uses remove_file (removes the link, not the target); a download writes <file>.partial and renames over the final path, and is only reached when the file is absent; tempdir cleanup does not follow symlinks.
  • Daemon owner-only directory handling: create_dir_owner_only tolerates a pre-existing directory and chmods it to 0700; no conflict.
  • std::env::home_dir() on the pinned 1.97.0: fine (un-deprecated in 1.85).

Nits (no action required)

  • 🟢 test-support/src/lib.rs:109: the user's model is found through std::env::home_dir() and ignores a NODESPACE_HOME in the developer's own environment, so a developer running their daemon under a custom home sees a spurious skip. The skip message names ~/.nodespace/models, so this is the documented location.
  • 🟢 test-support/src/lib.rs:413-419: on Windows symlink_file needs Developer Mode or privilege and would hit the .expect panic. A copy fallback is optional; the gate runs on macOS, so not worth a change now.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review of 75f11f4): APPROVE (posted as a comment; GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review: re-review of 75f11f4

No code changes. The re-review verdict is APPROVE with two optional nits, both deliberately not taken:

  • Developer's own NODESPACE_HOME is ignored when locating the user's model (test-support/src/lib.rs:109): the lookup is the documented ~/.nodespace/models, which the skip message names. Honouring a custom home would make the guard depend on an environment variable the isolated daemon itself overrides, which is the drift the previous fix removed. Revisit if someone runs their real daemon under a custom home and finds the skip confusing.
  • Windows symlink_file privilege (test-support/src/lib.rs:413-419): these two tests are model-gated and the gate runs on macOS. A copy fallback would duplicate a ~5 GB file per test, so it is not free. Revisit if the gate ever runs these on Windows.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED. No code changed since the approved commit, so there is nothing new to review. Merging is the user's call.

malibio and others added 2 commits October 12, 2026 13:06
…closes #3761)

GgufModelManager::new() read only HOME, which Windows does not set, so the
daemon logged "could not determine models directory: $HOME is unset" at
startup and ran with local GGUF model management disabled.

Add models_dir() beside nodespace_dir() in the daemon and use it for both the
embedding model lookup and the model manager, so the two share one
resolution that follows NODESPACE_HOME and finds the user's home through the
platform. Delete GgufModelManager::new() and default_models_dir(); the daemon
passes the directory to with_dir().

The degraded-mode test now redirects through NODESPACE_HOME, and a new test
opens the manager with HOME unset. Both fail against the HOME-only code.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…refs #3761)

A spawned test daemon's models directory sits under its isolated
NODESPACE_HOME, so now that the GGUF manager follows that home, the model
in the user's real ~/.nodespace/models is invisible to it while the old
model_file_available guard still checked the real home. The guard passed and
the daemon then started a live multi-gigabyte download.

- Replace model_file_available with SpawnedDaemon::spawn_with_user_model,
  which returns None (skip) when the user lacks the model and otherwise
  links that one file into the daemon's isolated models directory. The check
  and the link are one operation, so they cannot disagree. Only the file is
  linked, never the directory, so the embedding model stays invisible.
- Make the with_env test helper restore variables through a Drop guard.
- Resolve the golden runner's default model path with dirs::home_dir().

Skipped: bundled_model's hand-built models path (pinned by an existing test)
and nlp-engine's standalone fallback (only reached with no explicit path).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3761-models-dir-home branch from 75f11f4 to 2427a7e Compare October 12, 2026 11:06
@malibio
malibio merged commit bd278a0 into main Oct 12, 2026
@malibio
malibio deleted the issue-3761-models-dir-home branch October 12, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local model management is disabled on Windows because the models directory is resolved from $HOME

1 participant