Skip to content

Remove the empty_to_none sentinel in daemon NodeService — proto-presence audit (B5) - #1245

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1242-empty-to-none-audit
May 30, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1242-empty-to-none-audit

Conversation

@malibio

@malibio malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #1242

…tional (closes #1242)

B5 from architectural audit #1228 — eliminates the empty_to_none() helper that
silently collapsed proto3 "field unset" and "field set to empty string" into
the same None, making intent explicit at the type level.

Proto changes (11 fields converted from bare string to optional string):
- CreateNodeRequest: parent_id, collection, lifecycle_status, id
- UpdateNodeRequest: node_type, add_to_collection, remove_from_collection, lifecycle_status
- SearchRequest: collection, collection_id
- MoveNodeRequest: new_parent_id

Each conversion documents why "" is not a legitimate client value. prost now
generates Option<String> for all fields, and the daemon reads them directly
without the empty_to_none helper — which is deleted.

Consumer updates:
- daemon/node_service.rs: remove all 10 empty_to_none call sites; delete helper
- daemon/tests: update inline unit tests + integration tests to use Option<String>
- cli/commands: use None instead of String::new() for absent optional fields
- desktop-app/nodes.rs: use None/Some() correctly for all proto optional fields

New test:
- move_node_to_root_when_new_parent_id_unset: verifies new_parent_id=None moves
  node to root (documents the intentional sentinel semantics)

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

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1245 (B5: Remove empty_to_none sentinel)

Overall: This is a clean, well-scoped cleanup that achieves its stated goal. The empty_to_none helper is fully deleted, all 11 identified call sites are migrated to proto3 optional fields, and all consumers (daemon, CLI, desktop-app, integration tests) are updated consistently. The proto comments document the intent for each field. One functional correctness issue and two minor items are noted below.


Acceptance Criteria Coverage

Criterion Status Notes
All 11 call sites audited (Create×4, Update×4, Search×2, Move×1) PASS Verified by counting removed empty_to_none calls in diff
empty_to_none helper deleted PASS Zero remaining occurrences in workspace
No field where "" could be legitimate silently collapses to None PASS All fields are correctly none-or-present semantics
Proto changes regenerate cleanly Assumed PASS Build must be verified before merge
No lint suppression / no #[deprecated] PASS Clean deletion throughout
Tests updated for optional field semantics PASS All test sites use None/Some(...) correctly

[Improvement] Proto comment for new_parent_id claims "" still moves to root — it no longer does

File: packages/proto/proto/node_service.proto

// unset or "" = move to root (None on the ops layer); present = new parent ID.
optional string new_parent_id = 3;

File: packages/daemon/src/services/node_service.rs

let new_parent = req.new_parent_id;   // Option<String>
// ...
.move_node(&req.node_id, req.version, new_parent.as_deref(), position)

The old behavior was: empty_to_none("") → None → move to root.
The new behavior is: Some("") is passed as Some("".as_str()) to the ops layer, which calls node_exists(""), which returns false, which yields an InvalidParent error — not a move to root.

The proto comment promises a guarantee ("" = move to root) that the implementation no longer provides. Clients following the comment would get a runtime error instead of the documented behavior. The fix is a one-liner:

// Normalize Some("") to None: empty string is not a valid parent ID,
// and "" historically encoded "move to root" for callers that cannot
// distinguish absent from empty (e.g. generated gRPC stubs default-init to "").
let new_parent = req.new_parent_id.filter(|s| !s.is_empty());

…and update the proto comment to match:

// unset = move to root (None on the ops layer); present and non-empty = new parent ID.
// "" is treated as unset (move to root) to preserve compatibility with gRPC clients
// that default-initialize the field.
optional string new_parent_id = 3;

Rationale: The test move_node_to_root_when_new_parent_id_unset only exercises the None case. No existing caller currently sends Some("") (the desktop app uses Option<String> correctly; the CLI has no move implementation), so this is latent, but the comment is actively misleading and creates a correctness trap for future external callers.


[Improvement] Desktop-app create_node: inline id sentinel is correct but inconsistent with parent_id

File: packages/desktop-app/src-tauri/src/commands/nodes.rs

// id — uses inline sentinel because CreateNodeInput.id is String (not Option):
id: if node.id.is_empty() { None } else { Some(node.id) },

// parent_id — cleaner, because CreateNodeInput.parent_id is already Option<String>:
parent_id: node.parent_id,

The if/else sentinel for id is the correct approach given that CreateNodeInput.id is a bare String in the Tauri command input (the frontend always supplies a UUID or ""). A brief inline comment explaining why this field is not Option<String> in CreateNodeInput would prevent future readers from wondering why it differs from parent_id. This is a readability improvement, not a correctness issue.


Nit: The move_node_to_root_when_new_parent_id_unset test does not verify the Some("") behavior

grpc_round_trip.rs tests the None path but does not add a second move_node call with new_parent_id: Some("".to_string()) to confirm the documented behavior. This is only worth adding if the [Improvement] above is accepted and the filter() normalization is added.


What is not a concern

  • import_round_trip.rs uses collection: String::new() for ImportOptions.collection (a different proto message in import_service.proto, bare string, out of scope for this PR).
  • grpc_round_trip.rs uses node_type: String::new() for WatchRequest.node_type (bare string, where "" legitimately means "watch all nodes", also out of scope).
  • The test comment removal ("include a content change so NodeUpdate is non-empty") is correct: the ops layer explicitly handles the update.is_empty() case by fetching the current node, so a collection-only update without content is valid.
  • The .clone() removal on req.collection_id in search is correct — the field is now Option<String> and is consumed in place.

Verdict

The change meets the acceptance criteria and is a net positive. Merge is blocked only on the [Improvement] for new_parent_id: the proto comment advertises behavior the code no longer provides. The fix is a single .filter(|s| !s.is_empty()) call. The desktop-app id improvement and the test nit are optional.

@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 complete. See the full analysis in the PR comment above. Key issue: new_parent_id proto comment claims "" = move to root but the handler no longer normalizes Some("") to None after the empty_to_none removal. Recommend adding .filter(|s| !s.is_empty()) and updating the proto comment before merge.

…node

The proto comment said 'unset or "" = move to root' but the daemon was only
handling None (unset). Fix: apply .filter(|s| !s.is_empty()) so both None and
Some("") map to root-move. Add integration test for the "" case.

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 2541a7b into main May 30, 2026
@malibio
malibio deleted the worktree-issue-1242-empty-to-none-audit branch May 30, 2026 07:47
malibio added a commit that referenced this pull request Jun 22, 2026
…nce audit (B5) (#1245)

* Remove empty_to_none sentinel: convert bare proto string fields to optional (closes #1242)

B5 from architectural audit #1228 — eliminates the empty_to_none() helper that
silently collapsed proto3 "field unset" and "field set to empty string" into
the same None, making intent explicit at the type level.

Proto changes (11 fields converted from bare string to optional string):
- CreateNodeRequest: parent_id, collection, lifecycle_status, id
- UpdateNodeRequest: node_type, add_to_collection, remove_from_collection, lifecycle_status
- SearchRequest: collection, collection_id
- MoveNodeRequest: new_parent_id

Each conversion documents why "" is not a legitimate client value. prost now
generates Option<String> for all fields, and the daemon reads them directly
without the empty_to_none helper — which is deleted.

Consumer updates:
- daemon/node_service.rs: remove all 10 empty_to_none call sites; delete helper
- daemon/tests: update inline unit tests + integration tests to use Option<String>
- cli/commands: use None instead of String::new() for absent optional fields
- desktop-app/nodes.rs: use None/Some() correctly for all proto optional fields

New test:
- move_node_to_root_when_new_parent_id_unset: verifies new_parent_id=None moves
  node to root (documents the intentional sentinel semantics)

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

* Address review: normalize new_parent_id empty string to None in move_node

The proto comment said 'unset or "" = move to root' but the daemon was only
handling None (unset). Fix: apply .filter(|s| !s.is_empty()) so both None and
Some("") map to root-move. Add integration test for the "" case.

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

---------

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

Remove the empty_to_none sentinel in daemon NodeService — proto-presence audit (B5)

1 participant