Repository navigation
Closed
Labels
pro-boundaryPro/core boundary: Pro code moves to nodespace-sync (ADR-081..085)
Description
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_notifyis 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_edgesand 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'sapply_node_upsert" - "
nodespaced-pro'sapply.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_nodemust 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_nodemust 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)", butDOMAIN_EVENT_CHANNEL_CAPACITYis 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_CAPACITYdoc (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_ofedge 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".
- The
packages/core/src/services/node_service/relationship.rs- The
bulk_add_to_collections_notifydoc (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 ascreate_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.
- The
packages/daemon/src/services/import_service.rs, the comment at thebulk_add_to_collections_notifycall (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, thebulk_create_has_child_edgesdoc (1048-1061).- The new text: "Batched sibling of
create_parent_edgefor 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.
- The new text: "Batched sibling of
packages/core/src/db/sqlite_store/relationships.rs- The
assert_root_only_membershipdoc (503-513).- "the sync-apply cold-sweep (which calls
bulk_add_to_collectionsdirectly)" becomes "any batched caller ofbulk_add_to_collections". - "bulk/cold-sweep path" becomes "the bulk path".
- "the sync-apply cold-sweep (which calls
- The
bulk_create_has_childdoc (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 ofcollection_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-insertmember_ofedges, 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_edgesdoc. 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.
- The
packages/core/src/db/sqlite_store/nodes.rs, theassert_may_gain_parentdoc (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 outsideSCHEMA_SQLlistinghas_childwriters (338-340). "(create, append, move, bulk hierarchy attach, seeding, generic relationship create)". Leave the SQL comments insideSCHEMA_SQLto 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_createtitle test doc (5299-5310). Replace "The batched cold-pull/reconnect apply path (nodespaced-pro'sapply.rs) routes creates throughbulk_create" with "A batched caller applying writes made elsewhere routes creates throughbulk_create". Keep the rest. - Line 5370: "so a batched update stays title-searchable".
- The
packages/core/src/services/embedding_processor.rs, the doc ofscheduler_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 throughcreate_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_duplicateprovenance.
- The collection-collision comment in
packages/core/tests/it/collection_membership_test.rs, the comment intest_collection_name_uniqueness_is_best_effort_not_enforced(735-740). The same restatement, withoutnodespace-sync'sapply_node_upsertor "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_nodecould never get past that row", and "the realNodeService::create_nodepath 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_nodedirectly".
- Module doc (7-13, 17-20, 26-28). Describe the failure mode as "any caller applying another device's node through
packages/core/tests/it/person_duplicate_convergence_test.rs- Line 135: "(replicated apply)" instead of "(sync-apply)".
- Lines 26-27: drop "with no
nodespace-syncinvolved anywhere in this file". "reachable on a purely local-only install" stays. - Lines 38-40: "the real
create_node/update_nodepaths 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
- Any behaviour, signature or public-name change. The one test function is the only rename.
- The docs of these, which Move Pro-owned data out of core's data model (ADR-083) #3345 renames, rewrites or removes, and Sweep the Pro and sync wording C7 leaves around replicated writes and AI-chat privacy #3367 then checks:
get_multi_membership_edges(Generalize get_multi_membership_edges into member_of_edges with caller-supplied filters #3343);- the push channel,
subscribe_for_pushandset_push_excluded_origin(Rename the origin-filtered event channel to subscribe_to_events_excluding_origin #3338); - the embedding APIs and their SQL comments (Delete the dead embedding push/pull seam; keep embedding.origin for existing databases #3337);
- anything naming
SYNC_SERVICE_CLIENT_ID(Rename the origin-filtered event channel to subscribe_to_events_excluding_origin #3338).
playbook_engine_integration_test.rsandplaybook_invariant_integration_test.rs. Their prose names the sync origin, so they are Sweep the Pro and sync wording C7 leaves around replicated writes and AI-chat privacy #3367.- The access-gate docs in
node_service/mod.rsandcrud.rs(Describe core's access gate and daemon seams without naming the Pro daemon #3363), and the identity docs innode_service/mod.rs(Reword core data-model and identity docs that cite Pro, Supabase, RLS or tenants #3365). - Whether
bulk_create_has_child_edgesshould stay in core at all. Its only production caller is nodespace-sync's apply path; see the parent's open question. This PR assumes it stays.
Steps
- Follow CLAUDE.md's startup sequence:
- pull
main; EnterWorktree({name: "issue-<N>-batch-api-docs"});bun install, then thebun run testbaseline;- self-assign at pickup and set In Progress.
- pull
- Make the edits under Scope, checking each sentence against the code.
- Move the
bulk_add_to_collectionsdoc as described. Confirm withcargo doc(below) thatcollection_typed_idsnow shows only its own doc. - Run
bun run scripts/check-pro-boundary.tsand paste the printedBASELINESblock. Expected at af8ddb6, but use the real output:cloudWording−8,editionBranching−1. - 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
- The vocabulary grep below prints only lines owned by a Move Pro-owned data out of core's data model (ADR-083) #3345 sub-issue:
- the
get_multi_membership_edgesdoc insqlite_store/relationships.rs(Generalize get_multi_membership_edges into member_of_edges with caller-supplied filters #3343); - the embedding test in
sqlite_store/mod.rsand the SQL comments inschema.rs(Delete the dead embedding push/pull seam; keep embedding.origin for existing databases #3337); - the push-channel docs in
node_service/mod.rs(Rename the origin-filtered event channel to subscribe_to_events_excluding_origin #3338).
- the
-
bulk_add_to_collectionscarries its own doc, andcollection_typed_idscarries only its own. - No comment still says the event channel holds 128 slots, except the sizing-history sentence in the
DOMAIN_EVENT_CHANNEL_CAPACITYdoc and the 128 → 4096 burst test. - The renamed test runs and passes:
.tools/bin/cargo-nextest nextest run -p nodespace-core --lib bulk_add_to_collections_notify_emits_relationship_events. -
BASELINESinscripts/check-pro-boundary.tsis lowered to the counts the CLI prints, and the CLI exits 0. -
bun run scripts/check-code-references.tspasses. - Apart from the test rename, the diff touches only comment lines (
//,///,//!) and the string literals of assertion messages.
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:
One more expected leftover in
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.rsnode_service/mod.rsgoes with Describe core's access gate and daemon seams without naming the Pro daemon #3363: thesubtree_access_gatefield doc. cargo fmt --all --checkcargo clippy -p nodespace-core -p nodespace-daemon --all-targets -- -D warningsRUSTDOCFLAGS='-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
- Guardrail: stop new Pro code from landing in core #3302: the ratchet whose baselines this lowers.
Risks and rollback
- Conflicts with Move Pro-owned data out of core's data model (ADR-083) #3345.
node_service/mod.rsandsqlite_store/relationships.rsare also edited by Move Pro-owned data out of core's data model (ADR-083) #3345. The hunks differ, so a rebase resolves any conflict. If Move Pro-owned data out of core's data model (ADR-083) #3345 has already renamed or removed something this issue mentions, follow Move Pro-owned data out of core's data model (ADR-083) #3345. - A
BASELINESconflict with another marker-lowering PR. Rebase, rerun the CLI and paste. - Rollback. Revert the PR.
Plan key: C10.2 (pro-boundary DAG).
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
pro-boundaryPro/core boundary: Pro code moves to nodespace-sync (ADR-081..085)
Activity