Repository navigation
Description
Background
PR #1910 (closing #1908) fixed resolve_query silently returning no_match when its nested decomposition LLM call emits a filter value whose JSON type doesn't match the target schema field's declared type (e.g. a numeric field's value emitted as a JSON string "2400" instead of 2400). SQLite's json_extract preserves the stored value's real type, so a type-mismatched equality filter compares unequal — silently indistinguishable from "no such node."
The fix added coerce_filter_value_to_field_type (packages/agent/src/local_agent/tools.rs), which normalizes stringified numbers and booleans to their correct JSON type before the filter reaches the query layer. This is a per-type patch: it now covers number and boolean, added as each was confirmed reachable.
The underlying issue
The decomposition prompt (exec_resolve_query's nested LLM call) gives the model no explicit JSON-type guidance per field type — it only names field: type (e.g. replacement_cost: number). Nothing constrains how the model encodes a value it maps onto that field. This means the same class of silent failure is reachable for any field type not yet covered by coerce_filter_value_to_field_type, most plausibly:
- Reverse direction for
text/enumfields: a numeric-looking value (a numeric ID stored as text, or a numeric-looking enum member) emitted as a JSON number instead of a string would silently mismatch the same way, in the opposite direction. - Any future field type added to the schema system without a corresponding coercion arm.
Per-type coercion patching in Rust will accrete one match arm per observed failure, discovered only when a user hits it live (as #1908 itself was — split out of #1894, filed, then took two live-model debugging sessions to root-cause).
Proposed direction (not yet designed)
Constrain the decomposition model's output directly, rather than patching after the fact:
- Grammar/JSON-schema-constrained decoding for the decomposition call, if the inference engine supports it, so the model cannot emit a type-mismatched value in the first place.
- Or: have the decomposition prompt state the expected JSON encoding per field type alongside
name: type(e.g.replacement_cost: number (JSON number, not string)), and measure whether that alone closes the gap — cheaper to try first, consistent with this codebase's "measure against the real model, don't guess" standard for this subsystem.
Scope note
This needs its own live-model validation before implementation, following the same methodology PR #1910 used (drive the real locked model against the actual prompt, verify the fix genuinely changes model output — not just add code and assume). Not a quick patch; a proper investigation.
Reference
- Issue resolve_query returns no_match against a node whose property does contain the queried value #1908, PR Fix resolve_query no_match against a node whose property does contain the value #1910 — root cause and initial fix (number/boolean coercion).
Activity
malibio commentedon Aug 3, 2026
Frontend baseline: 171 test files passed, 4108 tests passed (49.87s)
malibio commentedon Aug 3, 2026
Scoping question before implementation
Issue proposes the cheaper fix first: state the expected JSON encoding per field type in the decomposition prompt (e.g.
replacement_cost: number (JSON number, not string)), then live-model-validate whether that alone closes the gap.The field-line rendering used by
exec_resolve_query's decomposition prompt (EntityFieldDescriptor::render_shape()inpackages/core/src/ops/entity_types_block.rs) is shared:render_shape()is also called (viarender(), which adds ", required") by the mainRELEVANT ENTITY TYPESblock used forcreate_node/search_nodesguidance to the primary agent.Two options:
Scope to resolve_query only — add the JSON-type hint in a local helper inside
exec_resolve_query's field_lines construction, not in the shared descriptor. Matches this issue's stated scope (the decomposition sub-prompt specifically), keeps blast radius to one prompt, and avoids touching prompt-snapshot/regression tests pinned elsewhere (routing latency suites reference the shared renderer's output).Add to shared
render_shape()— every caller gets the hint, including the main entity-types block. More consistent long-term (the same stringified-value drift is plausible oncreate_nodetoo, just not this issue's subject), but wider blast radius, and would need those other pinned tests (e.g.routinglatency suite, entity_types_block tests) updated/re-validated too.Which scope do you want for this issue — (1) resolve_query-local, or (2) shared renderer? If (2), should a follow-up issue be filed for validating it against the create_node path specifically, or is validating resolve_query's live-model behavior considered sufficient coverage since they share the renderer?
malibio commentedon Aug 3, 2026
Scope decision: (1), resolve_query-local
Go with option 1 — add the JSON-type hint in a local helper inside
exec_resolve_query's field_lines construction, not the sharedrender_shape().Reasoning: this cluster has a repeated, well-documented history of shared-surface changes validated only against their motivating scenario later regressing a bystander (#1904/#1912's routing regression, #1925/#1926's history-compaction fallout, the four rejected retrieval-merge variants in #1917). Option 2 would touch a renderer that
create_node/search_nodesguidance also depends on, without this issue's scope including validation of either of those paths. That's exactly the pattern to avoid — fix the thing you're scoped to fix, on the surface you're scoped to touch.If the same stringified-value drift is real on
create_node, that's genuinely separate scope per this project's standard (different call site, needs its own investigation/measurement) — file it separately if you find evidence for it while you're in this code, don't speculatively fix it here without validating it. Proceed with (1).malibio commentedon Aug 3, 2026
Implemented per the scope decision (resolve_query-local JSON-encoding hint). Live-model validation against the locked Gemma 4 E4B model confirms the fix, including the reverse-direction case (numeric-looking value into a
textfield). Pushing branch now; PR to follow.malibio commentedon Aug 3, 2026
Good — scope decision followed, live-model validated including the reverse-direction case. Proceed to PR,
/pragmatic-code-review, merge — same flow as everything else in this cluster.