Skip to content

Make schema and operation selection explicit, recorded decision points with a measured Gemma baseline #2802

Closed

Description

@malibio

Overview

Schema selection and operation (tool) selection are currently made implicitly, inside Gemma's generation. There is no point in a turn where "which schema applies" or "which operation to call" exists as a separable, recorded event — both are emergent properties of a tool call the model happens to emit.

This issue makes those two decisions explicit, named, and logged, with their inputs (candidate set) and outcome recorded per turn. It does not change who makes the decision — Gemma still decides, exactly as today. It creates the seam and the measurement.

Problem Statement

NodeSpace has been steadily removing judgment from the generative model, and the evidence keeps supporting that direction:

  • ADR-038 took retrieval away from the model entirely (the system sets K; search_skills is withheld via is_system_only_tool) because a model-driven retrieval could set its own K and bypass the trust filter.
  • ADR-064 measured the channel gradient: a constraint in the tool schema produced 100% compliance, the same rule in resident prose 87.5%, absent 62.5%. The more structural the constraint, the better the outcome.
  • routing.rs already derives blast radius deterministically (skill_is_mutating, skill_is_destructive) rather than asking the model.
  • agent_loop.rs carries a whole guard stack (anti-fabrication, fabricated-id, narrated-tool-call, no-op-success) built on the premise that the model's account of what it just did cannot be trusted.

Schema and operation selection are the two significant judgment calls still made inside generation, and both have measured failures. ADR-056's two E4B matrix failures are both decision failures, not generation failures:

  • Scenario 5: called execute_query instead of search_nodes — wrong operation.
  • Scenario 6: called search_nodes but never followed with update_node — the turn stopped short of the requested effect.

Neither is a malformed-output problem. Both are "picked the wrong thing" problems.

The blocker is that we cannot currently measure either one. Because the decisions are implicit, the only signal is end-to-end matrix pass/fail — and ADR-056 states plainly that those scores "describe the harness as much as the model" while guidance and eval prompts share wording. There is no baseline accuracy figure for "does the agent pick the right schema" or "does it pick the right operation," so there is no way to tell whether a proposed change helps.

Proposed Solution

Introduce a recorded decision point for each of the two selections. Scope is instrumentation and measurement only.

1. Name the decisions. A small struct per decision capturing: the candidate set actually considered, the selected candidate, and the turn/session identity. For schema selection the candidates are what retrieval already produced (bounded by MAX_SEMANTIC_SCHEMAS); for operation selection they are the tool surface stage2_tools() already computed.

2. Record the outcome. Emit each decision on the turn's structured log alongside the existing routed_skills / routing.top_score fields, following the precedent those set. No new storage.

3. Score it. A fixture in scripts/eval/ over both decision points, reusing the existing runner (runEval, pass^k aggregation, baseline diffing). Cases should include the two ADR-056 failures and realistic multi-schema workspaces where more than one type plausibly applies.

Both decisions are bounded, which is what makes them scoreable and makes any future replacement tractable: schema candidates are capped at MAX_SEMANTIC_SCHEMAS (5), and Tool::ALL is 21 variants (20 model-facing) before stage2_tools() scopes it further per turn.

What this deliberately does not do

  • Does not change who decides. Gemma still makes both calls. This is the baseline, not the replacement.
  • Does not add a model. Whether a purpose-trained decision model (Laya/System One-style), a GGUF encoder on the existing llama.cpp backend, or deterministic rules eventually fills the seam is a separate decision that this issue exists to make answerable with numbers.
  • Does not reopen schema-block contamination. create_schema field contamination still occurs on ~1 in 5 turns after #1846's context-block fix #1858 measured that residual (1 in 5) and was closed as consciously declined; the doc comment at context_ops.rs has been corrected to say so. This issue is about the decision itself, not that bug.

Architecture Impact

Extends ADR-038 rather than altering it. ADR-038 established two independently-sourced gates — Stage 1's structural choice and Stage 2's retrieval score plus the model's judgment — and explicitly warns against "inventing a third number." This issue adds no new gate and no new threshold: it records the outcome of a decision the pipeline already makes. The existing score bars (READ_SKILL_SCORE_BAR 0.15 / MUTATING_SKILL_SCORE_BAR 0.30 / DESTRUCTIVE_SKILL_SCORE_BAR 0.45) are untouched.

Worth noting for whoever picks this up: ADR-018 (in the bench repo) specified a DistilBERT decision gatekeeper, was marked Accepted, and was never implemented — while ADR-038's LLM routing shipped instead. Part of why is that it named a model before establishing a seam or a measurement. This issue is deliberately the inverse order. (ADR-018 is also still marked Accepted despite being contradicted by shipped code — a separate documentation cleanup, out of scope here.)

