Skip to content

Hold a routed turn's node_type to the schemas its skills link to #3419

Closed

Description

@malibio

Overview

When the local agent routes a turn to skills, each candidate's schema_metadata tells the model which types it may use. After #3418, a skill's applies_to links make that set deterministic: the skill's linked schemas plus their subtypes. But nothing holds the model to the set. This issue makes the offered set binding for the tools that reference an existing type. The set goes into the tool parameter schema as an enum, and dispatch refuses a type that is not on it.

Problem Statement

  • The routed prompt renders each eligible candidate's schema_metadata under the shared "EXISTING SCHEMAS" heading (packages/agent/src/local_agent/routing.rs). decisions::schema_candidates records that set as what the model was shown.
  • The code itself documents the gap (packages/agent/src/local_agent/decisions.rs, DecisionRecord::selected_off_menu): "nothing constrains a node_type argument to a retrieved candidate, so the model can and does name a type that was never on offer."
  • The grammar cannot close it on the locked model. ADR-056 records that llama.cpp's json-schema-to-grammar constrains only Gemma 4's outer tool-call envelope, not the argument body. An enum in the tool schema is therefore an instruction, not a hard constraint, on Gemma 4 E4B.
  • ADR-064 measured the tool-schema channel at 100% compliance for a constraint stated only there, against 87.5% for resident prose. So the tool schema is the right channel for the set, and a dispatch-side check is what makes it binding.

Proposed Solution

  1. The offered set for a routed turn is the deduplicated union of every eligible tool-bearing candidate's linked schemas (from Seed built-ins from fixed-UUID tables with Markdown bodies, order agent guidance, and link skills to their schemas #3418's applies_to) and their extends subtypes.
    • The set exists only when every eligible tool-bearing candidate is linked.
    • If any candidate uses the unlinked fallback (the type the query names, or the first five), or the turn is unrouted, there is no set and nothing changes from today.
  2. Put the set in the tool schema. For a turn that has a set, the per-turn ToolDefinitions of the tools that reference an existing type get enum: [<set>] on their type parameter. Today those tools are create_node, update_node, update_schema, search_nodes and resolve_query: the schema_scoped tools in decisions.rs, except create_schema, whose type is new by definition. Derive the list from the Tool enum, like schema_scoped, so a new tool forces a decision.
  3. Refuse an off-menu type at dispatch. In a turn with a set, a call whose type argument is not in it is not executed. It returns a tool-result error that names the allowed type ids, so the model can retry or call route_clarify. ADR-064 assigns errors to the tool-results channel.
  4. Record it. The decision record shows whether the set was enforced, so selected_off_menu can tell an enforced turn from an unconstrained one.

Architecture Impact

Acceptance Criteria

  • A routed turn whose eligible tool-bearing candidates are all linked computes the offered set: the union of linked schemas plus extends subtypes, deduplicated (unit test) — as built: the set is every type the candidate block lists, so it also includes the type of a schema-typed hit
  • A turn with any unlinked tool-bearing candidate, or no routing, has no offered set, and its tool schemas and dispatch are unchanged from today (test)
  • For a turn with a set, the type parameter of create_node, update_node, update_schema, search_nodes and resolve_query carries enum = the set; create_schema never does; the tool list is derived from the Tool enum (tests) — as built: node_type on create_node, search_nodes and resolve_query, schema_id on update_schema; update_node takes a node id, has no type parameter and is not held
  • An off-menu type in a turn with a set is not executed, and the tool result names the allowed ids (test per tool)
  • The decision record shows whether the set was enforced
  • eval:decisions on the locked model, before and after: off-menu selections for linked turns drop to zero executed, and no regression in operation accuracy; results posted on this issue
  • Prompt golden regenerated (UPDATE_GOLDEN=1) and the diff reviewed
  • The ADR-038 amendment is committed to nodespace-docs
  • bun run test:changed passes; bun run quality:fix clean

Technical Specifications

Reference Files

  • Routing and rendering: packages/agent/src/local_agent/routing.rs (Stage-2 candidate block, render_schema_metadata, stage2_permitted_names)
  • Decision record: packages/agent/src/local_agent/decisions.rs (schema_candidates, selected_schema, schema_scoped, DecisionRecord::selected_off_menu)
  • Turn loop and dispatch: packages/agent/src/local_agent/agent_loop.rs (tool surface per turn, decision recording)
  • Tool definitions: packages/agent/src/local_agent/tools.rs
  • Schema metadata source: packages/core/src/ops/skill_ops.rs (find_skills, as changed by Seed built-ins from fixed-UUID tables with Markdown bodies, order agent guidance, and link skills to their schemas #3418)

Implementation Notes

  • Read the set from the same schema_metadata the prompt renders, as schema_candidates does, so the enforced set is the set the model was shown.
  • Tool definitions are built per turn here. Check that per-turn enum changes do not defeat prompt-prefix reuse in the inference engine, and say so on the issue if they do.
  • Model-facing changes fail prompt_assembly_snapshot; regenerate with UPDATE_GOLDEN=1.
  • Check the eval fixture's age before an eval run.

Dependencies

Non-Goals

  • Constraining create_schema's type, or any turn without a linked set
  • Changes to Stage-1 routing or skill retrieval scoring

Activity

  1. malibio commented on Oct 2, 2026

    @malibio
    CollaboratorAuthor

    Baseline on d9f8974 — Frontend: 309 test files passed, 5606 tests passed

  2. self-assigned this
    on Oct 2, 2026
  3. malibio commented on Oct 2, 2026

    @malibio
    CollaboratorAuthor

    eval:decisions on the locked model, before and after (PR #3497)

    Setup. gemma-4-e4b-q4km, 32,768-token window, one rep each, each on a purged database. Both runs use the fixture and scripts at cf28c4e.

    • After: this branch as it will merge.
    • Before: the same commit with the offered set switched off (a one-line local patch, not committed), so no turn is ever held. Main itself could not be used: its daemon does not emit enforced, and this branch's parser drops a decision record without it.

    The twelve existing scenarios: no change

    Every scenario gave the same verdict and the same first tool call in both runs.

    Before After
    Passed 10 / 12 10 / 12
    Failed schema-on-menu-company, declarative-fact-report-resolved the same two

    Both failures are unrelated to this change and identical in both runs (a create_node sent without its type, and a create_relationship on a fact report). None of these twelve turns is held, since they route to built-in skills, which link to no schema.

    The two linked-skill scenarios

    These are new. Their group seeds a warranty_claim type and three skills linked to it through applies_to. In both runs retrieval returned the three linked skills and the warranty_claim schema hit, so the "after" turn was held to warranty_claim.

    Scenario Before (never held) After (held)
    held-on-menu-type: "File a warranty claim for the Aurora blender…" Filed the claim. (The run's scrape recorded no calls for this turn, so it is not scored; the reply confirms the record.) create_node on warranty_claim with three fields. Passed.
    held-off-menu-type: "…add a task to ring the buyer back on Friday." Named task twice. Both create_node calls reached the executor. They failed on an unrelated field-validation error, so nothing was written, but nothing stopped them for their type. Searched warranty_claim, then asked the user what to do. No call named an off-menu type, no record was created. Passed.

    Off-menu calls that reached the executor on the linked turn: 2 before, 0 after.

    What this does and does not show

    • The refusal itself did not fire in the "after" run. With the enum and the held description in place, the model did not name task this time. In an earlier trial of the same scenario on this branch (before the refusal's wording was revised) it did name task, dispatch refused the call with the allowed ids, and the turn ended without a write. So both paths have been seen on the model, but in different runs.
    • "0 ran" is the daemon's own per-call report (off_menu_ran on the Tool executed log line). It confirms the guard was in force on every call of the run. It would not detect the guard and an executor disagreeing about which argument names the type; they agree today.
    • One rep each. These are single observations, not rates. The before/after equality on the twelve existing scenarios is the meaningful part: unheld turns behave as they did.
    • How often this binds in practice. A turn is held only when every tool-bearing skill that clears its bar is linked. No built-in skill links to a schema, so the fixture needed three linked skills to fill the candidate list before any turn was held.
    • selected_schema now reads schema_id for update_schema. No scenario in this fixture calls update_schema, so no count moved for that reason.

    Prompt-prefix reuse

    Per-turn enums do not add a new divergence point. Tool definitions were already rebuilt per turn (declare_write_tool_fields declares field_values from the retrieved schemas), and the Stage-2 prompt already diverges from Stage 1 at the candidate block.

    One decision left with the issue owner

    A held turn refuses a core type the request names (task, text) unless a skill links to it, because a core type never reaches the candidate block as a schema hit. In the scenario above that is what makes "add a task…" end in a question to the user. It is recorded as a consequence in the ADR-038 amendment. If that is not the behaviour wanted, the options are to offer core types on a held turn, or to leave the turn open when the request names one.

  4. added 2 commits that reference this issue on Oct 2, 2026
    b75b867
    815ea2a
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