Skip to content

Add lifecycle_status as core node property with semantic search exclusion - #828

Merged
malibio merged 3 commits into
mainfrom
feature/issue-755-lifecycle-status
Jan 26, 2026
Merged

malibio merged 3 commits into
mainfrom
feature/issue-755-lifecycle-status

Conversation

@malibio

@malibio malibio commented Jan 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Changes

Database Schema (schema.surql)

  • Added lifecycle_status field with default "active"
  • Added index idx_node_lifecycle for efficient filtering

Node Model (node.rs)

  • Added lifecycle_status field with serde default "active"
  • Optimized serialization to skip "active" values (reduces payload size)
  • Added comprehensive tests for serialization/deserialization

Semantic Search (search.rs, tools.rs)

  • Added include_archived parameter to SearchSemanticParams (default: false)
  • Implemented lifecycle filtering logic:
    • "active" nodes: Always included
    • "archived" nodes: Excluded unless include_archived=true
    • "deleted" nodes: Always excluded (even with include_archived=true)
  • Updated MCP tool schema with include_archived boolean parameter

Other Updates

  • Updated all Node construction sites to include lifecycle_status
    • surreal_store.rs: SurrealNode struct and conversions
    • node_service.rs: Node creation methods
    • schema_node.rs: Schema node to Node conversion
    • task_node.rs: Task node to Node conversion

Test Plan

  • Rust tests pass (722 tests, 16 new tests added)
  • Frontend tests pass (3468 tests)
  • Quality checks pass (clippy, eslint, svelte-check)
  • Manual testing: Create node, archive it, verify search excludes it
  • Manual testing: Search with include_archived: true, verify archived nodes included

Acceptance Criteria Status

From issue #755:

  • lifecycleStatus field added to SurrealDB node hub table with default active
  • Index created for efficient lifecycle filtering
  • search_semantic excludes archived/deleted nodes by default
  • search_semantic includes archived nodes when include_archived: true
  • Policy schema defined (Phase 3 - separate issue)
  • UI Archive/Restore/Delete actions (Phase 3 - separate issue)
  • Documentation updated (Phase 4 - separate issue)

🤖 Generated with Claude Code

…sion

Implements Phase 1 and 2 of Issue #755 - adds lifecycle management to
enable knowledge governance across all nodes.

Changes:
- Add lifecycle_status field to SurrealDB schema with default "active"
  and index for efficient filtering (schema.surql)
- Add lifecycle_status to Node struct with serde defaults and skip
  serialization for "active" status (node.rs)
- Add include_archived parameter to search_semantic MCP tool (tools.rs)
- Implement lifecycle filtering in search handler - excludes archived
  nodes by default, always excludes deleted nodes (search.rs)
- Update SurrealNode and all Node construction sites to include
  lifecycle_status field (surreal_store.rs, node_service.rs,
  schema_node.rs, task_node.rs)

Lifecycle values:
- "active" (default): Included in search, visible in UI
- "archived": Excluded from search by default, hidden from default views
- "deleted": Always excluded, soft-deleted, purgeable

Tests added for:
- Node lifecycle_status serialization/deserialization
- include_archived parameter parsing and defaults
- Lifecycle filter logic (active/archived/deleted combinations)

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

malibio commented Jan 26, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review

Review Type: Initial Review
Branch: feature/issue-755-lifecycle-status -> main
PR #828: Add lifecycle_status as core node property with semantic search exclusion


Requirements Check (Issue #755)

Acceptance Criterion Status Notes
lifecycleStatus field added to SurrealDB node hub table with default active ✅ schema.surql line 43
Index created for efficient lifecycle filtering ✅ idx_node_lifecycle index on lifecycle_status
search_semantic excludes archived/deleted nodes by default ✅ Filter logic in search.rs lines 302-310
search_semantic includes archived nodes when include_archived: true ✅ Implemented with clear logic
Policy schema defined (Phase 3) N/A Out of scope for this PR
UI Archive/Restore/Delete actions (Phase 3) N/A Out of scope for this PR
Documentation updated (Phase 4) N/A Out of scope for this PR

Summary: All Phase 1 and Phase 2 acceptance criteria implemented correctly.


Code Review Findings

Critical Issues

None identified.

Suggested Improvements

[Improvement] Consider using an enum for lifecycle_status

Files: /packages/core/src/models/node.rs (line 193), /packages/core/src/mcp/handlers/search.rs (line 304-308)

Currently, lifecycle_status is a String type with expected values "active", "archived", "deleted". This relies on string comparison which:

  • Has no compile-time validation of valid states
  • Could allow invalid values (e.g., "ACTIVE", "archive")
  • Requires string matching in multiple locations

Consider a LifecycleStatus enum:

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum LifecycleStatus {
    Active,
    Archived,
    Deleted,
}

Rationale: Type safety (SOLID - stronger contracts), exhaustive match enforcement, IDE autocomplete support.

Priority: Low - current implementation is functional and well-tested. The string approach is pragmatic for Phase 1 and allows forward compatibility with potential future states. This can be addressed in a follow-up if the team prefers stronger typing.


[Improvement] Lifecycle filtering could be pushed to database level

File: /packages/core/src/mcp/handlers/search.rs (lines 267-271, 298-310)

The current implementation fetches extra results (limit * 3) to compensate for post-filtering by lifecycle status. While this works, it means:

  • Fetching 3x more results than needed from the embedding search
  • Post-filtering in application memory
  • Potential edge cases where very few active results exist in a mostly-archived dataset

For future optimization, consider pushing the lifecycle filter into the database query when SurrealDB's vector search supports WHERE clauses on joined tables.

Priority: Low - this is a reasonable pragmatic approach for Phase 1. The effective_limit * 3 multiplier handles typical use cases. Document this as technical debt for future optimization when needed.


Nitpicks

Nit: /packages/core/src/models/node.rs (line 54)

fn is_active_lifecycle(status: &String) -> bool {

Prefer &str over &String for the parameter type:

fn is_active_lifecycle(status: &str) -> bool {

This is idiomatic Rust and avoids unnecessary indirection.


Nit: Test naming consistency

The lifecycle tests in search.rs (lines 674-793) use descriptive names which is good. However, some tests like test_lifecycle_filter_logic_deleted_always_excluded could be slightly more concise as test_deleted_nodes_always_excluded.


Architecture Assessment

✅ Follows Existing Patterns: The implementation aligns with existing codebase patterns (serde defaults, skip_serializing_if, comprehensive test coverage).

✅ Single Responsibility: Each file change is focused - schema updates schema, model updates model, search updates search.

✅ No Breaking Changes: Default value "active" ensures backward compatibility with existing nodes.

✅ Proper Documentation: Comments reference Issue #755 consistently throughout the codebase.

✅ Comprehensive Testing: 16 new tests added covering serialization, deserialization, and filter logic edge cases.


Security Review

✅ No security concerns identified:

  • No user input directly used in queries (lifecycle_status is server-controlled)
  • No sensitive data exposure
  • Filter logic is deny-by-default (deleted always excluded)

Performance Assessment

✅ Index Added: idx_node_lifecycle index supports efficient filtering at database level.

🟡 Post-filtering Overhead: As noted above, current approach fetches 3x results. Acceptable for Phase 1 but document for future optimization.

✅ Serialization Optimization: skip_serializing_if = "is_active_lifecycle" reduces JSON payload size for the common case (active nodes).


Test Coverage

Area Coverage Assessment
Node serialization/deserialization ✅ 7 tests
Search parameter parsing ✅ 5 tests
Lifecycle filter logic ✅ 4 tests
Integration with existing params ✅ 1 test

All 54 relevant tests pass (26 node tests + 28 search tests).


Recommendation

✅ APPROVE

This PR is a net positive improvement to the codebase. The implementation:

  1. Correctly implements Phase 1 and Phase 2 acceptance criteria
  2. Follows established project patterns and conventions
  3. Includes comprehensive test coverage
  4. Has no critical issues or security concerns
  5. Uses pragmatic tradeoffs appropriate for early-stage development

The suggested improvements (enum type, database-level filtering) are minor optimizations that can be addressed in future iterations. They do not block this PR.


Reviewed by Claude Opus 4.5 - Principal Engineer Reviewer

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

Review Status: APPROVE (recommendation)

Implementation correctly addresses Phase 1 and Phase 2 acceptance criteria with comprehensive test coverage and no blocking issues. See detailed review comment above for suggested improvements that can be addressed in future iterations.

Note: Cannot self-approve - requires another reviewer to formally approve.

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

Review Status: APPROVE (recommendation)

Implementation correctly addresses Phase 1 and Phase 2 acceptance criteria with comprehensive test coverage and no blocking issues. See detailed review comment above for suggested improvements that can be addressed in future iterations.

Note: Cannot self-approve - requires another reviewer to formally approve.

Changed is_active_lifecycle parameter from &String to &str for
idiomatic Rust. This allows passing string literals directly and
avoids unnecessary indirection.

Addresses reviewer nitpick from PR #828 code review.

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

malibio commented Jan 26, 2026

Copy link
Copy Markdown
Collaborator Author

Review Recommendations Addressed

Summary

  • ✅ Addressed: 1 recommendation
  • ⏭️ Skipped: 3 recommendations (with justifications below)

Changes Made

✅ Use &str instead of &String (🟢 Nitpick)

  • Changed is_active_lifecycle parameter from &String to &str
  • Commit: 2716b5f
  • This is idiomatic Rust and a low-risk improvement

Skipped Recommendations

⏭️ Use enum for lifecycle_status (🟡 Improvement)

  • Reason: Reviewer explicitly marked as "Low priority" and "pragmatic for Phase 1"
  • Would require significant refactoring across multiple files for marginal benefit at this pre-release stage
  • Can be revisited when/if the string-based approach causes issues

⏭️ Push filtering to database level (🟡 Improvement)

  • Reason: Depends on SurrealDB vector search capabilities that don't currently support WHERE clauses on joined tables
  • Reviewer noted to "document as technical debt" - not actionable in current PR
  • Current 3x fetch multiplier is acceptable for Phase 1

⏭️ Test naming consistency (🟢 Nitpick)

  • Reason: Subjective style preference with negligible benefit
  • Current test names are descriptive and clear
  • Renaming adds churn without improving test functionality

Test Results

  • ✅ All 390 Rust tests pass
  • ✅ Clippy: No warnings
  • ✅ Pre-commit hooks: All quality checks pass

Addressed by Claude Opus 4.5

Resolved conflict in packages/core/src/db/surreal_store.rs:
- Main refactored get_all_collections_with_member_counts to use typed
  CollectionWithCount struct with .map().collect() pattern
- Feature branch added lifecycle_status field to nodes
- Resolution: Added lifecycle_status field to CollectionWithCount struct
  and included it in Node construction

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 3556d3c into main Jan 26, 2026
@malibio
malibio deleted the feature/issue-755-lifecycle-status branch January 26, 2026 13:02
malibio added a commit that referenced this pull request Feb 4, 2026
…sion (#828)

* Add lifecycle_status as core node property with semantic search exclusion

Implements Phase 1 and 2 of Issue #755 - adds lifecycle management to
enable knowledge governance across all nodes.

Changes:
- Add lifecycle_status field to SurrealDB schema with default "active"
  and index for efficient filtering (schema.surql)
- Add lifecycle_status to Node struct with serde defaults and skip
  serialization for "active" status (node.rs)
- Add include_archived parameter to search_semantic MCP tool (tools.rs)
- Implement lifecycle filtering in search handler - excludes archived
  nodes by default, always excludes deleted nodes (search.rs)
- Update SurrealNode and all Node construction sites to include
  lifecycle_status field (surreal_store.rs, node_service.rs,
  schema_node.rs, task_node.rs)

Lifecycle values:
- "active" (default): Included in search, visible in UI
- "archived": Excluded from search by default, hidden from default views
- "deleted": Always excluded, soft-deleted, purgeable

Tests added for:
- Node lifecycle_status serialization/deserialization
- include_archived parameter parsing and defaults
- Lifecycle filter logic (active/archived/deleted combinations)

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

* Address review: Use idiomatic &str instead of &String

Changed is_active_lifecycle parameter from &String to &str for
idiomatic Rust. This allows passing string literals directly and
avoids unnecessary indirection.

Addresses reviewer nitpick from PR #828 code review.

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

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
…sion (#828)

* Add lifecycle_status as core node property with semantic search exclusion

Implements Phase 1 and 2 of Issue #755 - adds lifecycle management to
enable knowledge governance across all nodes.

Changes:
- Add lifecycle_status field to SurrealDB schema with default "active"
  and index for efficient filtering (schema.surql)
- Add lifecycle_status to Node struct with serde defaults and skip
  serialization for "active" status (node.rs)
- Add include_archived parameter to search_semantic MCP tool (tools.rs)
- Implement lifecycle filtering in search handler - excludes archived
  nodes by default, always excludes deleted nodes (search.rs)
- Update SurrealNode and all Node construction sites to include
  lifecycle_status field (surreal_store.rs, node_service.rs,
  schema_node.rs, task_node.rs)

Lifecycle values:
- "active" (default): Included in search, visible in UI
- "archived": Excluded from search by default, hidden from default views
- "deleted": Always excluded, soft-deleted, purgeable

Tests added for:
- Node lifecycle_status serialization/deserialization
- include_archived parameter parsing and defaults
- Lifecycle filter logic (active/archived/deleted combinations)

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

* Address review: Use idiomatic &str instead of &String

Changed is_active_lifecycle parameter from &String to &str for
idiomatic Rust. This allows passing string literals directly and
avoids unnecessary indirection.

Addresses reviewer nitpick from PR #828 code review.

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

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
…sion (#828)

* Add lifecycle_status as core node property with semantic search exclusion

Implements Phase 1 and 2 of Issue #755 - adds lifecycle management to
enable knowledge governance across all nodes.

Changes:
- Add lifecycle_status field to SurrealDB schema with default "active"
  and index for efficient filtering (schema.surql)
- Add lifecycle_status to Node struct with serde defaults and skip
  serialization for "active" status (node.rs)
- Add include_archived parameter to search_semantic MCP tool (tools.rs)
- Implement lifecycle filtering in search handler - excludes archived
  nodes by default, always excludes deleted nodes (search.rs)
- Update SurrealNode and all Node construction sites to include
  lifecycle_status field (surreal_store.rs, node_service.rs,
  schema_node.rs, task_node.rs)

Lifecycle values:
- "active" (default): Included in search, visible in UI
- "archived": Excluded from search by default, hidden from default views
- "deleted": Always excluded, soft-deleted, purgeable

Tests added for:
- Node lifecycle_status serialization/deserialization
- include_archived parameter parsing and defaults
- Lifecycle filter logic (active/archived/deleted combinations)

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

* Address review: Use idiomatic &str instead of &String

Changed is_active_lifecycle parameter from &String to &str for
idiomatic Rust. This allows passing string literals directly and
avoids unnecessary indirection.

Addresses reviewer nitpick from PR #828 code review.

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

---------

Co-authored-by: Claude Opus 4.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.

1 participant