Acceptance Criteria

  • Schema selection is a named decision point recording its candidate set and selected outcome
  • Operation selection is a named decision point recording its candidate set and selected outcome
  • Both are emitted on the turn's structured log, consistent with the existing routed_skills / routing.top_score fields
  • An eval fixture in scripts/eval/ scores both decisions independently of end-to-end scenario pass/fail, using the existing runEval runner
  • Fixture cases include ADR-056's Scenario 5 (wrong operation: execute_query vs search_nodes) and Scenario 6 (incomplete read-then-write), plus multi-schema cases where several types plausibly apply
  • Fixture prompts stay independent of packages/agent/src/agent_guidance.rs, per the contamination guard the routing fixture already enforces (guidance_is_not_contaminated_by_eval_prompts)
  • A recorded baseline for Gemma 4 E4B on both decisions, committed or linked, with rep count stated
  • No new threshold or gate is introduced; existing score bars unchanged
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • packages/agent/src/local_agent/routing.rs — stage2_tools() (the operation candidate set), render_candidates_for_prompt, routed_skill_names (the structured-log precedent to follow)
  • packages/agent/src/local_agent/agent_loop.rs — turn orchestration; where tool calls are parsed and where the decision outcome is observable
  • packages/agent/src/local_agent/tools.rs — Tool::ALL (21 variants), is_system_only_tool, model_facing_tool_definitions()
  • packages/core/src/ops/context_ops.rs — build_workspace_context, MAX_SEMANTIC_SCHEMAS, SCHEMA_SIMILARITY_THRESHOLD (the schema candidate set)
  • scripts/eval/runner.ts — runEval, pass^k aggregation, baseline diffing
  • scripts/eval/fixtures/routing.ts — the shape to follow for a new fixture (stable id join keys, ExpectedOutcome discriminated union)

Related ADRs

  • ../nodespace-docs/decisions/038-skill-mediated-tool-routing.md — two-stage routing; the two-gate design and the "avoid a third number" constraint
  • ../nodespace-docs/decisions/056-gemma-4-e4b-locked-native-model.md — the two decision failures this issue makes measurable; the warning that current matrix scores are not trustworthy
  • ../nodespace-docs/decisions/064-instruction-channel-doctrine.md — channel ownership and the measurement methodology to follow

Related Issues

