Repository navigation
Count Stage-2 prose clarifications against the one-per-intent contract (closes #2905) - #3196
Conversation
Pragmatic Code Review — PR #3196Review Type: Initial Review Requirements Check (#2905)
Code Review Findings 🔴 Critical: an ordinary read-only answer can switch off the duplicate-entity guard📁
🟡 Important: in read-only chats the re-prompt fires with a false statement📁
🟡 Important: any earlier read-only turn turns off Stage-1 clarification (design trade-off)📁
🟡 Important: the persisted enum's doc comments describe the replaced rule📁
🟢 Suggestion: nothing pins "no re-prompt after a tool call"📁
🟢 Verified correct
🟢 Nits
Recommendation: REQUEST CHANGES
|
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-review verdicts). Full findings in the review comment above.
Review addressedCommits ✅ Addressed
⏭️ Skipped
Verification
Re-Review DecisionRE-REVIEW NEEDED. This round fixed a 🔴 finding and changed the counting rule the contract uses. |
Pragmatic Code Review — Re-Review (bd9dd38, d163948)Previous review: 7 recommendations.
Rejecting the composed-only alternative is sound. The eval's failing chat had two search-then-prose turns and nothing recorded Requirements (#2905):
🟡 A chat that only reads keeps one intent open indefinitely📁
🟢 Leftovers from deleting
|
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE with comments (posted as a comment — GitHub blocks self-approval). Findings in the comment above.
Re-review addressed (8be973b)
Re-Review DecisionNO RE-REVIEW NEEDED. Doc comments and a parameter rename only; no logic changed. |
…t (refs #2905) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t contract
## Completed in This Session
- [x] Design chosen with user: persisted turn outcome (acted/clarified/replied) + one-shot nudge + route_clarify guidance
- [x] AiChatTurnOutcome on core + wire AiChatMessage (and TS mirror); AgentSession.prior_turns / PriorTurn
- [x] AgentTurnResult::outcome() derives the outcome structurally; run_turn records it after the guards
- [x] answered_clarifications reads prior_turns (intent boundary = last Acted turn); opener string-match removed
- [x] Stage-2 nudge: zero-tool-call prose after an answered clarification is put back once (ALREADY_CLARIFIED_NUDGE)
- [x] Daemon persists outcome (AssistantRecord struct replaces append_assistant_message positional args) and seeds prior_turns_from_history
- [x] route_clarify Stage-2 description: "never ask one in a plain reply"; prompt golden regenerated
- [x] Tests: erasure case, prose counting, outcome derivation, nudge fires/doesn't/once, daemon round-trip; mutation-checked
- [x] bun run test:changed passes (rebased onto origin/main)
## Remaining Work
- [ ] Routing eval: clarification-then-fallthrough must pass (was 0/3). Run was stopped mid rep 1 before reaching it.
Setup: cargo build --release -p nodespace-daemon -p nodespace-cli; start isolated daemon per
nodespace-docs/development/agent-eval.md (/tmp/nodespaced-test, RUST_LOG=debug); model load gemma-4-e4b-q4km;
NS_BIN=target/release/nodespace ... bun run eval:routing issue2905 <out.json> --runs 3
- [ ] Partial rep 1 showed indirect-schema-{money-owed,freelance,expenses} and instance-not-schema-invoice failing —
single-turn, untouched by the guard/nudge; compare against a baseline (main) run before attributing
- [ ] bun run quality:fix + commit, push, gh pr create --head issue-2905-prose-clarification-guard
- [ ] /pragmatic-code-review then /address-review
- [ ] After merge: update ADR-038 "What the agent loop does today" clarification-contract bullet (enforced from
persisted turn outcome; a prose reply counts and does not close the intent) — commit straight to nodespace-docs main
## Current State
- Files modified: core ai_chat_node.rs/mod.rs, nodespace-types ai_chat.rs, desktop-app ai-chat-node.ts,
agent agent_types.rs/agent_loop.rs/tools.rs + stage2 golden, daemon local_agent_service.rs, AiChatMessage test literals
- Tests status: Passing (test:changed)
- Known issues: none known; eval result pending
- Dependencies: none
## Context for Next Session
The guard no longer reads reply text: each assistant turn persists how it ended, and a turn that did not call a
tool keeps the intent open and counts as its clarification. Counting alone cannot fix the eval's scored turn, so
Stage 2 is re-prompted once when it replies in prose after an answered clarification. Next: finish the eval run.
## Acceptance Criteria Status
From issue #2905:
- [x] A clarification asked in Stage-2 prose is counted against the at-most-one-per-intent contract
- [x] A Stage-2 prose clarification does not erase a prior route_clarify from the current intent window
- [x] Detection relies only on module-written text or structural turn properties
- [x] Guidance directs Stage 2 to clarify via route_clarify; detection holds when it is ignored
- [ ] clarification-then-fallthrough passes in the routing eval (erasure test is pinned: done)
- [ ] Tests pass / quality:fix (test:changed passes; quality:fix not yet run)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ct (refs #2905) A turn that searched and then asked in prose was recorded as Acted, so each search closed the intent and no clarification was ever on record. The routing eval hit exactly this: two search-then-ask turns, then a third prose question the guard could not see. Reading and then replying looks the same whether the reply showed results or asked about them, so only a successful write counts as acting; a read-only turn is Replied and stays on record. The re-prompt stays keyed on a turn with no tool call at all, so a search that answered the user is never pushed to call another tool. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…2905) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… (refs #2905) - The duplicate-entity guard disarms for a record a clarification asked about. It read answered_clarifications, which now holds every turn that did not act, so a read-only answer linking the record disarmed it. It now reads only Clarified turns in the intent. Test: a linked Replied answer followed by create_node is still refused (fails when the old list is passed). - Pin that a reply after a tool call is never re-prompted (fails without the no-tool-call condition). - Align the persisted outcome's doc comments (core enum, TS mirror) and the Stage1Outcome clarification doc with the write-only rule. Skipped: moving outcome() out of agent_types — optional; the dependency is a single registry lookup. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…g turns (refs #2905) Counting one turn that did not write as the intent's clarification made any chat that opened with conversation or a lookup lose its first genuine clarification, and re-prompted its next plain reply with a false 'the user already answered' statement. One such turn is as likely an answer as a question; two in one intent is the loop the contract stops. session_already_clarified: a composed clarification in the intent, or at least two turns that did not write. The re-prompt uses the same rule. The eval's shape (two search-then-ask turns, then a prose reply) still triggers it. answered_clarifications had no remaining non-test caller and is removed. Tests: threshold pinned both ways (>=1 and >=3 each fail a test); 'hi -> Hello!' then a plain reply is not re-prompted. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…es (refs #2905) - Document in session_already_clarified that a chat which only reads never closes its intent: from its third non-writing turn a tool-free reply is re-prompted once and an ambiguous request falls through to retrieval. - Point the CLARIFICATION_OPENER and nudge docs at session_already_clarified (the deleted answered_clarifications was still linked), rename the duplicate guard's parameter to composed_clarifications, and name both halves of the rule in the nudge comment. Skipped: rewording ALREADY_CLARIFIED_NUDGE. The 5/5 eval was measured on this wording; changing it needs another eval run. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
8be973b to
1c76ddb
Compare
Closes #2905.
What was wrong
ADR-038's contract allows at most one clarification per intent. The guard found the current intent by scanning back for the last assistant message that did not start with the composed-clarification opener. A clarification Stage 2 asked in its own prose carried no opener, so:
route_clarifyfrom the window. Clarifications could alternate forever.What this does
Each assistant turn records how it ended, structurally, and the guard reads that record instead of reply text.
AiChatTurnOutcome(Acted/Clarified/Replied) is persisted on each assistantAiChatMessageand seeded back intoAgentSession::prior_turnsfrom history.AgentTurnResult::outcome()derives it from what the turn did: a composed clarification isClarified; a successful write isActed; anything else, including a turn that only read, isReplied.Actedturn. ARepliedturn stays inside the intent, so a prose question can no longer erase an earlier clarification.ALREADY_CLARIFIED_NUDGE). The prose is dropped from history so the model does not re-read its own question. The nudge never fires after a tool call, so a turn whose search answered the user is not pushed to call another tool.route_clarify's Stage-2 description now says to clarify through it, never in a plain reply (tool-selection guidance, per ADR-064). The detection does not depend on it being followed.Why only a write closes an intent
The first version counted any tool call as acting. The routing eval showed why that fails: Stage 2 searched and then asked in prose, twice, so each search closed the intent and nothing was on record by the scored turn. Structurally, "searched, then showed results" and "searched, then asked about them" are identical, so reads cannot close an intent.
The cost is on the other side: a conversation that has only read keeps its intent open. With the two-turn rule above, that costs a clarification or a re-prompt only from its third non-writing turn, which errs toward acting over asking again — the direction ADR-038's contract prefers over looping.
A deleted test
an_unanswered_clarification_is_not_treated_as_already_clarifiedwas removed. It pinned two things:run_turnwrites thePriorTurnrecord only after a turn ends, and the guard reads it only inside the next turn, whose user message is the answer.the_clarification_contract_re_arms_on_a_new_intent(clarified → armed → acted → re-armed).Verification
Unit tests: the erasure case, prose counting (one non-writing turn does not count, two do — threshold pinned both ways), outcome derivation (read-only →
Replied, failed write →Replied), the re-prompt fires / does not fire after a tool call / does not fire after a single earlier reply / fires once, two search-then-prose turns count, a linked read-only answer does not disarm the duplicate guard, and the daemon round-trip. Each new test was checked to fail with its fix reverted.bun run test:changedpasses.Routing eval, targeted to the two scenarios this rule can reach (the only ones with prior turns in their chat), 5 reps, E4B, isolated daemon, no other model loaded:
clarification-then-fallthroughinstance-not-schema-invoice(control)Re-run on the final two-turn rule: again 5/5 and 5/5. The re-prompt fired on all 5 scored turns in both runs: each pass came through the new path, not a lucky first reply. The run reused a database where the model's search finds two plausible trackers, which is what produced the search-then-ask turns that failed before the write-only rule.
The full routing suite was not re-run. Its other scenarios start in a fresh chat, where no prior turn exists for the guard or re-prompt to read; the only change they see is the
route_clarifydescription. Rewording that fixture's scenarios into the developer-workflow domain is #3189, which is sequenced after this merges.After merge
Update ADR-038's "What the agent loop does today" clarification-contract bullet: the contract is enforced from the persisted turn outcome; only a successful write closes an intent; the intent is clarified by a composed clarification or two non-writing turns.
🤖 Generated with Claude Code