Skip to content

Read a how-question as a lookup; retrieve lookups and suppressed clarifications in context - #3621

Merged
mstomar125 merged 1 commit into
mainfrom
issue-3560-eval-routing-misses
Oct 5, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-3560-eval-routing-misses

Conversation

@malibio

@malibio malibio commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #3560.

Works through the five misses the re-themed decision eval surfaced. Three are fixed, one had its assertion corrected, and one is recorded as a miss with the measurements, because no wording fixed it without a cost elsewhere.

What changed

A question about how something is done is a lookup (finding 4). Asked "How do we onboard a new reviewer?", Stage 1 answers with route_query("onboard a new reviewer"), and did the same for the sponsor, contractor and "decide which cycle" questions, each on every rep. Five wordings of the Stage 1 prompt and route_lookup's description were measured; each fixed the questions and broke another control (questions about the agent, the compound split, or a find request). So the loop reads it off the message: on the pass that asks about the message alone, a route_query for a message that opens with a question word and does not address the assistant is a lookup of that message (routing::decision_on_the_message_alone). Every other decision stands.

A lookup's retrieval query opens with the search skill's verbs (finding 2). search stored knowledge for {topic} is now find, look up, or search stored knowledge for {topic}. A topic that is a record's name and a field ("Kestrel Sync sign off date") lost to Node Deletion by 0.001, which offers delete_node on a lookup; it now leads by 0.024. Rewording Research & Search's description was measured first and rejected: it lifted the skill on requests that are not lookups.

A suppressed second clarification retrieves in context (finding 3). When Stage 1 asks to clarify twice in one intent, the turn fell through to retrieval on the bare message. "Say that again more simply." retrieved Play Authoring, Conflict Journal and Graph Editing, and the model replied that it had no tool for rephrasing. It now retrieves on the message blended with the turns before it, as schema retrieval does.

schema-shared-name-signed asserts the reply (finding 5). A correct turn answers through search_semantic, which names no type, so the schema assertion failed it 3 of 3. It now asserts the seeded date in the reply, the same correction once made to schema-field-disambiguates.

Recorded, not fixed (finding 1). A request for a new kind of record leads with Schema Creation when its nouns are neutral (by 0.012 to 0.036) and with another skill when they are that skill's subject: "incident postmortems with severity" reads as Graph Editing, 0.889 to 0.868. About twenty variants of the two descriptions, Graph Editing's exclusion and the Stage 1 query were measured; the one that won "set up Postmortems…" lifted Schema Creation everywhere and broke two existing controls. The new retrieval test asserts the lead for the neutral nouns and the top 3 for the colliding ones, with the scores. The turn still calls create_schema in every rep.

Also folded in: stage1_type_line_routes_requests_that_name_a_known_type failed on main because it compared two queries byte for byte and the type line makes Stage 1 drop articles. It now compares content words.

Measurements

gemma-4-e4b-q4km, isolated daemon, database purged between reps, before and after built from the same main.

Scenario (3 reps) Before After
skill-type-request-direct 0/3 0/3
skill-type-request-indirect 0/3 0/3
outcome-record-field-is-answered 3/3 3/3
outcome-follow-up-keeps-its-answer 3/3 3/3
outcome-follow-up-statement-keeps-its-answer 0/3 3/3
schema-shared-name-signed 3/3 (0/3 under the old assertion) 3/3

One round of the whole fixture, as a regression smoke test: 20 of 25 before, 21 of 25 after. No scenario that passed before fails after. outcome-question-searches-first moved to a pass (routed as a lookup where it was a query). Still failing on both builds: the two type requests, entity-no-match-is-a-create and declarative-fact-report-resolved.

Live tests: live_skill_retrieval_stability 28 of 28 (two new guards); live_stage1_golden_prompts 13 of 13, from 10 of 13 on main, with "How do we onboard a new reviewer?" and two sibling questions added to both lookup lists.

Notes for review

  • The question rule is the one place a message's wording decides a route. It is English only and narrower than is_lookup_shaped: a question word first, a question mark last, not a suggestion ("How about …?", "Why don't we …?"), and nothing about the assistant (no "you" or "your", no skills, tools or assistant). A message it leaves out is routed as Stage 1 routed it.
  • Docs for these behaviours (architecture/prompt-skill-system.md, ADR-038) are pushed to nodespace-docs with the merge.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3621 (issue #3560)

Review Type: Initial Review (no prior reviews or comments on the PR)

Summary

A net improvement. Three measured failures are fixed with small, well-explained changes; one eval assertion is corrected; one finding is recorded with its numbers. The code follows the surrounding patterns and CLAUDE.md (no lint suppression, no compatibility code, no issue numbers in comments, docs kept in nodespace-docs). No Critical findings. Three Important items need attention before merge: one acceptance criterion is not met while the PR closes the issue, the new question rule overrides Stage 1 for a wider set of messages than the ones measured, and one branch of that rule has no test.

What I ran: 10 targeted unit tests in nodespace-agent (the four new routing::tests, the changed and new agent_loop tests, and guidance_is_not_contaminated_by_eval_prompts), all passing. I did not run evals or the live (--ignored) tests, so the 3-rep rates and the 28/28 and 13/13 live results are the PR's figures, not re-measured.

Requirements Check

  • ✅ Each of the five findings is fixed with before/after rates, or recorded as accepted with the reason. Findings 2, 3 and 4 are fixed, 5 has its assertion changed, 1 is recorded with scores and the variants tried. Two notes: finding 4's before/after is the live golden test (10/13 to 13/13), not a 3-rep eval rate; and finding 2's scenario was 3/3 before and after, so its evidence is the retrieval margin (-0.001 to +0.024).
  • ❌ skill-type-request-direct and skill-type-request-indirect lead with Schema Creation. Not met: both are 0/3 before and after. The first criterion lets a finding be recorded, but this criterion states the outcome outright. See finding 2 below.
  • ✅ "How do we onboard a new reviewer?" is added to the lookup golden tests and passes. Added to both lists, with two sibling questions. It passes because the harness applies the loop's rule, not because the model's output changed, which the test comment says.
  • ✅ No scenario that passes 3 of 3 today regresses. Per the PR: the six targeted scenarios at 3 reps, the rest of the fixture at one round (20/25 to 21/25, no pass turned into a fail). One round is weaker evidence than the criterion's "3 of 3" for the 19 scenarios outside the table.
  • ✅ guidance_is_not_contaminated_by_eval_prompts passes. Ran it: passes. The PR changes no model-facing guidance text.

Code Review Findings

🟡 Important

1. The question rule flips Stage 1's route_query for any message that opens with a question word, and only the intended cases were measured
📁 packages/agent/src/local_agent/routing.rs:259-303, packages/agent/src/local_agent/agent_loop.rs:5292-5296, 5318-5331

asks_what_the_workspace_holds is true for any message whose first word is how/what/why/when/where/who/which and that has no "you/your". It does not require a question mark, and decision_on_the_message_alone then turns a Query into a Lookup on both the alone pass and a chat's first message. Stage 1 answering route_query for these messages is sometimes the right call, and the rule now overrides it:

  • Writes and suggestions that open with a question word: "What about adding Harbour as a planning cycle?", "How about a task for that?", "What I need is a new task to call the vendor", "When the review is done, mark it signed off", "Which reminds me, add a note about the offsite".
  • Questions about the agent that do not say "you": "What skills are available?", "How does this assistant work?".
  • General questions: "what is 15% of 240?" (which the golden harness prints through run_stage1, so it is now reported as a lookup) and the out-of-scope-weather fixture prompt "What's the weather like in Tokyo today?".

A lookup turn retrieves on find, look up, or search stored knowledge for <message>, drops route_clarify, and runs a system search if Stage 2 makes no call. For the write-shaped cases that means the write skill has to place in the top 3 behind Research & Search to be offered at all. The unit tests cover only the "you" exclusion and "Could you …?"; none of the shapes above appears in a unit test or a live control, and the docs say "every other decision stands" without naming this cost.

Recommendation: add the write-shaped and agent-without-"you" openers as controls (unit cases for the predicate, and live Stage-1 cases showing what the model generates and what the loop then does). Then either narrow the predicate (for example, exclude "how about / what about / what if / why not" and require a question mark or an auxiliary after the question word) or record the accepted cost in ADR-038 beside the equivalent one for is_lookup_shaped. Principle: a deterministic override of a model decision needs its false-positive side measured as carefully as its true-positive side, which is the standard this file already sets for is_lookup_shaped.

2. The PR closes the issue with an acceptance criterion unmet
📁 PR description ("Closes #3560"); packages/agent/tests/it/live_skill_retrieval_stability.rs:1232-1319

Finding 1 is honestly recorded, and the measurements justify not rewording a description to win one sentence. But the second criterion is not met, and the test's own comment says the miss "is recorded here and not accepted", while the commit closes the issue. Once it closes, nothing tracks the lead for type requests whose nouns belong to another skill, which is what decides the fields declared on the write tools.

Recommendation: get the owner's decision before merge: either amend the criterion on the issue to the recorded outcome, or drop "closes" and leave the issue open for finding 1. Principle: requirements traceability; an open defect should not lose its tracker as a side effect of a merge.

3. The first-message branch of the rule has no test that fails without it
📁 packages/agent/src/local_agent/agent_loop.rs:5318-5331

The new a_question_stage1_reads_as_an_action_is_a_lookup_of_the_message goes through route_after_an_earlier_exchange, so it pins the alone pass only. The if first_message { … } application has no direct test: two existing tests were moved to "which skills do you have?" to step around it, which shows the branch is live, but by my reading every unit test still passes with the block deleted (not run as a mutation). A chat's first message is the most common place for "How do we …?".

Recommendation: add a test on a fresh session where Stage 1 returns route_query for a "How do we …?" message and assert the retrieval query is lookup_retrieval_query(...), plus one where the session has history and the alone pass failed, asserting the blended decision is left alone. Principle: each branch of a routing override should be pinned by a test that fails when it is removed.

🟢 Suggestions

4. The live harness and the loop differ on one path
📁 packages/agent/tests/it/live_stage1_golden_prompts.rs:75-82, 578-594

run_stage1 now applies the rule for every caller, which is right for a message with no history. route_stage1_as_the_loop_does with empty prior_turns skips the alone pass and calls run_stage1_with_history, which does not apply it, while the loop does (first_message). No current caller passes an empty history, so nothing is wrong today. Consider applying the rule there when prior_turns is empty, so the harness cannot drift from route. Also note the lookup golden tests now measure model plus rule; the printed "generated … read as …" line is the only record of what the model alone did.

5. Suppressed clarification: the blend includes the assistant's last reply
📁 packages/agent/src/local_agent/agent_loop.rs:2071-2077, 5393-5396

build_retrieval_query takes the last two turns, user or assistant, at up to 400 characters each. That is the right reuse (one construction shared with schema retrieval and Stage 1). session_already_clarified is also true after any two non-writing turns, so this path runs in read-only chats generally, and the retrieval query there is mostly the assistant's previous answer. The evidence is one sentence (0/3 to 3/3). Worth one retrieval control with a different follow-up ("shorter please", "put that in a table") before relying on it more widely. The unit test correctly pins the composed query and would fail without the fix.

Nit: a_new_kind_of_record_with_named_details_leads_with_schema_creation asserts the lead for three of its six queries and top-3 for the rest. A name such as …_leads_or_places_schema_creation would match what it asserts.

Nit: a converted lookup's topic is the whole message ("How do we onboard a new reviewer"), where a model-written topic drops the question frame ("how we onboard a new sponsor"). It is only the fallback search query, so this is cosmetic.

What is good

  • The lookup-prefix change is one line with the measured margins beside it, and the description rewording that was rejected is recorded with its cost.
  • turns_before_this_message removes a duplicated slice-and-filter instead of copying it.
  • The fixture change for schema-shared-name-signed asserts what the scenario is for, consistent with schema-field-disambiguates.
  • Docs edits in architecture/prompt-skill-system.md and ADR-038 describe the behaviour in present tense and match the code. They are uncommitted in the docs working tree and need pushing with the merge.
  • Security: no new input surfaces, secrets or logging of content. Performance: no added generations; a converted query saves the blended pass.

Recommendation

COMMENT. No blocking defect in the code, and the change is a net improvement. Before merge: settle item 2 with the issue owner, and address item 1 (controls plus either a narrower predicate or a recorded cost) and item 3 (a first-message test).

@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.

Automated pragmatic-code-review: COMMENT (no blocking defect; three Important items to settle before merge). Full findings in the review comment above.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (commit a07b6e2)

1. The question rule was wider than what was measured: addressed. asks_what_the_workspace_holds now requires a question mark, leaves out suggestions ("How about …?", "What about …?", "What if …?", "Why not …?"), and leaves out a question that names skills, tools or the assistant without saying "you". Each shape the review listed is a unit control: the writes that open with a question word, the suggestions, and "What skills are available?". A message the rule leaves out is routed as Stage 1 routed it. The one cost that remains is recorded on the function and in the architecture doc: a general question nothing stored can answer ("What's the weather like in Tokyo today?"), where a Stage 1 query becomes a lookup that searches, finds nothing and says so. "what is 15% of 240?" is unaffected: Stage 1 calls no routing tool for it, before and after. The two Stage 1 lookup tests were re-run live with the narrowed rule and pass.

2. The PR closes the issue with a criterion unmet: left for the owner. The description now says "Refs #3560" so a merge does not close the issue by default. Whether to amend the criterion or keep the issue open for the type-request lead is the owner's call.

3. The first-message branch had no test: addressed. a_first_message_stage1_reads_as_an_action_is_a_lookup_of_the_message runs a fresh session; with the if first_message block disabled it fails, and it passes restored. a_query_decided_in_context_is_not_read_as_a_lookup pins the other side: when the alone pass yields no decision, a query decided on the blended view stands.

4. Harness drift: addressed. route_stage1_as_the_loop_does applies the rule for an empty history, as the loop does.

5. More follow-up controls for the suppressed clarification: skipped. The retrieval tier has no seeded-conversation harness, so a control there means building one; the eval scenario measures the path end to end (0 of 3 to 3 of 3), and the unit test pins the composed query. Worth revisiting if a second follow-up shape misbehaves.

Nits. The retrieval test is renamed …_leads_or_places_schema_creation. The converted lookup's topic keeping the question frame is left as is: it is only the fallback search query.

Tests: 989 agent unit tests pass, test:changed passes (scripts, type drift, node-types sheet, Rust workspace).

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3621 (issue #3560)

Review Type: Re-Review (changes since d7e589a: one commit, a07b6e2)

Previous Review Summary

  • Previous recommendations: 5 (3 Important, 2 Suggestions), plus 2 nits
  • Addressed: 3 (items 1, 3, 4) and 1 nit
  • Left for the issue owner: 1 (item 2; the PR no longer closes the issue)
  • Not addressed, with a reason I accept: 1 (item 5) and 1 nit
  • New issues found: 0 Critical, 0 Important, 3 Suggestions, 2 nits

What I ran: 7 targeted nodespace-agent unit tests (the three routing::tests for the rule, the three agent_loop tests for its application points, and guidance_is_not_contaminated_by_eval_prompts), all passing. I did not run evals or the live (--ignored) tests, so the author's statement that the two Stage 1 lookup tests pass live with the narrowed rule is not re-measured. I did not run a mutation; the claim that the first-message test fails without its branch is checked by reading (below).

Previous items

1. The question rule was wider than what was measured: addressed.
📁 packages/agent/src/local_agent/routing.rs:249-313, 2143-2182, 2219-2237

asks_what_the_workspace_holds now requires a trailing question mark, leaves out a second word of "about / if / not", and leaves out a message that names skills, tools or the assistant. Every shape the first review listed is a unit control in the negative list: the four suggestions, the three writes that open with a question word, and the three agent questions without "you". every_other_decision_on_the_message_alone_stands pins that a suggestion's query is returned unchanged. All three exclusions fail safe: a message the rule leaves out is routed as Stage 1 routed it, which is the behaviour on main. The cost that remains (a general question such as the weather one, where a Stage 1 query becomes a lookup that finds nothing) is stated on the function, pinned as a positive unit case, and recorded in architecture/prompt-skill-system.md. That is the "narrow the predicate and record the cost" option the review asked for. The live Stage-1 controls I also suggested were not added; the unit controls cover the predicate, and what the model generates for those shapes no longer matters where the rule leaves them alone.

2. The PR closed the issue with a criterion unmet: left for the owner, as it should be.
The PR description now reads "Refs #3560" and the issue is open, so a merge does not close it by way of the description. Note that the first commit's message still says "(closes #3560)"; the queue squash-merges, so check that the squash commit message does not carry that line, or the issue closes anyway. The decision itself (amend the second criterion, or keep the issue open for the type-request lead) is still open and is not the author's to make.

3. The first-message branch had no test: addressed.
📁 packages/agent/src/local_agent/agent_loop.rs:18362-18419

a_first_message_stage1_reads_as_an_action_is_a_lookup_of_the_message runs a fresh session, where stage1_query_from_turns returns the trimmed message, so asks_about_the_message_first is false and the only place the rule can apply is the if first_message block. With that block removed, the retrieval query would be Stage 1's "onboard a new reviewer", and the assertion on lookup_retrieval_query("How do we onboard a new reviewer") fails. The generation count of 2 also pins that the first message gets one pass. a_query_decided_in_context_is_not_read_as_a_lookup pins the other side: with history, when the alone pass calls no tool, the blended query stands for the same message. The route_in extraction is a clean reuse, not a copy.

4. Harness drift: addressed.
📁 packages/agent/tests/it/live_stage1_golden_prompts.rs:583-586

route_stage1_as_the_loop_does now takes the one pass through run_stage1 for an empty history, so the rule applies as it does in the loop.

5. More follow-up controls for the suppressed clarification: not addressed, accepted.
It was a suggestion. The reason given holds: there is no seeded-conversation harness at the retrieval tier, the eval scenario measures the path end to end, and the unit test pins the composed query. Building a harness for one control is not proportionate (YAGNI).

Nits. The retrieval test is renamed and both references in skill_pipeline.rs follow it. The converted topic keeping the question frame is left as is, which is fine for a fallback query.

Code Review Findings (new)

No Critical or Important findings.

🟢 Suggestions

A. "Why don't we …?" still passes the rule
📁 packages/agent/src/local_agent/routing.rs:277-279, 306-311

The suggestion test reads the second word against "about / if / not". "Why don't we close the Q4 cycle?" splits into why, don, t, we, …, so it passes, and a Stage 1 route_query("close the Q4 cycle") for it becomes a lookup. It is the same class as "Why not …?", which is excluded. Recommendation: add it as a unit case on whichever side is intended; if it should be left to Stage 1, exclude "why don't / why doesn't" beside "why not". Not blocking: it is one phrasing, and a lookup turn still offers the top three skills. Principle: an exclusion list should cover the class it names, or say which members it leaves in.

B. The question mark is now required, so the unpunctuated form of the measured failure is not fixed
📁 packages/agent/src/local_agent/routing.rs:290-293, 2171

"how do we decide which cycle a slipped spec moves into" is now a pinned negative case. Typed without a question mark, "how do we onboard a new reviewer" goes back to Stage 1's route_query, which is the failure finding 4 describes. This is the safe direction and one of the two options the first review offered, so it is a recorded trade, not a defect. If chat logs show users dropping the question mark often, the other option (an auxiliary after the question word: do, does, did, is, are, was, can, should) recovers those without readmitting "When the review is done, …". The architecture doc states the question-mark condition; it does not say this form is given up, and one clause there would make the cost explicit.

C. "skill", "tool" and "assistant" are also workspace nouns
📁 packages/agent/src/local_agent/routing.rs:280-289

"Which tool do we use for deploys?", "What skills does the reviewer role need?" and "How do we onboard a new teaching assistant?" are questions about stored knowledge that the rule now leaves to Stage 1. NodeSpace's own domain has skills as stored things, so this is not far-fetched. It fails safe (Stage 1's own decision, as on main), so no change is needed now. Worth one sentence in the function's doc so the next reader knows the exclusion is by word, not by meaning.

Nit: route_stage1_as_the_loop_does returns the view "message" for an empty history, where the loop records routing.decided_on = "blended" for a chat's first message (agent_loop.rs:5312-5318). No caller passes an empty history or asserts the label there, so nothing is wrong; returning "blended" would match the loop's log.

Nit: the PR description's "Notes for review" still says the rule is "a question word first, and no 'you' or 'your'". It predates the narrowing; update it so anyone reading the PR later gets the rule as merged.

Checked and fine

  • No new compatibility code, lint suppression, issue numbers in comments or docs in the repository. No node-type, security or performance surface in this commit.
  • The uncommitted docs edits in nodespace-docs (architecture/prompt-skill-system.md, ADR-038) match the code as it now stands: the four conditions of the rule, the examples it leaves out, the accepted cost, the new lookup prefix and the in-context fall-through. They are present tense with no status labels. They still need committing and pushing with the merge.

Recommendation

APPROVE. The follow-up commit addresses the two code items properly, with tests that pin both application points of the rule, and introduces no new defect. The three suggestions are optional. One thing remains outside the code and outside this verdict: the issue owner's decision on the unmet second acceptance criterion (item 2), and making sure the squash commit message does not close the issue before that decision.

@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.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed (commit e7ee656)

A. "Why don't we …?" passed the rule: addressed. It is left to Stage 1 beside "Why not …?", with a unit case. "Why doesn't the sync retry?" is a question and still passes.

B. The unpunctuated form is given up: recorded. The function's doc and the architecture doc now say that a question typed without its question mark is left to Stage 1. The auxiliary-after-the-question-word test is the option to reach for if that form turns out to be common.

C. "skill", "tool" and "assistant" are also workspace nouns: recorded. Same two places, with "Which tool do we use for deploys?" as a unit case on the left-out side. It is routed as Stage 1 routes it.

Nits. The live harness labels a first message's pass "blended", as the loop logs it. The PR description states the rule as merged.

Item 2, decided by the owner: close #3560 with the second criterion amended to the recorded outcome. The description says "Closes #3560" again.

Tests: test:changed passes on the previous commit (scripts, type drift, node-types sheet, Rust workspace under nextest); this commit changes one word list, doc comments and unit cases, and the agent unit tests pass under nextest's process-per-test model. Under plain cargo test, a_held_update_nodes_schema_decision_is_the_nodes_type_and_enforced is order-dependent in one process (it captures logs through a thread-default tracing subscriber) and fails intermittently, on this branch and before these changes; it passes alone.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The re-review approved with optional suggestions only. This commit adds one word to an exclusion list (which fails safe: the message is routed as Stage 1 routed it), two unit cases, doc text and a test label.

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.

Fix the skill routing and follow-up misses the re-themed decision eval surfaced

2 participants