Activity

  1. added
    enhancement
    on Sep 22, 2026
  2. malibio commented on Sep 22, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 260 test files passed, 5240 tests passed (60.43s). Worktree: issue-2802-decision-seam.

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

    @malibio
    CollaboratorAuthor

    Baseline recorded: 5/8, deterministic across 3 reps

    bun run eval:decisions e4b --runs 3 --between-runs <purge+restart>, gemma-4-e4b-q4km, n_ctx 32768, clean database per rep.

    Category pass^3
    Skill routing 3/3
    Operation selection 4/4
    Instance-vs-type boundary 3/3
    ADR-056 known failures 2/2
    Schema selection 0/3
    Off-menu type named 0
    Stage-1 decision cost 1681 / 1799 / 1933 ms

    Zero variance. Every scenario passed 3/3 or failed 0/3 — no flips. Each rep ran against a purged database with the daemon restarted between them, so these are independent observations rather than one run's state carried forward.

    Two earlier claims corrected by this run

    • ADR-056's Scenario 6 shape now passes 3/3. An earlier run recorded it failing 0/3, but that was measured in a workspace where create_schema reports success with a populated field list for a schema that was never persisted #2815 had silently failed a create_schema, leaving nondeterministic state. That result should not be cited.
    • Instance-vs-type routing passes 3/3, including the indirectly-phrased type request ("I need a way to keep track of sponsorship deals…") that misrouted to Node Creation during fixture development. Stage-1 retrieval handles it correctly on a clean workspace.

    All three failures are one failure

    Every schema-selection scenario failed the same way: 4 candidates offered, model selected none, no tool called at all.

    "Add Northwind Trading to the companies we sell to."
      skill=Node Creation  candidates=company_sold_to, event_venue, sponsor, sponsorship_deal
      → "Could you confirm what you'd like me to do?"
    
    "Northwind can seat 200 people now."
      skill=Schema Creation  candidates=(same four)
      → "I need a Node ID to update the capacity for Northwind Trading."
    
    "When did we sign Northwind?"
      → "I do not have a specific node ID for Northwind Trading, so I cannot tell you
         the signing date."
    

    Skill routing was correct in each case and the schema candidates were present. The model could not resolve the entity name "Northwind" to a node, so it stopped and asked for a node ID rather than acting.

    This is not a schema-selection failure. The model never reached a choice among the four candidates — it failed upstream, at resolving a named entity to an instance. Scoring it as a schema decision mislabels it, and the fixture should be adjusted to reflect that these three scenarios are really entity-resolution cases.

    Tracked as its own design problem in the entity-grounded routing issue filed alongside this comment.

    What the instrumentation bought

    The three decisions are now separable, which is what made the above diagnosable:

    [decision skill]     selected=Node Creation  candidates=Node Creation, Graph Editing, Conflict Resolution
    [decision operation] selected=none           candidates=<9 scoped tools>
    [decision schema]    selected=none           candidates=company_sold_to, event_venue, sponsor, sponsorship_deal
    

    Before this, that turn was indistinguishable from a wrong-tool failure. The scorer also distinguishes "the right option was never offered" from "the wrong option was chosen" — which caught two fixture bugs during development before they were attributed to the model.

    Fixture bugs found and fixed while establishing this

    Recorded because each cost a full 3-rep run before being caught, and the pattern is reusable:

    1. Asserted on core seeded types. project is seeded, so a setup turn was asked to create a type that already existed. Core types are also filtered out of schema candidates by parse_and_filter_non_core_schemas, so a turn acting on one records candidates= empty and the selection reads as off-menu — unconstrained generation, not a selection.
    2. Predicted model-derived ids. create_schema derives the id from the model's phrasing: "companies we sell to" produced company_sold_to. Assertions naming company failed as naming mismatches wearing decision-error clothes. Schema expectations now assert the property being scored (on-menu? which of two?) rather than an id the fixture cannot predict.
    3. Shared database across reps. Without --between-runs, rep 1's created schemas persisted into reps 2-3, so the three reps were not independent observations.

    The lesson generalising from these: probe with single turns before committing to reps. Two 40-minute runs were spent measuring the fixture rather than the model; a 90-second single-turn probe found each bug.

    Also fixed: a marker-parsing bug that truncated multi-word skill names ("Schema Creation" → "Schema"), invisible until skill routing was recorded because tool names and type ids never contain spaces.

  5. malibio commented on Sep 22, 2026

    @malibio
    CollaboratorAuthor

    Baseline re-run on rebased code — unchanged, and now defensible

    The earlier baseline was measured before #2815's create_schema fix landed. Re-ran on a branch rebased onto current main (11 commits, including #2815's persisted-row fix and #2818's skill-guidance split), freshly built release binaries, purged database per rep.

    Result: identical. 5/8, zero variance, same three failures.

    Category pre-rebase post-rebase
    Skill routing 3/3 3/3
    Operation selection 4/4 4/4
    Instance-vs-type boundary 3/3 3/3
    ADR-056 known failures 2/2 2/2
    Schema selection 0/3 0/3
    Off-menu type named 0 0
    Stage-1 decision cost 1681 / 1799 / 1933 ms 1602 / 1638 / 1692 ms

    Every scenario passed 3/3 or failed 0/3 in both runs. The three failures are the same three, failing the same way:

    schema-on-menu-company        Named no type. Candidates: company_sold_to, event_venue, sponsor    tools: []
    schema-field-disambiguates    Named no type; expected /venue|event/i. Same candidates.            tools: []
    schema-shared-name-signed     Named no type; expected /compan/i. Same candidates.                 tools: []
    

    Candidates were offered, the model called no tool at all, and asked for a node ID instead — the entity-resolution gap tracked in #2841. #2815's fix did not affect it, which is the expected result: that bug was about a write reporting success without persisting, not about resolving a name to a node.

    This supersedes the earlier baseline comment as the reference figure. The earlier one was measured against pre-#2815 create_schema behaviour and should not be cited now that this run exists; its numbers happen to match, which is itself reassuring rather than coincidental — the failure is upstream of anything #2815 touched.

    Stage-1 cost came in slightly lower (1602-1692 ms vs 1681-1933 ms), well within run-to-run variance on the same machine. Nothing should be read into the difference.

    Reproduce

    cargo build --release --bin nodespaced --bin nodespace
    # start daemon with NODESPACE_HOME pointed at an empty dir, load gemma-4-e4b-q4km
    bun run eval:decisions e4b /tmp/out.json --runs 3 --between-runs <purge+restart script>

    --between-runs is load-bearing: without it rep 1's created schemas persist into reps 2-3 and the reps stop being independent observations.

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

Metadata

Metadata

Assignees

Labels

backendenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions