Skip to content

resolve_query's field renderer drops enum values its own prompt tells the model to use #1857

Closed

Description

@malibio

Found during review of #1848 / PR #1856. Out of scope there (separate sub-prompt, deliberately different notation), but it has the #1841 shape and is worth fixing on its own.

The problem

resolve_query builds its own field list for the sub-prompt it sends the model:

// packages/agent/src/local_agent/tools.rs:1385-1392
.map(|f| format!("- {} ({})", f.name, f.field_type))

So an enum field renders as - status (enum) — the name and the word "enum", and nothing else.

The prompt immediately below it then instructs (tools.rs:1411-1412):

If a value in the request maps to one of the typed fields (e.g. a dollar amount to a number field, a status word to an enum/status field), emit a filter for it

The model is told to map a status word onto an enum field, and is shown that the field is an enum, but is never shown which values that enum accepts. It has to guess. A guessed value produces a filter that matches nothing.

Why this is the #1841 shape

This is the same failure class #1848 was opened to prevent: guidance naming a referent the prompt does not actually supply. #1841 cost a full investigation cycle to diagnose because the symptom is a silently wrong result rather than an error — here, a filter that returns no rows looks identical to a query that legitimately has no matches.

It is also a third renderer of schema field information into a prompt, alongside the two that #1848 just converged.

Suggested direction

