Skip to content

create_node duplicates an entity the turn already resolved; instruction channels do not prevent it #2855

Closed

Description

@malibio

Overview

With entity resolution shipped (#2841), a turn that names an entity already in the graph now has that entity rendered in its prompt, with its id and type. The model reads it — and still creates a duplicate.

"Add Northwind Trading to the companies we sell to", against a workspace where Northwind Trading already exists as a company_sold_to, produces create_node and a second record. Measured 3/3 reps on gemma-4-e4b-q4km, and reproduced in isolation afterwards.

The ask is not "pick the other tool". "Add X" when X exists is genuinely ambiguous — a second, distinct record is a real thing to want — so the right behaviour is to hand the choice back to the user via route_clarify, naming the existing record. That is a human-in-the-loop decision the agent should not make silently either way.

Instruction does not fix this

Three channels were tried against the locked model, with the entity rendered in MENTIONED ENTITIES and route_clarify present on the offered tool surface. All three produced create_node and a duplicate:

Channel Result
Node Creation skill guidance (prose) duplicate
create_node tool description duplicate
Both together duplicate

The middle row is the interesting one. ADR-064 measured a constraint stated on a tool schema at 100% compliance where the same rule in resident prose reached 87.5%, and agent_guidance.rs:214 records that gradient directly. Here the schema channel moved the outcome not at all.

The plausible reading: that measurement covered output-shape constraints ("emit this field in this form"). This is a conditional suppression — "do not take the obvious action when a condition holds" — and it appears to be a materially harder ask. Worth recording, because it bounds what the instruction-channel doctrine can be expected to buy.

Verified it is not a plumbing failure. Debug logging on the turn confirms the tier ran and resolved:

workspace_context: entity resolution count=1 query="Add Northwind Trading to the companies we sell to."

So the model had the fact, had the tool, had the instruction in the strongest available channel, and created the duplicate anyway.

Proposed direction

Make it structural rather than advisory. The system already knows the entity resolved — that is what the tier computes — so the collision is detectable deterministically before the write, with no model judgment involved:

  1. create_node executes with node_type T and content C.
  2. The turn's resolved entities already contain a node of type T whose title matches C.
  3. Reject the create and return the clarify prompt, naming the existing record's id.

This follows the same posture as the existing guard stack in agent_loop.rs (anti-fabrication, fabricated-id, narrated-tool-call, no-op-success), all of which exist on the premise that the model's account of what it did cannot be trusted. A duplicate-create guard is the same shape: the system holds a fact the model was told and did not act on, and enforces it at the boundary.

Open design questions, deliberately not decided here:

  • Match strictness. Exact title match is the safe start. Anything fuzzier risks blocking a legitimately distinct record with a similar name.
  • Where the guard lives. In create_node's op, or in the agent loop alongside the existing guards? The op sees every caller; the loop sees the turn's resolved entities.
  • Reject vs rewrite. Return an error the model must handle, or have the system emit the clarification directly? The latter is stronger but takes the turn out of the model's hands.
  • Escape hatch. A user who genuinely wants a second record with the same name needs a way through on the follow-up turn.

Acceptance criteria

  • A create_node whose type and title match an entity already resolved for that turn does not silently create a second record
  • The user is asked which they meant, with the existing record offered by id
  • A create whose name does NOT match a resolved entity is unaffected — no new failure mode for ordinary creates
  • A follow-up turn can still create the duplicate when the user confirms they want one
  • schema-on-menu-company in scripts/eval/fixtures/decisions.ts passes; it currently asserts the wanted behaviour and fails, deliberately, as a known gap
  • Tests pass (bun run test:all), code passes bun run quality:fix

Reference files

  • packages/core/src/ops/context_ops.rs — resolve_entities, EntityResolution; the resolved set a guard would consult
  • packages/agent/src/local_agent/agent_loop.rs — the existing guard stack this would join
  • packages/agent/src/local_agent/tools.rs — def_create_node, and def_route_clarify (the HITL mechanism)
  • packages/agent/src/skill_pipeline.rs — Node Creation's guidance and whitelist; route_clarify was added there so the tool is reachable
  • scripts/eval/fixtures/decisions.ts — schema-on-menu-company, which pins this

Related

Activity

  1. added
    enhancement
    on Sep 22, 2026
  2. malibio commented on Sep 22, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 262 files / 5264 tests passed

  3. self-assigned this
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions