Skip to content

Reword core's batch-write, event and collision docs without naming the sync daemon #3364

Closed

Description

@mstomar125

Summary

Reword the docs of core's batch-write and event-emission APIs, the bulk store paths, and the local-first collection-collision rule. They should describe the contract, not the nodespace-sync code that happens to call them: apply_node_upsert, apply.rs, the "sync-apply cold-sweep" and the "cloud-sync push consumer".

Also:

  • move a misplaced doc block onto the function it documents;
  • fix a stale "128 slots" comment;
  • rename one test whose name says "push".

Comments, docs and one test-function name only. No behaviour or public API change.

Context

  • These APIs are generic and stay.
    • bulk_add_to_collections_notify is called by core's own batch importer (packages/daemon/src/services/import_service.rs), and every event subscriber needs its events.
    • bulk_create_has_child_edges and the store's bulk paths are generic batch writes with core tests.
  • Their docs justify them by what the Pro daemon does:
    • "so the cloud-sync push consumer replicates them"
    • "never reach cloud"
    • "for the sync-apply cold-sweep's batched reconnect path"
    • "nodespace-sync's apply_node_upsert"
    • "nodespaced-pro's apply.rs"
  • The collision rule is a core local-first rule (ADR-065, ADR-068). Two offline devices can each create a collection named "Work", so create_node must never hard-reject on a duplicate name.
    • Its comments and the convergence tests explain this through one sync function's cursor contract.
    • State the rule itself instead: any caller applying another device's writes through create_node must not stall on a benign duplicate.
  • The event-channel comment is stale. bulk_add_to_collections_notify's inline comment says the channel is "bounded (128 slots)", but DOMAIN_EVENT_CHANNEL_CAPACITY is 4096.
  • Follow the parent's wording guide. "sync" may stay as the generic ADR-060 term for a write that arrived from another device. Name no product, repository or sync-internal function.

Scope

Line numbers are hints at af8ddb6. Locate each item by the symbol named.

Event emission

  • packages/core/src/services/node_service/mod.rs
    • The DOMAIN_EVENT_CHANNEL_CAPACITY doc (455-468). Keep the sizing rationale, including the 128 → 4096 history.
      • Replace "the cloud-sync push consumer" and "memberships then never reach cloud, leaving those collections empty on other devices".
      • The new text: a subscriber doing slow per-event work (for example, forwarding each member_of edge over the network) drains slower than a batch import emits, so it lags and DROPs edges when a burst exceeds the buffer.
    • Test bulk_add_to_collections_notify_emits_push_events (9113-9175).
      • Rewrite its doc: every subscriber must see each new membership, and the raw store insert emits nothing.
      • Rename the function to bulk_add_to_collections_notify_emits_relationship_events.
      • Assertion message (9160): drop "so it pushes to cloud".
      • Comment (9164): "no spurious re-emit".
    • Test doc of bulk_membership_burst_does_not_overflow_the_event_channel (9177-9181). "drop edges for a lagging subscriber" instead of "leaves a collection empty on other devices".
  • packages/core/src/services/node_service/relationship.rs
    • The bulk_add_to_collections_notify doc (1959-1970). The raw store insert emits nothing, so without this no subscriber learns of the edges: other windows, CLI watchers, or a host that mirrors changes. This puts bulk import on the same event path as create_relationship. Keep the return-value sentence.
    • Its chunk-yield comment (1981-1986). "bounded (DOMAIN_EVENT_CHANNEL_CAPACITY)" instead of "bounded (128 slots)". A tight loop could make a slow subscriber lag and drop edges, so yield every chunk to let subscribers drain.
  • packages/daemon/src/services/import_service.rs, the comment at the bulk_add_to_collections_notify call (975-981). "…emits a RelationshipCreated event that every subscriber sees", instead of "PUSHES to cloud … every other device (and any first-time puller)".

Batch-write APIs and bulk store paths

  • packages/core/src/services/node_service/hierarchy.rs, the bulk_create_has_child_edges doc (1048-1061).
    • The new text: "Batched sibling of create_parent_edge for attaching many genuinely-unparented children in one store transaction — for example when applying a batch of hierarchy edges written elsewhere."
    • Replace "the from-scratch (cold) sweep" with "a from-scratch batch where every parent is fresh". Keep every other sentence.
  • packages/core/src/db/sqlite_store/relationships.rs
    • The assert_root_only_membership doc (503-513).
      • "the sync-apply cold-sweep (which calls bulk_add_to_collections directly)" becomes "any batched caller of bulk_add_to_collections".
      • "bulk/cold-sweep path" becomes "the bulk path".
    • The bulk_create_has_child doc (1206-1218): "…for a batched attach of hierarchy edges written elsewhere". Line 1227: "this bulk attach path".
    • The misplaced doc block (1275-1280). It documents bulk_add_to_collections, but it sits on top of collection_typed_ids, where rustdoc merges it with that function's own doc.
      • Delete it there.
      • Add a reworded doc directly above pub async fn bulk_add_to_collections: "Bulk-insert member_of edges, returning the edges actually created (skipping existing ones) as (rel_id, node_id, collection_id, order). Emits no events; callers whose writes must reach event subscribers use [crate::services::NodeService::bulk_add_to_collections_notify]."
    • Not here: the get_multi_membership_edges doc. Generalize get_multi_membership_edges into member_of_edges with caller-supplied filters #3343 rewrites or replaces it (ADR-083 §4), and Sweep the Pro and sync wording C7 leaves around replicated writes and AI-chat privacy #3367 checks for leftovers.
  • packages/core/src/db/sqlite_store/nodes.rs, the assert_may_gain_parent doc (2824-2847). Lines 2829-2830 become "bulk_create_has_child (the bulk attach path)", and lines 2846-2847 become "the bulk path".
  • packages/core/src/db/sqlite_store/mod.rs, the bulk-path parity test comments (1647-1648, 1671, 1695-1696, 1757-1759, 1824). Replace "sync-apply cold-sweep" and "cold-sweep parity" with "the bulk path", "a batched caller" or "bulk-path parity". Leave the embedding round-trip test to Delete the dead embedding push/pull seam; keep embedding.origin for existing databases #3337, which deletes it.
  • packages/core/src/db/schema.rs, the Rust // comment outside SCHEMA_SQL listing has_child writers (338-340). "(create, append, move, bulk hierarchy attach, seeding, generic relationship create)". Leave the SQL comments inside SCHEMA_SQL to Delete the dead embedding push/pull seam; keep embedding.origin for existing databases #3337.
  • packages/core/src/services/node_service/bulk.rs.
    • At 176-180: "A batched caller applying writes made elsewhere can't make that same assumption — it may send a non-null placeholder…".
    • At 929-931: "so a batched update re-renders…".
  • packages/core/src/services/node_service/mod.rs.
    • The bulk_create title test doc (5299-5310). Replace "The batched cold-pull/reconnect apply path (nodespaced-pro's apply.rs) routes creates through bulk_create" with "A batched caller applying writes made elsewhere routes creates through bulk_create". Keep the rest.
    • Line 5370: "so a batched update stays title-searchable".
  • packages/core/src/services/embedding_processor.rs, the doc of scheduler_grants_immediately_when_no_active_database (546-547). "the single-database path is unaffected".
  • packages/core/tests/it/reverse_relationship_name_test.rs:293. "The bulk attach path (bulk_create_has_child_edges)."

The local-first collision rule

  • packages/core/src/db/sqlite_store/nodes.rs
    • The collection-collision comment in create_node (320-329). Collection-name collisions are suggest-don't-block (ADR-065). Two offline devices can each validly create the same name. A hard rejection would propagate out of any caller applying another device's writes through create_node, and stall it permanently on a benign duplicate. Keep the "detect before insert" sentence.
    • Lines 375-378. "Best-effort and non-blocking … A marker-write failure must never fail node creation (ADR-065)." Drop the mark_possible_duplicate provenance.
  • packages/core/tests/it/collection_membership_test.rs, the comment in test_collection_name_uniqueness_is_best_effort_not_enforced (735-740). The same restatement, without nodespace-sync's apply_node_upsert or "the sync cursor".
  • packages/core/tests/it/collection_name_convergence_test.rs
    • Module doc (7-13, 17-20, 26-28). Describe the failure mode as "any caller applying another device's node through create_node could never get past that row", and "the real NodeService::create_node path that applies a peer's node".
    • Line 132: "(replicated apply)" instead of "(sync-apply)".
    • Lines 429-434 and 457-459: "a replicated rename — an apply whose node already exists locally, which calls NodeService::update_node directly".
  • packages/core/tests/it/person_duplicate_convergence_test.rs
    • Line 135: "(replicated apply)" instead of "(sync-apply)".
    • Lines 26-27: drop "with no nodespace-sync involved anywhere in this file". "reachable on a purely local-only install" stays.
    • Lines 38-40: "the real create_node/update_node paths a replicated apply uses".
    • Lines 368-370: "Applying a peer's node has three branches: create…, update…, and an already-exists fallback to update."

Out of scope

Steps

  1. Follow CLAUDE.md's startup sequence:
    • pull main;
    • EnterWorktree({name: "issue-<N>-batch-api-docs"});
    • bun install, then the bun run test baseline;
    • self-assign at pickup and set In Progress.
  2. Make the edits under Scope, checking each sentence against the code.
  3. Move the bulk_add_to_collections doc as described. Confirm with cargo doc (below) that collection_typed_ids now shows only its own doc.
  4. Run bun run scripts/check-pro-boundary.ts and paste the printed BASELINES block. Expected at af8ddb6, but use the real output: cloudWording −8, editionBranching −1.
  5. Verify, then finish:
    • bun run quality:fix, and commit;
    • git push origin HEAD:issue-<N>-batch-api-docs;
    • gh pr create --head issue-<N>-batch-api-docs;
    • merge only with bun run merge <PR#> once approved.

Acceptance criteria

Tests and verification

  • Vocabulary grep. It must print only the Move Pro-owned data out of core's data model (ADR-083) #3345-owned lines listed above:
    git grep -n -I -P '(?i:cold[- ]?sweep|nodespace-sync|nodespaced-pro|apply_node_upsert|mark_possible_duplicate\b|cloud-?sync|to cloud|reach cloud|push consumer|sync-apply|community single)' -- packages/core/src/services/node_service/relationship.rs packages/core/src/services/node_service/hierarchy.rs packages/core/src/services/node_service/bulk.rs packages/core/src/db/sqlite_store/relationships.rs packages/core/src/db/sqlite_store/nodes.rs packages/core/src/db/sqlite_store/mod.rs packages/core/src/db/schema.rs packages/core/src/services/embedding_processor.rs packages/daemon/src/services/import_service.rs packages/core/tests/it/collection_membership_test.rs packages/core/tests/it/collection_name_convergence_test.rs packages/core/tests/it/person_duplicate_convergence_test.rs packages/core/tests/it/reverse_relationship_name_test.rs packages/core/src/services/node_service/mod.rs
    One more expected leftover in node_service/mod.rs goes with Describe core's access gate and daemon seams without naming the Pro daemon #3363: the subtree_access_gate field doc.
  • cargo fmt --all --check
  • cargo clippy -p nodespace-core -p nodespace-daemon --all-targets -- -D warnings
  • RUSTDOCFLAGS='-D rustdoc::broken_intra_doc_links' cargo doc -p nodespace-core --no-deps --no-default-features. The moved doc carries an intra-doc link.
  • bun run test:changed. This runs the Rust tier, which takes the shared machine slot.
  • No new test. The only test change is the rename, a pure refactor, so no mutation check is needed.

Dependencies

Risks and rollback


Plan key: C10.2 (pro-boundary DAG).

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions