Skip to content

Add per-aspect seed durability guard with explicit reset (#2560) - #2564

Merged
malibio merged 2 commits into
mainfrom
issue-2560-seed-durability
Sep 11, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2560-seed-durability

Conversation

@malibio

@malibio malibio commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the design gap in #2560: seeded skill/prompt/tool nodes are reconciled against their compiled templates on every daemon startup (seed_nodes_from_templates), and system-tier nodes had no protection against a user's live edit being silently discarded the next time an unrelated code change touched that node's template.

Implements the design in ADR-072 (nodespace-docs/decisions/072-per-aspect-seed-durability-with-explicit-reset.md, committed to nodespace-docs main):

  • Per-aspect durability guard, tier-independent: a seeded node's config (root properties — description/tool_whitelist/max_iterations) and guidance (markdown children) are tracked and reconciled independently via _seed.config_modified / _seed.guidance_modified, since editing one doesn't touch the other. An untouched aspect keeps auto-replacing on every restart exactly as before; a user-touched aspect is now permanently protected.
  • nodespace skill reset <key> --guidance|--config|--all — the one path allowed to discard a modified aspect, via a new ResetSeedNode gRPC RPC and NodeService::reset_seed_node. Requires confirmation; in a non-interactive context with no --yes, it refuses outright rather than auto-proceeding (unlike install/mcp enable), since this is the sole destructive path in the system.

Key implementation notes

  • seed_nodes_from_templates's single whole-subtree "replace" became two independent operations: a config-only in-place property merge (update_node_unchecked, no delete/recreate) and a guidance-only delete-children-then-recreate (leaving the root untouched).
  • compute_seed_version's single content hash split into config_version/guidance_version.
  • update_node's stamping logic (previously starter-tier only) now applies to every tier, walking up to a child's seeded root via get_root_id when the edited node isn't itself the seed root.

Test plan

  • New nodespace-core unit tests: per-aspect independence (editing guidance doesn't block a config-only reseed, and vice versa) and reset_seed_node overriding the guard
  • New nodespace-agent integration test against the real production seed_skill_nodes() registry
  • New nodespace-cli tests: ArgGroup requiring an explicit scope flag, and an end-to-end gRPC round trip through run_reset
  • bun run test:all, cargo build --bin nodespaced, and test:e2e all pass via the pre-push gate
  • bun run quality:fix (Rust + TS) clean

Closes #2560

🤖 Generated with Claude Code

https://claude.ai/code/session_01NbFkxrpERmx9QNkkwoD4Dz

…set (closes #2560)

Extends the starter-tier user_modified durability guard to system-tier
seeded skill/prompt/tool nodes, tracked independently per aspect (config:
root properties, vs guidance: markdown children) since editing one doesn't
touch the other. Reconciliation keeps auto-replacing an untouched aspect on
every daemon startup exactly as before; an edited aspect is now permanently
protected until explicitly discarded via the new `nodespace skill reset
<key> --guidance|--config|--all` command, which requires confirmation
(refusing outright in a non-interactive context without --yes, since this
is the one destructive path in the system).

Implements the design in ADR-072 (nodespace-docs), written to resolve the
design question this issue opened around durability vs. the always-replace
system tier.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NbFkxrpERmx9QNkkwoD4Dz
@malibio

malibio commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This implements ADR-072 faithfully: config and guidance are tracked and reconciled as independent aspects via _seed.config_modified/_seed.guidance_modified, extended tier-independently as the ADR specifies, with nodespace skill reset as the sole explicit override path. The core reconciliation logic (per-aspect skip/replace matrix), the bulk_create_seed_children parent-id remapping for nested markdown, and the CLI's non-TTY refusal behavior all check out against direct trace-through and local test runs. This is a net improvement — it closes a real, previously-silent data-loss gap. I found one verified CLI parsing bug and one verified reconciliation cross-contamination bug, both narrow enough not to block, plus a perf concern on update_node's new unconditional get_root_id walk that's worth a deliberate look before this becomes a bigger subtree.

All unit/integration tests specific to this PR pass locally (cargo test -p nodespace-core, -p nodespace-cli --test cli_integration, -p nodespace-agent --test skill_guidance_fetch_mechanism), and cargo clippy --tests across the four touched packages is clean.

Findings

Critical Issues

None.

Suggested Improvements

  • packages/cli/src/commands/skill.rs — ResetArgs's ArgGroup rejects combining scope flags, contradicting the documented behavior. The reset_scope group is declared required(true) without .multiple(true), which clap defaults to mutually-exclusive. I verified this empirically (clap 4, isolated probe): --guidance --config together returns ArgumentConflict, not success. But both the doc comment on all ("Reset both guidance and config — equivalent to passing both flags") and the regenerated packages/skill/references/cli.md promise that combining flags works as an alternative spelling of --all. Every test in this PR exercises exactly one scope flag at a time, so the gap wasn't caught. It fails loud rather than silently misbehaving, so it's not a safety issue, but it's a real behavior/documentation mismatch a user will hit. Fix: add .multiple(true) to the ArgGroup, or drop the "equivalent to passing both flags" language if single-flag-only is intended (in which case --guidance --config should get a clearer error than the generic clap conflict message).

  • packages/core/src/services/node_service/mod.rs — replace_seed_config overwrites _seed.guidance_version even when guidance is untouched in that same reconciliation pass. replace_seed_config merges the entire freshly-prepared template_root.properties (including the current template's _seed.guidance_version) into the existing node via update_node_unchecked's deep merge — independent of whatever the guidance branch decided in the same pass. Concretely: guidance is user-modified and guarded (skip), config is unmodified and replaced — the config replace still stamps the node's stored guidance_version forward to match the current template, even though the actual guidance content was never touched. I traced the consequences: guidance_modified itself is untouched by this merge (it's not a key the template's _seed object carries), so the guard flag still correctly blocks a future replace — no data loss results. But the version-hash bookkeeping is now desynced from the real content, which corrupts the skipped_guidance_current vs. skipped_guidance_modified telemetry on the next pass (it'll misreport "current" instead of "user-modified"), and generally means _seed.guidance_version can no longer be trusted as "the hash of what's actually in the children" once any config replace has happened on a guidance-modified node. Scope the config replace to only the root's actual own fields, or merge in the existing node's guidance_version/guidance_modified rather than letting the incoming template's values win.

  • packages/core/src/services/node_service/crud.rs — update_node's new get_root_id walk now runs on every content/property edit to any non-seed-root node in the entire graph, not just seeded subtrees. For a node without its own _seed block, the code unconditionally calls self.get_root_id(node_id) (a has_child query per ancestor level — no cached root_id column exists on the node row) followed by a full get_node fetch of the root, purely to check whether that root happens to carry a _seed block. This is not scoped to agent/skill subtrees in any way — a routine edit to a task deep in a long daily note now pays a full-depth ancestor walk plus a root fetch it never used to pay. ADR-072's "Negative consequences" section describes this as "a small, bounded cost already paid today for starter tier," but that undersells the change: previously this check only ran for starter-tier root edits (no walk needed, _seed was on the node itself); now it walks from any descendant of any node, seeded or not, on every edit. Worth confirming this was measured against test:perf or a deeply-nested fixture, and/or adding a short-circuit (e.g. a depth cap, or restricting the walk to node types the agent subsystem actually owns) if it wasn't.

Nitpicks

  • Nit: packages/daemon/src/services/node_service.rs — resolve_seed_template resolves (node_type, seed_key) via .find() across three chained seed-source iterators with no uniqueness check. Today seed_agent_guidance_nodes/seed_skill_nodes/seed_tool_nodes produce disjoint root_node_types (prompt/skill/tool), so there's no real collision risk yet, but nothing enforces that invariant — a future seed source reusing an existing (node_type, title) pair would silently resolve to whichever template happens to iterate first, with no error or log. A cheap guard (debug_assert on uniqueness, or an explicit "ambiguous" error) would make this fail loud instead of picking silently.
  • Nit: packages/cli/src/commands/skill.rs::run_reset — when --json is passed without --yes, the interactive confirmation prompt (format_reset_summary + Proceed? [y/N]) still prints human-readable text to stdout before the JSON result. Not wrong (confirmation happens before output), but a --json caller filtering stdout for JSON only would see the prompt text mixed in on a TTY. Likely fine in practice since scripted/JSON use presumably pairs with --yes.
  • Nit: packages/core/src/services/node_service/mod.rs doc comment on SeedTier still says tiers are "labeling only" now that reconciliation is tier-independent — accurate, but might be worth a one-line pointer to whether Starter has any remaining behavioral difference anywhere else in the codebase (e.g. UI treatment), so a future reader doesn't have to grep to confirm the tier is genuinely vestigial for reconciliation purposes.

Verification Notes

  • Traced bulk_create_seed_children's parent-id remapping against a multi-level markdown case (heading with a nested bullet): only direct children (parent_id == template_root_id) get remapped to the real root id; grandchildren already reference a stable sibling id assigned once by prepare_nodes_from_markdown's PrepareContext, so they're correctly left alone. This is correct, not just correct-for-the-flat-case.
  • Confirmed confirm_reset's non-TTY behavior is a hard bail! (checks both stdin and stdout are terminals), not a hang or panic, and not an accidental auto-proceed — matches the ADR's "sole destructive path" intent.
  • Confirmed the replace_seed_config deep-merge caveat (a template removing a root_properties key wouldn't remove it from the existing node) is real but accurately self-documented and currently inapplicable, since every shipped template always carries the same fixed key set (description/tool_whitelist/max_iterations). Not a blocker as-is.
  • Ran cargo test -p nodespace-core --lib (targeted: reset_seed_node, reseed_skips), cargo test -p nodespace-cli --test cli_integration skill_reset, cargo test -p nodespace-agent --test skill_guidance_fetch_mechanism — all pass. cargo clippy -p nodespace-core -p nodespace-cli -p nodespace-daemon -p nodespace-agent --tests is clean.

Verdict: Approve, with the ArgGroup fix and the guidance-version cross-contamination noted above strongly recommended before/shortly after merge (neither blocks — both fail-safe rather than fail-silent-and-lossy). The get_root_id perf point is worth a deliberate look but isn't a regression severe enough to hold the PR given this is pre-release with no production load. (Posted as a comment, not an approval review, since this PR is self-authored by the same account driving this review — GitHub rejects self-approval.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01NbFkxrpERmx9QNkkwoD4Dz

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

Pragmatic code review complete (full report posted above). Verdict: APPROVE with two recommended-but-non-blocking fixes — (1) the ResetArgs ArgGroup rejects combining --guidance --config, contradicting the documented 'equivalent to --all' behavior (verified via isolated clap probe), and (2) replace_seed_config overwrites _seed.guidance_version even when guidance wasn't touched in that pass, desyncing version telemetry (traced through — no data loss, since the guidance_modified flag itself is untouched and still gates replacement correctly). A perf note on update_node's new unconditional get_root_id walk on every non-seed-root edit is flagged for awareness, not blocking. Posting as --comment, not --approve, since this PR is self-authored by the same account driving this review.

… confirmation stream

- packages/cli/src/commands/skill.rs: ResetArgs's ArgGroup now allows
  combining --guidance/--config/--all (.multiple(true)) — previously
  clap treated them as mutually exclusive, contradicting the documented
  "equivalent to passing both flags" behavior for --all.
- packages/core/src/services/node_service/mod.rs: replace_seed_config no
  longer overwrites _seed.guidance_version/guidance_modified with the
  template's values when only config replaces — those fields are now
  preserved from the existing node, so a config-only replace can't desync
  guidance's stored hash from its actual content.
- Fixed a second, related bug found while addressing the above:
  replace_seed_guidance never stamped _seed.guidance_version after
  recreating children, so a completed guidance replace was silently
  redone on every subsequent reconciliation pass. Added
  SqliteStore::set_property_string (mirroring set_property_bool) to fix
  it. New regression tests cover both bugs.
- packages/daemon/src/services/node_service.rs: resolve_seed_template now
  debug_asserts uniqueness of (node_type, seed_key) across the three
  chained seed sources, so a future collision fails loud instead of
  silently picking whichever template iterates first.
- confirm_reset's prompt now prints to stderr, not stdout, so a --json
  caller's stdout can never have prompt text interleaved with the JSON
  result even on a real terminal.

Skipped: the update_node get_root_id perf concern (flagged for awareness,
not blocking — pre-release with no production load, and a speculative
fix risks incorrectness for legitimate deep guidance nesting without a
measured problem to fix). SeedTier doc-comment nit (marginal value).

Addresses reviewer recommendations from PR #2564's pragmatic-code-review.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NbFkxrpERmx9QNkkwoD4Dz
@malibio

malibio commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary

Addressed all three substantive findings from the pragmatic-code-review, plus one additional bug found while fixing them.

✅ Addressed

  1. ResetArgs's ArgGroup rejected combining scope flags (packages/cli/src/commands/skill.rs) — added .multiple(true). --guidance --config now parses and behaves as documented ("equivalent to passing both flags"), confirmed by a new test asserting both flags parse together.

  2. replace_seed_config overwrote _seed.guidance_version/guidance_modified with the template's values on every config-only replace (packages/core/src/services/node_service/mod.rs) — now preserves the existing node's guidance fields when only config replaces. New regression test (reseed_config_replace_does_not_disturb_guidance_bookkeeping) asserts a config-only replace leaves a guarded guidance's version/flag untouched.

  3. New bug found while fixing Create design system foundation #2: replace_seed_guidance never stamped _seed.guidance_version after recreating children, so a completed guidance replace was silently redone on every subsequent reconciliation pass — the version hash never advanced, so every restart looked like guidance was still stale. Added SqliteStore::set_property_string (mirrors the existing set_property_bool) and stamp the new version after replace. New regression test (reseed_does_not_replay_a_guidance_replace_on_the_next_pass) asserts a third identical reseed doesn't recreate already-current children.

  4. Nitpick — resolve_seed_template had no collision guard (packages/daemon/src/services/node_service.rs) — added a debug_assert that fails loud if two seed sources ever produce the same (node_type, seed_key).

  5. Nitpick — confirm_reset printed to stdout, which a --json caller might be piping — the confirmation prompt now goes to stderr.

⏭️ Skipped

  • update_node's get_root_id walk perf concern — flagged for awareness in the review itself, not blocking. This is pre-release with no production load, and a speculative fix (depth cap, node-type restriction) risks incorrectness for legitimate deep guidance nesting without a measured problem to actually fix. Revisit if test:perf or real usage surfaces an actual cost.
  • SeedTier doc-comment nit — marginal value; the existing doc comment (from the original implementation) already states reconciliation is tier-independent.

Verification

  • New regression tests added for both real bugs (config/guidance bookkeeping cross-contamination, and the guidance-replay bug), all passing.
  • Full cargo test across nodespace-core, nodespace-cli, nodespace-agent, nodespace-daemon (the four touched packages) — all green.
  • cargo clippy --all-targets -D warnings -D clippy::unused-async clean across all four.
  • Pushed and passed the full pre-push gate (test:all, cargo build --bin nodespaced, test:e2e).

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: Two of the three addressed items were genuine bugs in core reconciliation logic (seed_nodes_from_templates's per-aspect replace paths), not style or documentation fixes — including one (the guidance-replay bug) that wasn't even in the original review and was only discovered while fixing another finding. This is exactly the "architectural/design changes in interconnected core logic" case the address-review criteria call out for re-review, regardless of how confident the new regression tests make me. A second pass should specifically verify: (a) the _seed field-preservation logic in replace_seed_config doesn't have a symmetric gap I missed, (b) the new set_property_string store primitive is safe under the same OCC-bypass caveats as set_property_bool, and (c) no other reconciliation path silently relies on the old (buggy) replace_seed_guidance behavior.

Run /pragmatic-code-review again.

@malibio

malibio commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review (verified directly — the automated reviewer agent stalled twice on this pass, so I traced the diff myself)

Reviewed only the 6ba1d010..e56c4982 diff (the address-review commit) against the prior review's 5 findings.

Findings verification

  1. ✅ ArgGroup fix confirmed correct. .multiple(true) added to reset_scope. skill_reset_requires_an_explicit_scope_flag passes — asserts both that a bare reset <key> (zero flags) still errors with MissingRequiredArgument (the required(true) guarantee is unweakened) AND that --guidance --config together now parses without conflict.

  2. ✅ replace_seed_config field-preservation confirmed correct, including the degradation case. Traced the if let Some(guidance_version) = existing_seed.and_then(...) guards: when an existing node has no prior guidance_version/guidance_modified key at all, the guard is simply skipped, leaving the template's own value in place — which is the correct fallback (a node with no such key has never been reconciled under the per-aspect scheme, so trusting the template's freshly-computed value for its own children is safe, not a data-loss risk). Every node this function is called on is already a seeded node with a _seed block (stamped at creation), so a fully-missing _seed isn't a real case here. reseed_config_replace_does_not_disturb_guidance_bookkeeping passes.

  3. ✅ replace_seed_guidance version-stamping bug fix confirmed correct. Checked SqliteStore::set_property_string's SQL side by side with set_property_bool: binding the value directly as a ?2 parameter to json_set(properties, ?1, ?2) (no json(...) wrapper) is the correct pattern for a string — SQLite's json_set auto-encodes an unwrapped scalar bind parameter as a JSON string, whereas wrapping it in json(...) would try to parse the string as JSON syntax and fail for anything not independently valid JSON (a hex digest included). Ran reseed_does_not_replay_a_guidance_replace_on_the_next_pass — passes, empirically confirming a sha256 hex hash round-trips correctly. Confirmed both call sites (seed_nodes_from_templates's guidance-replace branch, and reset_seed_node's reset_guidance branch) correctly derive new_guidance_version from the current template's _seed.guidance_version before calling replace_seed_guidance.

  4. ✅ resolve_seed_template debug_assert confirmed correct. The lazy filter iterator's first .next() extracts and retains the match in first; a second .next() call on the same iterator correctly probes for a further match without disturbing the retained first value. No logic bug.

  5. ✅ confirm_reset stderr change confirmed safe. No test asserts on the prompt's stdout content; the existing end-to-end test (skill_reset_discards_modified_guidance_end_to_end) passes --yes, bypassing the prompt entirely, so it was never coupled to which stream the prompt used.

Verification commands run

  • cargo check -p nodespace-core -p nodespace-cli -p nodespace-daemon — clean
  • cargo clippy -p nodespace-core -p nodespace-cli -p nodespace-daemon --all-targets -- -D warnings -D clippy::unused-async — clean
  • cargo test -p nodespace-core --lib -- reseed_does_not_replay_a_guidance_replace_on_the_next_pass — pass
  • cargo test -p nodespace-core --lib -- reseed_config_replace_does_not_disturb_guidance_bookkeeping — pass
  • cargo test -p nodespace-cli --test cli_integration -- skill_reset_requires_an_explicit_scope_flag — pass

No new issues found. All 5 findings from the initial review were properly and correctly addressed.

Verdict: Approve. (Posted as a comment, not an approval review — this PR is self-authored by the same account performing the review, and GitHub rejects self-approval.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01NbFkxrpERmx9QNkkwoD4Dz

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

Re-review complete (full findings posted above). All 5 items from the initial review verified as correctly fixed; no new issues found. Verdict: APPROVE (posted as a comment, not an approval review — self-authored PR, GitHub rejects self-approval).

@malibio
malibio merged commit 93d1c05 into main Sep 11, 2026
@malibio
malibio deleted the issue-2560-seed-durability branch September 11, 2026 05:27
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 skill-guidance nodes have no durability protection against code-driven content replacement

1 participant