Skip to content

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

Closed

Description

@malibio

Spun off from the architectural-audit tracking issue #1228 (finding B5). The audit predates a partial migration — this is now a NARROW cleanup, not a sweeping rewrite. The dangerous fields (content, properties, request version) were already migrated to proto3 optional (#1216 and follow-ups). What remains is auditing the ~12 surviving empty_to_none calls and deleting the helper if all can be removed/converted.

Background

empty_to_none(s: String) -> Option<String> (packages/daemon/src/services/node_service.rs line 1313) collapses proto3's "field unset" and "field set to empty string" into the same None. For any field where "" is a legitimate value, this silently discards the client's intent — the generalized root cause of #1216.

Already fixed (do not re-do): packages/proto/proto/node_service.proto already uses optional for the fields where "" is legitimate:

  • UpdateNodeRequest.content (line 158: "unset = no change; "" is a legitimate value")
  • UpdateNodeRequest.properties (line 159)
  • UpdateNodeRequest.version / DeleteNodeRequest.version (lines 154, 175 → Option<i64>)
  • NodeData.parent_id (line 85 — note this is the response shape, not a request).

So prost already generates Option<T> for those, and the daemon reads them directly (e.g. req.content at line 179, no empty_to_none).

The actual task: audit the remaining empty_to_none call sites

For each call site, decide one of three actions. Check whether the proto field is already optional (→ prost yields Option<String>, so empty_to_none is now redundant — delete it and use the Option directly), or a bare string where "" means absent (→ ask: can "" ever be a value a client legitimately sends? If no, the helper is acceptable but optional is cleaner; if yes, the field MUST become optional).

# Line Field "" legitimate? Action
1 82 req.collection (Create) No — a collection path is present-or-absent convert field to optional string for clarity OR leave + document. empty_to_none removable either way.
2 83 req.parent_id (Create) — bare string; the optional parent_id at proto 85 is on the response NodeData, NOT this request No — "" deliberately encodes "root" ""-means-root is an intentional sentinel; safe to keep, but optional makes "root" explicit. Document.
3 96 req.id (Create) — "Empty = server generates" No — "" intentionally means "generate" Keep or convert; intentional sentinel. Document.
4 120 req.lifecycle_status (Create) — "defaults to active when empty" No — enum-like Safe to keep; optional optional.
5 178 req.node_type (Update) — proto: "empty is not legitimate" No Safe to keep; optional matches content/properties siblings.
6 182 req.lifecycle_status (Update) No Same as #5.
7 201 req.add_to_collection (Update) No — collection path Same as #1.
8 210 req.remove_from_collection (Update) No — collection id Same as #1.
9 393 req.collection_id (Search) No — filter present-or-absent Safe to keep; optional optional.
10 394 req.collection (Search) No Same.
11 540 req.new_parent_id (Move) — "empty = move to root" No — intentional sentinel ""-means-root; safe to keep, or convert to optional. Document.

The audit said "~12 remaining"; the verified list is 11 distinct call sites (#1228's count is approximate). Re-grep empty_to_none in the file and reconcile — if a 12th exists, add it with the same analysis.

Decision rule

For every field in the table, "" is NOT a legitimate user-supplied value — they're all naturally present-or-absent (paths, ids, enum-like statuses, or intentional ""-as-sentinel like parent_id/new_parent_id meaning "root"). Therefore:

  1. No field in this set strictly requires proto optional for correctness (unlike content/properties, already migrated).
  2. The goal is to eliminate the empty_to_none helper. Preferred: convert the bare-string request fields to optional string in the proto so prost yields Option<String> and the daemon reads the option directly — deleting empty_to_none entirely. Consistent polish with the already-migrated fields; makes intent (root / no-change / generate-id) explicit at the type level.
  3. If converting any specific field to optional is undesirable (e.g. a ""-as-sentinel field where the team prefers the sentinel), that field may keep an inline if s.is_empty() check — but then document why in a code comment, and justify whether the shared helper still earns its keep.

Target outcome: empty_to_none is deleted. Every former call site either reads a proto optional field as Option<String>, or has an inline documented ""-sentinel check. No field where "" could be legitimate is left collapsing silently (none in this set, but the audit documents that conclusion).

Out of scope

Coordination with #1241 (B3+B4)

#1241 and this issue edit the same handler bodies (create_node, update_node, move_node). Land #1241 FIRST. #1241 replaces the inline create/update logic with one-line node_ops delegations, which deletes several call sites in the table above (row #4 lifecycle, rows #7/#8 collection add/remove move into node_ops input construction). Doing B5 after #1241 means this issue operates on smaller handlers against the final node_ops-input mapping. If parallelizing, branch this off #1241's branch (not main) and merge after.

If #1241 lands first, re-grep empty_to_none before starting — the surviving set will be smaller, and the Create/Update collection/lifecycle rows may already be gone.

Acceptance criteria

  • Every surviving empty_to_none call site is audited per the table; each is either (a) replaced by reading a proto optional field as Option<String>, or (b) an inline documented ""-sentinel check.
  • The empty_to_none helper (line 1313) is deleted — or, if at least one inline-sentinel field justifiably remains, a code comment documents why the helper stays.
  • No field where "" could be a legitimate client value silently collapses to None. (Document that none in this set qualify.)
  • Any proto changes regenerate cleanly (prost build) and the daemon compiles against the new Option<...> field types.
  • No lint suppression, no #[deprecated]. Delete, don't deprecate.
  • cargo test (core + daemon) and cargo clippy pass; no new warnings.

Testing

  • For any field converted to optional: add/extend a daemon handler test asserting the unset case and the "" case behave as documented (e.g. for new_parent_id, unset/"" both move-to-root; for a converted path field, unset = no collection).
  • Regenerate proto and confirm the workspace builds: cargo build -p nodespace-proto -p nodespaced.
  • cargo test -p nodespaced. Run bun run test once; if the desktop-app proto bindings regenerate, run bun run test:all.

Standard NodeSpace startup / PR sequence

Primary checkout git status + git pull origin main, then EnterWorktree({name: "issue-<N>-empty-to-none-audit"}); inside: bun install, baseline, bun run gh:assign <N> "@me", bun run gh:status <N> "In Progress". Before PR: cargo test + bun run test:all, bun run quality:fix (revert unrelated cargo fmt churn via git status), commit, bun run gh:pr <N>. /pragmatic-code-review before merge, then ExitWorktree({action: "remove", discard_changes: true}) and gh pr merge <PR#> --squash --delete-branch.


Spun off from #1228 (architectural audit), finding B5.

Activity

  1. self-assigned this
    on May 30, 2026
  2. added a commit that references this issue on May 30, 2026
    2541a7b
  3. added a commit that references this issue on Jun 22, 2026
    4a12864
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions