Skip to content

create_schema reports success with a populated field list for a schema that was never persisted #2815

Closed

Description

@malibio

Overview

A create_schema call returned is_error=false with result_field_count=2 and a fully-populated result payload, and the schema was never persisted. The agent then told the user the type had been created. Observed on a clean database with the locked native model (gemma-4-e4b-q4km).

This is the silent-degradation-plus-fabricated-completion class ADR-056 records as still open for Scenario 6 — "the miss degrades silently to an empty result reported as success" — but on the write path rather than the resolution path, and with the tool layer (not the model) producing the false success.

Problem Statement

Reproduced twice in a row, same daemon, same session, minutes apart. Two create_schema calls, identical in shape; the first persisted, the second did not.

Call 1 — persisted.

Tool executed tool=create_schema is_error=false duration_ms=0 result_field_count=1
  args_preview={"fields":[{"name":"signed_date","type":"date"}],"name":"Company Sold To"}
  result_preview={"description":"Schema for Company Sold To","fields":[{"friendlyName":"Signed date",...

Result: schema company_sold_to exists and is retrievable.

Call 2 — reported success, did NOT persist.

Tool executed tool=create_schema is_error=false duration_ms=0 result_field_count=2
  args_preview={"fields":[{"name":"booking_date","type":"date"},{"name":"capacity","type":"number"}],"name":"Event Venue"}
  result_preview={"description":"Schema for Event Venue","fields":[{"friendlyName":"Booking date","indexed":false,"name":"booking_date","protection":"user","type":"date"},{"friendlyName":"Capacity",...

Agent's reply to the user:

"The new type, 'Event Venue,' has been set up to track events with a name (which is the node's title), booking date, and capacity."

Verified afterwards against the daemon:

  • nodespace search --type schema returns 20 nodes
  • 20 ids, 20 content names
  • Company Sold To / company_sold_to present
  • Event Venue / event_venue absent from both the id list and the content list

No error, warning, or rejection appears anywhere in the daemon log for that call. The only nearby warnings are unrelated OCC notices (OCC bypassed: version not provided for batch update) that also accompany the call that did succeed, so they do not distinguish the two.

Three defects compound, and the third is the damaging one:

  1. The write did not land.
  2. The tool layer reported is_error=false with a populated result payload describing fields that were never stored.
  3. The agent, correctly trusting its own tool result, told the user the type existed.

A user in this state has been told a type was created, sees no error, and will hit a confusing failure later when they try to use it. This also defeats the existing no-op guard (persisted_field_count), which is designed to catch a write that persisted zero fields — here the result claims two.

Reproduction

Against a clean database (NODESPACE_HOME pointed at an empty dir), locked model loaded:

bun run scripts/aichat.ts ask "Set up a new type for the companies we sell to, with a name and the date we signed them."
bun run scripts/aichat.ts ask "Set up a new type for the places we hold events, with a name, a booking date and a capacity."
nodespace search --type schema | grep -E "^id:"

Expected: both company_sold_to and an event_venue-shaped id. Actual: only the first.

Not yet established whether this is deterministic for this particular phrasing or an intermittent race — it reproduced once, in the ordering above. Establishing that is the first task.

Investigation Notes

The OCC bypassed: version not provided for batch update (race condition possible) warnings fire on a node id immediately before each create_schema execution, including the successful one. They are therefore not by themselves the cause, but a write-path race is the obvious first hypothesis given the warning text and the fact that two structurally identical calls diverged.

Worth checking in order:

  • Whether the create_schema result payload is constructed from the input rather than from the persisted row — which would explain a populated result_preview for a write that never landed, and would make the false success systematic rather than racy.
  • Whether a second schema creation in quick succession in the same session collides on the OCC-bypassed batch update above.
  • Whether the id derivation (Event Venue → event_venue) collides with or is rejected by something that does not surface as an error.

Acceptance Criteria

  • Determine whether the failure is deterministic for this input or intermittent, and record which
  • Root-cause why the write did not persist while the tool reported success
  • create_schema reports an error, or a result that does not claim fields, when the schema was not persisted
  • The result payload reflects persisted state rather than requested state (or, if it cannot, the tool verifies persistence before returning success)
  • A regression test pins the failing case: revert the fix and confirm the test fails
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • packages/agent/src/local_agent/tools.rs — create_schema's handler and the result payload it constructs
  • packages/core/src/ops/schema_ops.rs — the schema write path
  • packages/daemon/src/services/node_service.rs — the OCC bypassed: version not provided for batch update warning site
  • packages/agent/src/local_agent/agent_loop.rs — persisted_field_count and the no-op-success guard this case evades

Related

Activity

  1. added
    bug
    on Sep 22, 2026
  2. malibio commented on Sep 22, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 5240 passed (260 test files)

  3. self-assigned this
    on Sep 22, 2026
  4. malibio commented on Sep 22, 2026

    @malibio
    CollaboratorAuthor

    Investigation: not reproducible in-process; the write path is sound

    Wrote a probe replicating the exact two-call sequence (Company Sold To then Event Venue) against a fresh DB via handle_create_schema. Both persisted. So AC#1's answer: the failure is not deterministic for this input, and the "write did not land" premise does not hold at the core layer.

    Verified sound:

    • with_transaction (core/services/node_service/mod.rs:594, db/sqlite_store/tx.rs:63) propagates commit errors; buffered events flush only on Ok.
    • INSERT INTO node is a plain insert (no OR IGNORE); node.id is PRIMARY KEY, so a duplicate id errors rather than silently skipping.
    • No schema cache; get_schema_node reads committed state.
    • The OCC bypassed warning is on update_nodes_batch only — no create_schema path reaches it. It is a red herring, as the issue suspected.

    The three real defects

    1. The result payload is an echo of the input — packages/core/src/schema/mod.rs:1292. CreateSchemaOutput is built from stored_fields/schema_id, both derived from the request. The value the transaction actually returned is discarded at mod.rs:1245 as let _created_schema_id. Nothing is read back, so the payload cannot distinguish a write that landed from one that didn't.

    2. The no-op-success guard is structurally blind to create_schema — agent_loop.rs:1243 computes result["fields"].len(), which for create_schema is the model's own input. Its own doc comment at agent_loop.rs:2561 asserts "the result is the executor's report of what it persisted, while args are only the model's report of what it asked for" — false for the first tool it names. Only fields: [] trips the guard, and core treats that as a valid relationship-only schema.

    3. The exists-check swallows errors — mod.rs:1180 is if let Ok(Some(existing)) = .... An Err from get_schema_node falls through to the write. And get_schema_node returns Ok(None) for a schema that physically exists when SchemaNode::from_node fails to parse it (db/sqlite_store/nodes.rs:3438 warns, returns Ok(None)).

    One genuine divergence vector, noted not fixed here

    The agent turn runs against its per-database NodeService with no routing — LocalAgentServiceImpl::route is only called by subscribe_token_stream/cancel_turn/get_status, not the turn itself. A CLI nodespace search with no x-ns-database-id header resolves to registry.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 exactly (no error, populated payload, absent row). Filing separately rather than widening this issue.

    Fix being implemented

    Read back the committed schema node and build the output from it; propagate Err from the exists-check rather than treating it as absent; make the guard's field count reflect persisted state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions