Repository navigation
Description
Spun off from architectural-audit tracking issue #1228, finding C3 (hierarchy/ordering business logic in the frontend). This is the headline piece: ordering math. Container rules → #C3B; atomic child-transfer-on-split → C3c (deferred).
Background — what's actually still client-side
The audit says "move ordering math + depth into the daemon; return order hints in RPC responses." Investigation shows the write path already delegates ordering to the daemon — the residue is narrower than the finding implies:
outdentNodealready callsbackendAdapter.moveNode(nodeId, version, newParentId, { type: 'after', siblingId: oldParentId })(reactive-node-service.svelte.ts:1138-1141). The daemon'smove_noderesolvesInsertPosition::Afterand computes the fractional order server-side viaFractionalOrderCalculator(packages/core/src/services/node_service/mod.rs:1621-1628,sqlite_store.rs:1224-1307).- The authoritative order is returned from the store as
actual_orderand emitted in theRelationshipUpdatedevent as{"order": actual_order}(mod.rs:1631-1641). - The frontend already consumes that authoritative order:
hierarchy-sync.ts:56readspayload.orderfromrelationship:updatedand applies it viastructureTree(C2/C2: Make structureTree single source of truth — unify dual sync paths + invariant check #1250).
So what remains frontend-side is purely the optimistic pre-echo: calculateOutdentInsertOrderPure() (reactive-node-service.svelte.ts:61-73) and its wrapper calculateOutdentInsertOrder() (83-86) re-derive a fractional order client-side to feed the optimistic structureTree.moveInMemoryRelationship(oldParent, newParent, nodeId, insertOrder) at three sites (lines 1033, 1060, 1085). This is a second, divergent implementation of the daemon's ordering rule — exactly the audit's "if the daemon's rules change, the frontend diverges; can't validate end-to-end."
Note FractionalOrderCalculator is now deterministic (jitter removed in B7/#1256), but hierarchy-sync.ts:40 still adds Math.random() * 0.001 on the append fallback — a second place the frontend invents order values. That should also stop.
Target architecture
The frontend stops computing fractional order values entirely. Optimistic placement expresses positional intent (the same InsertPosition semantics the RPC uses), and the authoritative numeric order arrives via the relationship:updated event and reconciles the optimistic placement.
- Delete
calculateOutdentInsertOrderPure+calculateOutdentInsertOrderand the threeinsertOrder-passing call sites. The optimisticstructureTree.moveInMemoryRelationship(oldParent, newParent, nodeId)keeps placing the node under the new parent for instant feedback, but without a hand-computed numeric order. - Optimistic placement uses relative intent ("insert after
oldParentId"), not an absolute float.reactive-structure-tree.svelte.tsalready supports order-bearing inserts; add/confirm an insert-after-sibling placement that doesn't require the caller to invent a float. The authoritative float lands whenapplyHasChildUpdatedfires. - Remove the
Math.random()jitter append fallback inhierarchy-sync.ts:39-40— forhas_childthe daemon always supplies a real order; preserve existing order or log an anomaly, never invent a random float.
On "return order hints in RPC responses": in event-connected modes (Tauri invoke + browser SSE), the relationship:updated event already carries the authoritative order, so a response hint is redundant. Decision: do NOT add fields to ReorderNodeResponse/NodeResponse. Rely on the event as the single reconciliation channel (consistent with C2). Proto stays untouched.
Exact changes
reactive-node-service.svelte.ts:
- Delete
calculateOutdentInsertOrderPure(61-73),calculateOutdentInsertOrder(83-86), and the doc block (41-60). - At lines 1033, 1060, 1085: drop the
insertOrderargument; optimisticmoveInMemoryRelationship(oldParentId, newParentId, nodeId)places under the new parent with relative-after intent. - Remove the now-unused sibling-transfer integer-order assignment at line ~1103 (
i + 1) if relative-intent placement covers it (the daemon already orders these via the per-siblingmoveNode).
hierarchy-sync.ts:
- Remove the
Math.random() * 0.001jitter append fallback (39-40). If no order is supplied for ahas_childcreate, preserve existing order or log a warning (matching therelationship:updatedwarn at 58) — don't invent a value.
Daemon/proto: none. InsertPosition (#1216) already expresses Beginning/End/After; move_node already returns the moved node and emits RelationshipUpdated{order}.
Acceptance criteria
-
calculateOutdentInsertOrderPure/calculateOutdentInsertOrderno longer exist anywhere in the frontend. - No frontend code computes a fractional
ordernumber forhas_childplacement; optimistic updates use positional intent only; authoritative order arrives viarelationship:updated. - The
Math.random()jitter inhierarchy-sync.tsis gone; no invented order values anywhere. - Outdent (single node, node-with-siblings-below, outdent-to-root) produces correct visual ordering optimistically AND after event reconciliation, in both Tauri and browser/HTTP modes.
- No regression in the in-flight-CREATE outdent paths (lines ~1019-1075).
Testing — the audit's core complaint is "can't validate end-to-end"
- End-to-end ordering-parity test (required): drive an outdent through the daemon RPC and assert the resulting
has_childorder sequence is identical to the optimistic frontend placement afterrelationship:updatedreconciliation. Rust integration test on the daemon move path + a Happy-DOM test (bun run test, neverbun test) assertinghierarchy-syncapplies the daemon-supplied order and the optimistic placement converges to it. - Vitest covering the three outdent variants and both in-flight-CREATE branches; assert
structureTreechild order matches the daemon'sFractionalOrderCalculatoroutput for the same scenario. -
cargo testformove_nodewithInsertPosition::After(oldParent)returns the expectedactual_order(regression-lock the contract the frontend now depends on). -
bun run checkclean;createLogger; noany/{@html}/lint-suppression.
Risks
- Live outliner / Delete obsolete cache management code from SharedNodeStore #557 class. Removing the optimistic numeric order risks transient mis-ordering. Mitigate by keeping relative-after placement (not append-to-tail) so the optimistic position already matches intent; the event only refines the float.
- Browser/HTTP timing. Confirm SSE
relationship:updatedlatency doesn't flicker; relative-intent placement must be visually correct on its own. - Jitter removal collisions. Verify removing the random fallback can't produce duplicate orders now that the daemon (B7/B7: Remove SurrealDB-era fractional-ordering jitter — make ordering deterministic under SQLite #1256) is deterministic.
Coordination
- Unblocks C1b (deferred store/service-boundary re-audit) — once ordering math leaves the service, the split can be re-audited cleanly.
- Builds on C2 (C2: Make structureTree single source of truth — unify dual sync paths + invariant check #1250) hierarchy-sync/structureTree single source of truth and C1a (C1a: Consolidate the node-CRUD transport layer — fold tauri-commands node half into backendAdapter #1255) backendAdapter single transport — do not reintroduce a second order path.
- Parallel-safe with B8 (B8: Close TOCTOU in bulk_update / bulk_create_hierarchy (read escapes the transaction) #1258) and B4 follow-up: fold remaining 11 CollectionService::new daemon sites into core (collection_ops) #1243 — disjoint files.
- Precedes C3b (container rules) and C3c (atomic split-transfer; build on this settled move path).
Standard NodeSpace startup / PR sequence
git status + git pull origin main, EnterWorktree({name: "issue-<N>-c3a-outdent-ordering"}), bun install, bun run test baseline, gh:comment/gh:assign/gh:status. Before PR: bun run test:all (no new failures), bun run quality:fix + commit (revert unrelated cargo fmt churn via git status), bun run gh:pr <N>, /pragmatic-code-review, then ExitWorktree + gh pr merge --squash --delete-branch.
Spun off from #1228 (architectural audit), finding C3 (C3a — ordering math).
Activity
malibio commentedon May 30, 2026
Frontend baseline: 132 files, 3873 tests passed
C3a: Delete frontend outdent ordering math — trust the daemon's autho…
C3a: Delete frontend outdent ordering math — trust the daemon's autho…