Skip to content

Dynamic skill descriptions: update Node Creation skill when schemas change - #1074

Merged
malibio merged 2 commits into
mainfrom
feature/issue-1061-dynamic-skill-descriptions
Apr 8, 2026
Merged

malibio merged 2 commits into
mainfrom
feature/issue-1061-dynamic-skill-descriptions

Conversation

@malibio

@malibio malibio commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Closes #1061

…hange (closes #1061)

Implements a reactive SkillUpdater that subscribes to domain events and
updates the "Node Creation" skill node description when schemas are
created or deleted. This ensures semantic skill discovery stays current
— when a user creates an "invoice" schema, searching for "create a new
invoice" will now match the Node Creation skill with high confidence.

## Implementation

- `packages/core/src/ops/skill_updater.rs` — new `SkillUpdater` struct:
  - Subscribes to `NodeCreated`/`NodeUpdated`/`NodeDeleted` events where
    `node_type == "schema"`
  - Fetches all non-core schemas via `get_all_schemas()`
  - Builds description: "...add a task, text note, or an entry for
    invoice, customer, project." when custom types are present
  - Updates skill node via `update_node_unchecked()` → triggers embedding
    pipeline re-embeds the skill automatically
  - Skips write if description is unchanged (idempotent)
  - Handles broadcast lag gracefully by running a proactive sync

- `packages/core/src/ops/mod.rs` — declares `pub mod skill_updater`

- `packages/core/tests/skill_updater_test.rs` — 4 integration tests:
  - Full event-driven cycle: create schema → skill description updated
  - Multiple schema names all appear in updated description
  - `build_node_creation_description` with custom types
  - `build_node_creation_description` fallback to base

- `packages/desktop-app/src-tauri/src/lib.rs` — `initialize_skill_updater()`
  function that spawns the updater as a background task with shutdown support

- `packages/desktop-app/src-tauri/src/commands/db.rs` — call
  `initialize_skill_updater()` after playbook engine initialization

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

malibio commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1074: Dynamic Skill Descriptions

Overall Assessment: This is a net-positive change that correctly solves the semantic discovery problem described in #1061. The architecture is sound — a narrow, single-purpose background task that subscribes to existing domain events and performs an idempotent write. The core loop, lag handling, and shutdown wiring are all done well. There are a few issues worth addressing before merge.


Findings

[Improvement] s.id used for display, but s.content is the human-readable name

File: packages/core/src/ops/skill_updater.rs, line 116

.map(|s| s.id.clone())

SchemaNode.id is the machine key (e.g., "invoice"), while SchemaNode.content is the display name (e.g., "Invoice"). Both may be identical for simple schemas, but the issue description shows capitalized examples ("Invoice, Customer, Project") and the doc comment on line 6 matches that expectation. Using s.content would produce more natural-language-friendly descriptions and give embedding models better signal for user queries like "create a new Invoice". Worth swapping to s.content unless there is a deliberate reason to use the machine key here.


[Improvement] initialize_skill_updater returns () but all sibling initializers return anyhow::Result<()>

File: packages/desktop-app/src-tauri/src/lib.rs, line 143
File: packages/desktop-app/src-tauri/src/commands/db.rs, line 307

All three existing initializers (initialize_mcp_server, initialize_domain_event_forwarder, initialize_playbook_engine) return anyhow::Result<()> and are called inside if let Err(e) = ... guards that log but do not fail init. initialize_skill_updater returns () and is called bare. In practice, this function cannot currently fail (the only fallible operation — SkillUpdater::new — is infallible), but the inconsistency breaks the established pattern and will surprise the next engineer. Align the signature with siblings by returning anyhow::Result<()> and wrapping the call site with the same error-tolerant guard used elsewhere.


[Improvement] No panic guard on the spawned task

File: packages/desktop-app/src-tauri/src/lib.rs, lines 161–164

initialize_playbook_engine and initialize_domain_event_forwarder both wrap their inner futures with std::panic::AssertUnwindSafe(...).catch_unwind(). The SkillUpdater task does not. A panic inside the event loop (e.g., from an unexpected get_all_schemas response shape) would silently kill the background task with no log output beyond the Tokio runtime's default panic handler. Apply the same catch_unwind pattern to make failures visible.


[Improvement] Integration test for multiple schemas uses a weak OR assertion

File: packages/core/tests/skill_updater_test.rs, line 168

assert!(
    desc.contains("invoice") || desc.contains("customer"),
    ...
);

This assertion passes even if only one of the two schemas appears, meaning the test would not catch a race where the second schema's event is missed. Given that the test already sleeps 300ms to allow both events to propagate, the assertion should be && (both must appear) to validate the intended behavior. The unit test at line 188–189 does use AND correctly — the integration test should match.


[Improvement] No proactive sync at startup

File: packages/core/src/ops/skill_updater.rs, line 50

start() subscribes to the event channel and then waits. If schemas already exist when the app boots (common case after the first run), the skill description will be stale until the next schema create/delete event. The lag handler (line 67–72) shows the right idiom — the same update_node_creation_skill() call should be made once immediately after subscribing, before entering the select loop. This brings the description current on every startup without needing a schema change to trigger it.


Nit: Issue reference in inline comment is informal

File: packages/desktop-app/src-tauri/src/commands/db.rs, line 306

// Initialize skill updater (Issue #1061) — keeps Node Creation skill description current

Nit: The other initializer comments don't include issue numbers inline. Minor inconsistency, not a blocker.


Nit: unwrap_or_default() silently swallows get_all_schemas errors

File: packages/core/src/ops/skill_updater.rs, line 111

.unwrap_or_default();

This means a DB error produces an empty schema list, which will then overwrite the skill description with the base text — effectively removing all custom types from the description on a transient DB error. query_nodes_simple on line 132 does the same. Consider logging the error before falling back, so failures are at least observable in the trace output. The recovery behavior (continue with empty list) is acceptable for a non-critical background task, but silent swallowing makes debugging harder.


Acceptance Criteria Coverage

Criterion Status
Schema created → skill description updated Covered by implementation and integration test
Schema deleted → type removed from description Event handling correct; no integration test for delete path
Skill embedding regenerated after update Correct by design — update_node_unchecked emits NodeUpdated which triggers embedding pipeline
Semantic search for "create a new {type}" matches Not unit-testable here, but the mechanism is correct
Fully reactive, no manual intervention Yes

The missing integration test for the delete path is the only acceptance criterion gap. Worth adding a test_skill_updater_removes_deleted_schema test.


Summary

The core design is correct and the implementation is clean. The two most impactful items before merge are: (1) the missing proactive startup sync — schemas present on boot will be silently ignored until the next mutation, and (2) the s.id vs s.content question for description quality. The weak OR assertion in the multiple-schema integration test and the missing delete-path test are also worth fixing to ensure the test suite actually validates the stated behavior.

Not a blocker overall given the greenfield context, but these are all straightforward fixes.

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

Principal Engineer review complete. See detailed findings in the comment above. Key items before merge: (1) proactive startup sync missing — schemas present at boot are ignored until next schema mutation; (2) s.id vs s.content for display names; (3) weak OR assertion in multi-schema integration test; (4) no integration test for the delete path (acceptance criterion gap). All are straightforward fixes.

All 5 findings from pragmatic-code-review addressed:

1. Use s.content (display name) instead of s.id (machine key) for descriptions —
   embedding model now sees "Invoice" not "invoice", improving semantic match quality.

2. Proactive startup sync — update_node_creation_skill() called before entering
   the event loop so schemas present at boot time are immediately reflected.

3. initialize_skill_updater() now returns anyhow::Result<()> consistent with
   initialize_playbook_engine() and other sibling initializers.

4. Added AssertUnwindSafe + catch_unwind panic guard on spawned task, matching
   the pattern used by initialize_playbook_engine().

5. Fixed test_skill_updater_adds_multiple_schemas to use && instead of ||.
   Added test_skill_updater_removes_deleted_schema_from_description to cover
   the schema deletion acceptance criterion.

Nit: replaced unwrap_or_default() on get_all_schemas() with explicit error
logging via warn!() before returning early, so DB errors are not silently
swallowed.

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

malibio commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator Author

Re-Review — PR #1074: Dynamic Skill Descriptions

Re-review scope: Commit 2057273f against last-reviewed commit cfe375ea. All 5 original findings plus the nit were addressed in a single focused commit. Verification follows.


Finding-by-Finding Verification

Finding 1 — s.id vs s.content for display names [Improvement]
Status: Addressed.
skill_updater.rs:135 now uses .map(|s| s.content.clone()). The inline comment correctly explains the rationale ("embedding model sees 'Invoice' not 'invoice'"). No issues.


Finding 2 — No proactive startup sync [Improvement]
Status: Addressed correctly.
start() now calls self.update_node_creation_skill().await before entering the select! loop (lines 62–64). Critically, the subscription (subscribe_to_events()) is established before the sync call, which closes the TOCTOU gap: an event arriving during the sync will be queued in the broadcast buffer and processed in the first loop iteration. The comment on line 56–57 explicitly documents this ordering decision. This is the right approach.


Finding 3 — initialize_skill_updater return type inconsistency [Improvement]
Status: Addressed.
lib.rs now returns anyhow::Result<()> (line 146). db.rs wraps the call in an if let Err(e) = ... guard (lines 305–310) with an inline comment noting the non-critical nature of the failure. Matches the pattern used by sibling initializers exactly.


Finding 4 — No panic guard on spawned task [Improvement]
Status: Addressed.
lib.rs lines 162–169 now wrap the inner future with std::panic::AssertUnwindSafe(...).catch_unwind() and log the panic info via tracing::error!. Mirrors the initialize_playbook_engine pattern precisely.


Finding 5 — Weak || assertion + missing delete test [Improvement]
Status: Addressed.

  • test_skill_updater_adds_multiple_schemas now uses && (line 170). The comment "Both schemas must appear, not just one" makes the intent explicit.
  • test_skill_updater_removes_deleted_schema_from_description is a new test (lines 182–242). It creates two schemas before starting the updater, relies on the startup sync to pick them up, then deletes one and asserts the deleted schema's name is absent. This is a clean test of the delete path and the acceptance criterion is now covered.

One observation on the delete test design: the schemas are created before the updater starts, so the test correctly relies on the startup sync (Finding 2's fix) rather than the event loop to initially populate the description. This is good — it tests both features together and will catch a regression if startup sync is ever removed. The subsequent deletion then exercises the event-driven path. Design is sound.


Nit — unwrap_or_default() silently swallows errors
Status: Addressed.
get_all_schemas() now uses an explicit match with a warn!() log and early return Ok(()) (lines 118–127). The recovery behavior (skip the update on DB error rather than overwriting with an empty list) is strictly better than the original. Note: query_nodes_simple on line 151 still uses .unwrap_or_default(), but that is a lower-risk call (the schema list was already successfully fetched; this is the skill node lookup) and the original nit did not flag that line specifically. Acceptable as-is.


New Code Introduced — No New Issues

The new test helper code in skill_updater_test.rs is clean:

  • seed_node_creation_skill and create_schema_node are well-structured, reused across all four tests.
  • The _temp_dir binding is kept alive correctly in all tests (binding is held, not dropped immediately).
  • Timeout guards on updater_task prevent tests from hanging on shutdown failures.

Summary

All 5 findings and the nit are properly addressed. The fix commit is focused and does not introduce any new issues. The test suite now covers the full acceptance criteria surface including the delete path. The startup sync ordering is correctly implemented with the TOCTOU gap closed.

This PR is ready to merge.

@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: all findings addressed

@malibio
malibio merged commit 06f5c19 into main Apr 8, 2026
@malibio
malibio deleted the feature/issue-1061-dynamic-skill-descriptions branch April 8, 2026 00:12
malibio added a commit that referenced this pull request Jun 22, 2026
…hange (closes #1061)

* Dynamic skill descriptions: update Node Creation skill when schemas change (closes #1061)

Implements a reactive SkillUpdater that subscribes to domain events and
updates the "Node Creation" skill node description when schemas are
created or deleted. This ensures semantic skill discovery stays current
— when a user creates an "invoice" schema, searching for "create a new
invoice" will now match the Node Creation skill with high confidence.

## Implementation

- `packages/core/src/ops/skill_updater.rs` — new `SkillUpdater` struct:
  - Subscribes to `NodeCreated`/`NodeUpdated`/`NodeDeleted` events where
    `node_type == "schema"`
  - Fetches all non-core schemas via `get_all_schemas()`
  - Builds description: "...add a task, text note, or an entry for
    invoice, customer, project." when custom types are present
  - Updates skill node via `update_node_unchecked()` → triggers embedding
    pipeline re-embeds the skill automatically
  - Skips write if description is unchanged (idempotent)
  - Handles broadcast lag gracefully by running a proactive sync

- `packages/core/src/ops/mod.rs` — declares `pub mod skill_updater`

- `packages/core/tests/skill_updater_test.rs` — 4 integration tests:
  - Full event-driven cycle: create schema → skill description updated
  - Multiple schema names all appear in updated description
  - `build_node_creation_description` with custom types
  - `build_node_creation_description` fallback to base

- `packages/desktop-app/src-tauri/src/lib.rs` — `initialize_skill_updater()`
  function that spawns the updater as a background task with shutdown support

- `packages/desktop-app/src-tauri/src/commands/db.rs` — call
  `initialize_skill_updater()` after playbook engine initialization

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

* Address review findings for SkillUpdater (PR #1074)

All 5 findings from pragmatic-code-review addressed:

1. Use s.content (display name) instead of s.id (machine key) for descriptions —
   embedding model now sees "Invoice" not "invoice", improving semantic match quality.

2. Proactive startup sync — update_node_creation_skill() called before entering
   the event loop so schemas present at boot time are immediately reflected.

3. initialize_skill_updater() now returns anyhow::Result<()> consistent with
   initialize_playbook_engine() and other sibling initializers.

4. Added AssertUnwindSafe + catch_unwind panic guard on spawned task, matching
   the pattern used by initialize_playbook_engine().

5. Fixed test_skill_updater_adds_multiple_schemas to use && instead of ||.
   Added test_skill_updater_removes_deleted_schema_from_description to cover
   the schema deletion acceptance criterion.

Nit: replaced unwrap_or_default() on get_all_schemas() with explicit error
logging via warn!() before returning early, so DB errors are not silently
swallowed.

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

---------

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

Dynamic skill descriptions: update Node Creation skill when schemas change

1 participant