Repository navigation
Make create_schema's result reflect the persisted row, and pin the CLI's target database - #2832
Conversation
…loses #2815) `create_schema` returned `is_error=false` with a fully-populated field list for a schema that was never persisted, and the agent — correctly trusting its own tool result — told the user the type had been created. Investigation: the write path is sound. A probe reproducing the reported two-call sequence against a fresh database persisted both schemas. The transaction machinery propagates commit errors, `INSERT INTO node` is a plain insert (a duplicate id errors rather than silently skipping), and there is no schema cache. The `OCC bypassed` warnings are on `update_nodes_batch` and no create_schema path reaches them. So the failure is not deterministic for that input, and the "write did not land" premise does not hold at the core layer. What was actually broken is that nothing would have caught it if it had: 1. The result was an echo of the request. `CreateSchemaOutput` was built from `stored_fields`/`schema_id`, both derived from the caller's arguments, and the id the transaction actually produced was discarded as `_created_schema_id`. Such a payload is identical whether or not the write landed, so it cannot report the difference. It now reads the committed schema node back and is built from that; a schema that cannot be verified is an error naming the schema and stating plainly that nothing was created. 2. The agent's no-op-success guard was structurally blind to this. It counts `result["fields"].len()`, which for create_schema *was* the model's own input echoed home, so every non-empty call reported a non-zero count regardless of what persisted. Its doc comment asserted the opposite premise; the read-back now makes that premise true, and the comment says so. 3. The exists-check swallowed read failures. `if let Ok(Some(..))` routed both `Err` and `Ok(None)` into the write, which then hit the primary-key constraint and surfaced as an opaque internal error naming neither the real problem nor the repair. An unreadable schema table is not evidence of an absent schema, so the error is now propagated. Testing the read-back needs a seam. On every path reachable through the public API an echoed payload and a read-back payload are byte-identical — verified for fields, derived friendly names, relationships and `extends` — and the store is sealed by design, so no test can make a committed row vanish. `NodeService::set_write_verification_fault` (inert unless armed, never called by the daemon) reaches that branch. The regression test was confirmed to fail with the fix reverted, reproducing the reported shape exactly: `is_error=false`, two fields, `schemaId: event_venue`, and no such schema. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Pragmatic Code Review — PR #2832Review Type: Initial Review (zero prior reviews, zero prior comments) SummaryThis is a net positive change and I recommend merging after one small correctness fix. The framing is the strongest thing about it. The reporter's premise ("the write did not land") turned out not to hold at the core layer, and rather than paper over that, the PR says so explicitly, keeps the investigation evidence in the commit message, and then fixes the thing that was genuinely broken: the result payload could not distinguish a write that landed from one that did not. That is the correct reduction. A tool result that is a function of its own input carries zero information about the world, and every downstream consumer — including Defect 3 ( I verified the 5 new tests build and pass ( Requirements Check — acceptance criteria from #2815
Findings🔴 CriticalNone. Nothing here is a security issue, a data-integrity regression, or an architectural regression. 🟡 Improvements🟡-1 📁
|
| Rule | Status |
|---|---|
| No lint suppression | ✅ none added |
No #[allow(dead_code)] |
✅ none |
No #[deprecated] |
✅ none |
| No backward-compat / migration code | ✅ — and worth stating plainly, since a "read the row back" change is adjacent to the banned shape: this adds no schema-version check, no backfill, and no on-read format upgrade. It reads the row it just wrote, in the shape it just wrote it. Not a migration. |
| No docs added to this repo | ✅ no .md files, no docs/ directory |
| Logging standards | ✅ Rust-only change; existing tracing usage untouched |
| No issue numbers in code comments | ✅ — the new comments reference behavior and ADRs, not issue numbers |
| Test command discipline | ✅ bun run rust:test:core used, not bare cargo test -p nodespace-core |
Verdict
✅ APPROVE — with 🟡-1 requested before merge
The core change is right, the reasoning is unusually well documented, the investigation is honest about what it could and could not reproduce, and the test that matters genuinely pins the fix. This measurably improves code health: a tool result that was structurally incapable of reporting failure now is capable of it, and a cross-package guard that was resting on a false premise now rests on a true one.
Before merge:
- 🟡-1 — make the "It was NOT created" claim one the code can support, or soften it. This is small and it is the same class of defect the PR fixes.
Before closing #2815:
- 🟡-4 — file the CLI database-routing follow-up and reference it from the closing comment.
Author's call, no re-review needed:
- 🟡-2 (
test-supportfeature — defensible as-is; introduce the feature when a second seam appears), 🟡-3 (one comment line ondescription), and the nits.
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (with one item requested before merge) (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Review findings from PR #2832. Addressed: - The "It was NOT created" error could be a false statement, and in the damaging direction. `get_schema_node` folds two facts into one `Ok(None)`: the row is absent, or it is present and `SchemaNode::from_node` failed on it. Asserting the first without checking was this PR's own bug in miniature — claiming more than the read established. An agent told a schema it did commit was never created retries, the exists-check reads `Ok(None)` too, and the retry hits the primary-key collision the exists-check exists to prevent. One raw row read tells them apart, and each case now gets its honest diagnosis. New test verified to fail without the fix. - `description` is the one output field still taken from the request. It is parsed into a markdown child subtree rather than stored on the schema node, so reading it back would mean reassembling prose from nodes and would not round-trip. Documented, with why it carries none of the weight that made echoing the field list a defect. - `#[non_exhaustive]` on `WriteVerificationFault`, so a later variant is not a breaking change to the re-export. - Recorded the consequence of a predicted/actual schema-id divergence: the verification read fails loudly rather than emitting a wrong `schemaId`. - Documented that `pub` on `set_write_verification_fault` is forced, not chosen — the only caller is an integration test under `tests/`, a separate crate that neither `#[cfg(test)]` nor `pub(crate)` reaches. Filed #2835 for the CLI database-routing divergence, rather than leaving the hypothesis in a PR description. Verified before filing: the CLI stamps no `x-ns-database-id` unless given `--database`, so a bare read resolves to the daemon default while an agent turn writes to its own event watcher's database. Skipped, with reasons: - A `test-support` Cargo feature for the seam. The review rated this "introduce it when a second seam appears"; a feature plus a self-referencing dev-dependency is disproportionate for one. The asymmetry it correctly flagged is documented instead. - `parse_declaration_row`'s warn-and-drop in relationships.rs — pre-existing and outside this change. - Trimming the agent_loop.rs comment — it is the record of why the no-op guard's premise is now sound, which is the point of the change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The other half of the create_schema disappearance. #2815 fixed the tool reporting a success it had not verified; this fixes the divergence that most likely made a verified write look absent in the first place. With no `--database`, the CLI stamped no `x-ns-database-id` header at all, so the daemon resolved the request against whatever `registry.default_database` held when it arrived. An agent turn, meanwhile, writes to the database its own event watcher is bound to — the one the ai-chat node lives in. Chat in a non-default database and the write lands correctly while a bare `nodespace search` reads somewhere else. Both paths reached the same database whenever the default happened to be the right one, which is why this never showed up as an error. The failure mode is silence: a wrong-database read returns a well-formed empty result, indistinguishable from a write that never happened, and a user or an agent verifying its own work concludes the data is gone. `resolve_routing` now resolves the default to a concrete id and stamps it, so the target is a fact the CLI knows rather than one the daemon decides per request, and it stays fixed for the whole invocation rather than following a default that changes mid-session. The single behavioral change: the id is resolved once at startup. `None` is returned only when the daemon reports no default at all, which is left for the command to surface — an unstamped request would have failed downstream on the same condition. `resolve_routing` becomes `pub` because it is the function whose contract changed and the unit the regression test drives. Regression test verified to fail without the fix (resolved `None` where the seeded default's id was expected). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Address-review summaryTwo commits since the review: Addressed🟡-1 — the requested-before-merge fix. Correct and important catch: 🟡-3 — 🟡-4 — file the routing follow-up. Filed as #2835, then folded into this PR on the author's instruction (see below). 🟢 🟢 Correction acceptedThe review was right that I mis-cited the precedent for the test seam. Also in scope now: #2835Folded in at the author's request rather than left as a follow-up. With no
Skipped, with reasons
Verification
Re-Review DecisionDecision: RE-REVIEW NEEDED Rationale: |
Pragmatic Code Review — PR #2832 (Re-Review)Review Type: Re-Review Previous Review Summary
Addressed: 5. Skipped with sound reasons: 3. New issues: 2 (both 🟡). I verified every claim in the address-review summary against the diff rather than taking it at face value. All of them hold. I also re-ran the tests myself: 1. Was 🟡-1 properly addressed? — Yes, correctly.📁 The author took the preferred option, not the cheap one. The
This is the right resolution on both counts I care about. The distinction is drawn correctly, and — the part that matters more — the second message closes the trap the prior review described. The retry loop I sketched (agent told "NOT created" → retries → exists-check also reads The honesty is also right in a subtler place. The fault model is faithful. 📁 One deliberate detail worth naming as correct: The test genuinely pins it. 🟡-1 is resolved. It does not block. 2. The new CLI work in
|
| Rule | Status |
|---|---|
| No lint suppression | ✅ none added |
No #[allow(dead_code)] / #[deprecated] |
✅ none |
| No backward-compat / migration / dual-mode | ✅ — worth stating for the CLI change specifically: the old unstamped path is deleted, not kept behind a flag or a fallback. None now means "the daemon has no default", not "route the old way". That is the greenfield shape. |
| No docs added to this repo | ✅ no .md, no docs/ |
| No issue numbers in code comments | ✅ — the new comments describe behavior; the #2835 reference is confined to the commit message, which is correct |
| Logging standards | ✅ Rust-only; no new logging |
| Test discipline | ✅ bun run rust:test:core reported; my own cargo test -p nodespace-cli --test cli_integration is a targeted single-test run, not the banned bare cargo test -p nodespace-core |
| Tests pass | ✅ 6 core + 1 CLI verified green locally |
Verdict
✅ APPROVE — no blocking items
🟡-1 was addressed with the preferred fix rather than the cheap one, and the result is better than what I asked for: both states are modelled in the fault enum, both get an honest message, and the unparseable case actively steers the agent away from the retry that would compound the problem. The distinction is drawn correctly and the new error claims exactly what the code can support.
The folded-in CLI work is a sound, well-scoped change that closes the other half of the original report. The behavioral change flagged for scrutiny — pinning the database id per invocation — is correct; I traced database use, session, long-running and MCP paths and found no case where it breaks something, and one case (mcp) where the right thing already happens for free.
Optional, author's call, no re-review needed:
- 🟡-5 — wrap
resolve_routing's failure in the caller's vocabulary (one.context()). - 🟡-6 — read
default_database_idinstead of scanningis_default.
Neither changes behavior today. Both are small enough to fold into a follow-up or drop entirely without loss.
Automated pragmatic re-review. Verified independently: cargo build -p nodespace-cli clean; create_schema_result_reflects_persisted_state_test 6/6; routing_with_no_selection_pins_the_resolved_default_database_id 1/1.
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
…its errors Both items the re-review marked optional. Neither changes behavior today; both protect the property the routing change exists to establish. Read `default_database_id` rather than scanning entries for `is_default`. The response carries the same fact twice — the scalar is the registry's answer, the flag is derived from it — and they cannot disagree today, since both come from one snapshot under one lock. The scalar is still the one to trust: were that to slip (a default id naming an entry the listing omits), a scan would match nothing and return `None`, quietly restoring exactly the unstamped routing this function replaced. An empty string is the daemon's "unset", not an id, so it is filtered rather than treated as one. Re-frame a registry-side failure at the routing boundary. Every data-plane command now resolves the default, including ones that never mention the registry, so a bare "List RPC failed" could surface from `nodespace search` in vocabulary that command never used. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Address-review summary (round 2)Commit Addressed🟡-6 — read 🟡-5 — re-frame registry failures at the routing boundary. Added Verification
No new tests: neither change alters behavior in any state reachable today, which is exactly why both were optional. The existing routing test covers the path 🟡-6 rewrote, and it still pins (verified it runs through the new code, not around it). Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: Both changes are small, low-risk, and confined to code the re-review just examined in full. 🟡-6 swaps one read of a response field for another read of the same response — no new control flow, no new failure mode, and the reviewer had already traced that the two sources agree. 🟡-5 is a single The PR is ready for merge, pending the user's decision. |
Closes #2815.
What was reported
A
create_schemacall returnedis_error=falsewithresult_field_count=2and a fully-populated payload, and the schema was never persisted. The agent, correctly trusting its own tool result, told the user the type had been created.What the investigation found
The write path is sound. A probe reproducing the reported two-call sequence (
Company Sold To, thenEvent Venue) against a fresh database persisted both.with_transactionpropagates commit errors,INSERT INTO nodeis a plain insert (node.idis PRIMARY KEY, so a duplicate errors rather than silently skipping), and there is no schema cache. TheOCC bypassedwarnings live onupdate_nodes_batch; no create_schema path reaches them — a red herring, as the issue suspected.So AC#1's answer: not deterministic for that input, and the "write did not land" premise does not hold at the core layer.
What was actually broken is that nothing would have caught it if it had.
The three defects
1. The result was an echo of the request.
CreateSchemaOutputwas built fromstored_fields/schema_id— both derived from the caller's arguments — and the id the transaction actually produced was discarded as_created_schema_id. A payload built that way is identical whether or not the write landed, so it cannot report the difference. It now reads the committed schema node back and is built from that. A schema that cannot be verified is an error that names it and says plainly that nothing was created.2. The agent's no-op-success guard was structurally blind to this.
agent_loop.rscountsresult["fields"].len()on the premise that a result reports persisted state — but for create_schema that array was the model's own input echoed home, so every non-empty call reported a non-zero count regardless of what persisted. Onlyfields: []could trip it, and core treats that as a valid relationship-only schema. The read-back makes the premise true; the comment now records that the guard depends on it.3. The exists-check swallowed read failures.
if let Ok(Some(..))routed bothErrandOk(None)into the write, which then hit the primary-key constraint and surfaced as an opaque internal error naming neither the real problem nor the repair. An unreadable schema table is not evidence of an absent schema, so the error is propagated now.Why there is a test seam
On every path reachable through the public API, an echoed payload and a read-back payload are byte-identical — I verified this for fields, derived friendly names, relationships and
extends. And the store is sealed by design, so no test can make a committed row vanish. Without a seam the read-back is untestable and silently rots.NodeService::set_write_verification_faultreaches that branch. It is inert unless armed, never called by the daemon, and defaults to ordinary behavior — following the existingset_subtree_access_gate/set_playbook_lifecycleinjector pattern.Verification
a_write_that_cannot_be_verified_is_an_error_not_a_populated_successwas confirmed to fail with the fix reverted, reproducing the reported shape exactly:bun run rust:test:core— exit 0, 35 test binariesbun run rust:test:libsql-linked— exit 0bun run quality:fix— exit 0 (clippy-D warnings)Noted, not fixed here
The agent turn runs against its per-database
NodeService, while a CLInodespace searchwith nox-ns-database-idheader resolves toregistry.default_database. If the chat ran in a non-default database, the write landed correctly and the CLI read a different one — which fits the reported evidence. #2187/#2267 already routed the turn-state RPCs; what remains is CLI-side default resolution, which wants its own issue rather than widening this one.🤖 Generated with Claude Code