Skip to content

Give the skill core type a strongly typed SkillNode model (closes #3101) - #3145

Merged
malibio merged 2 commits into
mainfrom
issue-3101-skill-node-model
Sep 27, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3101-skill-node-model

Conversation

@malibio

@malibio malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #3101. skill fields were decoded from the properties bag in five independent places, and each one guessed between the hoisted properties.skill.* shape and the flat shape. SkillNode is now the only thing that reads or writes them.

  • SkillNode (nodespace-types/src/skill.rs, re-exported as nodespace_core::models::SkillNode) has typed name, description, exclusion: Option<String>, tool_whitelist: Vec<String>, max_iterations: u32 and node_types: Vec<String>.
    • from_node / from_properties read either shape. The skill bucket wins, checked field by field.
    • They return an error for a wrong-typed field and for a non-positive max_iterations.
    • properties() / into_node write the flat shape, which the store then hoists.
  • Readers switched to it: SkillNodeBehavior::validate (its field checks are now the model's), get_embeddable_content and default_metadata, find_skills plus its exclusion rerank, SkillUpdater, and nodespace skill guidance in the CLI.
  • Deleted: skill_ops::SkillProperties and the unused nodespace_agent::props helpers.
  • Seeds: all 11 agent seeds and the Playbook skills are now built with NodeTemplate::skill(SkillNode::new(..).with_exclusion(..), guidance). Every measurement comment stays next to its field.

Why nodespace-types instead of core/models

The CLI is a gRPC client and has no runtime dependency on core. It still has to decode a skill's description, and core's Node is already nodespace_types::Node, so the model lives in the shared crate. Because of that, the seed constructor is NodeTemplate::skill(...) in core rather than SkillNode::template(...).

Behavior notes

  • find_skills now leaves out a skill whose properties fail to decode, with a warning. validate rejects that shape on write, so only a raw store write can produce one.
  • validate now also type-checks node_types.
  • The CLI's --json guidance description is "" when unset. It used to be null.

Verification

  • Seeds unchanged: I snapshotted title, type, root_properties, tier and the full guidance markdown of every seeded skill before and after the change. The two snapshots are byte-identical.
  • Live retrieval: live_skill_retrieval_stability.rs (ignored by default; needs the embedding model) passes 13/13 against the locked nomic GGUF.
  • Unit and integration: nextest across core, agent and cli ran 3213 tests, all passing. nodespace-types has 85 passing, including new round-trip tests for the flat, hoisted and mixed shapes.
  • The push check passed.

🤖 Generated with Claude Code

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #3145 (closes #3101)

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

Summary

This is a good consolidation. Skill fields were read in five separate places, each with its own logic, and now one model reads them. That model is SkillNode in nodespace-types, re-exported from core::models. It fixes the hoisted-vs-flat shape problem once, and it deletes SkillProperties and agent::props rather than leaving them behind. I checked the per-field "bucket wins, flat falls back" precedence against the write path, and it is sound. update_node runs normalize_flat_properties_to_namespace on the patch before deep_merge (crud.rs ~L905-917), and that function moves every non-_ key into the bucket. So a stored node never holds a newer value at the flat level than in the bucket. The changes to validation only make it stricter and keep it consistent: node_types is now type-checked, and max_iterations must fit in a u32. I found no blockers, just one leftover reader and two robustness points.

Requirements Check

  • ✅ SkillNode with from_node / into_node and round-trip tests, including the hoisted properties.skill.* shape (round_trips_through_the_hoisted_storage_shape, hoisted_field_wins_over_flat_per_field, null_skill_bucket_falls_back_to_flat)
  • ⚠️ No skill field read from the properties bag outside SkillNode: all production code complies. One leftover is in a CLI example binary (see 🟡 Set up Tauri + Svelte project structure #1). The raw read in the node_service test (mod.rs:8541) is intentional, because that test asserts the storage path.
  • ✅ skill_ops::SkillProperties deleted, and agent::props too
  • ✅ Seeds construct skills through a typed API (NodeTemplate::skill(SkillNode::new(..)...), used in both skill_pipeline.rs and methodology/skills.rs)
  • ✅ live_skill_retrieval_stability.rs still passes. The author reports 13/13 against the real model and a byte-identical before/after snapshot of the seeds. The one seed exclusion has no surrounding whitespace, so trimming it does not change the text.

Code Review Findings

🟡 [Improvement] One raw skill read is left in the doc generator
📁 packages/cli/examples/gen_skill_md.rs:455
skill.root_properties["description"].as_str().unwrap_or("") is exactly the kind of hand-written reader the issue removes. It reads the flat shape only and silently returns "" on a mismatch. nodespace-core is already a dev-dependency of the CLI, so replace it with SkillNode::from_properties(&skill.title, &skill.root_properties) and panic on a decode failure, as the test helpers do. Principle: DRY / single source of truth. This is the last place the "silently read as empty" failure mode can happen.

🟡 [Improvement] SkillUpdater now writes every config field, not just description
📁 packages/core/src/ops/skill_updater.rs:~161-185
Before this PR it sent {"description": ...}. Now it sends skill.properties(), which is description + tool_whitelist + max_iterations (+ exclusion/node_types), through update_node_unchecked with no version check. That creates a lost-update window: if a user or agent edits the Node Creation skill's tool_whitelist or max_iterations between the query_nodes_simple read and this write, the updater overwrites that edit with the older values. It also writes the default max_iterations into the node if the node never set one. The value is equivalent, but the write set is larger than the intent. Consider a narrow patch built through the model, for example a SkillNode::description_patch(&str) -> Value, or pass the read version to a checked update. Principle: minimal write set, and avoid unguarded read-modify-write on unrelated fields. Low probability, since this runs on schema change, but it is a regression in guarantees.

🟡 [Improvement] No test for the new "skip a malformed skill" path
📁 packages/core/src/ops/skill_ops.rs:~568-580 (find_skills), also rerank_with_exclusions (.ok()) and the SkillUpdater early return
This is a real behavior change. Before, a skill that failed to decode got empty/default tools. Now it is dropped from the results with a warn!. Dropping it is the right choice, because guessing a tool set is worse. But only a raw store write can reach this branch, and nothing exercises it. Add a unit test that puts a skill with, say, tool_whitelist: "x" next to a valid skill and asserts the valid one is still returned. That keeps a future refactor from turning the continue into a ?, which would let one bad node break skill search for every turn. Principle: test the error paths a change introduces.

🟢 [Nit] The default lives in two places
📁 packages/nodespace-types/src/skill.rs:9 and packages/core/src/models/core_schemas.rs (max_iterations default json!(2))
DEFAULT_SKILL_MAX_ITERATIONS says "the core schema's default", but the schema hard-codes 2 separately. Use the constant in core_schemas.rs (json!(DEFAULT_SKILL_MAX_ITERATIONS)) so the two cannot drift apart.

🟢 [Nit] CLI JSON output changed slightly
📁 packages/cli/src/commands/skill.rs:522
guidance --json used to emit "description": null when the field was absent. It now emits "", and also "" when decoding fails. That is fine, since there are no users and a stable string type is arguably better. Mention it in the PR body, because it is a contract change on the JSON surface.

🟢 [Nit] Comment wording in get_embeddable_content
📁 packages/core/src/behaviors/mod.rs:~1988
"embed its name" is correct, since it falls through to the desc.is_empty() branch. But .unwrap_or_default() quietly hides the decode failure. A debug! on the Err arm would make an in-memory malformed node visible when debugging retrieval scores. Optional.

🟢 [Positive] Architecture and placement
Putting the model in nodespace-types so the gRPC-only CLI can decode skills without a runtime dependency on core is the right call. It is a narrow typed model with no I/O, so it fits a shared-types crate. NodeTemplate::skill using ..NodeTemplate::skill(...) in methodology/skills.rs to override tier is tidy. Moving the long exclusion rationale comment onto the builder chain keeps the "why" next to the value. There are no issue numbers in comments, and nothing uses #[allow] or #[deprecated].

Recommendation: APPROVE

All acceptance criteria in production code are met, the precedence logic is correct against the actual write path, and the change clearly improves code health. Before merge, I recommend fixing the gen_skill_md.rs reader (one line, and it finishes AC #2) and narrowing the SkillUpdater write set. The malformed-skill test is also strongly suggested.

@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 27, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (53717b8)

✅ Addressed

  • 🟡 SkillUpdater write set: it now sends only SkillNode::description_patch(..). It no longer writes the full config, so a concurrent edit to tool_whitelist or max_iterations survives, and no default gets written onto the node.
  • 🟡 gen_skill_md.rs raw read: it now reads through SkillNode::from_properties and panics on a decode failure. --check reports SKILL.md up to date.
  • 🟡 Malformed-skill path: added find_skills_skips_a_malformed_skill_and_keeps_the_rest.
    • The test creates two skills and first asserts that both are returned.
    • It then corrupts one with a raw store write and asserts the valid one is still returned and the malformed one is not.
    • I checked that it fails when the continue is replaced with a fallback skill.
  • 🟢 Schema default: the max_iterations default in core_schemas.rs now uses DEFAULT_SKILL_MAX_ITERATIONS.

⏭️ Skipped

  • 🟢 JSON null → "": the PR body already mentions this.
  • 🟢 debug! on get_embeddable_content decode failure: validation blocks that shape on write, so the log would almost never fire.

Re-review: NO RE-REVIEW NEEDED. The changes are small and low-risk: one narrowed patch, one read switched to the typed model, one constant, and a test that I confirmed fails on the mutant.

malibio and others added 2 commits September 27, 2026 17:04
Skill fields were decoded ad hoc from the properties bag in five places,
each guessing between the hoisted `properties.skill.*` shape and the flat
one. `SkillNode` (nodespace-types, re-exported from core::models) is now the
only reader and writer:

- from_node / from_properties decode either shape, preferring the `skill`
  bucket per field, and reject wrong-typed fields
- SkillNodeBehavior::validate and get_embeddable_content, find_skills,
  SkillUpdater and `nodespace skill guidance` all read through it
- skill_ops::SkillProperties and the unused agent::props helpers deleted
- Seeds build skills via NodeTemplate::skill(SkillNode::new(..)); the seeded
  templates are byte-identical to before (verified by snapshot diff)

Lives in nodespace-types rather than core so the CLI, a gRPC client with no
runtime core dependency, can decode skill fields too.

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

- SkillUpdater writes only the description (SkillNode::description_patch)
  instead of the whole config, so a concurrent edit to tool_whitelist or
  max_iterations is not clobbered and no default is written onto the node
- gen_skill_md reads Playbook skill descriptions through SkillNode
- core schema's max_iterations default uses DEFAULT_SKILL_MAX_ITERATIONS
- New test: find_skills drops a malformed skill (planted by raw store write)
  and still returns the valid one; verified it fails when the skip is
  replaced by a fallback

Skipped: debug! on get_embeddable_content's decode failure (validate blocks
that shape on write; negligible diagnostic value). The JSON null -> "" note
was already in the PR body.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3101-skill-node-model branch from 53717b8 to 8dc7802 Compare September 27, 2026 15:13
@malibio
malibio merged commit d40c59d into main Sep 27, 2026
@malibio
malibio deleted the issue-3101-skill-node-model branch September 27, 2026 15:13
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.

Give the skill core type a strongly typed SkillNode model instead of ad-hoc property-bag readers

1 participant