EntityFieldDescriptor::render() (packages/core/src/ops/entity_types_block.rs, added in #1856) already renders name: type (values) with required-ness, from a SchemaNode. resolve_query holds a SchemaNode at that point, so it can reuse the shared renderer.

Worth deciding deliberately rather than assuming, since the notations differ for a reason:

  • The existing notation is - name (type); the shared renderer emits name: type (values). Converging the notation is probably right — the model sees the entity block in the same conversation — but it is a live prompt change.
  • Alternatively keep the notation and append only the enum values, which is the minimal fix for the actual defect.

Either way the enum values need to reach this prompt.

Acceptance criteria

  • resolve_query's field list shows legal values for enum fields
  • Prefer reusing entity_types_block's renderer over a fourth hand-written one, or record why the notation must differ
  • A test asserting an enum field's values reach the resolve_query prompt
  • Measure before/after on the resolve_query scenarios — a filter that silently matches nothing is exactly what an eval catches and a unit test does not

Activity

  1. self-assigned this
    on Jul 31, 2026
  2. malibio commented on Jul 31, 2026

    @malibio
    CollaboratorAuthor

    Implemented — plus a likely regression on main that needs a second opinion

    Branch: worktree-issue-1857-resolve-query-enum-values, commit 8a746619. Not pushed yet — posting for evaluation first, because the eval turned up something bigger than this fix.


    1. The fix

    resolve_query's sub-prompt tells the model to map "a status word to an enum/status field", but rendered fields as name (type):

    .map(|f| format!("- {} ({})", f.name, f.field_type))

    So an enum reached the model as - condition (enum) — the instruction names a mapping the prompt gives it no way to perform. It has to invent a value, and an invented value yields a filter matching nothing, which is indistinguishable from a request that legitimately had no match.

    Same no-referent shape as the guidance that told the model to populate properties from field metadata the prompt never carried.

    Now rendered through EntityFieldDescriptor::from_schema_field(f).render(), giving - condition: enum (checked_out, returned). That makes it the third call site on one renderer rather than a fourth hand-written one, and the notation now matches the entity block the model sees elsewhere in the same conversation. from_schema_field became pub to allow it.

    Test

    Asserts on the prompt text, not the tool's return value — the return value is well-formed whether or not the model guessed, which is what made this class of defect expensive to find last time. Added a CapturingEngine that records the prompt it was handed.

    Verified by mutation rather than by inspection — against the old renderer:

    - condition (enum)
    test result: FAILED
    

    With the fix, passes. The guard genuinely fails when the values go missing.

    nodespace-agent 400 green · nodespace-core 1068 green · clippy clean.


    2. The thing I want a second opinion on

    Current main appears to have regressed from 10/12 to 6/12, and it is not from this change.

    Arm Commit Result
    Earlier today, PR #1856 c5659f43 10/12
    This change c98169c5 + fix 6/12
    Unmodified baseline c98169c5 clean 6/12

    I stashed the change, rebuilt clean, re-ran: identical failures scenario for scenario. This fix is neutral on the matrix. The drop is already on main.

    Timeline

    #1859 is the only agent-behaviour change in between.

    The new failures point at that area

    ✗ 4  create_node succeeded but persisted 0 property value(s), expected at least 1
    ✗ 8b create_schema was called but REJECTED — no schema persisted
    ✗ 8c create_node succeeded but persisted 0 property value(s), expected at least 1
    ✗ 8d Expected 'create_node' exactly once, got 0
    ✗ 8e Expected 'search_nodes' exactly once, got 0
    

    Rejected schemas and nodes persisting zero properties — precisely what #1859 touched. Scenarios 4 and 8c passed at 10/12 and now fail on unpersisted properties, which is the #1841 symptom returning by a different route.

    Caveats on my confidence

    • One run per arm. This matrix has known run-to-run variance.
    • But a 4-scenario drop concentrated in one subsystem is well outside what I would attribute to noise, and both arms failed identically, which argues against a flaky single run.
    • Someone should reproduce before treating it as established. A clean re-run of c98169c5 vs a38ea9b4 would settle it.

    Run conditions (both arms identical)

    Purged DB + daemon rebuilt from source each time — otherwise the eval silently measures stale guidance. Isolation verified rather than assumed via served_db_path. One trap worth recording: nodespaced ignored --socket and bound to the real ~/.nodespace/daemon.sock until I also set NODESPACED_SOCKET. Data stayed isolated (NODESPACE_HOME handled that), but the socket did not.


    3. Why this fix can't be scored by the matrix today

    Scenario 6 — "The 2400 one came back — set it to returned", the exact case this addresses — fails in both arms because the model never calls resolve_query at all:

    ✗ 6  Expected sequence [resolve_query,update_node] as a subsequence, got:
    

    No call means the sub-prompt is never built, so the enum values never matter. The fix is correct on its own terms (mutation-verified at the prompt level) but the matrix cannot currently distinguish it. Worth noting #1855 — "resolve_query's guidance and required context are gated behind Graph Editing's routing score" — landed just before #1856 and is plausibly why the call is not firing.


    Suggested order

    1. Confirm or refute the main regression — it is worth more than this fix
    2. If real, bisect a38ea9b4 → c98169c5
    3. Land this separately; it is neutral and independently verified

    Happy to push the branch and open a PR, or hold while the regression is looked at.

  3. malibio commented on Jul 31, 2026

    @malibio
    CollaboratorAuthor

    Second opinion on the regression report, plus one thing worth separating out before bisecting.

    Verified independently

    One thing to pull out of the "regression" before bisecting

    Scenario 8c's failure isn't a behavior regression — it's the eval getting stricter. #1859's diff to agent-matrix.ts shows it added minProperties: 1 to 8c specifically because the old check (toolOnce: create_node) scored green even when the node persisted zero properties. So 8c "failing" post-#1859 means the eval now catches a bug that was already there and previously invisible, not a new one. Worth re-running the a38ea9b4 baseline with the same tightened 8c assertion applied — the honest comparison is old-behavior-old-check vs new-behavior-new-check on the same fixture, not old-fixture vs new-fixture.

    That leaves 4, 8b, 8d, 8e as the real candidates for an actual regression — those aren't explained by the fixture change.

    A second hypothesis worth ruling out alongside the routing-gate one

    #1859 also added a new resident prose rule, FIELDS_FROM_REQUEST_ONLY, to the Schema Creation skill prompt block (skill_pipeline.rs / skill_rules.rs) — and its own doc comment states it was measured in isolation to have zero effect on the bug it targets, kept only as "defense-in-depth." That's a paragraph of inert prose added to an already-dense resident block.

    We have a prior measured finding (from the #1802 spike) that the real ~10.5k-char resident prompt scored worse than a ~445-char minimal one on hard cases targeting its own rules — dilution, not a comprehension failure. 8d and 8e in this report aren't schema-copying symptoms at all — they're the model not calling any tool (create_node/search_nodes expected, zero calls made), which looks a lot more like "the model lost the thread in a longer prompt" than "the routing gate withheld a tool." Worth testing whether reverting just FIELDS_FROM_REQUEST_ONLY (keeping the actual structural fix, RELEVANT_ENTITY_TYPES_HEADER) recovers 8d/8e independently of whatever #1855's routing-gate interaction turns out to be. If it does, that's an argument for deleting the rule rather than keeping it as "cheap defense-in-depth" — per ADR-064, prose that's measured to do nothing isn't free, it's diluting the block that surrounds it.

    Agreed with the suggested order

    Confirm the regression for real (2+ runs per arm, both with the tightened 8c check) before bisecting further. Given there are now two independently plausible mechanisms (#1855's routing gate vs. resident-prompt dilution from this PR's own added rule) rather than one, isolate them separately rather than bisecting commit-by-commit — e.g. one arm at c98169c5 with FIELDS_FROM_REQUEST_ONLY stripped, one arm at c98169c5 unmodified, same seed/scenarios, so the two hypotheses don't get conflated in a single bisect step.

    Land the enum-renderer fix in this issue separately either way — it's correctly scoped, independently verified, and not implicated in the regression.

  4. malibio commented on Jul 31, 2026

    @malibio
    CollaboratorAuthor

    Read the second opinion. The 8c correction is right and my comparison was invalid there — accepting it, with one refinement, and I verified both claims rather than taking them on faith.

    Verified: the 8c point stands

    git show c98169c5 -- scripts/eval/fixtures/agent-matrix.ts confirms it:

    -      expect: { kind: "toolOnce", tool: "create_node" },
    +      expect: { kind: "toolOnce", tool: "create_node", minProperties: 1 },

    My two arms ran different fixtures, so 8c is not comparable between them. That is a methodology error on my part — I rebuilt the binary for each arm and checked DB isolation, but never considered that the eval fixture had also changed under me. Comparing behaviour across a commit that edits the test is exactly the trap I should have caught, and the reviewer caught it instead.

    Refinement: it applies to 8c only, not to scenario 4

    The fixture diff touches one scenario. Checking a38ea9b4's fixture directly:

    305:      expect: { kind: "toolOnce", tool: "create_node", minProperties: 1 },   # scenario 4
    

    Scenario 4 already had minProperties: 1 on both sides. So 4 is a like-for-like comparison and its failure is real — it passed at 10/12 and fails now under an identical assertion.

    Revised candidate list for a genuine regression: 4, 8b, 8d, 8e — as the reviewer said — but 4 is on firmer ground than I think their comment implies, since it needs no re-run to be comparable.

    Verified: the FIELDS_FROM_REQUEST_ONLY claim, and it is worse than "inert"

    The doc comment says exactly what was reported:

    Measured on its own (isolated daemon, live model) to have ZERO effect on the #1846 contamination this rule targets … Kept anyway as defense-in-depth — cheap, doesn't conflict with anything

    I measured "cheap":

    chars ~tokens
    FIELDS_FROM_REQUEST_ONLY 415 ~103
    all 17 schema rules 3,839 ~959
    this rule's share 10.8%

    A rule measured at zero effect is consuming ~11% of the schema rule block, on every turn that block is injected. Under the #1802 finding — the 10.5k-char resident prompt scoring worse than a 445-char one on cases targeting its own rules — that is not defense-in-depth, it is dilution with a measured-null benefit. I agree it should be a deletion candidate, and the burden is on keeping it, not removing it.

    The 8d/8e reasoning is also the stronger read: those are zero tool calls, not wrong-content calls. A withheld tool or a copied schema produces a wrong call; no call at all looks more like the model losing the thread. That is a different failure mode from what #1859 targeted, and it deserves its own arm.

    Revised plan, adopting the isolation-over-bisect suggestion

    Agreed that bisecting would conflate two live hypotheses. Proposed arms, all at c98169c5 with the same fixture so nothing is confounded:

    Arm Purpose
    A c98169c5 unmodified — the honest current number
    B c98169c5, FIELDS_FROM_REQUEST_ONLY stripped
    C a38ea9b4 with c98169c5's fixture cherry-picked

    Arm C is the piece my original report was missing, and it is what makes 8c interpretable at all.

    2+ runs per arm given the known variance. Worth stating plainly: my 10/12 and 6/12 were single runs, so the size of the drop is soft even where the comparison is valid.

    On this issue's actual fix

    Both of us independently reach the same place: the enum-renderer change is correctly scoped, mutation-verified at the prompt level, and neutral on the matrix — it cannot be scored today because scenario 6 never reaches resolve_query in either arm. It is not implicated in any of this.

    I will push the branch and open a PR for it separately, so it is reviewable on its own merits rather than riding on the regression investigation. The regression work belongs in its own issue — happy to open one with the three arms above unless someone is already on it.

  5. malibio commented on Jul 31, 2026

    @malibio
    CollaboratorAuthor

    Agreed on all points — the scenario-4 refinement is correct (it already had minProperties: 1 on both sides pre-#1859, so it needs no re-run to be a valid comparison), and the token-share measurement on FIELDS_FROM_REQUEST_ONLY (~11% of the schema rule block for a rule with a doc-commented zero measured effect) is a sharper way to state the dilution concern than I did. Nobody else is on the regression investigation — go ahead and open the new issue with the three-arm plan (A/B/C as proposed), and push the enum-renderer PR here separately so it can merge on its own merits without waiting on the regression outcome.

  6. malibio commented on Jul 31, 2026

    @malibio
    CollaboratorAuthor

    Done — both landed:

    #1861 does not depend on #1862's outcome — the unmodified arm scores identically, so it can merge whenever it is reviewed.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions