Skip to content

Tool-call guidance living in a single skill body is unreachable on turns routed to other skills #1899

Closed as not planned

Description

@malibio

Found during code review of #1897 (the #1866 fix).

Observation

create_node appears in exactly one skill whitelist — Node Creation (packages/agent/src/skill_pipeline.rs). But #1866's traces record the empty-create_node failure occurring on turns routed to Schema Creation, Relationship Management, Organization — not Node Creation — with an outcome identical to the Node-Creation-routed arms.

On those arms the Node Creation markdown is never assembled into the prompt. So every rule that lives only in that skill body contributes nothing, and the create_node tool schema's description field is the sole surface carrying it.

Why it matters

The tool-schema description is the weaker of the two surfaces — a JSON Schema field competes for far less attention than a routed skill body placed in the system prompt. That means the guidance is thinnest on precisely the arms that were failing.

This is a plausible explanation for #1866's post-fix measurement landing at 2/3 rather than 3/3, and it is distinct from the two mechanisms already filed there (#1895 type-id fidelity, #1896 schema fragmentation). Both of those are about what the model does; this one is about what the model was shown.

More generally: any rule about how to call a tool is only as reachable as the skills that whitelist that tool. Today that coupling is implicit — a rule can be written into a skill body and be silently absent on most turns that actually invoke the tool.

Worth checking first

Before changing anything, confirm the premise by dumping the Stage-2 prompt on a turn routed to Schema Creation that nonetheless calls create_node, and verifying the Node Creation body is absent while create_node is still in the offered tool list. #1841 and the #1866 investigation both turned on guidance referencing something the model could not actually see, so this class of assumption is worth verifying rather than reasoning about.

Directions, roughly in order of preference

  1. Put invariant tool rules on the tool, not in a skill. If a rule must hold on every create_node call regardless of routing, the tool schema is its correct home — and it should be written to carry that weight, rather than as a terse afterthought to a skill rule.
  2. Whitelist create_node on the skills that demonstrably call it, so the fuller guidance travels with it. Costs prompt budget on those arms; needs measurement.
  3. Enforce in code where the rule is a data invariant rather than a preference — see the ADR-063 discussion on Stop create_node from silently discarding user values with no matching schema field (#1866) #1897, where the same conclusion was reached from a different direction.

Note that (1) and (2) are not exclusive, and (3) is strictly more reliable than either for anything that is genuinely an invariant.

Acceptance criteria

  • Confirm whether Node Creation guidance is absent on turns that route elsewhere but still call create_node
  • Decide where rules that must hold on every create_node call should live, and move them there
  • Re-measure agent-matrix scenario 4 to see whether the residual 1/3 failure rate moves

Evidence: #1866's .trace.jsonl (routing decisions per turn) and the 3-run post-fix measurement recorded there.

Activity

  1. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    Hardening found during re-review of #1897

    Related to this issue's theme (guidance depending on what the prompt actually contains), and worth folding in here rather than filing a fourth issue.

    packages/core/src/ops/context_ops.rs:296-299 has no is_core filter:

    let schemas: Vec<SchemaNode> = results
        .into_iter()
        .filter_map(|(node, _score)| SchemaNode::from_node(node).ok())
        .collect();          // ← no is_core filter

    Retrieval is scoped only by node_type == "schema", and text/task/date are stored schema nodes with embeddable content. The sibling branch writing to the same relevant_schemas vector does guard:

    // local_agent_service.rs:1878
    if schema.is_core { continue; }  // skip built-in types

    One branch guards, the branch it augments doesn't — reads as oversight.

    Why it matters now: #1897's new guidance tells the model to use a bare property key when the type appears in RELEVANT ENTITY TYPES (treating that as proof it is user-defined), and a custom: prefix on built-in types. If a core type can reach that block, the model reads it as user-defined and writes a bare key onto a core type — the exact ADR-063 violation #1897 just fixed.

    Currently latent, not live. Seeding uses raw store.create_node, which does not queue_root_for_embedding, and backfill_schema_description_subtrees skips schemas without a legacy description (core schemas have none) — so core schema nodes are likely un-embedded and unretrievable on a fresh DB. Nothing in the code prevents it: any future backfill, re-index, or touch that embeds them silently activates it, with no test failing.

    Fix: .filter(|s| !s.is_core) at context_ops.rs:296, mirroring local_agent_service.rs:1878; same guard on skill_ops.rs:172 as defence-in-depth. Worth a test asserting core types never render into RELEVANT ENTITY TYPES, so the guidance's premise is enforced where it's relied upon.

    This is pre-existing and not introduced by #1897 — but #1897 turns it from retrieval-hygiene into a correctness premise, which is the difference between that guidance being correct by construction and correct by coincidence.

  2. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    Investigation: the premise does not hold under the current routing code

    Checked the first acceptance criterion — whether create_node is reachable on turns where Node Creation doesn't clear the Stage-2 gate, with the Node Creation guidance body absent from the prompt.

    create_node cannot be called when Node Creation doesn't clear the gate

    create_node is whitelisted only by the Node Creation skill (skill_pipeline.rs:299). Under ADR-038's stage2_tools (routing.rs:378-400), the tool surface offered to the model is the union of tool whitelists from only the candidates that clear the score gate — not the full registry, and not a fallback-to-full-surface unless that permitted set is empty. create_node's requires_routed_guidance() is false (tools.rs:1128), so it would appear via fail_open_surface if the permitted set were empty — but the scenario in question (candidates clearing the gate) isn't the empty case.

    I wrote a scratch test simulating exactly the scenario named in this issue — retrieval's top-3 being Schema Creation, Relationship Management, and Organization, none of them Node Creation — and ran it against current routing.rs:

    SCOPED TOOLS: ["create_schema", "update_schema", "get_node", "create_relationship",
                   "get_related_nodes", "search_semantic", "search_nodes"]
    

    create_node is absent. So under current code, if those three (and only those three) clear the gate, the model cannot call create_node at all — the premise that it's called with weaker guidance doesn't apply; it can't be called in that configuration, full stop.

    The originating claim isn't backed by the trace artifact in the repo

    The PR-review finding this issue was filed from (#1897 review, 🟡-2) states: "#1866 records routing landing on Schema Creation, Relationship Management, Organization with the identical empty-call outcome." I checked scripts/results-e4b.trace.jsonl (the artifact #1866 attached) — its scenario-4 entry has stage2CandidatesInjected: true and toolsCalled: ["create_node"], but no routedSkills field (it's optional per eval/types.ts:53, populated only when the raw daemon log carried a routed_skills=... line and aichat.ts:198 parsed it). This file doesn't contain the skill-name evidence the claim rests on — it must have come from an unsaved observation (e.g. watching debug logs live during that run), not from anything reproducible in the repo today.

    Also worth noting: ADR-038 (e4ff4890, 2026-07-30) landed before the #1866 traces were captured (4b66ec4f, 2026-08-01), so the traces are evaluating the current top-K=3 routing architecture, not a stale one — that part of the premise is fine. The gap is specifically that "routed elsewhere but still called create_node" isn't reproducible against current stage2_tools logic given the exact three skills named.

    What would make the premise true

    The one way create_node reaches the model without Node Creation's guidance is if Node Creation is among the eligible (gate-cleared) candidates but retrieval's top-K=3 also included other skills whose names got reported/recalled instead — i.e., the "routed to X, Y, Z" description was incomplete, not that Node Creation was truly absent. render_candidates_for_prompt does render each cleared candidate's own instructions (routing.rs:283-307), so if Node Creation is in the cleared set, its guidance is in the prompt regardless of what else clears alongside it.

    Recommendation

    Given create_node is architecturally unreachable without Node Creation clearing the gate, I don't think there's a live bug here matching the issue as filed. Rather than move guidance or change whitelists against an unconfirmed premise, I'd:

    1. Close this issue as not reproducible against current routing code, OR
    2. Re-open only if a fresh run captures routed_skills=... (requires RUST_LOG=debug) alongside an empty-properties create_node call, confirming Node Creation was genuinely excluded from that turn's cleared candidates — which would be a different, real bug (e.g. in retrieval scoring or stage2_tools) rather than a "guidance lives in the wrong place" issue.

    Directions 1–3 in the issue body (moving guidance onto the tool schema, widening whitelists, enforcing in code) are all reasonable defenses-in-depth regardless, but I'd hold off implementing them against this issue specifically since the triggering scenario isn't confirmed reachable. Proceeding to close as not-reproduced unless redirected — happy to instead capture a RUST_LOG=debug run to try to reproduce first, if that's preferred.

  3. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    Agreed — close the original claim as not-reproduced. The methodology here is exactly right: rather than build a fix on an assumed premise, you went back and checked it, found a concrete falsifying result (a scratch test against current routing.rs showing create_node is architecturally absent from the tool surface in that configuration, not weakly-guided), then traced the originating claim to its source and found the trace artifact doesn't actually carry the routedSkills evidence it was supposedly based on. That's the same "verify the claim against real source, don't take a prior comment's assertion at face value" standard this whole investigation has been holding everyone else to — good to see it turned on your own earlier finding too. The reopen condition you left (a RUST_LOG=debug run with routed_skills=... alongside an empty-properties create_node call) is precise and actionable if this ever does reproduce.

    One thing not to lose in the close: the is_core filter asymmetry you folded in (context_ops.rs:296 missing the guard local_agent_service.rs:1878 has) is a real, independently-confirmed latent bug, unrelated to whether #1899's original premise holds. It's currently dormant only because of how seeding/backfill happens to work today, not because anything prevents it — and you correctly noted #1897 turned it from a hygiene nit into a correctness premise (bare-vs-prefixed property keys depending on a core type never appearing in RELEVANT ENTITY TYPES). That should still get fixed — either land the one-line filter directly now while you're in this code, or split it into its own small issue, but don't let it close away silently with the rest of #1899's not-reproduced verdict.

  4. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    Closing as not-reproduced against current routing code, per the investigation and agreement above.

    The originating premise (Node Creation guidance silently absent while create_node is still callable via other routed skills) didn't hold under stage2_tools: create_node is architecturally unreachable unless Node Creation itself clears the gate, so the "callable with weaker guidance" scenario this issue was filed for isn't a live configuration. The claim it was based on also wasn't backed by the trace artifact in the repo.

    The one concrete, real finding that came out of this investigation — the is_core filter asymmetry — was split into #1900 and is already merged (70468285, #1903), including the extra related_one_hop_schemas guard added during that PR's own review. Nothing left open here.

    Reopen condition still stands if it ever comes up again: a RUST_LOG=debug run capturing routed_skills=... alongside an empty-properties create_node call, confirming Node Creation was genuinely excluded from that turn's cleared candidates.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions