Skip to content

Point external agents' name lookups at a command that can see entities (closes #2850) - #2860

Merged
malibio merged 3 commits into
mainfrom
issue-2850-external-entity-resolution
Sep 23, 2026
Merged

malibio merged 3 commits into
mainfrom
issue-2850-external-entity-resolution

Conversation

@malibio

@malibio malibio commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Propagates entity resolution to the external agent surface (#2850), now that #2841 has landed. The first step was measurement, as the issue required, and it changed the shape of the fix.

Finding: Claude Code (Sonnet) does not stall asking for an id, so the local agent's failure does not reproduce externally. But every name lookup started with a nodespace search miss. search is embedding-only, and embeddings cover only prose types (ADR-029), so tasks and any user-defined entity type are unreachable by search at any query. The skill was sending agents there. This also rules out the issue's proposed fallback, search --type <type> "<name>": it returns empty whether the entity exists or not, so combined with "no match means create" it would duplicate every existing record.

Decision (confirmed in conversation): no resolve verb. The guidance points at the existing nodespace node query --title-contains "<name>". It is deterministic, returns empty on absence, and carries node_type.

Changes

  • skill_rules::NAMED_RECORD_RESOLUTION: a new shared InteractionRule.
    • The seeded Node Creation guidance now interpolates its imperative form. The output is byte-identical, and the prompt golden is unchanged.
    • SKILL.md carries the prose form, pinned by the existing skill_md_still_mentions_every_interaction_rule test. I mutation-checked it: removing the phrase makes the test fail.
    • The two surfaces can no longer drift on substance.
  • SKILL.md:
    • A new Finding things row for lookup by name.
    • The ordering rule, which judges results on sameness ("same name, same type") rather than an empty list, because the stem fallback also returns word-sharing records.
    • The recovery for each outcome: one match, several matches, none.
  • Size cap: the body hit ~5300 tokens against the <5000 limit. The four query --filters worked examples moved to references/cli.md's Structured property query section. That section had been pointing back at them in the body. The body is now ~4987.

Measurement

Harness: an isolated nodespaced per scenario on a seeded workspace (Northwind Trading, Northwind Logistics, Contoso Ltd, plus noise-word decoys), driven by claude -p with SKILL.md appended. Full tables are on the issue.

Baseline This PR
Sonnet outcomes 10/10 (2 reps) 10/10 (2 reps) + 5/5 on the final wording
Sonnet: runs starting with a search miss 6/6 name lookups 0
Sonnet calls (update / read / ambiguous) 5,7 / 5,3 / 3,3 3,4 / 2,2 / 2,2
Haiku outcomes (1 rep) 1/5 3/5

Haiku still skipped the clarifying question on the ambiguous "Northwind" and picked text over company on a create. That's one rep, so the wording wasn't tuned against it.

Not in scope, observed

In a fresh database, search surfaces seeded skill/guidance fragments (e.g. a node whose content is just TOOL STRATEGY:). Sonnet flagged them as prompt injection in 4 of 10 baseline runs.

Test plan

  • cargo test -p nodespace-agent: 672 passed, prompt golden unchanged
  • skill_md_generation passes, including the size cap; bun run skill:check is clean
  • Presence test mutation-checked
  • Pre-push gate: full pyramid passed. The first attempt failed a frontend timing benchmark under load from the concurrent measurement runs; it passed on retry

🤖 Generated with Claude Code

malibio and others added 2 commits September 23, 2026 00:50
closes #2850)

Measured before writing anything: Claude Code (Sonnet, 2 reps) with the
shipped skill never stalls asking for an id, so the local agent's failure
does not reproduce externally. What it does instead is start every name
lookup with `nodespace search`, which misses. The skill sent it there
("find nodes by keywords or meaning"), but search is embedding-only, and
embeddings cover only prose types (ADR-029). So a task, or any
user-defined entity type, is unreachable by search at any query. Sonnet
recovered each time by trial and error, taking 3 to 7 calls.

That also rules out the issue's proposed fallback, `search --type <type>
"<name>"`. It returns empty whether the entity exists or not, so paired
with "no match means create" it would duplicate every existing record.

The guidance now points at `node query --title-contains`, the existing
lexical title lookup. No `resolve` verb is added: that command already
returns empty on absence and carries node_type, which is all the judgment
needs. The rule states the recovery the local tier established, judged
on sameness (same name, same type) rather than on an empty list, because
the stem fallback also returns records that merely share a word.

The rule is a shared `skill_rules` InteractionRule. The seeded Node
Creation guidance interpolates its imperative form (byte-identical
output), and SKILL.md carries the prose form, pinned by the existing
presence test. The two surfaces can no longer drift on substance.

Re-measured with the new skill: Sonnet 10/10, with the first lookup
always `--title-contains`, zero search misses, and 2 to 4 calls. Haiku
(1 rep) moved from 1/5 to 3/5. It still skipped the clarifying question
on an ambiguous name and chose the wrong type on a create.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The ordering rule pushed SKILL.md's body to ~5300 tokens, over the Agent
Skills <5000 recommendation that skill_md_generation enforces. The four
`nodespace query --filters` worked examples moved to references/cli.md's
Structured property query section. They are argument shape, which ADR-064
rule 5 keeps out of the body, and that section was pointing back at them
("see the Tool Decision Guide above") from the file they now live in. The
rule's own prose is tightened with no change in substance, and its
skill_rules copy is kept verbatim-identical.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio

malibio commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Review Type: Initial Review

Code Review Summary

This change is small and a net improvement. The shared NAMED_RECORD_RESOLUTION rule is the right architecture: the seed interpolates the imperative, SKILL.md carries the prose, and the existing skill_md_still_mentions_every_interaction_rule test pins the key phrase. That is the same one-source pattern FIND_THEN_ACT and the schema rules already use. The main claims check out:

  • Seed text is unchanged. I extracted the old r#"# Node Creation Guidance…"# literal from origin/main and compared it with the new format! template after substituting the unescaped imperative. They are byte-identical, 739/739 chars for the paragraph and an exact match for the whole seed. The only {} in the template is the placeholder, so format! has no escaping hazard.
  • Nothing was lost in the move. The four worked examples moved to references/cli.md verbatim. The dropped operators/filter-types line is fully covered by cli.md's --filters option line, which lists property|content|relationship|metadata and equals|contains|gt|lt|gte|lte|in|exists. The YYYY-MM-DD line also moved. The edited cli.md region sits outside the BEGIN/END GENERATED markers, so regeneration won't overwrite it.
  • The --title-contains description is accurate. It is a case-insensitive LOWER(title) LIKE with escaped wildcards. On an exact miss it falls back to OR-matching on stems (query_nodes_title_stem_fallback), so word-sharing records do come back. An empty result means no match.
  • Tests: nodespace-agent --lib 672 passed / 1 ignored. skill_md_generation 12/12 passed, which includes the body size cap. bun run skill:check reports "Skill content is up to date."

My findings are about guidance consistency on the external surface, not code correctness.

Requirements Check

  • ✅ Measure external-agent behaviour before writing guidance. Recorded in the first measurement comment on the issue, with baseline and post-change tables.
  • ✅ Ordering rule added to SKILL.md, derived from the local tuned wording. The prose copies the local "same name, same type" and "none means it doesn't exist" framing.
  • ✅ No-match-means-create recovery. It is stated as "no result is that record" rather than "the list is empty", which matches how the stem fallback actually behaves.
  • ✅ Points at the correct command without restating argument shape. node query --title-contains "<name>" is the settled decision, with no resolve verb.
  • ✅ (N/A) resolve verb and cli.md regeneration. No verb was added, and skill:check is clean.
  • ✅ SKILL.md does not trail the seed nodes. Both render from one skill_rules const, and the key-phrase test enforces the pairing.
  • ✅ Tests pass and skill:check is clean. quality:fix and the full test:all are left to the pre-push gate, per project convention.

Code Review Findings

🟡 [Improvement] The on-demand reference still sends name lookups to search first
📁 packages/skill/references/cli.md:113, :135, :316
"Find then update", "Find then delete" and the relationship create note still say "run nodespace search or nodespace node query", with search listed first. An agent reads cli.md for update/delete flags at exactly the moment it is resolving a named record. So this hand-authored text still produces the "search miss, then fallback" pattern your measurement removed from the body. For a task or typed record, a search miss followed by the adjacent "zero matches → ask the user" advice leads to a needless clarification, or worse, a create.
Fix: In those three places, name nodespace node query --title-contains for lookups by name and keep search for finding content by meaning. All three are outside the generated markers, so this is a text edit only.
Principle: one source of truth for a procedure (DRY/consistency). Two conflicting orderings in the same skill bundle leave the agent to pick one.

🟡 [Improvement] "Typed records never appear in it" contradicts the row directly below it
📁 packages/skill/SKILL.md:129 vs :119
The new prose says nodespace search "only reaches prose, so tasks and typed records never appear in it". The table's next row still says search "" --type <type> lists all nodes of a type, and it does: the enumerate path skips the scope filter (should_skip_scope_filter in search_ops.rs). Your own measurement shows Sonnet using that listing to get the duplicate and create scenarios right. As written, a careful model could decide the listing row is wrong, or that the new rule is.
Fix: Qualify it, for example "a query search never returns them — only the empty-query listing (search "" --type <type>) does."
Principle: guidance must not contradict itself. For an LLM reader, an absolute statement that a neighbouring line disproves weakens both.

🟡 [Improvement] The rationale in the doc comment names the wrong mechanism
📁 packages/agent/src/skill_rules.rs:259-264 (doc comment on NAMED_RECORD_RESOLUTION)
The comment says "nodespace search is embedding-only and embeddings cover only prose types (ADR-029), so it cannot see a task or any user-defined entity type at all." Embeddability is decided per behaviour, and several non-prose types are embeddable:

  • CustomNodeBehavior, used for every user-defined type, inherits the default get_embeddable_content, which returns Some(content) whenever content is non-empty.
  • PersonNodeBehavior and ProjectNodeBehavior are embeddable too.

What actually hides them on the CLI path is the default knowledge scope. The daemon passes scope: None, so parse_scope returns Knowledge, and matches_scope keeps only text|header|code-block|schema|table. Tasks are the only case where "not embedded" is the real reason.
The conclusion is right today, but the stated reason is not. Someone who later exposes --scope or sets include_title_matches on the CLI path will read this comment and assume entities still can't be reached.
Fix: Reword along the lines of "the CLI's search runs with the default knowledge scope (text/header/code-block/schema/table) and no title-match half, so it never returns a task or user-defined record."
Principle: comments explain the why, and a wrong why is worse than none. It also ties the guidance to the real coupling point, search_nodes in daemon/src/services/node_service.rs.

🟢 Nit: The parenthetical is incomplete
📁 packages/skill/SKILL.md:129, :131
"(notes, documents, headings, code)" leaves out schemas and tables, which the knowledge scope also returns. Consider dropping the parenthetical and saying "prose and schema nodes".

🟢 Nit: The Delete example resolves by content, not title
📁 packages/skill/SKILL.md:249
The Delete example resolves with --content-contains "draft spec". For a record whose title comes from title_template (e.g. a Person from first/last name), content and title can differ. Using --title-contains would match the rule a few lines up.

🟢 Nit: The "exact substring" row is not strictly exact
📁 packages/skill/SKILL.md:122
The row calls --title-contains an "Exact substring match". That was already true before this PR. It isn't strictly exact any more, because of the stem fallback on a miss, which the new rule itself relies on. Consider "substring match (title falls back to shared-word matching on a miss)".

🟢 Positive: Building the seed with node_creation_guidance() and format! keeps the two surfaces from drifting on substance, and the byte-identical render means the prompt golden and the measured local behaviour are untouched. Choosing "same name, same type" as the key phrase is a good call: it is the judgment both surfaces share, and so the first place the external copy would fall behind.

Recommendation: APPROVE

None of these block the merge. The two 🟡 guidance items (cli.md's search-first lookup text, and the "never appear" absolute) are cheap text edits and worth doing in this PR, because they cause the exact wasted-call and false-negative pattern this change exists to remove. The comment fix is a one-line correctness improvement.

@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: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

- references/cli.md: the "Find then update", "Find then delete" and
  relationship-create notes listed `nodespace search` first for locating
  a record. That reintroduced the search-miss-then-fallback pattern at the
  moment an agent reads the reference, which is while resolving a named
  record. Those notes now name `node query --title-contains` for lookup by
  name, and keep `search` for notes and documents.
- SKILL.md: "typed records never appear in it" contradicted the
  `search "" --type` listing row right above it. It now reads "a name
  search only matches prose", and the Delete example resolves with
  `--title-contains`.
- skill_rules.rs: corrected the stated reason that search misses
  entities. User-defined types ARE embedded. What hides them is the
  default `knowledge` scope (text/header/code-block/schema/table) with no
  title matching on the CLI path. Only tasks are genuinely unembedded.

Skipped: rewording the pre-existing "exact substring" note on
`node query`. It predates this PR, and the body sits at ~4986 of its 5000
token cap.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio

malibio commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (b84a9bb)

✅ Addressed (5)

  • 🟡 references/cli.md: the Find then update, Find then delete and relationship-create notes now use node query --title-contains for lookups by name, and keep search for notes and documents.
  • 🟡 SKILL.md: "typed records never appear in it" now reads "a name search only matches prose". This no longer contradicts the search "" --type listing row.
  • 🟡 skill_rules.rs doc comment: now gives the real reason. The default knowledge scope and the lack of title matching hide user-defined types; they are embedded. Only tasks are genuinely unembedded. I also posted a correction on Propagate entity resolution to the external agent surface: skill guidance, and whether a resolve verb should exist #2850, where I'd stated the wrong cause.
  • 🟢 The Delete example resolves with --title-contains.
  • 🟢 Prose types: covered by the "prose" wording. I didn't enumerate them, because of the size cap.

⏭️ Skipped (1)

  • 🟢 The "exact substring" wording on node query (SKILL.md:122) predates this PR, and the body is at ~4986 of its 5000-token cap. Worth revisiting if the body is ever restructured.

Verification:

  • SKILL.md prose is still verbatim-identical to NAMED_RECORD_RESOLUTION.prose.
  • nodespace-agent lib: 672 passed.
  • skill_md_generation: 12/12.
  • skill:check is clean.
  • The pre-push gate passed in full.

Re-review: not needed. These are text-only corrections to guidance and one doc comment, with no logic change, and the seed text and prompt golden are untouched.

@malibio
malibio merged commit 9848a99 into main Sep 23, 2026
@malibio
malibio deleted the issue-2850-external-entity-resolution branch September 23, 2026 04:54
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