Repository navigation
Refuse a create_node that duplicates an entity the turn resolved - #2859
Conversation
#2855) The entity tier renders an existing record under MENTIONED ENTITIES, and the locked model created it again anyway under every instruction channel measured (skill prose, the create_node tool description, both). So the collision is enforced at the write path instead of requested in the prompt. - The daemon now hands the resolved set to the session in structured form (`AgentSession.mentioned_entities`), from the same WorkspaceContext the prompt block is rendered from. - A create_node whose type and title (markdown-stripped, case/whitespace folded, otherwise exact) match one of them is refused before it executes. The refusal is returned to the model, naming the existing id and telling it to route_clarify, so the model keeps its chance to correct itself. - If the turn then ends without the model clarifying or completing another write, a backstop replaces the reply with a clarification naming the existing record by id: the user is always asked. - The refusal is flagged as an error so it is never persisted as a completed write; it is excluded from tool-failure surfacing. - Escape hatch: on a turn answering a clarification (session_already_clarified, taken at turn start), the guard is disarmed so a confirmed second record can be created. schema-on-menu-company now scores the outcome (no duplicate; user asked, or the existing record updated) via a new `outcome` expectation, since a write-path guard cannot change the model's recorded operation decision. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Pragmatic Code Review: PR #2859 (duplicate-create guard)Review Type: Initial review. The PR had no reviews or comments yet. SummaryThis is a clear improvement. The structural guard is the right answer to an ADR-064 finding: instruction channels do not stop a conditional suppression. The design fits the existing guard stack. There is one resolved set, built from the same I ran them locally:
I am requesting changes for two edge cases, both small and well scoped. In each one the guarantee the issue promises ("the user is asked") breaks, or the reply claims something that did not happen. Both show up when one message names more than one entity. Requirements Check
Code Review Findings🟡 1. Any later write turns the backstop off, and the refusal is also excluded from failure surfacing, so a false success claim can get through📁
Take "Add Northwind Trading and Tailspin Toys":
The user is never asked, and the reply states that a record which was refused was created. This PR creates that fabrication path; before it, the claim was at least true, because the duplicate got written. Principle: keep a guard's release condition as narrow as the risk it covers, the same way the neighbouring guards narrow by name and retry (see the Fix: only count a later write that touches the refused entity, for example a successful write whose args or result name 🟡 2. The escape hatch opens after any answered clarification in the current intent, not the one about this duplicate📁
Example:
A related problem: the hatch also opens when the user's answer was "Use the existing". On the model that duplicates 3 out of 3 times, a create on that turn goes straight through, against the user's stated choice. Principle: least privilege. An override should be scoped to the decision it authorises. Fix, at minimum: disarm only when the answered clarification names this entity. Every clarification the backstop builds contains 🟡 3. After the daemon reloads history, the clarification is replaced by write facts when the same turn also completed a write📁 The backstop runs even when writes happened before the refusal; The persisted assistant message then has a non-empty
The replaced reply also drops any mention that Tailspin was created. The existing confirmation test seeds Principle: test at the boundary where the state actually persists, not only in memory. Fix: keep the clarification text when 🟢 4. A streamed reply can be replaced after the user has seen it📁
🟢 5. Types with a
|
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
- Backstop releases only on a write that targets the refused record's id. Any write released it before, so "add Northwind and Tailspin" -> "Added both." slipped through. The replacement clarification now also lists writes the turn did complete, which the replaced reply may have been the only report of. - The escape hatch disarms only for the entity an answered clarification asked about (by title or id), not after any answered clarification in the intent. answered_clarifications() is factored out of session_already_clarified. - History reload keeps a clarifying question verbatim even when its turn also wrote. Replacing it with terse write facts erased the question, so the confirmation turn re-asked it. The writes still follow as their own record. - The fixture scorer fails loudly when tools ran but no per-call outcomes were recorded, instead of reading that as "no create succeeded". - Docs: mentioned_entities is per-turn; title_template types never match (the safe direction, deliberately not fuzzy). Tests: a write to another record keeps the backstop armed; an unrelated answered clarification does not disarm the guard; the backstop applies on the loop-breaker exit; a clarification that also wrote survives reload. All four fixes were mutation-checked (reverting each one fails its test). Skipped: replacing an already-streamed reply (finding 4). The existing guards share this behaviour and the persisted message is correct, so it is out of scope here. The create_node tool-description prose stays: it is consistent with the refusal and costs only prompt tokens. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Review addressed (5407f2a)✅ Addressed
⏭️ Skipped
Still outstanding: the live The pre-push gate passed. |
Pragmatic Code Review: PR #2859 (duplicate-create guard), re-review of 5407f2aReview Type: Re-Review. Scope is Previous Review SummaryThe earlier review had 6 findings (three 🟡, three 🟢) and 3 nits.
I ran the new and changed tests locally, and all pass:
Requirements Check
Verification of the specific points
See 🟢 A for one semantic widening.
Daemon Fixture scorer. The loud failure is correct. Findings🟡 1. The "Already done" summary is never shown to the user📁 The problem: the summary is appended after the options list, separated by A second problem: even where it is visible, Principle: verify a user-facing guarantee at the layer that renders it. The test only asserts Fix: put the completed writes into the header paragraph. One option is to fold them into 🟡 2. Matching on the title in the escape hatch partly reopens finding 2📁 The hatch opens when any answered clarification contains the entity's title after normalization ( But the title check brings back the case the previous review used as its example. For "Add Northwind Trading", a Stage-1 routing question will very likely name the entity: "Should Northwind Trading be a customer or a company you sell to?". Once the user answers it, the guard is disarmed for Northwind, and a duplicate create goes through without the duplicate question ever being asked. The new test There is a secondary issue. The comparison is a plain substring match over the whole clarification text, with no word boundaries. A short title, or one that is a prefix of another word ("Acme" inside "Acme Holdings", "Box" inside "Boxwood"), matches unrelated text. Principle: least privilege. An override should be keyed to the decision it authorizes, and a model's paraphrase is not a reliable key. Fix (small): make the id always present in any clarification raised about a refused duplicate, then match on the id only.
If that is too much for this PR, at least require word boundaries and a mention of "already exists" alongside the title. Also add a test where the routing clarification names "Northwind Trading" and check that the guard stays armed. 🟢 A.
|
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE WITH SUGGESTIONS (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
… writes - The escape hatch now recognises a confirmation by the existing record's id only. The title substring match let a routing question that merely named the entity disarm the guard, and ignored word boundaries. - To make id-only matching complete, the backstop now also covers turns where the model asked for itself: if its route_clarify does not carry the id (its option ids never reach the user), the id is appended to the question. - Writes the turn did complete are named in the question (e.g. node creation "Tailspin Toys"), not appended after it. The chat UI renders only the first paragraph above the option chips, so the "Already done" block never reached the user. - Documented that a write merely referencing the record (a child under it) deliberately releases the backstop, and that only the turn's last refusal is raised. - Added a fixture test for the scorer's loud-failure branch. Both new fixes are mutation-checked. Follow-up, not addressed here: telling "use the existing" apart from "create a second" in the user's answer. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Re-review addressed (590ade0)✅ Addressed
Both fixes were mutation-checked, and the pre-push gate passed. ⏭️ Follow-up, not in this PR: telling "use the existing" apart from "create a second" in the user's answer. Once the user has been asked, acting on the answer stays with the model. Still outstanding: the live |
Live eval:
|
| Scenario | Baseline | This branch |
|---|---|---|
schema-on-menu-company |
0/3 | 2/2 scored (rep 3 never ran — see below) |
| the 8 other shared scenarios | 3/3 each | 3/3 each |
The guard fired on the path it was built for, in every scored rep. The model called create_node for "Northwind Trading", and the guard refused it. The model then neither clarified nor updated the record, so the backstop asked the user:
I can take that a couple of ways. "Northwind Trading" already exists as a company_sold_to (nodespace://…). Did you mean that record, or do you want a second, separate one?
- Use the existing "Northwind Trading" (nodespace://…)
- Create a second "Northwind Trading"
In one rep the model had even put the existing id into a field value of its create call. It knew the record existed and created it anyway, which is the conditional-suppression failure this issue describes.
Ordinary creates were unaffected: entity-no-match-is-a-create (Tailspin) and skill-instance-request (Contoso) both passed 3/3.
Rep 3 of schema-on-menu-company was excluded, not failed. In that group, the setup-company turn produced no tool call at all (a model flake on a setup prompt; the guard never ran), so the harness excluded the scenario before sending it. The summary still printed 2/3 ← FLIPPED. That is a runner bug: aggregateReps doesn't drop excludedAsSetupFailed reps, although partitionExcluded does. It is separate from this PR.
Out of scope for this branch: the two declarative scenarios in the baseline, which were added on main after this branch was cut.
…uplicate-create-guard
Closes #2855
Problem
With entity resolution, "Add Northwind Trading to the companies we sell to" renders the existing record under MENTIONED ENTITIES, and the locked model creates a duplicate anyway: 3 of 3 reps, under prose guidance, the tool description, and both together.
Approach: enforce it at the write path, with a chance for the model to self-correct
AgentSession.mentioned_entities. Both come from the sameWorkspaceContextthat renders the prompt block, so the guard checks exactly what the model was shown.create_nodewhosenode_typeandcontentmatch a mentioned entity is refused before it executes. Matching is exact once markdown is stripped and case and whitespace are folded. The refusal goes back to the model, naming the existing id and directing it toroute_clarify, so the model gets a turn to correct itself.update_nodeon the existing record), the system replaces the reply with a clarification that names the existing record by id. The user is always asked.session_already_clarified, captured at turn start), the guard is disarmed, so a user who confirms they want a second record gets one.is_error, so it is never persisted as a completed write; otherwise it would enterprior_writesand block the confirmed follow-up. It is also excluded from tool-failure surfacing.Eval
schema-on-menu-companynow uses a newoutcomeexpectation. It passes when nocreate_nodesucceeded and the reply is a clarification naming the record, or when the existing record was updated. A write-path guard can't change the model's recorded operation decision, so the fixture couldn't pass on that decision alone;operationDecisionstill records the model's miss. A test binds the fixture's clarification opener to the Rust constant.Tests
decisions.test.ts.Not yet done
The live
eval:decisionsrun ofschema-on-menu-companyon the locked model hasn't happened. Another session was running a 3-rep eval on the shared test daemon, and I didn't disrupt it.🤖 Generated with Claude Code