Skip to content

Investigate how skills are surfaced to a turn: retrieval can make a turn unwinnable #2276

Closed

Description

@malibio

Investigate how relevant skills are surfaced to a turn, and design a replacement. Measurements from the #2239 model runs show the current mechanism can make a turn impossible — not merely unguided — and that this is invisible in eval scores.

This is an investigation-and-design issue, not a request to implement any specific option below.

What we measured

DeepSeek V4 Pro, 3 reps, d393ad19, freshly seeded database per rep. Full data in deepseek-post2254.json.

Tool surfaces are unstable across identical reps. 12 of 21 scenarios received a different tool surface on repeated runs of the same prompt. Scenario 7 — "Is anything on our plate longer than forty days?", a pure read — routed three different skill sets:

rep1  Research & Search, Schema Creation, Relationship Management
rep2  Node Creation, Schema Creation, Research & Search
rep3  Node Deletion, Relationship Management, Organization      <- no search skill at all

A destructive tool reached surfaces where deletion was never the intent. delete_node was offered on 5 of 63 scored turns (~8%), every time on a turn that was an update, a create, or a read. The Stage-1 queries that produced those surfaces contain no deletion vocabulary whatsoever:

query sent to find_skills top_score actual intent
mark the five-day write-up as signed off 0.724 update
mark the incident Rowan was on call for resolved 0.825 update
record decision to use event-based cache clearing from Priya 0.854 create
find anything on our plate longer than forty days 0.800 read

No delete, remove, erase, purge, discard, trash, drop, or get rid of in any of them. Scores are 0.72–0.85, far above DESTRUCTIVE_SKILL_SCORE_BAR (0.45) — these are confident rankings, not near-ties separated by noise.

One case is deterministic, not flaky. Scenario 13 (mark the incident Rowan was on call for resolved) routed Node Deletion first in all three reps. The rank-1 destructive safeguard (skill_pipeline.rs:1008) therefore offers no protection there at all: the skill wins retrieval every time. Nothing was deleted only because the model chose correctly.

The skill that owns updates does not win updates. Scenario 6 ("The five-day one got signed off — mark it that way") never routed Graph Editing in any rep:

rep1  Schema Creation, Node Deletion, Node Creation
rep2  Node Deletion, Schema Creation, Node Creation
rep3  Schema Creation, Node Deletion, Node Creation

The turn succeeded only because Node Creation also whitelists update_node (skill_pipeline.rs:319), acting as an unintended fallback owner. Remove that overlap and the plainest update prompt in the suite becomes unwinnable.

None of this is visible in the score. Every scenario above passed. A pass/fail run cannot detect this class of defect; it was found only by reading routedSkills and toolsOffered per turn.

Why the current design is exposed

Retrieval decides whether a core tool is reachable at all. find_skills takes the top 3 by rank (skill_ops.rs:281,305) with SKILL_SEARCH_THRESHOLD = 0.0, so exactly three skills always win regardless of fit, and the risk-tiered score bars are applied only after that truncation. A skill that would clear its bar comfortably is still dropped if it ranks 4th.

The consequence is that a retrieval miss does not degrade a turn — it can make it impossible. The model is asked to act without the tool the action requires, and the resulting red looks like a model failure.

Stage-1 is not the weak link. It already writes a clean intent paraphrase, resolving ellipsis and pronouns well ("the five-day one" -> "the five-day write-up"). The model understands the intent correctly and retrieval still returns the wrong skill.

Directions to evaluate

A. Always-available core tools. Make non-destructive core CRUD (create_node, update_node, get_node, search_nodes, search_semantic, update_task_status) unconditionally present, independent of retrieval. Retrieval then only adds specialist capability and guidance rather than gating basic reachability.

This inverts the failure mode: a wrong retrieval degrades to "no extra guidance" instead of "cannot act". It composes with the existing risk tiering — delete_node and schema mutation stay retrieval-gated, so the always-on set is exactly the operations where a wrong guess is cheap and recoverable. It also removes the accidental dependence on Node Creation's whitelist overlap documented above.

Open questions: prompt-size cost of always-on tools; whether always-on tools should carry always-on guidance or none; whether create_schema belongs in the set (it is mutating but not destructive, and scenario 8a shows it is the hardest to retrieve correctly).

B. Structured intent instead of a prose paraphrase. Have Stage-1 declare the operation and target type — e.g. update node of feature_write_up schema — rather than free text, and constrain candidates by declared operation before ranking. Node Deletion is then not a candidate for an update, whatever the embedding scores.

The type name is reliable input rather than a guess: the schema list is already in the model's prompt (EXISTING SCHEMAS ... feature_write_up "Feature Write-up" -> signed_off: boolean), so the model copies a name it was given.

Open questions: turns where no schema exists yet (scenario 8a is creating the type) need a fallback path; a declared type that does not exist must degrade to semantic retrieval rather than fail; operation misclassification fails harder than a mis-rank, because filtering is absolute where ranking is soft — scenario 8c ("Put down that we went with…") is genuinely ambiguous between create and update.

C. Retrieval-mode by risk. Read-only skills retrieve semantically (recall matters, wrong guesses are cheap); destructive skills additionally require lexical evidence of intent, so delete_node is unreachable unless the query actually says delete/remove/drop.

Note the codebase contains a documented counter-example to going keyword-only wholesale: skill_pipeline.rs:1261 records scenario 3 failing because a keyword-style description ("new type", "create schema") did not lexically match "I want to keep a record of the equipment my team checks out". Semantic matching fixed that. So the two failure modes pull in opposite directions and a global switch trades one for the other. Retrieval is already hybrid (HYBRID SEARCH PROFILE ... tier1/tier2/tier3 in the daemon log), so the question is tier weighting per risk class, not keyword-versus-semantic.

D. WRONG SKILL? clause in every procedure. Node Deletion is currently the only skill carrying one, and its own comment explains why it lives in the procedure rather than the description: "the description is embedded for retrieval, and an embedding cannot represent 'not'". Procedures are not embedded, so this cannot affect ranking. It is a post-routing backstop, not a fix — and for scenario 13, where the wrong skill wins deterministically, it is currently the only remaining line of defence.

Prerequisite for any of them

Log per-skill retrieval scores, not just top_score. Today only the winner's score is recorded, so we cannot distinguish two very different situations:

  • Graph Editing scores 0.81 against Node Deletion's 0.82 — a tiebreak problem, fixed by (A) or (B).
  • Graph Editing scores 0.3 on its own core use case — its description is mis-placed in the vector space, and (A)/(B) would mask that rather than fix it.

These call for different work, and nothing distinguishes them from outside the process today. This should land before any option above is chosen.

Acceptance criteria

  • Per-skill retrieval scores observable for a turn
  • Measured: what all eight skills score on the four queries listed above
  • A decision recorded on which direction(s) to take, with the measurement as its basis
  • Repeated-prompt stability check, so a routing flip is detectable rather than surfacing as an intermittent eval red
  • No turn can be made unwinnable by a retrieval miss on non-destructive core operations
  • Scenario 6 and 13 routing verified across repeated reps after the change

Related

Activity

  1. malibio commented on Aug 24, 2026

    @malibio
    CollaboratorAuthor

    Ran the prompt-register A/B this issue's framing depends on. The result substantially revises the premise: most of the mis-routing measured here is driven by prompt phrasing, not by a defect in retrieval alone.

    Method

    Two fixtures, identical in every respect except nine prompt: literals. Assertions, groups, setup flags and comments are byte-identical (verified by diff), so a routing difference is attributable to phrasing and nothing else. Rewrites supply what a user looking at their own workspace would type — naming the type, field and value — instead of a bare demonstrative:

    elliptical:  "The incident Rowan was on call for — mark it resolved"
    explicit:    "Set resolved to true on the incident report where on_call is Rowan"
    
    elliptical:  "Is anything on our plate longer than forty days?"
    explicit:    "Search for records with estimated_days greater than 40"
    

    Run on DeepSeek V4 Pro (served) and Gemma 4 E4B (local), one rep each, same daemon and rebased HEAD, database purged between arms.

    Result: the destructive-tool exposure is phrasing-driven

    DeepSeek E4B
    delete_node offered — elliptical 5 / 63 turns 5 / 21 turns
    delete_node offered — explicit 0 1 / 24
    Node Deletion ranked #1 — elliptical 4 scenarios 4 scenarios
    Node Deletion ranked #1 — explicit 0 0

    Scenario 13 is the sharpest case. Under elliptical phrasing it routed Node Deletion first in all three reps of the earlier DeepSeek run — deterministic, the case where the rank-1 destructive safeguard offers no protection at all. Under explicit phrasing it drops to rank 3 and delete_node never reaches the surface.

    Graph Editing also recovers. It previously routed on zero reps of scenario 6 (an update), the turn surviving only because Node Creation happens to whitelist update_node. With explicit phrasing it routes normally. Scenario 7 likewise recovers Research & Search at rank 1.

    The effect replicates across chat models

    This is the load-bearing observation. Skill retrieval runs on the embedding model, which is identical in both arms; the chat model only writes the Stage-1 paraphrase. E4B's paraphrases differ noticeably from DeepSeek's:

    DeepSeek:  find anything on our plate longer than forty days
    E4B:       items on our plate longer than forty days
    

    Both mis-route identically under elliptical phrasing, and both are fixed by explicit phrasing. So the mechanism is embedding placement responding to prompt content, not a quirk of how one model phrases queries.

    Why the elliptical prompts route badly

    The Stage-1 query is written from the prompt before the schema block is consulted. Scenario 7's tool call, once made, is correct:

    search_nodes({"node_type":"feature_write_up",
                  "filters":[{"operator":"gt","property":"estimated_days","value":40}]})

    The model resolves the type from EXISTING SCHEMAS in its prompt. But retrieval already ran, against items on our plate longer than forty days — a vector carrying no type, no field, and an idiom that denotes nothing in a knowledge graph. The schema context that saves the tool call arrives too late to save the routing.

    Note also that at scenario 7 only one user-defined type existed, so type inference was elimination with a single survivor. "On our plate" is a better colloquial fit for task or project, both of which exist as built-ins. Reorder the group and the same prompt plausibly resolves elsewhere.

    The fixture causes models to build different data models

    E4B read scenario 8a's "the calls we make on how the system is built" as system calls and created a schema named system_call_log. DeepSeek read it as decisions and created a decision type.

    Every downstream scenario in that group then operates on a different graph — 8e asks E4B to "list every decision" in a workspace containing a syscall log. This makes cross-model comparison unsound at the fixture level, independently of any scoring defect, and it is not visible in a pass/fail score.

    Consequence for this issue

    The four directions filed here were premised on retrieval needing to cope with prompts like mark the incident Rowan was on call for resolved. If that register is not representative of real use, the priority order changes:

    • Fixture register is now the first question, not a footnote. Before building retrieval changes, decide which register the suite is meant to test. Testing idiom comprehension and NodeSpace operations in the same assertion means a red identifies neither.
    • (A) always-available core tools — still valuable, and now for a clearer reason: it removes the accidental dependence on Node Creation's update_node whitelist that masked Graph Editing's failure to route.
    • (B) structured intent — strengthened. Explicit phrasing works precisely because it puts type and field into the retrieval query; declaring them structurally achieves the same thing without depending on how the user types.
    • (C) risk-tiered retrieval mode — weakened as a priority. The destructive exposure largely disappears once prompts name their target.
    • (D) WRONG SKILL? clauses — unchanged; still the only post-routing defence.

    Per-skill score logging remains the prerequisite. Node Deletion still appears at rank 3 on scenario 13 under explicit phrasing, so the semantic adjacency is real and merely demoted. Under a different ranking it could resurface.

    Caveats

    Single rep per arm. The routing flips are large and consistent across two models, but the score differences are not separable from ordinary run-to-run variation at n=1. Anyone acting on the score numbers should re-run with more reps; the routing counts are the durable part.

  2. malibio commented on Sep 9, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 4929 passed (239 files), 0 failed. Duration 78.57s.

  3. self-assigned this
    on Sep 9, 2026
  4. malibio commented on Sep 9, 2026

    @malibio
    CollaboratorAuthor

    Issue #2276 investigation — findings

    Headline finding

    The measurements in this issue were taken at d393ad19. Since then — and in
    some cases, before that commit but describing the same underlying defects —
    substantial work has already landed on main that directly addresses nearly
    every acceptance criterion. This is not a "still needs doing" issue; it's
    mostly a "verify and close" issue, with exactly one concrete gap remaining.

    Key context the issue's write-up doesn't make explicit: b5c892b0 ("Gate
    destructive tools behind winning retrieval and a destructive score bar",
    closing #2240) is an ancestor of d393ad19, the commit this issue's data
    was measured against. #2240's own measurement (11 turns / 5 scenarios,
    delete_node offered on decision/status/due-date/question turns) is quoted
    almost verbatim in this issue's "delete_node offered on 5 of 63 scored turns"
    table. That table is background motivation carried forward, not a fresh
    regression found after the fix — the fix for that exact defect already
    existed when d393ad19 was measured.

    Current architecture (superseding this issue's premise)

    packages/agent/src/local_agent/routing.rs + ADR-038
    implement a two-stage routing pipeline that did not exist in the form this
    issue describes:

    • Stage 1 (model): emits a structural route_query / route_clarify /
      route_multi choice — not a confidence number.
    • Retrieval (system): RETRIEVAL_TOP_K = 3, unchanged from this issue's
      description, but now followed by a risk-tiered score gate applied
      before the model ever judges a candidate:
      READ_SKILL_SCORE_BAR = 0.15 < MUTATING_SKILL_SCORE_BAR = 0.30 <
      DESTRUCTIVE_SKILL_SCORE_BAR = 0.45, derived from each candidate's own
      tool_whitelist (not a stored property, so it can't drift from what the
      skill can actually fire).
    • Stage 2 (model): judges only candidates that already cleared the score
      gate.

    This is Option C from the issue ("retrieval-mode by risk") — not exactly
    as described (it's a score-bar ladder, not lexical-vs-semantic switching),
    but the same intent: destructive skills need a stronger signal than read-only
    ones to become actionable.

    Per acceptance criterion

    1. "Per-skill retrieval scores observable for a turn" — PARTIAL.
      SkillCandidate.score is populated for every one of the top-K candidates
      and is fully available inside agent_loop::route() (the merged vec at
      agent_loop.rs:3107-3140), but the only things actually logged are
      routing.candidates (count), routing.top_score (winner only), and
      routed_skill_names() (names of gate-clearing candidates, no scores).
      destructive_candidates_below_bar() logs scores, but only for destructive
      candidates that failed the gate. This is the one real gap — see
      "Remaining work" below.

    2. "Measured: what all eight skills score on the four queries listed
      above"
      — NOT DONE as a standalone artifact, but scenario-level
      equivalents exist: skill_pipeline.rs's Node Deletion seed doc-comment
      records a direct re-measurement of "mark it that way"-style prompts (6
      reps × 3 models, Node Deletion in the Stage-2 top-3 on all 18 turns)
      after the description-narrowing fix, which is the same class of
      measurement criterion 2 asks for, just not tabulated per the issue's exact
      four queries.

    3. "A decision recorded on which direction(s) to take" — DONE, as
      ADR-038 (Status: Accepted), which predates this issue's filing and
      already implements a variant of Option C. No ADR references issue Investigate how skills are surfaced to a turn: retrieval can make a turn unwinnable #2276
      by number (correctly — per this repo's own documentation standard, ADRs
      shouldn't embed issue numbers).

    4. "Repeated-prompt stability check" — DONE. scripts/eval/runner.ts
      gained --runs N repetition with pass^k reporting (a scenario only counts
      as passing if it passes in every rep) in 00b6f17e, before d393ad19.
      scripts/eval/fixtures/routing.ts is a dedicated routing-accuracy fixture
      (direct/indirect/ambiguous/adversarial scenarios, mutating-vs-read-only
      gate checks) that runs under this repetition harness.

    5. "No turn can be made unwinnable by a retrieval miss on non-destructive
      core operations"
      — DONE, via a different, more general mechanism than
      Option A ("always-available core tools"). skill_pipeline.rs's
      all_write_tools_have_a_second_owner-class test enumerates every write
      tool in the registry and fails the build if it has fewer than 2 owning
      skills, unless explicitly listed in SINGLE_OWNER_BY_DESIGN (currently:
      delete_node, create_schema, update_schema,
      create_nodes_from_markdown — i.e. exactly the tools risk-tiering says
      should be harder to reach). update_node is deliberately whitelisted by
      both Graph Editing and Node Creation — the issue's "unintended fallback
      owner" is actually a structurally-enforced intentional redundancy now, not
      an accident of overlap. A companion test
      (a_skill_carrying_both_write_verbs_disambiguates_them_in_its_guidance)
      requires that any skill whitelisting both create_node and update_node
      names both tools in its own guidance, so the redundancy doesn't create a
      silent wrong-tool-pick risk.

    6. "Scenario 6 and 13 routing verified across repeated reps after the
      change"
      — DONE, but via a different validation route than "verify
      original routing was fixed": 932f92ca ("Audit scenarios 6, 8e and 11d",
      closing Scenarios 6, 8e and 11d fail for every model measured — audit whether they are winnable #2242) found all three were fixture defects, not routing or
      capability defects — the matrix's own scoring was wrong. Deterministic
      winnability tests for scenario 6 and 13's ideal call sequences now live in
      packages/agent/tests/matrix_scenario_winnability.rs
      (scenario_6_ideal_update_is_accepted_and_persists_the_state_change,
      scenario_13_ideal_lookup_then_write_is_accepted), which prove the write
      path is accepted and persists regardless of which route got the model
      there. skill_pipeline.rs's Node Deletion doc-comment separately confirms
      scenario 13's failure mode (Node Deletion winning retrieval on an update
      request) no longer reproduces after the description-narrowing fix.

    Remaining work

    Log every candidate's score, not just the winner's, in
    agent_loop::route() (packages/agent/src/local_agent/agent_loop.rs:3160)
    and find_skills (packages/core/src/ops/skill_ops.rs:379). Both currently
    log only top_score; both already hold the full per-candidate score list
    (merged / skill_results) at the log site. This is a small, mechanical
    change — extend the existing tracing::info! calls with something like
    all_scores = %candidates.iter().map(|c| format!("{}={:.3}", c.name, c.score)).collect::<Vec<_>>().join(", ") — and it's the one piece of
    infrastructure this issue's acceptance criteria call for that doesn't already
    exist. It directly enables distinguishing, from ordinary logs, "a tiebreak
    problem" from "a skill scoring low on its own core use case" — the exact
    distinction the issue's "Prerequisite for any of them" section asks for.

    Recommendation

    Close this issue's design question against ADR-038 (already accepted and
    implemented) rather than opening a new ADR. File a small, separate follow-up
    for the one concrete gap (per-candidate score logging) rather than treating
    it as part of this investigation — it's a mechanical logging change, not a
    design decision.

  5. malibio commented on Sep 9, 2026

    @malibio
    CollaboratorAuthor

    Closing to match board status (Done).

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions