Skip to content

Fix: Smart navigation resolveWithRootAncestor breaks task node viewer opening - #916

Merged
malibio merged 2 commits into
mainfrom
feature/issue-915-fix-entity-node-navigation
Feb 28, 2026
Merged

malibio merged 2 commits into
mainfrom
feature/issue-915-fix-entity-node-navigation

Conversation

@malibio

@malibio malibio commented Feb 27, 2026

Copy link
Copy Markdown
Collaborator

Closes #915

…viewer (#915)

findRootAncestor() now checks if the target node has its own dedicated
viewer (via pluginRegistry.hasViewer) before walking up the tree. Entity
nodes like task, date, and query open in their own viewer instead of
being resolved to a parent's viewer. Primitive child nodes (text, header)
still correctly resolve to their nearest viewer-owning ancestor.

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

malibio commented Feb 28, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review -- PR #916

Reviewer: Principal Engineer AI (claude-opus-4-6)
Review Type: Bug Fix
Files Changed: 2 (navigation-service.ts, navigation-service.test.ts)
Risk Level: Low-Medium (core navigation path modified)


Requirements Check (Issue #915)

Acceptance Criterion Status
Clicking open on a task node opens TaskNodeViewer (not parent's viewer) Covered by test task node nested under date node opens as task
Wikilink to primitive child still resolves to root ancestor + scroll Covered by test primitive text node under date still resolves to date ancestor
Other entity types with viewers (date, query) also open correctly Covered for date (date node nested under another node still opens as date); query has no viewer yet so N/A
Existing navigation tests pass Must verify -- no existing tests removed or modified
New test coverage for entity-within-parent scenario 5 new tests added

All acceptance criteria are addressed.


Code Review Findings

No Critical Issues Found

The implementation is clean, minimal, and correctly scoped.

Suggested Improvements

1. [Improvement] Defensive handling when node is not in sharedNodeStore (navigation-service.ts:145-148)

const targetNode = sharedNodeStore.getNode(nodeId);
if (targetNode && pluginRegistry.hasViewer(targetNode.nodeType)) {
  return nodeId;
}

If sharedNodeStore.getNode(nodeId) returns undefined (node not yet loaded from backend), the function falls through to the tree-walking loop. For a viewer-owning entity node whose data hasn't loaded yet, this would incorrectly resolve it to an ancestor. The same applies to the mid-walk check on line 162.

In practice this is likely safe because resolveWithRootAncestor is called after resolveNodeTarget (line 216), which itself calls sharedNodeStore.getNode and returns null if the node isn't found (line 213-214), short-circuiting the whole flow. So the defensive path works correctly end-to-end.

However, findRootAncestor is a private method that could be called from new call sites in the future. Consider adding a brief comment noting the precondition: the target node is expected to already be in the store when this method is called. This is a minor documentation concern, not a blocker.

2. [Improvement] Method name findRootAncestor is now misleading (navigation-service.ts:141)

The method no longer finds the root ancestor -- it finds the nearest viewer-owning ancestor, or the root if no viewer-owning ancestor exists. The name findRootAncestor and the variable rootId at the call site (line 216) create a semantic mismatch with the new behavior.

Consider renaming to findNavigationAncestor or findViewerAncestor to reflect the updated semantics. The JSDoc was correctly updated, but the method name and the rootId variable at line 216 still suggest root-level resolution.

Nitpicks

  • Nit: navigation-service.ts:216 -- The variable const rootId = this.findRootAncestor(...) could be renamed to ancestorId or navAncestorId to match the updated behavior semantics.

  • Nit: Test file -- The makeNode helper duplicates the pattern from the existing tests above (line ~50). Not worth refactoring now since the existing tests use inline object literals, but if more test suites are added, extracting a shared factory would reduce duplication.


Architecture Assessment

The design decision to use pluginRegistry.hasViewer() as the boundary detector is the right call. It:

  1. Leverages existing infrastructure rather than introducing a new concept of "entity" vs "primitive" node types.
  2. Is automatically correct for any future node types -- if a plugin registers a viewer, navigation will respect it.
  3. Follows Open/Closed Principle -- new node types with viewers work without modifying navigation code.

The two-checkpoint approach (check target first, then check during walk) correctly handles both cases: (a) directly navigating to a viewer-owning node, and (b) a primitive node walking up and stopping at the first viewer-owning ancestor rather than overshooting to the tree root.

Testing Assessment

The 5 new tests cover the critical scenarios well:

  • Entity (task) under entity (date) -- opens as entity, not parent
  • Entity in other-pane navigation -- same behavior across navigation modes
  • Primitive (text) under entity (date) -- correctly resolves to entity parent
  • Entity (date) under non-viewer node (text) -- entity still opens as itself
  • Deeply nested primitive chain -- walks up to nearest viewer-owning ancestor

One scenario that could be added in the future (not blocking): a viewer-owning node under another viewer-owning node under another viewer-owning node (3+ levels of entities). The current tests cover 2 levels, which is sufficient for now.


Recommendation

APPROVE -- This is a clean, well-tested bug fix that correctly addresses the regression from #910. The implementation is minimal, uses existing infrastructure (pluginRegistry), and follows the Open/Closed Principle for future extensibility. The naming suggestions above are improvements but not blockers.

The change is a clear net positive to code health.

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

APPROVE (posted as comment since self-review is restricted). Clean, minimal bug fix with good test coverage. The pluginRegistry.hasViewer() approach is architecturally sound -- it leverages existing infrastructure and automatically handles future node types. See detailed review in PR comments for two optional naming improvements.

The method no longer finds the tree root — it finds the nearest
viewer-owning ancestor. Renamed method, variables, and comments
to reflect the updated semantics.

Skipped: precondition comment suggestion — the call chain is
self-evident (resolveWithNavigationAncestor always calls
resolveNodeTarget first, which populates the store).

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

malibio commented Feb 28, 2026

Copy link
Copy Markdown
Collaborator Author

Review Feedback Addressed

✅ Addressed (1)

  • Rename findRootAncestor → findNavigationAncestor: Renamed method, wrapper (resolveWithNavigationAncestor), variables (rootId → ancestorId, rootTarget → ancestorTarget), and updated all comments to reflect the updated semantics.

⏭️ Skipped (1)

  • Precondition comment: The call chain is self-evident — resolveWithNavigationAncestor always calls resolveNodeTarget first, which populates the store before findNavigationAncestor is called. Adding a comment for this would be over-documenting an obvious contract.

Summary

  • 📝 1 commit: badb0593
  • 🧪 All 39 navigation tests passing
  • ✅ Quality checks clean

@malibio
malibio merged commit 68ac72d into main Feb 28, 2026
@malibio
malibio deleted the feature/issue-915-fix-entity-node-navigation branch February 28, 2026 00:59
malibio added a commit that referenced this pull request Jun 22, 2026
… opening (#916)

* Fix entity node navigation resolving to parent viewer instead of own viewer (#915)

findRootAncestor() now checks if the target node has its own dedicated
viewer (via pluginRegistry.hasViewer) before walking up the tree. Entity
nodes like task, date, and query open in their own viewer instead of
being resolved to a parent's viewer. Primitive child nodes (text, header)
still correctly resolve to their nearest viewer-owning ancestor.

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

* Address review: rename findRootAncestor to findNavigationAncestor

The method no longer finds the tree root — it finds the nearest
viewer-owning ancestor. Renamed method, variables, and comments
to reflect the updated semantics.

Skipped: precondition comment suggestion — the call chain is
self-evident (resolveWithNavigationAncestor always calls
resolveNodeTarget first, which populates the store).

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

---------

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

Fix: Smart navigation resolveWithRootAncestor breaks task node viewer opening

1 participant