Skip to content

Seeded content never reaches an existing install: replace type-level skip with per-node versioned re-seed - #1818

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1812-per-node-reseed
Jul 30, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1812-per-node-reseed

Conversation

@malibio

@malibio malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #1812

Seeded prompt/skill/tool nodes now carry a `_seed` object (key, content-hash
version, system/starter tier) so a template content change reaches an
already-seeded database on next start instead of being permanently frozen by
the first node of that type. System-tier content always replaces on hash
mismatch; starter-tier content replaces until the user edits it, then is
skipped and logged once. `_seed` is nested under a single object key so core
schema types (prompt, skill) don't hoist its contents into their own
properties namespace on write.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This is a well-targeted fix for a real measurement-integrity bug (#1812): the type-level seed skip meant any change to seeded skill/prompt/tool content was permanently frozen after first install. The replacement — per-node reconciliation keyed by _seed.key, with system/starter tiers and a content hash — is the right shape for the problem, and the namespace-hoisting workaround (nesting the bookkeeping under one object-valued _seed key so normalize_flat_properties_to_namespace treats it as a dormant namespace) is a genuinely clever, well-explained fix for a real interaction with the schema-governed property normalizer. Code compiles cleanly, no new dependencies, all 4 new tests pass.

The main gap is that the mechanism the PR is built around — _seed surviving namespace hoisting — is only tested against prompt, the one seeded type whose schema has zero fields and therefore is least likely to exercise the hoisting path meaningfully. skill (real schema fields: description, tool_whitelist) and tool (pre-namespaced flat properties, a second normalization mechanism) are never exercised by the reconciliation tests, despite being explicitly called out as required checks in this review's scope and being exactly the cases the design doc comments reason about. There's also a real, if low-probability and low-blast-radius, correctness gap in set_property_bool's OCC bypass, and a stable-ID loss on the "replace" path that's worth a documented tradeoff even if not fixed now. None of these rise to blocking severity given this is pre-release, internal engineering content with no external references today — but they should be tracked.

Requirements Check

  • ✅ Seeded nodes carry seed_version (content hash) and a tier marker — _seed.version / _seed.tier, stamped in prepare_nodes_from_template (packages/core/src/markdown/mod.rs).
  • ✅ Reconciliation is per-node; the type-level skip is deleted — seeded_types HashSet skip logic is gone; packages/core/src/services/node_service/mod.rs seed_nodes_from_templates now keys off _seed.key per node.
  • ✅ A system-tier content change reaches an already-seeded DB on next start — verified by test — reseed_replaces_system_tier_node_on_content_change.
  • ✅ A user-edited starter node survives re-seeding — verified by test — reseed_skips_user_modified_starter_tier_node.
  • ✅ An unedited starter node is updated — verified by test — reseed_updates_unmodified_starter_tier_node.
  • 🟡 Reconciliation cost is bounded and does not measurably affect startup — the doc comment's claim ("one query per distinct node_type... bounded by the number of seeded types") matches the code (one query_nodes call per entry in the root_types HashSet), but this is asserted, not benchmarked. Acceptable given the tiny seeded-type count (3) and no measurable-startup-impact requirement being test-enforced either way.
  • ✅ Per the pre-release stance: no migration path, no dual-mode — confirmed; existing DBs converge purely via hash mismatch on next seed_nodes_from_templates call, no version-gated migration code added.

Findings

Critical Issues

None. No security, data-loss-on-the-happy-path, or architectural-regression issues found.

Suggested Improvements

  • 🟡 packages/core/src/services/node_service/mod.rs (new tests, ~L4149-4291): All 4 reconciliation tests use seed_template(), hardcoded to root_node_type: "prompt" — the one seeded type with an empty core schema (fields: vec![] in core_schemas.rs), so normalize_flat_properties_to_namespace barely exercises the hoisting logic for it. Neither skill (real schema fields: description, tool_whitelist — this is the type whose hoisting risk this PR's own doc comments call out by name) nor tool (pre-namespaced flat properties, a second, independent mechanism for reaching a stable namespace) is covered by any test that asserts _seed actually survives to properties._seed after going through create_node's real normalization path. This is exactly the scenario the review brief flagged as needing verification, and I confirmed by inspection that it does work (_seed is object-valued and not a schema field name, so normalize_flat_properties_to_namespace correctly treats it as a dormant namespace for skill; for tool, the pre-existing "tool": {...} key already trips the early-return "already namespaced" branch, so _seed alongside it is untouched) — but this is currently proven only by reading the code, not by any test. Given this is the load-bearing mechanism of the whole PR, add at least one reconciliation test using root_node_type: "skill" with non-empty schema-shaped properties, and ideally one exercising the real seed_tool_nodes()/seed_skill_nodes() production templates end-to-end (similar to skill_pipeline.rs's existing full_daemon_seed_inserts_all_tool_nodes test) asserting _seed round-trips correctly for all three real seeded types.

  • 🟡 packages/core/src/services/node_service/crud.rs (~L943-971, update_node): set_property_bool bypasses OCC entirely (no version check, no version bump on the _seed.user_modified stamp). Walking the sequence: (1) get_node pre-check reads _seed.tier/user_modified with no lock, (2) the version-checked UPDATE applies the caller's edit and bumps version, (3) set_property_bool issues a second, separate, version-blind UPDATE ... SET properties = json_set(properties, '$._seed.user_modified', true) WHERE id = ?. Between (2) and (3) a concurrent writer could apply its own version-checked update (bumping the version again); (3) will still succeed unconditionally and graft the flag onto whatever properties currently exists, without bumping version itself. Net effect: the node's version column undercounts the true number of property mutations, so a client that polled/cached version after step (2) won't know a further write landed in step (3), and if a concurrent writer's edit cleared _seed for some reason, json_set will silently recreate a bare _seed.user_modified object without the sibling key/tier/version fields. This is a narrow window (only matters if update_node races another update_node on the exact same starter-tier node within milliseconds) and the blast radius is metadata-only (never corrupts content), so it's not blocking, but it's worth a short doc-comment caveat on set_property_bool and/or update_node acknowledging the bypass is intentionally best-effort, matching how the tracing::warn! on failure already treats it as non-fatal.

  • 🟡 packages/core/src/services/node_service/mod.rs (reconciliation loop, "replace" path) + packages/core/src/markdown/mod.rs (prepare_nodes_from_template, let root_id = uuid::Uuid::new_v4()): confirmed that prepare_nodes_from_template assigns a fresh random UUID on every call, so a "replace" (delete old subtree, recreate via the same insert path) gives the re-seeded skill/prompt/tool a new node ID every time its content changes. Today nothing appears to reference these nodes by stable ID across replaces (tool_whitelist in skill properties references tools by name/handler string, not node ID; search_skills presumably discovers by embedding/type, not ID) so this is currently safe. But it is a latent trap: any future feature that stores a direct node-ID reference to a skill/prompt/tool (a mentions edge, a saved conversation's tool-call provenance, a UI pin) will silently break across a system-tier content update. Worth a one-line doc comment on the "replace" branch calling this out explicitly as a known constraint, so a future author doesn't need to rediscover it by reading prepare_nodes_from_template.

Nitpicks

  • 🟢 Nit: packages/core/src/services/node_service/mod.rs (reconciliation loop): on the replace path, self.delete_node(&existing_node.id, existing_node.version).await? propagates via ?, aborting the entire remaining batch on any single version conflict — consistent with the pre-existing all-or-nothing semantics skill_pipeline.rs's full_daemon_seed_inserts_all_tool_nodes test comment already documents for template validation failures, so not a new pattern, but now also applies to a delete-then-recreate step. Given system-tier nodes aren't supposed to be concurrently user-edited, this is low risk, but a per-group Result accumulation (log-and-continue rather than abort-the-batch) would make one broken template less able to starve all the others of reconciliation.
  • 🟢 Nit: packages/core/src/markdown/mod.rs compute_seed_version: hashes node_type + content + properties for every node in the group including children, but not parent_id/order-derived structure beyond insertion order in the nodes vec (which is documented as intentional and correct) — just flagging that reordering two children with identical content/type between template versions would not register as a hash change, but this is a non-issue in practice since content differs across your actual seeded templates.
  • 🟢 Nit: packages/core/src/db/sqlite_store/nodes.rs set_property_bool doc comment says "Set a boolean value at a JSON path" — consider naming the method or doc more explicitly as "bypasses OCC, best-effort, logged-not-propagated on failure by convention" so a future caller outside update_node doesn't assume it's safe to use for anything version-sensitive.

Recommendation: COMMENT

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

See detailed comment above.

…ass and ID-churn tradeoffs

- Add reseed tests for skill (real schema fields, exercises namespace
  hoisting) and tool (pre-namespaced properties) node types, plus a
  mixed-batch test — the existing tests only covered prompt, whose empty
  schema never exercises the hoisting path the whole fix depends on.
- Document set_property_bool's OCC-bypass as intentionally best-effort,
  safe only for idempotent values (crud.rs, nodes.rs).
- Document that the replace path assigns a fresh UUID rather than reusing
  the deleted node's ID — safe today since nothing references seeded
  content by stable ID, called out as a latent trap for future features.

Addresses reviewer recommendations from PR #1818 review.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed review feedback

All 3 🟡 suggestions from the initial review were addressed (none were skipped):

  • ✅ Test coverage gap: added reseed_replaces_skill_tier_node_with_real_schema_fields (proves _seed survives namespace hoisting for a type with real required schema fields — prompt, used by every prior test, has an empty schema and never exercised this), reseed_replaces_tool_tier_node_with_pre_namespaced_properties (proves _seed coexists with the pre-existing "tool" namespace), and reseed_handles_mixed_node_types_in_one_batch_independently (proves a mixed prompt+skill batch, as the daemon actually sends, doesn't cross-contaminate reconciliation between types).
  • ✅ set_property_bool OCC-bypass: documented as intentionally best-effort in both the helper's doc comment (nodes.rs) and its call site (crud.rs) — safe because _seed.user_modified is idempotent (setting true twice is a no-op), so the only possible harm from the race window is an undercounted version column, never lost content.
  • ✅ Replace-path ID churn: documented that "replace" assigns a fresh UUID rather than reusing the deleted node's ID — safe today (nothing references seeded content by stable ID) but flagged as a latent trap for future features.

New commit: feb1e38. All 1042 nodespace-core + 314 nodespace-agent lib tests pass, cargo clippy -D warnings clean, full pre-push gate (including Tauri-seam e2e tests) passed on push.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: All changes are additive (new tests) or doc-comment-only — no logic changes to the reconciliation algorithm, set_property_bool, or the replace path itself. The reviewer's recommendation was COMMENT (non-blocking) with no critical issues; these were coverage/clarity improvements, not corrections to defects. Ready for merge pending final review.

@malibio
malibio merged commit 06a94ee into main Jul 30, 2026
2 checks passed
@malibio
malibio deleted the worktree-issue-1812-per-node-reseed branch July 30, 2026 07:34
malibio added a commit that referenced this pull request Jul 30, 2026
…inference test

Fixes two Important findings from the PR review:

1. seed_core_schemas_if_needed() gated the entire schema-seeding batch on a
   single task_exists check — the exact type-level skip pattern #1818 (06a94ee)
   eliminated for seeded content, just one abstraction level up. On any
   pre-existing dev database, the new agent-guidance schema node introduced by
   this PR would never be created, silently orphaning it. Now checks each core
   schema individually and creates only what's missing, so a schema added after
   a database's first run still reaches that database on the next start.
   Covered by a new test that deletes agent-guidance post-seed, reopens the
   same DB file (mirroring a daemon restart), and confirms it's recreated
   without touching the already-present task schema.

2. No test exercised seed_skill_nodes()'s real templates through the actual
   child_node_type: None inference path and asserted on the resulting
   children's node_type — the literal claim of this PR's item 1. Added a test
   that runs every seeded skill through prepare_nodes_from_template and
   confirms children are header/text (never prompt), with at least one header
   node per skill (every seed's guidance starts with a markdown heading).
   Verified both new tests fail against the pre-fix code and pass against the
   fix, by temporarily reverting each in isolation and confirming the failure
   before restoring.

Suggestions from the same review (markdown_test.rs's inert "prompt" placeholder
strings, core_schemas.rs's longer doc comment, props.rs's doc-example swap,
the reconciliation test's count/comment update) were left as-is per the
reviewer's own assessment that none warranted a change.

Co-Authored-By: Claude <[email protected]>
malibio added a commit that referenced this pull request Jul 30, 2026
… type; expose skill in nav (#1824)

* Skill guidance becomes real markdown children; retire prompt type for agent-guidance (closes #1699)

seed_skill_nodes() no longer routes children through child_node_type: Some("prompt")
— they now come out as ordinary header/text nodes via markdown type inference,
consistent with every other markdown-ingested document in NodeSpace.

The prompt schema/behavior is retired, but PromptAssembler's base-system-prompt
override nodes had a live, every-turn consumer keyed on node_type == "prompt",
so this introduces a purpose-named agent-guidance schema in its place rather
than leaving that lookup with no valid identity. agent-guidance carries no
discovery metadata (unlike skill, which is matched via search_skills) — it's
simply fetched by type, same mechanism prompt used, just named for what it is.
NON_EMBEDDABLE_CONTAINER_TYPES and its parity test were updated in lockstep so
embeddability stays correctly gated.

The subtree-render consolidation and SIDENAV_CORE_TYPES nav exposure from this
issue's remaining scope already shipped in #1755.

Co-Authored-By: Claude <[email protected]>

* Address review: per-schema seed reconciliation + skill-children type-inference test

Fixes two Important findings from the PR review:

1. seed_core_schemas_if_needed() gated the entire schema-seeding batch on a
   single task_exists check — the exact type-level skip pattern #1818 (06a94ee)
   eliminated for seeded content, just one abstraction level up. On any
   pre-existing dev database, the new agent-guidance schema node introduced by
   this PR would never be created, silently orphaning it. Now checks each core
   schema individually and creates only what's missing, so a schema added after
   a database's first run still reaches that database on the next start.
   Covered by a new test that deletes agent-guidance post-seed, reopens the
   same DB file (mirroring a daemon restart), and confirms it's recreated
   without touching the already-present task schema.

2. No test exercised seed_skill_nodes()'s real templates through the actual
   child_node_type: None inference path and asserted on the resulting
   children's node_type — the literal claim of this PR's item 1. Added a test
   that runs every seeded skill through prepare_nodes_from_template and
   confirms children are header/text (never prompt), with at least one header
   node per skill (every seed's guidance starts with a markdown heading).
   Verified both new tests fail against the pre-fix code and pass against the
   fix, by temporarily reverting each in isolation and confirming the failure
   before restoring.

Suggestions from the same review (markdown_test.rs's inert "prompt" placeholder
strings, core_schemas.rs's longer doc comment, props.rs's doc-example swap,
the reconciliation test's count/comment update) were left as-is per the
reviewer's own assessment that none warranted a change.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
mstomar125 added a commit that referenced this pull request Sep 10, 2026
…essions (#2559)

* Add fetch-at-activation guidance mechanism for external agent skill sessions

Implements the two unbuilt pieces #2532 tracked for issue #1958's fetched,
hybrid-shaped delivery-channel decision:

- `nodespace skill guidance <query>` (packages/cli) fetches procedural
  guidance from the graph's seeded `skill` nodes via the existing
  NodeService.SearchNodes RPC (node_type=skill, subtree markdown attached),
  wrapping every result in a provenance marker -- a `GRAPH-FETCHED
  GUIDANCE` banner in human mode, a `"provenance": "graph-fetched"`
  envelope in `--json` -- so fetched content is never silently
  indistinguishable from the skill's own static instructions.
- SKILL.md's body gains a `## Graph-Authored Guidance (Fetched)` section
  instructing an activated agent to run this command before a nontrivial
  operation, and a new on-demand reference
  (references/graph-authored-guidance.md) spells out the trust boundary:
  fetched content can supply procedure, never permission, and any fetched
  instruction that tries to skip a confirmation or claims system/developer
  authority is itself the signal of a compromised graph entry.
- The new reference file is wired through every place that ships
  packages/skill's reference tier: all five installer targets'
  `shims` lists (agents.ts), the PTY-spawned-agent path's embedded
  reference tier (context_assembly.rs, mechanical addition mirroring the
  two existing embeds -- required because that path reuses the same
  SKILL.md/references/ verbatim), and the public-repo publish script
  (publish-skill-repo.ts, already derived dynamically from agents.ts's
  shim lists so no logic change was needed there, only comments/tests).

Also verifies, via new tests against the real seed_skill_nodes() registry,
that the seeding-skips-by-node-type prerequisite #2532 listed as
still-needed is already fixed (PR #1818/#1812, per-node versioned
reconciliation, merged 2026-07-30 -- predating both #1958 and #2532): a
compiled-template content change reaches an already-seeded database on
next seed, and a live graph edit is immediately visible to a fetch with no
reseed or restart. Manually verified end-to-end against a real isolated
daemon + embedding model: edited a seeded guidance node's content, then
confirmed `nodespace skill guidance` returned the edit.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* Address review: cap guidance --limit, remove bare issue refs, harden banner against spoofing

- Cap `--limit` itself (not just include_markdown) at the server's
  markdown-attachment ceiling in a new build_guidance_request(), so a
  guidance entry can no longer print a full provenance banner around empty
  content when more than 5 results are requested.
- Reword code/test comments that cited issue or PR numbers to describe the
  underlying behavior or history directly instead.
- Harden print_guidance's human-mode provenance banner against a malicious
  or corrupted graph node forging a banner-shaped line: each banner now
  carries a per-invocation random tag (fresh UUIDv4, generated at call
  time and announced once at the top of the output) that fetched content
  authored before the call cannot have predicted. Fetched title,
  description, and markdown content is also passed through a new
  sanitize_for_terminal that strips ANSI CSI sequences and other control
  characters, so raw escape bytes in fetched content can no longer redraw
  or conceal the banner. --json output is unchanged (already unspoofable
  by construction).

Also updates the reference doc to explain the tag mechanism to an agent
reading it, and adds a uuid dependency to nodespace-cli for the tag.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
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.

Seeded content never reaches an existing install: replace type-level skip with per-node versioned re-seed

1 participant