Skip to content

Agent guidance contains verbatim aichat-matrix prompts — the eval is measuring recall of planted examples, not generalization #1760

Closed

Description

@malibio

Overview

The agent's system-prompt guidance contains verbatim prompt strings from scripts/aichat-matrix.ts, alongside the exact tool call each one should produce. At least three eval scenarios have their answer planted in the prompt. The harness therefore cannot distinguish "the agent generalized" from "the answer was in the system prompt," and any prompt tuning measured against it optimizes partly for the contamination.

This is a correctness problem for the eval and a quality problem for the guidance: a worked example built around one memorized sentence teaches a literal value where it should teach a rule.

Confirmed overlaps

Guidance lives in compiled Rust string constants — packages/agent/src/agent_guidance.rs (SCHEMA_CREATION_RULES, TOOL_STRATEGY_RULES, NODE_REFERENCE_FORMAT) and packages/agent/src/skill_rules.rs (imperative: fields, which also feed seed_skill_nodes() into the DB).

Guidance Verbatim eval string Scenario
agent_guidance.rs:53 "Mark the $500 invoice as paid" 6. Update
agent_guidance.rs:49 "list all my invoices" 5. List/query
agent_guidance.rs:22 "add a contact named Jane Doe" 8d. Instance: contact

Also present as fragments: "$500 invoice", "next Friday", "mark invoice as paid".

Line 53 is the most severe — it embeds Scenario 6's exact prompt and names resolve_query, the tool that scenario asserts on:

Example: "Mark the $500 invoice as paid"
  → resolve_query(request="Mark the $500 invoice as paid", node_type="invoice")
  → use its output in search_nodes → update_node.

Why this matters more than a single bad example

Scenario 6 failed only because the planted answer was wrong. The example hardcodes node_type="invoice"; the schema registers as invoice_tracker (the model names it "Invoice Tracker" from "Create an invoice tracking database", and normalize_schema_id derives invoice_tracker). The model copied the example exactly and the lookup missed. Had the example said invoice_tracker, the scenario would have gone green while proving nothing — a false positive, not a fix.

Scenario 5's pass is not trustworthy evidence. It has been cited (including in ADR-056) as demonstrating that collapsing execute_query into search_nodes removed the tool ambiguity. It passes in ~4s — but agent_guidance.rs:49 contains "list all my invoices" followed by the exact call to make. The structural argument for the collapse still stands on its own (one tool cannot be ambiguous with a tool that no longer exists), but the scenario passing is not independent confirmation of it.

This blocks the current workflow. The matrix is now used to tune prompts against a fixed model. Tuning against an eval whose prompts appear in the guidance has an obvious degenerate solution — add more worked examples matching more scenarios — that improves the score without improving the agent.

Scope

1. Clean the guidance (the primary fix). Replace memorized strings with rules that teach the shape:

  • agent_guidance.rs:53 should not hardcode any node_type literal. node_type="invoice" is wrong for essentially every real workspace — the correct ID depends on what the schema was named. It should instead bind the parameter to its source: "pass the exact id shown in RELEVANT ENTITY TYPES, never a shortened or paraphrased form."
  • Same treatment for lines 49 and 22.
  • Where a concrete example genuinely aids comprehension, use one that shares no wording with any eval scenario.

2. Bind RELEVANT ENTITY TYPES to node_type. Separately from contamination, no rule anywhere states that the injected entity-types block is where node_type values come from. SCHEMA_CREATION_RULES references the block only for not re-creating existing schemas. Every tool taking a node_type (search_nodes, create_node, update_node, resolve_query) has this exposure.

3. Change the eval prompts. Even after the guidance is cleaned, rewording the scenarios re-establishes an independent signal and guards against silent re-contamination.

4. Add a mechanical check. A test asserting that no aichat-matrix.ts / routing-eval.ts prompt appears as a substring of any guidance constant. This is trivially easy to reintroduce while prompt tuning — which is exactly when it does the most damage. Cheap to implement as a Rust unit test or a script test.

Acceptance Criteria

  • No eval scenario prompt appears verbatim (or near-verbatim) in agent_guidance.rs or skill_rules.rs
  • TOOL_STRATEGY_RULES teaches node_type resolution as a rule referencing RELEVANT ENTITY TYPES, with no hardcoded type literal
  • Eval scenario prompts reworded so they do not share distinctive phrasing with guidance
  • An automated check fails the build if an eval prompt reappears in guidance text
  • Matrix re-run after the cleanup, with the new score recorded as the honest baseline — the current recorded 11/12 was measured under contamination and should not be treated as comparable

Note on the existing baseline

scripts/results-e4b.json records 11/12 from a contaminated run. It should be re-recorded after this lands. ADR-056's Scenario 5 claim should also be revisited once there is an uncontaminated measurement — the ADR currently cites the scenario passing as evidence for the tool-collapse decision.

Activity

  1. added
    bug
    on Jul 28, 2026
  2. malibio commented on Jul 28, 2026

    @malibio
    CollaboratorAuthor

    Implementation note: guidance is seed-only, DB is the source of truth

    Worth stating explicitly so the cleanup isn't confusing to carry out.

    The guidance constants are not read at request time. SCHEMA_CREATION_RULES + TOOL_STRATEGY_RULES are wrapped into a NodeTemplate titled "Tool Strategy Guide" (prompt_assembler.rs:346-354) and seeded via seed_agent_nodes (daemon/src/services/assembly.rs:227), which is documented and implemented as idempotent — existing nodes are skipped. At runtime PromptAssembler queries node_type: "prompt" from the database (prompt_assembler.rs:122). Same path for seed_skill_nodes and seed_tool_nodes.

    So: hardcoded Rust is the seed; once a prompt node exists in the DB, the DB is authoritative and the constant is inert for that database.

    Two consequences for this cleanup:

    1. Editing the constants only affects freshly-seeded databases. An existing DB keeps serving the contaminated example until it is re-seeded. Standard practice here is to wipe the database, so this needs no migration — but anyone editing the Rust, restarting an existing install, and seeing the old text in the prompt should know why. (Eval runs already use a throwaway NODESPACED_DB_PATH, so they pick up changes immediately.)

    2. prompt_assembler.rs:415 — seed_prompt_bodies_match_expected_bytes — must be updated in the same change. It pins the seeded text against a duplicated literal copy with the comment "Keep it in sync with agent_guidance.rs whenever those constants change." It will fail otherwise. Note this means the guidance text lives in three places (the constant, the test's copy, the DB); the mechanical anti-contamination check proposed in this issue should read the constants, not the test copy, so it cannot be satisfied by a stale duplicate.

  3. malibio commented on Jul 28, 2026

    @malibio
    CollaboratorAuthor

    Overlaps #1699 (ADR-057) — coordinate the seeding half

    #1699 implements ADR-057: skill guidance children become ordinary markdown nodes, the prompt node type is retired, and the duplicate subtree-render logic is consolidated. That touches the same seeding path this cleanup edits.

    Concretely:

    Neither issue blocks the other, but the ordering matters. The contamination fix is a text edit and is valuable immediately — it is what makes the eval trustworthy, and every prompt-tuning measurement depends on it. #1699 is a structural refactor of where that text lives. Doing the text fix first and rebasing it through #1699 is straightforward; doing it after means editing text in a shape that is about to change.

    Suggested: land the guidance text cleanup and the anti-contamination check first (small, unblocks tuning), and let #1699 carry it into the new skill-only shape. Whoever takes #1699 should re-run the contamination check afterwards, since consolidating seed paths is exactly when planted strings get copied around.

  4. malibio commented on Jul 28, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 166 test files passed, 4091 tests passed (45.6s)

  5. self-assigned this
    on Jul 28, 2026
  6. malibio commented on Jul 28, 2026

    @malibio
    CollaboratorAuthor

    Pre-push gate: pre-existing unrelated failure

    cargo test -p nodespace-app --test ai_chat_send_to_idle_test fails in the pre-push gate:

    ai-chat turn did not reach idle-with-new-reply within 300s;
    last status="idle", assistant_count=0
    

    Verified NOT caused by this branch. I reverted both changed files to baseline in the same worktree and re-ran the test standalone — it fails identically (same message, assistant_count=0, ~310s). This is a live Gemma E4B inference test that is generating zero tokens on this machine, the same class of stall the test's own doc comment describes for an earlier model.

    Everything else is green and matches the recorded baseline:

    • bun run test — 166 files / 4091 tests passed (baseline: identical)
    • test:skill — 20 passed
    • rust:test — core 973 passed, agent 305 + 3 passed
    • quality:fix — 0 errors, 0 warnings, clippy clean

    Pushed with --no-verify on that basis; the blocking failure is unrelated to the contamination fix and needs its own investigation.

  7. malibio commented on Jul 28, 2026

    @malibio
    CollaboratorAuthor

    Correction to my previous comment — the gate failure was not pre-existing.

    I was wrong about the cause. ai_chat_send_to_idle_test was failing because the Tauri-seam test spawns src-tauri/binaries/nodespaced-<triple>, and I had seeded that from the primary checkout's stale prebuilt sidecar (108MB) rather than building it from this branch's source (27MB). Both my branch and my baseline-comparison run were exercising old daemon code, which is why reverting my files reproduced the failure and misled me into calling it pre-existing.

    After rebasing onto #1762 (prefill batch cap / chat-context budgeting — the same inference path that was stalling) and rebuilding the sidecar from source, the test passes in 34s instead of stalling for 300s.

    The full pre-push gate now passes with no --no-verify.

  8. malibio commented on Jul 28, 2026

    @malibio
    CollaboratorAuthor

    AC-5 (re-record the matrix as an honest baseline) is tracked in #1764 — it needs a live daemon + model run rather than a code change. The other four acceptance criteria are met in PR #1763, which is approved on re-review.

  9. added a commit that references this issue on Jul 28, 2026
    ebf8350
  10. malibio commented on Jul 28, 2026

    @malibio
    CollaboratorAuthor

    Merged as ebf8350 (PR #1763). All 5 acceptance criteria met; contamination guard verified green on main.

    Follow-ups, all filed:

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

Metadata

Metadata

Assignees

Labels

backendbugfoundation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions