Skip to content

Skill exclusion text: penalize retrieval score on what a skill is not for (closes #2268, closes #3076) - #3105

Merged
malibio merged 2 commits into
mainfrom
issue-3076-remove-resolved-routing
Sep 27, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3076-remove-resolved-routing

Conversation

@malibio

@malibio malibio commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Closes #2268, closes #3076.

Problem

"remove the resolved tickets" ranked Graph Editing 0.855 > Node Deletion 0.841 in Stage-2 retrieval on Graph Editing's "mark it resolved". delete_node is offered only from the winning candidate, so the deletion was silently withheld. On the production stack, E4B found both tickets and replied "node search completed" without deleting anything.

The request differs from "mark incident resolved" only in the verb, which the embedding barely weights. About 30 description and title rewordings were swept: every one that lowered Graph Editing on the deletion request lowered it by the same amount on the completion-state guards. The best left "mark incident resolved" 0.003 from falling out of the top 3. Measurements are in #2268.

Change

A skill may carry an optional exclusion, a new core skill schema field describing what the skill is not for. find_skills:

  • embeds the query once and shares it across the skill search, the schema search and exclusion scoring
  • scores a pool larger than the registry (SKILL_RERANK_POOL), because a penalty can promote a skill from below the K cut
  • embeds each exclusion in the description's own name\n\ntext shape and applies a margin penalty: score − 1.0 · max(0, exclusion_score − score)
  • re-ranks, then truncates to K; routing's score bars read the adjusted score

The margin form means a query closer to the description than to the exclusion keeps its score exactly. Plain subtraction would lower the skill on every query and push it through the score bars.

Graph Editing is seeded with "Remove them, delete them, get rid of them, purge them.". The composite-score formula and a cosine helper are shared from the store so the exclusion is scored on the same scale as the KNN results.

Measured (locked nomic model, full seeded registry)

before after
remove the resolved tickets Graph Editing #1 (−0.014) Node Deletion #1, +0.047
remove the closed/done/completed/paid… Node Deletion #1 Node Deletion #1, wider margins
every completion-state request — Graph Editing score unchanged (pinned by test)
remove the due date from the launch task Graph Editing 0.800 0.791, still top 3 (the one measured cost)

The exclusion wording matters. Two longer phrasings also lowered "mark the outage report done" or "record that we decided to use Postgres" by 0.02–0.035. Embedding the exclusion bare (without the name) lowered completion requests too. So exclusions are pinned to measured skills (only_measured_skills_carry_an_exclusion).

Tests

  • New live tests (live_skill_retrieval_stability.rs):
    • remove_requests_mentioning_a_state_route_node_deletion: rank 1 on every rep
    • removing_a_field_still_reaches_graph_editing
    • graph_editing_exclusion_leaves_completion_state_scores_unchanged: identical scores with and without the exclusion, not just the same rank
  • "remove the resolved tickets" added to deletion_requests_mentioning_resolved_route_node_deletion
  • All 13 live retrieval tests pass
  • Unit tests: penalty math (inert below the margin), blank exclusion treated as absent, skill schema field, measured-skills pin
  • cargo nextest for core/agent/cli: 3190 run, all pass after bun run skill:gen (the CLI help text now lists exclusion)

Related, filed separately

🤖 Generated with Claude Code

@malibio

malibio commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #3105

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

Summary

A small, well-contained change. exclusion is scored at query time against the already-computed query vector. It uses the same name\n\ntext shape and the same composite scale as the KNN results, and a margin penalty that has no effect on the requests the skill serves. That design avoids stale-embedding bookkeeping: editing an exclusion never needs a re-index. The query is now embedded once instead of twice, which is a small net performance gain. Seed reconciliation, CLI help, the generated skill reference and prompt-skill-system.md are all updated. I found no blockers. The findings below are suggestions about test precision and one doc overclaim.

Requirements Check

#2268 (exclusion mechanism)

  • ✅ Optional exclusion property on skill nodes, embedded as a separate vector. It is a core schema field, validated in SkillNodeBehavior (string or null), and decoded in SkillProperties with blank treated as absent. It is embedded per query rather than stored in vec0. That is a deliberate and better trade (no staleness when edited), and the LRU cache in EmbeddingService (keyed by prefixed text, capacity 10k) makes it a one-time cost.
  • ✅ Retrieval applies the margin penalty, and the score bars read the adjusted score. rerank_with_exclusions filters on SKILL_SEARCH_THRESHOLD after the penalty, and the adjusted value is what confidence carries into routing.
  • ✅ Graph Editing is seeded with the deletion-verb exclusion, and no other skill has one. This is pinned by only_measured_skills_carry_an_exclusion.
  • ✅ "remove the resolved tickets" routes to Graph Editing, silently withholding delete_node #3076's phrasings rank Node Deletion first on every rep. Covered by remove_requests_mentioning_a_state_route_node_deletion (6 phrasings × REPS).
  • ✅ Guard: "remove the due date from the launch task" keeps Graph Editing in the top 3. Covered by removing_a_field_still_reaches_graph_editing.
  • ✅ All existing live retrieval tests pass (13/13, as reported by the author).
  • ✅ Test that the exclusion changes no completion-state score. graph_editing_exclusion_leaves_completion_state_scores_unchanged covers it; see 🟢 Set up Tauri + Svelte project structure #1 for a precision caveat.

#3076 (the failing case)

  • ✅ "remove the resolved tickets" ranks Node Deletion first on every rep, plus 2–3 similar phrasings.
  • ✅ Added to deletion_requests_mentioning_resolved_route_node_deletion, with a sibling rank-1 test.
  • ✅ All existing live retrieval tests pass.

Existing installs: compute_seed_version hashes the root properties, so adding exclusion changes config_version. Reconciliation then replaces root properties on unmodified seeded nodes (node_service/mod.rs ~L1970). Nodes a user has edited (config_modified) are skipped, as ADR-072 intends. No data migration is involved. ✅

Code Review Findings

🟢 1. The score-invariance test compares 3-decimal strings and could pass vacuously

📁 packages/agent/tests/live_skill_retrieval_stability.rs (new graph_editing_exclusion_leaves_completion_state_scores_unchanged)

let a = graph_editing(scored_ranking(&with, &with_ns, query, 8).await);
let b = graph_editing(scored_ranking(&without, &without_ns, query, 8).await);
if a != b { changed.push(query); }

scored_ranking formats confidence with {:.3}, so a penalty below about 0.0005 would be rounded away. The doc comment promises "identical scores — not merely the same rank", and this is the guard for that property. Also, if Graph Editing fell out of both top-8 lists, None == None would pass silently. With 8 seeded skills and a threshold of 0.0 this is unlikely today, but it is free to rule out.
Recommendation: Read the raw confidence f64 from find_skills for Graph Editing. Assert is_some() for both arms and compare exactly, or within 1e-9.
Principle: A test should fail for the exact property it names.

🟢 2. The SKILL_RERANK_POOL doc claims "exact" promotion, which only holds under conditions it doesn't state

📁 packages/core/src/ops/skill_ops.rs (the SKILL_RERANK_POOL doc comment, plus its use at ~L558)
The rerank is exact only if (a) the registry has at most 20 skills and (b) every skill root survives the typed KNN window. search_embeddings_by_node_type filters node_type after a global top-k over all chunks. That k is now 20 × 10 × 5 = 1000, up from 150 at the default limit of 3. In a large corpus, a skill can still be crowded out before reranking. This is a pre-existing recall limit and the larger k helps it, but the comment reads as a guarantee.
Performance: the vec0 cost is dominated by the brute-force scan, not k. Hydration is one batched get_nodes_by_ids of at most 20 rows. The impact is negligible, and embedding the query once instead of twice more than pays for it.
Recommendation: Change "makes that promotion exact" to something like "…exact for registries up to this size whose skills all survive the typed KNN window".
Principle: Comments should state the conditions an invariant depends on, not an unconditional guarantee.

🟢 3. Scale mismatch for multi-chunk skill descriptions (edge case, user-authored skills only)

📁 packages/core/src/ops/skill_ops.rs (rerank_with_exclusions: composite_similarity_score(cos, 1, 1))
The exclusion is always scored as a fully-matching single chunk, which gives a ×1.3 density boost. That matches a seeded skill, whose name\n\ndescription fits in one chunk. A user skill with a description long enough to chunk would get max_sim × (1 + 0.3 × matching/total) from the store, which can be below ×1.3. Its exclusion would then be over-weighted relative to its description score.
Recommendation: No change needed now. Seeded exclusions are the only ones, and the pin test enforces that. Mention the assumption in the inline comment ("assumes a single-chunk description"), so that #3101 or a future user-exclusion path picks it up.
Principle: Make implicit assumptions explicit where they are relied on.

🟢 4. The exclusion embedding runs synchronously inside the async find_skills

📁 packages/core/src/ops/skill_ops.rs (rerank_with_exclusions)
On a cache miss, llama inference blocks the tokio worker. This follows the existing pattern (query embedding was already synchronous here), and the LRU makes it a one-time cost per exclusion text. Heavy bulk indexing can evict the entry, which costs one extra embed of about 10 ms. No action needed. I'm noting it only because each future exclusion-bearing skill adds one more potential miss per query.

Nits

  • Nit: skill_ops.rs: SkillProperties::from_node_properties is now decoded twice for returned skills, once in the rerank and once in the result loop. It's trivial, but carrying the decoded struct through skill_results would remove the exclusion: _ destructure and its comment.
  • Nit: exclusion_penalty_lowers_by_the_weighted_margin recomputes the expected value with the same formula as the implementation, so it's partly tautological. A literal expected value (0.81) reads more clearly.
  • Nit: The warn in rerank_with_exclusions fires on every query when the exclusion fails to embed. That is acceptable, since query embedding would almost certainly have failed first.

Standards Check

  • No lint suppression, no backward-compat or migration code, no #[allow(dead_code)]. ✅
  • No issue numbers in code comments or docs added by this diff. ✅
  • Docs: nodespace-docs/architecture/prompt-skill-system.md already documents exclusion, the margin formula, and the "measured only" policy. ✅
  • Error handling: a failed exclusion embed falls back to the unpenalized score with a warn. That is the right choice, because the ranking degrades to its pre-feature state rather than failing the search. ✅
  • Sorting: sort_by is stable, ties keep KNN order, and NaN maps to Equal. ✅

Recommendation

APPROVE. The change fixes the failing case with a measured, well-guarded mechanism, keeps the blast radius to one seeded skill, and does not change the semantics of any request a skill serves. Findings 1 and 2 are cheap and worth doing, but they are not blocking.

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

@malibio

malibio commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (aba2192)

✅ Addressed

  • 🟢1: the invariance test now compares raw f64 confidences and requires Graph Editing to be present on both sides. Scores are bit-identical with and without the exclusion on all 7 completion-state requests (e.g. 0.8369406849 vs 0.8369406849 on "mark the outage report done").
  • 🟢2: the SKILL_RERANK_POOL doc now states when promotion is exact: registry within the pool, all skills surviving the typed KNN window.
  • 🟢3: added an inline note on the single-chunk density assumption in rerank_with_exclusions.
  • Nit: the weighted-margin unit test asserts the literal 0.81.

⏭️ Skipped

🧪 Live retrieval suite 13/13, penalty unit tests 8/8, push check passed.

Re-review: not needed. The changes are test precision, comments and one test literal. No production logic changed.

malibio and others added 2 commits September 27, 2026 07:42
… for (closes #2268, closes #3076)

"remove the resolved tickets" ranked Graph Editing (0.855) above Node
Deletion (0.841) on Graph Editing's "mark it resolved", and since
delete_node is offered only from the winning candidate, the deletion was
silently withheld. The request differs from "mark incident resolved" only
in the verb, which the embedding barely weights: every description
rewording that lowered Graph Editing on one lowered it equally on the
other.

A skill may now carry an optional `exclusion` (core skill schema field).
find_skills embeds it in the description's own name+text shape, scores
it against the query, and applies a margin penalty:

  score - 1.0 * max(0, exclusion_score - score)

A query closer to the description than to the exclusion keeps its score
exactly, so the exclusion costs a skill nothing on requests it serves;
plain subtraction would lower it everywhere and through the routing
score bars, which read the adjusted score. find_skills scores a pool
larger than the registry before truncating to K, since a penalty can
promote a skill from below the cut. The query is embedded once and
shared by the skill search, the schema search and exclusion scoring.

Graph Editing is seeded with "Remove them, delete them, get rid of them,
purge them." Measured on the locked model: Node Deletion first on
"remove the resolved tickets" by +0.047; all completion-state scores
unchanged; one cost, "remove the due date from the launch task" -0.009
(still top 3). Longer phrasings also lowered unrelated updates by
0.02-0.035, so exclusions are pinned to measured skills.

Live guards: remove_requests_mentioning_a_state_route_node_deletion,
removing_a_field_still_reaches_graph_editing,
graph_editing_exclusion_leaves_completion_state_scores_unchanged; "remove
the resolved tickets" added to the resolved rank-1 test. All 13 live
retrieval tests pass.

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

- graph_editing_exclusion_leaves_completion_state_scores_unchanged now
  compares raw f64 confidences and requires Graph Editing present on both
  sides; the 3-decimal ranking strings hid penalties below 0.0005 and let
  None == None pass. Scores are bit-identical with and without the
  exclusion on all seven completion-state requests.
- SKILL_RERANK_POOL's doc states when promotion is exact (registry within
  the pool, all skills surviving the typed search's KNN window).
- rerank_with_exclusions notes the single-chunk assumption behind scoring
  an exclusion at full density.
- The weighted-margin unit test asserts a literal (0.81), not the formula.

Skipped: double SkillProperties decode (the typed SkillNode follow-up
replaces that decoder); synchronous exclusion embedding and the per-query
warning on embed failure (reviewer: no action; cached, and the query
embedding would fail first).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3076-remove-resolved-routing branch from aba2192 to e61ebdf Compare September 27, 2026 06:11
@malibio
malibio merged commit 7591ade into main Sep 27, 2026
@malibio
malibio deleted the issue-3076-remove-resolved-routing branch September 27, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant