Skip to content

Fix Schema Creation routing so the model can reach create_schema for natural tracking phrasing - #1904

Merged
malibio merged 2 commits into
mainfrom
issue-1896-two-schema-split
Aug 2, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-1896-two-schema-split

Conversation

@malibio

@malibio malibio commented Aug 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Partially addresses Model splits one tracking request into two schemas, populates one, and leaves the other empty and unlinked #1896 (routing/retrieval sub-problem — acceptance criteria 1 and 3). Acceptance criterion 2 ("if a split is ever correct, the resulting types are actually linked and both are populated") is not addressed by this PR — filed as a separate fast-follow, Enforce that a legitimate multi-schema split ends up linked and populated, not silently half-empty #1905, per code review.
  • Agent-matrix scenario 3's prompt ("I want to keep a record of the equipment my team checks out, whether it's been returned, and what each item costs to replace") consistently routed to Node Creation / Organization / Research & Search — never Schema Creation — so create_schema was never reachable and the model fell back to a bare create_node, or in other runs split the request into two schemas trying to recover.
  • Reproduced 3/3 single-turn runs and confirmed via purged-DB/rebuilt-daemon matrix runs that routed_skills omitted Schema Creation for this prompt every time.
  • Root cause: the skill's description (the only field embedded for semantic retrieval — SkillNodeBehavior::get_embeddable_content) was written as a keyword list ("Use when user says 'new type', 'create schema'...") rather than the natural phrasing real users use. "Keep a record of X" embeds closer to Organization's "categorize... group" and Node Creation's "records, entries" than to Schema Creation's technical vocabulary — same pathology as a prior retrieval-wording investigation.
  • Reworded the description to lead with natural-language phrasing (keep track of, log, maintain records for, a place to record or organize instances of something new), keeping the existing keyword list as secondary coverage.
  • Added a unit test pinning the new wording against accidental future trim/revert, since the fix's actual mechanism (embedding retrieval) is not covered by cargo test/CI.

Verification

Two independent purged-DB/rebuilt-daemon eval:agent matrix runs against the local E4B model (n_ctx 32768), both showing scenario 3 passing cleanly with exactly one create_schema call and no split:

[agent-matrix] → 3. Schema creation
[agent-matrix]   ✓ tools=[create_schema] 21385ms

Scenario 8b (an equivalent "I also need a tracker for the venues I book" prompt) also newly passes. Overall matrix went from 4/12 to 7/12 passing; the remaining failures (6, 8a, 8c, 8d, 8e) are pre-existing, unrelated routing/behavior issues outside this issue's scope.

Per code review, also spot-checked for false-positive regression risk (the reworded description now shares more vocabulary with Node Creation's description): 3 manual runs against existing-type create_node prompts ("add a record of the laser cutter we checked out today", "add a task to review the Q3 budget") both correctly routed to Node Creation / Graph Editing without misrouting into Schema Creation.

guidance_is_not_contaminated_by_eval_prompts and all skill_pipeline tests (16, including the new wording-pin test) pass.

Also tried tightening the description (644 → 395 chars, cutting redundant examples) per review nit about length vs. sibling skills — measured a real regression (scenario 4 lost Node Creation from its routing candidates in the very next turn of the same conversation) and reverted; see PR comments for detail.

Test plan

  • bun run test:all — no new failures
  • bun run quality:fix — clean
  • cargo test -p nodespace-agent guidance_is_not_contaminated_by_eval_prompts — passes
  • cargo test -p nodespace-agent skill_pipeline — 16/16 pass (15 existing + 1 new wording-pin test)
  • Two independent purged-DB/rebuilt-daemon agent-matrix runs — scenario 3 passes both times with exactly one create_schema call
  • 3 manual spot-checks confirming no false-positive misroute of existing-type create_node prompts into Schema Creation
  • Pre-push gate (test:all + cargo build + e2e) passed twice

🤖 Generated with Claude Code

https://claude.ai/code/session_01DkqjrfV1G6kugsEjvyU9wU

…it (closes #1896)

Agent-matrix scenario 3 traced "I want to keep a record of the equipment my
team checks out..." routing to Node Creation, Organization, and Research &
Search -- never Schema Creation -- so create_schema was never reachable and
the model fell back to a bare create_node, then in other runs split the
request into two schemas trying to recover. Reproduced 3/3 single-turn runs
and confirmed via two independent purged-DB/rebuilt-daemon matrix runs: every
turn's routed_skills omitted Schema Creation for this prompt.

Root cause matches a known pattern: skill descriptions are keyword lists
("Use when user says 'new type', 'create schema'...") consumed by semantic
embedding retrieval, which real users' phrasing rarely matches. "Keep a
record of X" embeds near Organization's "categorize... group" and Node
Creation's "records, entries" rather than Schema Creation's technical schema
vocabulary.

Reworded the description to lead with the natural-language phrasing users
actually use for wanting a new kind of thing tracked (keep track of, log,
maintain records for, a place to record or organize instances of something
new), keeping the existing keyword list as secondary coverage. Verified
across two independent purged-DB/rebuilt-daemon matrix runs: scenario 3 now
calls create_schema exactly once with no split, and scenario 8b's equivalent
prompt now passes too.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DkqjrfV1G6kugsEjvyU9wU
@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

The fix plausibly addresses the measured mechanism (retrieval never surfacing the Schema Creation skill for this prompt phrasing), and the verification methodology (two independent purged-DB/rebuilt-daemon matrix runs) is consistent with how this project validates retrieval changes. However, this PR is a pure prose/embedding change with zero code-level enforcement and zero automated regression coverage, which is a materially different risk profile than the two sibling issues it's explicitly grouped with (#1895, #1866) — both of which backed a guidance change with a structural guard and pinned it with new tests. Issue #1896's second acceptance criterion ("if a split is ever correct, the resulting types are actually linked and both are populated — no silently empty half") is not addressed at all by this diff. Net: this is a reasonable partial fix for the routing symptom, but it is being merged as if it closes the issue when it only closes one of three acceptance criteria, with no safety net if it regresses.

Findings

Critical Issues

  • packages/agent/src/skill_pipeline.rs:345 — Acceptance criterion 2 is unaddressed and untouched. The issue explicitly asks: "if a split is ever correct, the resulting types are actually linked and both are populated — no silently empty half." Nothing in this PR touches that path. Compare to create_node accepts a nonexistent node_type (display name instead of schema id) and silently persists zero properties #1895 (PR Reject create_node against a nonexistent node_type (closes #1895) #1902), which added NodeServiceError::UnknownNodeType — a structural guard that fails loudly instead of silently persisting a broken state — and create_node succeeds but persists zero properties: matrix scenario 4 drops the user's supplied values #1866 (PR Stop create_node from silently discarding user values with no matching schema field (#1866) #1897), which added a VALUES WITH NO MATCHING FIELD guidance section plus a code-visible change to the create_node tool schema description, backed by 3 new persistence tests. This PR ships prose only, with no equivalent for "reject/flag a create_relationship failure between two just-created schemas" or "warn/refuse a second create_schema call within the same skill invocation." If retrieval now routes correctly but the model still occasionally decides to split (which remains possible — routing to the right skill doesn't guarantee the model obeys ONE SCHEMA PER REQUEST once inside it), the exact silent-half-empty failure mode described in the issue is still fully reachable and undetected. Given skill_pipeline.rs:346 already whitelists create_schema for up to 3 iterations, nothing stops two create_schema calls in one skill invocation, and nothing checks that a create_relationship between them actually succeeded before the skill reports success to the user.
  • No automated regression protection for the fix's actual mechanism. The diff changes embedded retrieval text; the only verification is manual/ad-hoc eval:agent runs against a local model, which per the project's own agent-eval docs are manual/scheduled and explicitly not part of test:all/CI. That's an accepted tradeoff for this class of fix per project precedent (noted in point 2 of the review brief), so I'm not blocking on it alone — but combined with the missing structural guard above, this PR has literally no mechanism (test or code) that will ever tell you if this regresses. A future change to Node Creation's or Organization's skill description (equally plausible, equally untested) could silently pull retrieval back away from Schema Creation for this exact prompt shape and nothing in cargo test or bun run test:all would notice.

Suggested Improvements

Wording Quality Assessment (point 4)

Read in full, the new description is reasonable but does increase the plausible overlap with Node Creation's description, which itself starts with "Create new nodes, records, entries, or instances of any type." The new Schema Creation text opens with "keep track of, log, or maintain records for a kind of thing" — the word "records" now appears in both skills' descriptions, and "instances of something new" (Schema Creation) is semantically close to "instances of any type" (Node Creation). This is a real, non-hypothetical risk: a prompt like "add a record of the laptop I just bought" (intending create_node against an existing type) could now pull toward Schema Creation more than before. The PR's own evidence partially confirms the vocabulary space between these two skills is contested — that's the whole reason scenario 3 was misrouting in the first place — so narrowing the gap on one skill without checking the other side's false-positive rate is a legitimate gap in the verification. The eval matrix apparently still shows other Node Creation scenarios passing (matrix went 4/12 → 7/12 with no new failures reported), which is reassuring but not the same as a targeted check of "does this new wording ever cause an existing-type prompt to misroute into Schema Creation." Worth a quick manual spot-check against 1-2 existing-type create_node prompts before considering this fully verified — not a blocker given the matrix evidence already available, but flagged for awareness.

Nitpicks

  • Nit: The reworded description is now noticeably longer (roughly 2x) than sibling skill descriptions (Node Creation, Delete are both single short sentences). Length itself can dilute embedding signal (per this project's own prior finding that a diluted/verbose prompt underperforms a terse one on hard cases) — worth a follow-up pass to see if the natural-language lead can be tightened without losing the retrieval win, rather than treating "keyword list + natural language list" concatenation as the final form.
  • Nit: Commit message and PR body are thorough and give good reproduction detail — no complaints there, just calling out as a positive since it materially helped this review.

Verdict

Net positive for the specific routing symptom, backed by real (if manual) verification — I'm not blocking merge over the single-line scope. But this PR should not be treated as fully closing #1896: acceptance criterion 2 is untouched, and there is no automated safety net specific to this fix (test coverage gap acknowledged as project-accepted for retrieval-only changes, but combined with the missing structural guard, it means a regression here would be silent). Recommend: either (a) file a fast-follow issue for the link/populate enforcement before closing #1896, or (b) keep #1896 open and re-scope this PR's linked issue reference to the routing sub-problem only.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review comment posted above with full findings. Summary: net positive for the specific routing symptom, but this is a pure prose/embedding change with no code-level enforcement and no automated regression coverage, unlike sibling PRs #1897/#1902 which paired guidance fixes with structural guards + tests. Acceptance criterion 2 from #1896 (link + populate on a legitimate split) is entirely untouched. Recommend NOT merging as a full close of #1896 without either (a) filing a fast-follow issue for the link/populate guard, or (b) re-scoping this PR to the routing sub-problem only. Not requesting formal changes only because GitHub blocks self-authored change requests on this account; treat this as a Request Changes in substance.

Per code review on #1904: the fix's actual mechanism (semantic embedding
retrieval) can't be validated by cargo test, so nothing previously protected
the reworded description's wording itself against an accidental future trim
or revert. This test can't assert retrieval outcome, but it pins the natural-
language lead against silent regression, since editing this string later has
no other signal in cargo test or bun run test:all.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DkqjrfV1G6kugsEjvyU9wU
@malibio malibio changed the title Reword Schema Creation skill description so retrieval actually finds it Fix Schema Creation routing so the model can reach create_schema for natural tracking phrasing Aug 1, 2026
@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed all three actionable points:

  1. Acceptance criterion 2 (link + populate enforcement) is genuinely separate scope, not something to bolt onto this diff. The mechanism itself (reject a 2nd create_schema? require a successful create_relationship first? warn only?) needs its own investigation/design decision, matching this project's own "file separately when it requires its own investigation, live measurement, or design decision before a fix is even known" guideline. Filed as Enforce that a legitimate multi-schema split ends up linked and populated, not silently half-empty #1905, referencing this PR and the create_node accepts a nonexistent node_type (display name instead of schema id) and silently persists zero properties #1895/create_node succeeds but persists zero properties: matrix scenario 4 drops the user's supplied values #1866 code-level-guard precedent the reviewer pointed at. PR title/description updated to stop implying full closure of Model splits one tracking request into two schemas, populates one, and leaves the other empty and unlinked #1896 — it now explicitly scopes to criteria 1 and 3, with Enforce that a legitimate multi-schema split ends up linked and populated, not silently half-empty #1905 covering criterion 2.

  2. Added schema_creation_description_covers_natural_tracking_phrasing in skill_pipeline.rs, pinning the natural-language phrasing against an accidental future trim/revert. Can't validate retrieval outcome (needs the real embedding model) but closes the "no signal at all" gap the review flagged.

  3. Spot-checked the false-positive concern (new description sharing vocabulary with Node Creation's). Ran 3 manual prompts against a purged/rebuilt daemon: an existing-type "add a record of the laser cutter..." prompt and an unrelated "add a task to review the Q3 budget" prompt both routed correctly (Node Creation / Graph Editing, no Schema Creation misroute). Details in the updated PR description.

Not treating criterion 2's absence as blocking per the review's own verdict ("net positive for the specific routing symptom... not blocking merge over the single-line scope"), but wanted the scoping to be honest and the fast-follow to actually exist rather than be a TODO that quietly vanishes when #1896 closes.

@malibio

malibio commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Investigated the remaining nitpick (description length/dilution vs. sibling skills) and am not applying it — it caused a real regression, not a hypothetical one.

Tried trimming the description from 644 to 395 chars (cutting the redundant "Also covers..." transition and example list while keeping both the natural-language lead and technical keywords). Rebuilt, purged, and ran the matrix twice on the trimmed wording:

  • Scenario 3 still passed cleanly both times (the fix itself holds).
  • Scenario 4 ("Log a laser cutter checked out on the 12th, replacement cost 2400" — same chat, right after scenario 3) newly failed both times with an identical pattern: routing returned "Schema Creation, Relationship Management, Organization" for that turn, dropping Node Creation out of the top-3 entirely. Pre-trim, scenario 4 passed cleanly in both prior runs (create_node called correctly).

So trimming the description made Schema Creation crowd out Node Creation in the very next turn of the same conversation — the two skills' embeddings are close enough that length/redundancy in one was apparently doing useful disambiguating work against the other in-context. Reverted to the original wording (verified stable 2/2 pre-trim, now re-confirmed 0 diff against what's already pushed). Not pursuing this nit further without a much more careful before/after comparison than "shorter is better," which is exactly the kind of unmeasured wording change this whole issue is about.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: All changes since the review are either (a) already covered by the review's own "not blocking merge" verdict — the wording-pin test and false-positive spot-checks are additive verification/coverage, not behavior changes — or (b) a net no-op (the description-trim experiment was tried, measured, found to regress, and fully reverted, leaving the file identical to the already-reviewed commit). The only net content change since the review is the new fast-follow issue #1905 and PR/issue description rescoping, which are process/documentation, not code. No new logic, no new risk surface.

@malibio
malibio merged commit dbb21c3 into main Aug 2, 2026
2 checks passed
@malibio
malibio deleted the issue-1896-two-schema-split branch August 2, 2026 01:08
malibio added a commit that referenced this pull request Aug 2, 2026
… started

## Completed in This Session

- [x] Live reproduction of the compound-intent gap against the locked native
      model (gemma-4-e4b-q4km, in-process), not a served stand-in
      (PR #1916, packages/agent/tests/live_stage1_compound_intent.rs)
- [x] Initial n=5 pass: route_clarify 0/5, lossy merge 1/5
- [x] Widened to n=11 (varied phrasing, 3-intent requests, mutating/
      read-only combinations) + 18 single-intent controls: route_clarify
      0/11, lossy merge 5/11 (45%)
- [x] Recommendation posted and folded into issue #1909's body: a third
      typed Stage-1 tool, route_multi, taking an array of per-intent query
      strings (mirrors route_query's single `query: string`, pluralized)
- [x] Pragmatic code review completed on PR #1916 (APPROVE, two suggestions
      addressed: doc comment on run_stage1's session simplification, and a
      keyword-coverage unit test)
- [x] Issue #1909 body and acceptance criteria updated to reflect all of the
      above; all investigation-phase criteria checked off

## Remaining Work

- [ ] Implement `route_multi` as a third Stage-1 tool in
      packages/agent/src/local_agent/routing.rs:
      - Add `ROUTE_MULTI_TOOL: &str = "route_multi"` alongside the existing
        ROUTE_QUERY_TOOL/ROUTE_CLARIFY_TOOL constants (line 89-91)
      - Extend `RouteDecision` (line 75) with a `Multi(Vec<String>)` variant
        (or equivalent) carrying per-intent queries
      - Add its ToolDefinition to `stage1_tool_definitions()` (line 114) —
        array-of-strings schema, mirroring route_query's single-string one
      - Extend `parse_route_decision()` (line 164) to parse route_multi calls
      - Update STAGE1_SYSTEM_PROMPT (packages/agent/src/local_agent/agent_loop.rs:58)
        to describe the third option per ADR-064's channel doctrine (tool
        descriptions own selection, not resident prose)
      - Wire the caller in agent_loop.rs (~line 1776, the stage1_routing
        block) to re-enter retrieval once per element of a Multi decision,
        the same way it currently does once for a Query decision — Stage-2's
        per-candidate trust boundary and score gating should not need to
        change, only how many times retrieval runs per turn
- [ ] Before merging: full routing/retrieval matrix run (3+ reps vs. current
      baseline), per the #1904/#1911 precedent — not just a re-run of the
      compound-prompt probe. This is a hard requirement per #1909's own
      acceptance criteria and #1917's operating rule 3.
- [ ] Optional, non-blocking: repeat the widened n=11 probe once to check the
      45% lossy figure for run-to-run variance (per #1862) — proceeding with
      route_multi does not need to wait on this.

## Current State

- Files modified this session: packages/agent/tests/live_stage1_compound_intent.rs
  (new), .gitignore (+trace artifact entry) — both committed and pushed
- No production code touched yet — routing.rs/agent_loop.rs are unmodified
  from origin/main plus whatever else has landed there since this branch
  diverged
- Tests: all passing (cargo test -p nodespace-agent --test
  live_stage1_compound_intent — 4 non-ignored unit tests pass; the live
  #[ignore]'d probe was run manually twice, not part of default test:all)
- PR #1916 open against main, reviewed and approved, addressing its review
  feedback is complete
- Issue #1909 fully up to date with findings, recommendation, and remaining
  acceptance criteria

## Context for Next Session

This is a CONTINUING FROM WIP case (CLAUDE.md) for whoever picks this up
next — most likely #1917's autonomous orchestrator, per that issue's Step 0.
Do not create a new worktree; re-enter this one
(.claude/worktrees/issue-1909-stage1-compound-intent, branch
worktree-issue-1909-stage1-compound-intent) and continue its history.

The investigation is done and the fix shape is decided (route_multi, a
third typed Stage-1 tool). What's left is implementation plus the mandatory
full-matrix verification before merge — this is real work on shared routing
surface, not a mechanical follow-up. Read issue #1909's full comment history
for the raw traces behind the 45% figure before starting; the borderline
"search + create + reminder" case noted in the last comment is a heuristic
false-negative worth keeping in mind so it doesn't get miscounted again in
a future run.

## Acceptance Criteria Status

From issue #1909:
- [x] Live reproduction with raw traces
- [x] Recommendation for the minimal extension (route_multi)
- [x] Widen the compound-prompt sample past 5
- [ ] Optional repeat run of the widened sample (non-blocking)
- [ ] Implement route_multi as a third typed Stage-1 tool
- [ ] Full routing/retrieval matrix run before merging the implementation

Co-Authored-By: Claude <[email protected]>
malibio added a commit that referenced this pull request Aug 3, 2026
… started

## Completed in This Session

- [x] Live reproduction of the compound-intent gap against the locked native
      model (gemma-4-e4b-q4km, in-process), not a served stand-in
      (PR #1916, packages/agent/tests/live_stage1_compound_intent.rs)
- [x] Initial n=5 pass: route_clarify 0/5, lossy merge 1/5
- [x] Widened to n=11 (varied phrasing, 3-intent requests, mutating/
      read-only combinations) + 18 single-intent controls: route_clarify
      0/11, lossy merge 5/11 (45%)
- [x] Recommendation posted and folded into issue #1909's body: a third
      typed Stage-1 tool, route_multi, taking an array of per-intent query
      strings (mirrors route_query's single `query: string`, pluralized)
- [x] Pragmatic code review completed on PR #1916 (APPROVE, two suggestions
      addressed: doc comment on run_stage1's session simplification, and a
      keyword-coverage unit test)
- [x] Issue #1909 body and acceptance criteria updated to reflect all of the
      above; all investigation-phase criteria checked off

## Remaining Work

- [ ] Implement `route_multi` as a third Stage-1 tool in
      packages/agent/src/local_agent/routing.rs:
      - Add `ROUTE_MULTI_TOOL: &str = "route_multi"` alongside the existing
        ROUTE_QUERY_TOOL/ROUTE_CLARIFY_TOOL constants (line 89-91)
      - Extend `RouteDecision` (line 75) with a `Multi(Vec<String>)` variant
        (or equivalent) carrying per-intent queries
      - Add its ToolDefinition to `stage1_tool_definitions()` (line 114) —
        array-of-strings schema, mirroring route_query's single-string one
      - Extend `parse_route_decision()` (line 164) to parse route_multi calls
      - Update STAGE1_SYSTEM_PROMPT (packages/agent/src/local_agent/agent_loop.rs:58)
        to describe the third option per ADR-064's channel doctrine (tool
        descriptions own selection, not resident prose)
      - Wire the caller in agent_loop.rs (~line 1776, the stage1_routing
        block) to re-enter retrieval once per element of a Multi decision,
        the same way it currently does once for a Query decision — Stage-2's
        per-candidate trust boundary and score gating should not need to
        change, only how many times retrieval runs per turn
- [ ] Before merging: full routing/retrieval matrix run (3+ reps vs. current
      baseline), per the #1904/#1911 precedent — not just a re-run of the
      compound-prompt probe. This is a hard requirement per #1909's own
      acceptance criteria and #1917's operating rule 3.
- [ ] Optional, non-blocking: repeat the widened n=11 probe once to check the
      45% lossy figure for run-to-run variance (per #1862) — proceeding with
      route_multi does not need to wait on this.

## Current State

- Files modified this session: packages/agent/tests/live_stage1_compound_intent.rs
  (new), .gitignore (+trace artifact entry) — both committed and pushed
- No production code touched yet — routing.rs/agent_loop.rs are unmodified
  from origin/main plus whatever else has landed there since this branch
  diverged
- Tests: all passing (cargo test -p nodespace-agent --test
  live_stage1_compound_intent — 4 non-ignored unit tests pass; the live
  #[ignore]'d probe was run manually twice, not part of default test:all)
- PR #1916 open against main, reviewed and approved, addressing its review
  feedback is complete
- Issue #1909 fully up to date with findings, recommendation, and remaining
  acceptance criteria

## Context for Next Session

This is a CONTINUING FROM WIP case (CLAUDE.md) for whoever picks this up
next — most likely #1917's autonomous orchestrator, per that issue's Step 0.
Do not create a new worktree; re-enter this one
(.claude/worktrees/issue-1909-stage1-compound-intent, branch
worktree-issue-1909-stage1-compound-intent) and continue its history.

The investigation is done and the fix shape is decided (route_multi, a
third typed Stage-1 tool). What's left is implementation plus the mandatory
full-matrix verification before merge — this is real work on shared routing
surface, not a mechanical follow-up. Read issue #1909's full comment history
for the raw traces behind the 45% figure before starting; the borderline
"search + create + reminder" case noted in the last comment is a heuristic
false-negative worth keeping in mind so it doesn't get miscounted again in
a future run.

## Acceptance Criteria Status

From issue #1909:
- [x] Live reproduction with raw traces
- [x] Recommendation for the minimal extension (route_multi)
- [x] Widen the compound-prompt sample past 5
- [ ] Optional repeat run of the widened sample (non-blocking)
- [ ] Implement route_multi as a third typed Stage-1 tool
- [ ] Full routing/retrieval matrix run before merging the implementation

Co-Authored-By: Claude <[email protected]>
malibio added a commit that referenced this pull request Aug 3, 2026
…g under history (#1909) (#1916)

* Add live Stage-1 compound-intent probe (#1909)

Fires production's exact Stage-1 request against the locked native
model (in-process Gemma 4 E4B) for compound-but-unambiguous prompts
("log this expense and remind me Friday"), to check whether Stage 1
has a correct move when a request carries two distinct intents.

Measured: route_clarify is never called for these prompts. Stage 1
always calls route_query with a single merged query, which sometimes
silently drops one intent's specifics (e.g. "find notes and create
task from content" lost the "Q3 budget" detail entirely).

Ignored by default (loads a ~9.6GB GGUF, ~4 min), matching
routing_latency.rs's convention.

Co-Authored-By: Claude <[email protected]>

* Address review: document run_stage1's session simplification, guard keyword_pair_for coverage

- Documented that run_stage1 skips stage1_query's prior-turn blending
  since each prompt is a fresh single-turn request with no session
- Added a test asserting every COMPOUND_PROMPTS label has a matching
  keyword_pair_for arm, so a future label addition can't silently
  drop its mentions_both trace hint

Skipped two nits from the review (Stage1Outcome variants only
exercised via live traces; report/println duplication) — reviewer
itself judged both as acceptable for this throwaway diagnostic test.

Co-Authored-By: Claude <[email protected]>

* Widen Stage-1 compound-intent probe past n=5 (#1909)

Per #1909's follow-up acceptance criterion, widen the compound-prompt
sample to size the degradation rate rather than rely on the original
1-of-5 anecdote. Adds varied phrasing, 3-intent requests, and mutating/
read-only intent combinations, for 11 compound prompts total (up from
5) plus 18 matching single-intent controls (up from 5).

Also folds each prompt's keyword set directly into a CompoundPrompt
struct instead of a separate keyword_pair_for lookup, so the mapping
is unmissable by construction (a suggestion from PR #1916's review).

Live result (gemma-4-e4b-q4km, native, single run):
- route_clarify called: 0/11 — structural finding holds at wider n
- route_query, faithful: 6/11
- route_query, lossy (dropped/fabricated a detail): 5/11

Still a single run — per #1862's standing lesson, not decision-grade
without a repeat to compare against.

Co-Authored-By: Claude <[email protected]>

* WIP: #1909 investigation complete, route_multi implementation not yet started

## Completed in This Session

- [x] Live reproduction of the compound-intent gap against the locked native
      model (gemma-4-e4b-q4km, in-process), not a served stand-in
      (PR #1916, packages/agent/tests/live_stage1_compound_intent.rs)
- [x] Initial n=5 pass: route_clarify 0/5, lossy merge 1/5
- [x] Widened to n=11 (varied phrasing, 3-intent requests, mutating/
      read-only combinations) + 18 single-intent controls: route_clarify
      0/11, lossy merge 5/11 (45%)
- [x] Recommendation posted and folded into issue #1909's body: a third
      typed Stage-1 tool, route_multi, taking an array of per-intent query
      strings (mirrors route_query's single `query: string`, pluralized)
- [x] Pragmatic code review completed on PR #1916 (APPROVE, two suggestions
      addressed: doc comment on run_stage1's session simplification, and a
      keyword-coverage unit test)
- [x] Issue #1909 body and acceptance criteria updated to reflect all of the
      above; all investigation-phase criteria checked off

## Remaining Work

- [ ] Implement `route_multi` as a third Stage-1 tool in
      packages/agent/src/local_agent/routing.rs:
      - Add `ROUTE_MULTI_TOOL: &str = "route_multi"` alongside the existing
        ROUTE_QUERY_TOOL/ROUTE_CLARIFY_TOOL constants (line 89-91)
      - Extend `RouteDecision` (line 75) with a `Multi(Vec<String>)` variant
        (or equivalent) carrying per-intent queries
      - Add its ToolDefinition to `stage1_tool_definitions()` (line 114) —
        array-of-strings schema, mirroring route_query's single-string one
      - Extend `parse_route_decision()` (line 164) to parse route_multi calls
      - Update STAGE1_SYSTEM_PROMPT (packages/agent/src/local_agent/agent_loop.rs:58)
        to describe the third option per ADR-064's channel doctrine (tool
        descriptions own selection, not resident prose)
      - Wire the caller in agent_loop.rs (~line 1776, the stage1_routing
        block) to re-enter retrieval once per element of a Multi decision,
        the same way it currently does once for a Query decision — Stage-2's
        per-candidate trust boundary and score gating should not need to
        change, only how many times retrieval runs per turn
- [ ] Before merging: full routing/retrieval matrix run (3+ reps vs. current
      baseline), per the #1904/#1911 precedent — not just a re-run of the
      compound-prompt probe. This is a hard requirement per #1909's own
      acceptance criteria and #1917's operating rule 3.
- [ ] Optional, non-blocking: repeat the widened n=11 probe once to check the
      45% lossy figure for run-to-run variance (per #1862) — proceeding with
      route_multi does not need to wait on this.

## Current State

- Files modified this session: packages/agent/tests/live_stage1_compound_intent.rs
  (new), .gitignore (+trace artifact entry) — both committed and pushed
- No production code touched yet — routing.rs/agent_loop.rs are unmodified
  from origin/main plus whatever else has landed there since this branch
  diverged
- Tests: all passing (cargo test -p nodespace-agent --test
  live_stage1_compound_intent — 4 non-ignored unit tests pass; the live
  #[ignore]'d probe was run manually twice, not part of default test:all)
- PR #1916 open against main, reviewed and approved, addressing its review
  feedback is complete
- Issue #1909 fully up to date with findings, recommendation, and remaining
  acceptance criteria

## Context for Next Session

This is a CONTINUING FROM WIP case (CLAUDE.md) for whoever picks this up
next — most likely #1917's autonomous orchestrator, per that issue's Step 0.
Do not create a new worktree; re-enter this one
(.claude/worktrees/issue-1909-stage1-compound-intent, branch
worktree-issue-1909-stage1-compound-intent) and continue its history.

The investigation is done and the fix shape is decided (route_multi, a
third typed Stage-1 tool). What's left is implementation plus the mandatory
full-matrix verification before merge — this is real work on shared routing
surface, not a mechanical follow-up. Read issue #1909's full comment history
for the raw traces behind the 45% figure before starting; the borderline
"search + create + reminder" case noted in the last comment is a heuristic
false-negative worth keeping in mind so it doesn't get miscounted again in
a future run.

## Acceptance Criteria Status

From issue #1909:
- [x] Live reproduction with raw traces
- [x] Recommendation for the minimal extension (route_multi)
- [x] Widen the compound-prompt sample past 5
- [ ] Optional repeat run of the widened sample (non-blocking)
- [ ] Implement route_multi as a third typed Stage-1 tool
- [ ] Full routing/retrieval matrix run before merging the implementation

Co-Authored-By: Claude <[email protected]>

* Implement route_multi as a third typed Stage-1 tool (closes #1909)

Per #1909's investigation: Stage-1 had exactly two moves (route_query,
route_clarify), neither correct for a compound-but-unambiguous request
("log this expense and remind me to follow up Friday") — nothing is
ambiguous, there are just two intents. Measured live against the
locked native model: route_clarify never fired (0/11), and merging
both intents into one route_query string dropped or fabricated a
detail 45% of the time (5/11).

Adds route_multi as a third Stage-1 tool taking an array of per-intent
query strings, mirroring route_query's single string, pluralized.
RouteDecision gains a Multi(Vec<String>) variant; parse_route_decision
requires at least two non-empty queries (fewer falls through to no
decision, since a one-element "multi" is really a route_query call the
model over-triggered on). agent_loop.rs's routing block re-enters
retrieve_skills once per query for a Multi decision — the same way it
already does once for a Query — and merges the results by skill id,
capped at the existing RETRIEVAL_TOP_K bound so a compound request
cannot silently widen Stage 2's candidate count past what ADR-038
requires the system to own.

Verified against the real model via the existing compound-intent probe
(live_stage1_compound_intent.rs, extended to categorize Multi
outcomes): all 11 compound prompts now call route_multi with faithful
per-intent queries (11/11, 0% lossy — down from 45% lossy pre-fix), and
all 18 single-intent controls still correctly call route_query with no
false-positive route_multi calls.

Co-Authored-By: Claude <[email protected]>

* Add RouteDecision::Multi arms to the golden-prompt harness's match blocks

live_stage1_golden_prompts.rs predates route_multi (it landed on main
via 83bdabe, before this branch's Multi variant existed) and its 4
match-decision blocks were exhaustive over the old 2-variant
RouteDecision, breaking the build once this branch's Multi variant is
in the mix. Adds a Multi arm to each, printing the parsed queries the
same way the other golden tests already print their outcome — no
behavior change to the existing 3 variants' handling.

Co-Authored-By: Claude <[email protected]>

* Label prior context vs current request in Stage-1's routing message (#1909)

route_multi fired on genuinely single-intent turns during multi-turn
conversations, fabricating a second intent out of blended prior-turn
content. Root cause: build_retrieval_query's unlabeled parts.join("\n")
blob gives Stage 1 no way to tell "this happened before" from "this is
the current request" — read as several things to do rather than one
request in light of history.

Wraps the Stage-1 chat message with an explicit PRIOR CONTEXT / CURRENT
REQUEST boundary via a new stage1_query_from_turns, extracted so the
golden-prompt test harness exercises the same code path production uses
rather than calling build_retrieval_query directly (which would have
missed this fix entirely). build_retrieval_query's own output, used
verbatim for schema retrieval's embedding query, is untouched — the
framing only changes what the Stage-1 chat turn sees.

Validated: all 4 golden-prompt cases (8a, 8b control, scenario 4,
scenario 6) pass under the new framing. 3-rep matrix gate shows zero
spurious route_multi firings across 36 trials (up from a confirmed,
reproducible defect); the aggregate 7.3/12 mean is unmoved because
scenario 6 still fails on the separately-tracked Stage-2 resolve_query
refusal gap, and the rep-to-rep score decline traces to already-tracked
pre-existing issues (#1926, #1927) unrelated to this change.

Co-Authored-By: Claude <[email protected]>

* Address review: unit test route_multi's fan-out and dedup

The review on PR #1916 found route_multi's retrieval fan-out/merge/dedup
path (agent_loop.rs's RouteDecision::Multi arm) was covered only by
#[ignore]'d live tests, not run in default test:all.

Adds a mocked-engine test exercising two route_multi queries against a
fixed candidate set: asserts retrieval fires once per query in order,
and that a candidate matching both queries is merged once in Stage 2's
injected prompt, not duplicated. Verified the test actually catches a
regression by temporarily removing the dedup check and confirming the
test fails, then reverting.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant