Skip to content

Give resolve_query's sub-prompt the enum values it tells the model to use (#1857) - #1861

Merged
malibio merged 2 commits into
mainfrom
issue-1857-resolve-query-enum-values
Jul 31, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-1857-resolve-query-enum-values

Conversation

@malibio

@malibio malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Closes #1857.

The defect

resolve_query's sub-prompt instructs 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 produces a filter matching nothing, which is indistinguishable from a request that legitimately had no match.

This is the same no-referent shape as the guidance that told the model to populate properties from field metadata the prompt never carried (#1841): an instruction naming something the prompt does not supply, failing silently.

The change

Rendered through the shared EntityFieldDescriptor instead of a local spelling:

- condition: enum (checked_out, returned)

That makes this the third call site on one renderer rather than a fourth hand-written one — the same convergence #1848 did for the two entity-block renderers. EntityFieldDescriptor::from_schema_field becomes pub to allow it.

Side benefit: the notation now matches the entity block the model already sees elsewhere in the same conversation, so one concept has one spelling.

Test

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

Verified by mutation, not by inspection. Against the old renderer:

- condition (enum)
test result: FAILED

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

Eval: neutral, and currently unscoreable

Arm Result
c98169c5 + this change 6/12
c98169c5 unmodified 6/12

Identical failures scenario for scenario — this change is neutral on the matrix.

It cannot be scored 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. No call means the sub-prompt is never built, so the enum values never matter. The fix is verified at the prompt level instead, which is where the defect lives.

Note on the 6/12 baseline

That number is below the 10/12 measured earlier today on c5659f43, but this PR is not implicated — the unmodified arm scores identically. A separate regression investigation is being opened for it (see #1857 discussion); part of the earlier drop turned out to be a tightened eval fixture in #1859 rather than a behaviour change, which is being isolated properly there.

Checks

nodespace-agent 400 green · nodespace-core 1068 green · clippy clean · pre-push gate passed in full.

🤖 Generated with Claude Code

… use

The sub-prompt instructs the model to map "a status word to an enum/status
field", but rendered fields as `name (type)` — so an enum arrived as
`condition (enum)` with its legal values nowhere in sight. The model had to
invent one, and an invented value yields a filter matching nothing, which
reads exactly like a request that legitimately had no match.

This is the same no-referent shape as the guidance that told the model to
populate `properties` from field metadata the prompt never carried: the
instruction names something the prompt does not supply, and the failure is
silent.

Rendered through `EntityFieldDescriptor` rather than a local spelling, so
this is the third call site on one renderer instead of a fourth hand-written
one. `from_schema_field` becomes public to allow it. The notation now also
matches the entity block the model sees elsewhere in the same conversation.

The test asserts on the prompt text, not the tool's return value — the
return value is well-formed whether or not the model guessed. Verified by
mutation: against the old renderer the prompt shows `- condition (enum)` and
the test fails.

Eval: 6/12 with this change, and 6/12 on an unmodified build of the same
commit — identical failures scenario for scenario, so this is neutral on the
matrix. Note that baseline is down from the 10/12 measured before #1859
landed; scenario 6 (this change's target) fails in both arms for want of a
resolve_query call at all, so the fix cannot be scored by the matrix today.
Worth a look at whether #1859 regressed schema creation — 4, 8b and 8c all
fail on rejected schemas or unpersisted properties, which is that area.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163
@malibio

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Review Type

Initial review — PR #1861, single commit 8a746619, 2 files changed (packages/agent/src/local_agent/tools.rs, packages/core/src/ops/entity_types_block.rs). No prior reviews on the PR.

Verification actually run (not taken on faith):

  • cargo test -p nodespace-agent → 400 passed, 0 failed (plus 3 latency benches, 199s)
  • cargo test -p nodespace-core → 1068 + 275 across suites, 0 failed
  • cargo clippy -p nodespace-core -p nodespace-agent --all-targets → zero warnings, zero errors
  • Mutation check re-performed independently (see AC 3)
  • Required-suffix probe run (see 🟡 finding 1)
  • Repo-wide sweep for a fourth/fifth hand-rolled field renderer

Requirements Check

AC Status Evidence
resolve_query's field list shows legal values for enum fields ✅ Verified by running the test with the prompt dumped: the prompt now contains - condition: enum (checked_out, returned) where it previously read - condition (enum).
Prefer reusing entity_types_block's renderer over a fourth hand-written one, or record why the notation must differ ✅ EntityFieldDescriptor::from_schema_field(f).render() is now the single call. I swept packages/*/src for other hand-rolled schema-field renderers and found none — this is genuinely the third call site on one renderer, not a fourth spelling.
A test asserting an enum field's values reach the resolve_query prompt ✅ resolve_query_prompt_carries_enum_values_for_status_fields. Mutation-verified below.
Measure before/after on the resolve_query scenarios ⚠️ Partially — see the "On the eval AC" section. Not an un-run AC being explained away, but not a satisfied one either.

Findings

🟡 1. The required suffix leaks node-creation semantics into a search prompt

📁 packages/agent/src/local_agent/tools.rs:1445-1456 (via packages/core/src/ops/entity_types_block.rs:73-76)

This is the one finding I'd want addressed. EntityFieldDescriptor::render() appends ", required" for required fields. I probed this rather than reasoning about it — adding "required": true to the test's replacement_cost field and dumping the prompt:

Fields on this type:
- replacement_cost: number, required
- condition: enum (checked_out, returned)

Two things make this more than cosmetic noise:

(a) The term has a definition, and it is the wrong one. packages/agent/src/skill_pipeline.rs:309 defines required for this model, verbatim:

fields marked required MUST be included in the properties map

That is a write obligation — a create_node contract. resolve_query is a read path: it emits search filters. There is no sense in which a field being required-on-write constrains which filters a search should carry. A model that has internalized that rule and then meets replacement_cost: number, required in a filter-emission prompt has a live incentive to emit a filter for it whether or not the user's request mentions a replacement cost — and a spurious equals filter on a numeric field is precisely the "filter matching nothing, indistinguishable from a legitimately empty result" failure this PR exists to eliminate. The fix would import the defect class it removes, by a different route.

(b) The word arrives with no definition at all in this call. tools.rs:1493 builds the sub-prompt as messages: vec![ChatMessage::text(Role::User, prompt)] — a single user message, no system prompt, no skill block, tools: None. So the model does not in fact see skill_pipeline.rs:309 here; it sees a bare , required and has to infer its meaning. That also means the commit message's own justification —

"the notation now matches the entity block the model sees elsewhere in the same conversation"

— is not accurate for this call. The sub-prompt is an isolated inference; there is no "same conversation" from the sub-model's point of view. The convergence argument is sound as a maintenance argument (one renderer, one place to fix), which is the argument the issue actually made and which fully carries the change. It is not sound as a model-facing coherence argument, and the comment at tools.rs:1442 states it as if it were.

Principle: least astonishment / interface segregation. render() was designed for a block whose surrounding guidance defines every token it emits. Reusing it in a context that supplies none of that guidance re-exports a term the new context cannot ground.

Suggested fix — smallest thing that works, keeping the single-renderer win:

// on EntityFieldDescriptor
/// Type and legal values only. `required` is a node-creation obligation
/// (see the FIELD VALUES guidance) and has no meaning in a filter-emission
/// prompt, which resolve_query's isolated sub-call has no guidance to ground.
pub fn render_without_obligations(&self) -> String { /* same, minus the required push_str */ }

Alternatively express render() in terms of a RenderOptions/include_required: bool. Either keeps one renderer as the choke point — a field added to SchemaField still can only reach any prompt through this struct, which is the property entity_types_block.rs's module doc says it exists to guarantee. Whichever you pick, add a required: true field to the new test's fixture and assert the resulting line, so the decision is pinned rather than re-litigated.

If you'd rather keep , required deliberately, that's defensible — but then it needs a comment saying why required-ness is meaningful in a search prompt, because the current code reads as if the suffix came along unnoticed. Right now nothing in the diff acknowledges it exists.

🟢 2. pub is correct here, and pub(crate) genuinely would not work

📁 packages/core/src/ops/entity_types_block.rs:81-85

Verified rather than assumed: packages/agent/Cargo.toml:2 declares name = "nodespace-agent" and line 10 pulls nodespace-core as a dependency. Different crate ⇒ pub(crate) on a nodespace-core item is unreachable from tools.rs. pub is the minimal widening that compiles.

It's also reasonable surface. EntityFieldDescriptor is already pub, all four of its fields are pub, render() is pub, and EntityTypeDescriptor::{from_schema, to_json, from_json} are pub. from_schema_field was the odd one out — a private constructor on an otherwise fully public value type, which meant an external caller could construct the struct by hand (all fields public) but not through the canonical conversion. Making it pub narrows the drift surface rather than widening it: hand-construction was already possible and is the thing that loses fields. The doc comment added on it says exactly this. Good change.

🟢 3. The notation change stays coherent with the surrounding prompt

📁 packages/agent/src/local_agent/tools.rs:1466-1484

I read the full prompt string looking for text that assumed - name (type). There is none. The prompt refers to the list only as "the fields above" and instructs "property":"<field name>" — both notation-agnostic. The one nearby risk is skill_pipeline.rs:309's prose "lists each type's fields as (name: type)", but that describes the RELEVANT ENTITY TYPES block, not this sub-prompt, and it was already describing render()'s output before this PR. No coherence break introduced.

Worth flagging for a future reader though: skill_pipeline.rs:309 says fields are listed as (name: type) and its inline example at :315 shows no enum values, while render() actually emits name: type (a, b) and , required. That prose is now stale against the renderer it describes — pre-existing, not caused by this PR, and out of scope, but it's the kind of drift this PR's whole thesis is about. Worth an issue.

🟢 4. The test genuinely guards the defect — mutation independently re-verified

📁 packages/agent/src/local_agent/tools.rs:3135-3196

I did not take the PR's claim on faith. I reverted the renderer to format!("- {} ({})", f.name, f.field_type) and ran the test:

Fields on this type:
- replacement_cost (number)
- condition (enum)
...
failures:
    local_agent::tools::tests::resolve_query_integration::resolve_query_prompt_carries_enum_values_for_status_fields
test result: FAILED. 0 passed; 1 failed

Then restored and confirmed green. The claim holds. The guard fails for the right reason, at the right granularity.

The design decision to assert on prompt text rather than return value is the right call and is well argued in the doc comment. The return value is well-formed whether or not the model guessed — asserting on it would have produced a test that passes through the defect. This is a materially better test than the obvious one.

The second assertion (prompt.contains("replacement_cost: number")) also correctly pins the non-enum notation change, so a future revert of the whole renderer can't slip through by fixing only the enum case.

🟢 5. CapturingEngine / FixedJsonEngine duplication — acceptable, but consolidation is easy

📁 packages/agent/src/local_agent/tools.rs:3063-3103 vs 3029-3060

CapturingEngine is FixedJsonEngine plus an Arc<Mutex<String>> field and three lines in generate(); model_info and token_count are byte-identical. ~40 lines of test-double duplication.

Not blocking — two test doubles in one test module is well under the threshold where DRY earns its cost, and they read clearly. But Nit: FixedJsonEngine could grow an Option<Arc<Mutex<String>>> capture slot (or CapturingEngine could subsume it entirely, with the non-capturing constructor passing a throwaway Arc), collapsing to one double. Third ChatInferenceEngine stub in this module is the point to actually do it.

🟢 6. No fourth (or fifth) hand-rolled renderer remains

Swept packages/*/src for schema-field-into-prompt rendering. Post-merge, every path from a real SchemaNode to a model-facing string goes through EntityFieldDescriptor. Adjacent things I checked and cleared:

  • packages/agent/src/local_agent/tools.rs:819-838 (def_update_task_status) hard-codes the task-status enum in prose + JSON enum — duplication, but of a static built-in list, not of the schema renderer. Out of scope.
  • packages/core/src/services/node_service/crud.rs:1728-1740 renders a real schema field's enum values into a validation error as label (value) — a different spelling that the model does see (tool errors come back as tool results). It carries the values so it isn't a drop, and it's an error path not a prompt path, so I wouldn't fold it in. Noting it as the one remaining divergent enum spelling a model can encounter.
  • skill_ops.rs:189, prompt_templates.rs:17-32, acp/context_assembly.rs:98-129 — all either already on the shared path or rendering something other than schema fields.

AC 2 is met on the strongest reading.

🟢 7. Dead code / imports / clippy

Clean. cargo clippy -p nodespace-core -p nodespace-agent --all-targets produced zero output. No #[allow], no #[deprecated], no suppression. The fully-qualified nodespace_core::ops::entity_types_block::EntityFieldDescriptor::... path inline is verbose and pushes the line long, but avoids adding an import to a file with a large use block — defensible either way. Nit: a use would read better if this file ever gains a second reference.


On the eval AC

The argument is self-consistent and I believe it, with one caveat about how it's framed.

The chain checks out: scenario 6 ("The 2400 one came back — set it to returned") fails in both arms with Expected sequence [resolve_query,update_node] as a subsequence, got: — i.e. resolve_query is never called. If the tool is never invoked, exec_resolve_query never runs, the sub-prompt is never built, and the enum values are unreachable. A change confined to a string that is never constructed cannot move a score. 6/12 in both arms is exactly what that predicts, and the identical scenario-for-scenario failure set is the right corroboration. That is a real negative result, not a dodge.

Where I'd push back slightly on framing: the PR says the AC "cannot be scored today," which is true of the matrix, but the AC's own rationale was "a filter that silently matches nothing is exactly what an eval catches and a unit test does not." The prompt-level test satisfies the letter (values reach the prompt) but not that rationale (does the model now emit condition=returned instead of a guess?). Nothing in this PR demonstrates the model uses the values — only that they're present. That's not a reason to hold the PR; the missing measurement is blocked on a separate defect and the change is provably neutral. But the honest statement is "the behavioural half of AC 4 is deferred to #1862," not "AC 4 is unmeasurable." Worth carrying that forward so it isn't quietly considered closed.

Related: the required concern in finding 1 is exactly the kind of thing this blind spot would hide. A spurious required-field filter is silently-empty in the same way, and no test in this PR would catch it.

The 6/12-vs-10/12 baseline discussion is correctly excluded from this PR's scope. The issue thread's methodology self-correction (8c's minProperties: 1 fixture tightening making the two arms non-comparable, while scenario 4 already had it on both sides and so is comparable) is careful work and lands in the right place — #1862, with arm C as the only valid "before".


Recommendation

COMMENT — approve-with-one-question, in practice.

This is a clearly net-positive change and the engineering around it is a cut above: it fixes a real silent-failure defect, removes a renderer rather than adding one, and the test is mutation-verified at the layer where the defect actually lives rather than at the convenient layer. Tests and clippy are green as claimed — I re-ran all of it. The negative eval result is honestly reported rather than massaged, and the author's methodology self-correction on the adjacent regression is exactly right.

The one thing I'd want before merge is a decision on the , required suffix (finding 1) — not because it's certainly harmful, but because right now nothing in the diff shows it was noticed. Either strip it from this call site or add a line saying why it belongs; both are a few minutes' work, and either resolves it. Everything else is nits.

Given the change is measurably neutral and independently verified, I would not block a merge on finding 1 if the author judges the suffix benign — but I'd want that judgement stated, not implied.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review posted above: COMMENT. Net-positive change, all claims independently verified (agent 400 green, core 1068+ green, clippy clean, mutation check re-performed). One item worth a decision before merge: EntityFieldDescriptor::render() appends , required — a node-creation obligation — into resolve_query's isolated filter-emission sub-call, where it has no guidance to ground it. See finding 1.

Reusing `render()` wholesale carried ", required" into `resolve_query`'s
prompt. Reproduced before fixing: a required field rendered as
`- replacement_cost: number, required`.

That is not cosmetic. `required` has exactly one definition in front of this
model — the node-creation guidance's "MUST be included in the properties
map" — which is an obligation on a *write*. This sub-call is a lone user
message with no system prompt and no tools, so the word arrives with no
definition at all, and a model applying the one it knows would filter on a
field the request never mentioned. That matches nothing, which is
indistinguishable from a genuinely empty result: the same silent failure
this PR set out to remove, reintroduced from the other side.

Split `render_shape` (name, type, enum values) from `render` (that plus
required-ness). The entity block keeps `render` — required-ness is exactly
what it should say when the model is about to create a node. Read and filter
prompts get `render_shape`. Both still share one renderer, so the
convergence this PR is about is intact.

Pinned by assertion rather than left to inspection: the fixture's number
field is now required, so the test proves the suffix is suppressed rather
than merely absent. Mutation-verified — restoring `.render()` fails it.

Also corrected a comment claiming this notation "matches the entity block the
model sees elsewhere in the same conversation." There is no same
conversation; this is an isolated sub-call. The maintenance argument for
convergence carries the change on its own.

Reviewer's other findings needed no code change: `pub` is correct
(`pub(crate)` cannot work across crates), the notation is coherent with the
surrounding prompt, and the CapturingEngine/FixedJsonEngine duplication is
worth consolidating at a third double, not a second.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163
@malibio

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

/address-review — 44b69af

The , required finding was correct, and it was a real defect I introduced by reusing render() wholesale. Reproduced it before fixing rather than acting on the report:

- replacement_cost: number, required

Why it mattered more than noise

Verified both halves of the reviewer's reasoning in the code:

  • skill_pipeline.rs:309 defines required for this model as "MUST be included in the properties map" — an obligation on a write.
  • tools.rs:1493 builds this sub-call as a lone user message, tools: None, no system prompt — so the word arrives with no definition attached.

A model applying the only definition it knows would emit a filter for a field the request never mentioned. That matches nothing, which is indistinguishable from a genuinely empty result — the same silent failure this PR removes, reintroduced from the other side. Stripping it.

The fix

Split the renderer by what the prompt is for:

contents used by
render() name: type (values) + , required entity block — the model is about to create a node, so required-ness is exactly right
render_shape() name: type (values) read/filter prompts — no write-time obligations

Both still share one renderer, so the convergence this PR is about is intact. This is a split by context, not a fork.

Pinned, not assumed

The fixture's replacement_cost is now required, so the test proves the suffix is suppressed rather than merely absent — otherwise it would pass for the wrong reason. Mutation-verified:

--- mutant: .render_shape() → .render() ---
write-time obligations must not leak into a read/filter prompt
test result: FAILED
--- restored: ok ---

Entity block unaffected — renders_type_field_enum_required_and_template and required_and_enum_values_survive_the_routing_path both still green.

Also corrected

The reviewer caught that my comment claimed this notation "matches the entity block the model sees elsewhere in the same conversation." There is no same conversation — this is an isolated sub-call. Removed; the maintenance argument for convergence carries the change on its own without a model-facing-coherence claim that isn't true.

Findings needing no change

  • pub is correct — confirmed nodespace-agent is a separate crate, so pub(crate) cannot work. Agreed it also narrows drift: the struct and its fields were already pub, so hand-construction was always possible; exposing the canonical conversion is the safer surface.
  • Notation coherent — the prompt refers to the list only as "the fields above" / <field name>, both notation-agnostic.
  • CapturingEngine duplication — consolidate at a third double, not a second. Deliberately skipped.

On the eval AC framing

Reviewer's pushback is fair and I'll restate it their way: nothing here shows the model uses the values, only that they reach it. "The behavioural half is deferred to #1862" is the honest phrasing, not "unmeasurable." And their point that finding 1 is exactly what that blind spot would hide is well taken — a prompt-presence test would not have caught the required leak either. It took a human-style read of what the word means to this model.

Checks

nodespace-agent 400 green · nodespace-core 1068 green · clippy clean · pre-push gate passed in full.


Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: One finding, addressed exactly as scoped. The change is a two-method split with no new logic — render() is byte-identical in behaviour for its existing caller (proven by the unchanged entity-block tests), and the new render_shape() is render() minus one conditional suffix. The guard is mutation-verified in both directions. Nothing architectural moved, and the remaining findings were explicitly no-change or deferred-by-agreement.

Ready for merge, pending your call.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant