Skip to content

Move the daemon's settings into each database's settings node and delete daemon.toml (ADR-095) - #3664

Merged
mstomar125 merged 4 commits into
mainfrom
issue-3649-db-settings-node
Oct 6, 2026
Merged

mstomar125 merged 4 commits into
mainfrom
issue-3649-db-settings-node

Conversation

@malibio

@malibio malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #3649. Implements ADR-095.

Type: database-settings, now a structured core type (leaf, singleton database-settings-singleton, not embedded).

Fields added (base bucket): capture_enabled (bool, false), capture_content (enum metadata_only|summary|full, metadata_only), external_tools_enabled (bool, false), providers (list of ProviderConfig {id, name, base_url, api_key, model, routing_ok}, []), beside required_extensions. Nested config is snake_case, deny_unknown_fields; ids must be UUIDs.

Behaviour

  • Typed update is tri-state per field, also writes a singleton retyped to a subtype; a write that changes a provider's base_url/model drops its routing_ok.
  • Local agent resolves openai-compat:<uuid> against the chat's database; discovery cache is per database; probe verdict stored in the config.
  • Capture reads the session's database at launch; nodespace mcp serves a database only when its external_tools_enabled is on; mcp install/uninstall/status act on --database (else default) and name it.
  • Settings screen reads/writes through the node's typed update; providers are held in memory only (no localStorage copy of keys).

Removed: daemon.toml, DaemonConfig, reader/writer/lock, the SettingsService gRPC service and proto, the four Tauri commands, hand-copied OpenAiCompatConfig TS type.

Docs: node-types sheet, daemon protocol, agent-eval, ADR-056 sentence (docs repo, pushed before merge); skill CLI reference; eval preflight message.

bun run test:changed passes; new tests cover defaults, write/clear/reject, retyped singleton, verdict lifetime, and two open databases with different settings.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Review Type: Initial review (no prior reviews or comments on #3664).

The shape is right: the settings live as declared fields of database-settings, every consumer reads through NodeService::database_settings() in its own database, settings_service.rs, settings_service.proto, the Tauri commands and the daemon.toml path plumbing are gone, and no daemon.toml/DaemonConfig/SettingsService reference remains in packages/, scripts/ or .claude/skills. I found no compatibility code, no literal node_type == comparisons, no lifecycle_status reads and no #[allow(dead_code)]/#[deprecated] in the diff. One acceptance criterion is defeated by a bypass in the MCP passthrough (finding 1), so I am requesting changes.

Requirements Check

The type

  • ✅ Fields capture_enabled, capture_content, external_tools_enabled, providers declared in the base bucket (packages/core/src/models/core_schemas.rs, packages/nodespace-types/src/database_settings.rs).
  • ✅ Provider config is a declared nested object with deny_unknown_fields; provider ids must be UUIDs (database_settings.rs:139).
  • ✅ Registry entry stays a structured leaf singleton.
  • ✅ Wire type and typed update in nodespace-types; TypeScript regenerated and committed.
  • ✅ Typed update writes/clears/rejects; behaviour validates wrong type, unknown key, missing id (behaviors/mod.rs, database_settings_fields_test.rs).
  • ✅ Retyped singleton: a_retyped_singleton_keeps_its_base_bucket_settings_readable_and_writable uses a fixture subtype and type_is_a, not a literal compare.

Consumers

  • ✅ Local agent resolves openai-compat:<uuid> from the routed database's providers (local_agent_service.rs load_model); covered by a_provider_exists_only_in_the_database_that_configured_it and the daemon per_db_settings test. Discovery cache moved from the process-global handle to the per-database service inner: correct.
  • ✅ Verdict stored in routing_ok; dropped on endpoint/model change (see finding 3 for edge cases).
  • ✅ Capture reads from the session's database at launch (agent_session_service.rs).
  • ❌ nodespace mcp serves tools for a database only when that database's flag is true: bypassable (finding 1).
  • ✅ install/uninstall set the flag in the selected database and name it.
  • 🟡 Two databases in one test: present (daemon/tests/it/per_db_settings.rs, cli/tests/it/mcp_integration.rs), but the capture and external-tools halves do not drive the real consumers (finding 4).
  • ✅ New database defaults asserted.

Removal

  • ✅ daemon.toml, DaemonConfig, reader/writer, gRPC service, proto and Tauri commands deleted.
  • ✅ Settings screen goes through the typed update (database-settings.ts, settings.svelte.ts).
  • ✅ No carry-over of file contents.

Guidance and docs

  • ✅ packages/skill/references/cli.md, mcp-installer.ts, scripts/eval/preflight.ts updated; the docs listed in the issue no longer mention daemon.toml, and node-types.md already carries the new fields (checked in the docs checkout).
  • Not verified by me: node-types:check, SKILL.md drift check, test:changed.

Findings

🔴 Critical

  1. packages/cli/src/commands/mcp.rs build_child_args (~l.837-875): per-database enablement is bypassed by the passthrough. run_server checks the flag once, for the database selected at start. But an explicit --database <other> (or --socket) inside the tool call's args is honoured ("an explicit override in the tool call is honored"), so an external client enabled for database A can run any command against database B, whose external_tools_enabled is false. It can also run nodespace node update on B's settings node and enable the flag there. Under the old machine-wide flag this was coherent; with per-database enablement it defeats the ADR-038 trust boundary this issue exists to enforce. Fix: reject (or ignore and replace with the bound value) --database/--socket in dispatched args, with a test that a call carrying --database <disabled db> is refused. Related: when started without --database, child calls omit it and follow the daemon's current default, which can later differ from the database checked at start; forward the resolved database id instead of the raw selection.

🟡 Important

  1. mcp.rs install/uninstall/status/server now require a running daemon. Previously they worked from a file. uninstall can no longer disable the passthrough when the daemon is down while an installed client config persists. Give a clear error naming the daemon. Also confirm the ordering: the flag is set before the client config is written, so a failed client write leaves the flag enabled.

  2. Verdict-drop edge cases (packages/core/src/services/node_service/schema.rs update_database_settings_node; local_agent_service.rs record_routing_probe_verdict).

    • If DatabaseSettingsFields::from_properties(&existing.properties) errors, the if let Ok silently skips clearing and client-sent verdicts are stored as sent. Fail the write instead.
    • The recorder matches on base_url only. A model edit during a probe stores a verdict keyed by the old served model under the new config. Lookups by served model are unaffected, but the stated rule is endpoint or model; match model too or document that verdicts are keyed by served model.
    • The Settings screen sends its in-memory routing_ok back; a verdict written by the daemon after the last read is overwritten by the stale map for providers whose url/model did not change (costs one re-probe). Prefer treating routing_ok as server-owned in the client update.
  3. Test coverage. per_db_settings.rs proves providers per database through the real load_model, but capture only asserts CaptureConfig::from(settings) and external tools only asserts the stored boolean; neither drives session launch or the mcp gate there (the gate has its own CLI test, good). Add a launch-path test that two databases finalize with different capture content, a test for finding 1, and a test that two databases do not share a discovery cache.

🟢 Nits

  • Nit: local_agent_service.rs load_model: the comment "stored in the database's settings\n // node, not part" wraps awkwardly; reflow.
  • Nit: packages/desktop-app/src/lib/services/database-settings.ts updateDatabaseSettings retries with a re-read version but resends the same full providers list, so a concurrent provider edit is overwritten (last write wins). Say so in the doc comment.
  • Nit: the unreachable! after the retry loops (record_routing_probe_verdict, set_external_tools_enabled) can be avoided by structuring the loop so the final attempt returns.

Recommendation

REQUEST CHANGES. Finding 1 breaks the acceptance criterion that a database serves external tools only when its own flag is true; fix it with a test before merge. Findings 3 and 4 are strong recommendations; the rest is optional.

@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.

Review verdict: REQUEST CHANGES (self-authored PR, so posted as a comment). The MCP passthrough honours an explicit --database/--socket in tool args, which bypasses the per-database external_tools_enabled gate. See the full review comment on the PR.

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (d0299c7)

✅ 🔴 Passthrough bypass — build_child_args now refuses any --database/--socket in a call (both --flag v and --flag=v) unless it repeats the bound value (so a printed delete command still replays); the server binds to the resolved database id it checked at start, not the raw selection or the daemon's moving default. New unit tests + an end-to-end test (mcp_refuses_a_call_that_names_a_database_that_never_enabled_tools).
✅ 🟡 Unreadable stored list — verdicts are cleared instead of silently kept.
✅ 🟡 uninstall with daemon down — client configs are removed first; only the setting write needs the daemon.
⏭️ Daemon required for install/status/server — inherent: the setting lives in the database (ADR-095). Failure message is the standard "could not connect" text.
⏭️ Probe verdict matches base_url only — verdicts are keyed by served model, which may be discovered and differ from the config's model; a model change already drops verdicts server-side.
⏭️ Stale routing_ok from Settings overwriting a newer verdict — costs one re-probe; not worth a daemon-owned-field split.
⏭️ Extra tests (session-launch capture, discovery cache), nits — capture and discovery read the same per-database NodeService covered by the two-database test; not adding more plumbing tests.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED — hmm, see below.

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Correction — Re-Review Decision: RE-REVIEW NEEDED. The critical fix changes how the MCP passthrough binds and parses routing flags (new logic plus an e2e test), so the new commit needs a review.

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review: Re-Review of d0299c7 (PR #3664)

Review Type: Re-Review (scope: git diff fa36f5019..HEAD)
Previous review: 1 Critical, 3 Important, 3 Nits. Addressed: the Critical, the unreadable-list Important, and the uninstall ordering. Skipped with reasons: 4 items (see below).

Summary

The critical bypass is closed. build_child_args now parses the post-shell_words word list, which is exactly what the child's clap parser sees, and refuses any --socket/--database whose value is not the bound one. The server binds to the resolved database id.

Bypass verification (packages/cli/src/commands/mcp.rs build_child_args, ~l.850-915)

  • --flag v and --flag=v: both split and compared; covered by unit and e2e tests.
  • Quoting ("--database", '--database=x'): matching is on unquoted words, so quoting cannot hide the flag.
  • Abbreviations: Cli in packages/cli/src/lib.rs has no infer_long_args (no infer_ anywhere in the crate), so --data/--sock are rejected by clap, not accepted as aliases. No alias on either arg.
  • Short flags: neither arg declares short, so -d is not accepted.
  • After --: the loop does not stop at --, so --database other after it is refused (conservative; clap would treat it as a positional). No bypass.
  • Env vars: NODESPACED_SOCKET/NODESPACE_DATABASE are read only when the flag is absent. The argv always carries --socket and, since the server always binds an id, --database, so env cannot reach the child.
  • nodespace prefix strip: only the first word, consumed before the loop, so it cannot be used to skip the check.
  • Binding: run_server uses target.id (registry id) and fails with a clear error if the daemon has no default. A later database use no longer moves a running server.
  • Uninstall ordering: client configs are removed first, then the flag write. Install already wrote client config before setting the flag. Both orderings fail safe.
  • Unreadable stored list (packages/core/src/services/node_service/schema.rs): unwrap_or_default() clears every submitted verdict. Fail-closed; the write replaces the unreadable list anyway.

Findings

Critical

None.

Suggested Improvements (non-blocking)

  • packages/cli/src/commands/mcp.rs (tests): the unit tests do not pin the -- case, the nodespace prefix interaction, or a quoted flag. The loop handles them today; one table row each would stop a later refactor (e.g. making the loop stop at --) from reopening the hole.
  • packages/cli/src/commands/mcp.rs: the passthrough can still run registry commands (database remove|rename|use|create|register). These cannot read or write another database's data or flip its flag, so they are not a gate bypass. database remove <bound> leaves a bound server pointing at an unregistered id; calls then fail closed. Whether the passthrough should allow database subcommands at all is a separate question from this PR.

Nits

  • Nit: build_child_args refuses a trailing value-less flag and a positional equal to the literal --database. Over-refusal only; acceptable.

Skipped items

  • Daemon required for install/status/server: reasonable, the setting lives in the database (ADR-095).
  • Probe verdict keyed on base_url, not model: reasonable, verdicts are keyed by served model and a config model change already drops them server-side.
  • Stale routing_ok overwrite from Settings: reasonable, costs one re-probe.
  • Extra capture/discovery-cache tests and nits: acceptable, the shared per-database NodeService is covered by the two-database test.

Recommendation

APPROVE. The per-database external_tools_enabled gate is now enforced for the whole life of the server, with unit and end-to-end tests. Posted as a comment because the PR is self-authored. No further re-review needed.

@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.

Re-review verdict: APPROVE (posted as a comment, self-authored PR). The MCP passthrough bypass is closed; see the full re-review comment.

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed: added the three suggested refusal rows (--, nodespace prefix, quoted flag) to the unit test. Declined: whether database subcommands belong in the passthrough (not a gate bypass; separate question).

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: the re-review approved with no critical findings; the only change since is three test rows.

malibio and others added 4 commits October 6, 2026 11:24
…ete daemon.toml (ADR-095)

database-settings declares capture_enabled, capture_content, external_tools_enabled
and providers beside required_extensions; the local agent, session capture and
nodespace mcp each read the database they are routed to. The settings gRPC
service, daemon.toml and its Tauri commands are deleted.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- A tool call may not name another --database/--socket (refused in both flag
  spellings); the server forwards the resolved database id, so a later change
  of the default cannot move it. Only the bound values are accepted, so a
  printed delete command still replays.
- uninstall removes client configs before it needs the daemon.
- An unreadable stored provider list clears routing verdicts rather than
  keeping them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…efix and quoted-flag forms

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.

Move the daemon's settings into each database's settings node and delete daemon.toml (ADR-095)

2 participants