Repository navigation
Description
Overview
Split out of #2815. That issue reported a create_schema that returned success while the schema was absent from nodespace search --type schema. Investigation showed the core write path is sound — the schema very likely was written, to a different database than the one the CLI read.
#2815 fixed the reporting defect (the result payload was an echo of the request and so could not have reported a miss either way). This issue is the remaining half: write and read can silently resolve to different databases.
Problem
DatabaseIdInterceptor::none() stamps no x-ns-database-id header (packages/cli/src/lib.rs:48-52), and the daemon then resolves the request against registry.default_database (db_routing.rs → resolve_database_id(None)). So any CLI invocation without --database reads the default database.
An agent turn, meanwhile, runs against the NodeService its per-database event watcher is bound to — the database the ai-chat node lives in. If the user is chatting in a non-default database, the write lands there correctly and a subsequent bare nodespace search reads somewhere else.
Nothing surfaces the mismatch. The write succeeds, the read succeeds, and the row is simply not in the result — indistinguishable from a write that never happened, which is exactly how #2815 was first diagnosed.
Why this is worth fixing separately
The failure mode is silence. A wrong-database read returns a well-formed empty answer, so a user (or an agent verifying its own work) concludes the data is gone and takes destructive corrective action — re-creating a type that already exists, or reporting data loss that did not occur.
Note #2187/#2267 already addressed the daemon side of this area, routing the local-agent turn-state RPCs by x-ns-database-id. What remains is the CLI's default-resolution behavior, which was not in that scope.
Possible directions
Not a decided design — worth discussing before implementing:
- Have the CLI resolve and stamp the active database id explicitly rather than relying on the daemon's default, so "which database am I talking to" is always answered client-side.
- Print the resolved database (id and name) in the header of read commands like
search, so a wrong-database read is visible rather than silent. - Have the daemon echo the database it served in response metadata, and have the CLI surface it on an empty result.
Acceptance Criteria
- A CLI read and an agent write in the same session cannot silently resolve to different databases, or the divergence is surfaced where a user would see it
- An empty result from a read makes clear which database was searched
- Regression test pins the case: revert the fix and confirm the test fails
- Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Reference Files
packages/cli/src/lib.rs:42-74—DatabaseIdInterceptor,none()vsfor_id()packages/daemon/src/db_routing.rs—routed_database_services, header resolution and default fallbackpackages/daemon/src/services/local_agent_service.rs— the turn's per-databasenode_servicebinding../nodespace-docs/decisions/053-one-daemon-multiple-databases.md— ADR-053, "the desktop app stamps the active database id on every call"
Related
- create_schema reports success with a populated field list for a schema that was never persisted #2815 — the reporting half, fixed separately
- LocalAgentService is not database-routed while its engine/turn state is per-database — AI chat broken on every non-default database #2187 / PR Route LocalAgentService per database over one daemon-global engine, and make DatabaseServices teardown a single complete operation #2267 — daemon-side routing of local-agent turn state
Activity
Address review: distinguish an absent schema from an unreadable one
Pin the resolved default database id on CLI reads (closes #2835)