Skip to content

Batch D (P2): collection pagination (#1430) + transactional bulk_delete (#1433) + bulk_update merge (#1434) - #1459

Merged
mstomar125 merged 2 commits into
NodeSpaceAI:mainfrom
mstomar125:fix/batch-d-bulk-pagination
Jun 24, 2026
Merged

mstomar125 merged 2 commits into
NodeSpaceAI:mainfrom
mstomar125:fix/batch-d-bulk-pagination

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Phase 1 bug-sweep Batch D (P2), core bulk/query fixes.

#1430 — collection pagination paginated the wrong set

Collection-filtered queries pushed offset/limit to SQL, but membership is filtered in memory after the query — so offset>0 paged the unfiltered set and a fixed 1000 over-fetch silently dropped members outside the newest 1000 rows.
Fix: scope the query to the collection's members (NodeFilter::with_ids, bounded) and apply offset/limit in memory after the membership filter; short-circuit empty collections.

#1433 — bulk_delete was not transactional

Documented all-or-nothing, but looped store.delete_node (each its own autocommit) → the Nth failing left the first N-1 committed.
Fix: new transactional store.bulk_delete (single tx, FK cascade, one Deleted event per node post-commit); service routes through it.

#1434 — bulk_update empty changed_properties + wholesale replace

Emitted NodeUpdated with hardcoded empty changed_properties and wholesale-replaced (un-normalized) properties, diverging from single-update and no-opping property-change automation.
Fix: normalize + deep-merge like update_node, validate the merged candidate, persist the merged value, emit the real changed_properties.

Tests

Free/community impact

Community-build fixes (core data layer) — additive correctness; free-users green.

Closes #1430, closes #1433, closes #1434.

@mstomar125

Copy link
Copy Markdown
Contributor Author

REQUEST CHANGES

Solid work on #1433 and #1434 — but the headline #1430 fix is built on a method that doesn't do what the PR claims, and it introduces an unbounded full-table scan on every collection query.

Blocker — #1430: with_ids does not scope the query; collection queries are now unbounded.
ops/node_ops.rs:438 scopes the collection query via filter.with_ids(member_ids…) with a comment promising it's "bounded." It isn't — NodeFilter.ids is never translated into SQL:

  • NodeQuery (packages/nodespace-types/src/node.rs:118) has no ids field — only id, mentioned_by, content_contains, title_contains, node_type, limit, offset (verified). The NodeFilter→NodeQuery conversion (services/node_service/query.rs:55) silently drops the plural ids.
  • db/sqlite_store.rs query_nodes builds its WHERE only from title_contains + node_type; there is no id IN (…) path. A crate-wide grep confirms NodeFilter.ids is never read to build a query.

Net effect: the collection branch sets with_ids but not limit/offset, so filter.limit == None. DEFAULT_QUERY_LIMIT is applied only in query_nodes_simple (query.rs:299), not in the filter-based query_nodes — so the store runs SELECT * FROM node with no LIMIT and no id filter: a full-table scan that materializes every node, runs per-type schema fetch + lazy migration over the whole table, then filters membership in memory. That's a regression from the old bounded 1000 over-fetch — large workspaces load the entire node table on every collection-scoped query. The result is functionally correct (the in-memory filter still yields the right members), which is exactly why the new 5-node test passes and hides it.

Required fix (one of):

  1. Actually honor ids — add ids: Option<Vec<String>> to NodeQuery, carry it through query.rs:55, and build an id IN (?, …) clause in query_nodes (mind SQLite's ~999 bound-param ceiling — chunk if a collection can exceed it); OR
  2. If in-memory membership filtering is intentional, drop the misleading with_ids/"(bounded)" comment and push a real SQL bound (e.g. capped with_limit(offset+limit)) so the query isn't unbounded.

Either way, add a test that fails under the current implementation — e.g. create >limit non-member nodes after the members and assert members are still returned; the current test_collection_query_paginates_members_not_global_set can't catch the unbounded/scope bug.

Looks correct:

Community impact: all changes are shared-core data layer (not Pro-gated). #1433/#1434 are behavior-preserving; the #1430 change alters shared query behavior and adds the unbounded-scan regression above — resolve before it lands in the community build.

Nit: the "re-intersect defensively" comment (node_ops.rs:493) is misleading — since the SQL isn't id-scoped, that in-memory member_ids.contains is the only thing producing the correct set, i.e. load-bearing, not defensive.

CI: no checks on the branch; the local suite is exactly what masks the #1430 scope bug.

Mayank Tomar and others added 2 commits June 24, 2026 12:07
…ge (closes #1430, closes #1433, closes #1434)

Three P2 bulk/query data-integrity fixes.

is filtered in memory AFTER the query, so offset paginated the wrong (unfiltered)
set and a fixed 1000 over-fetch dropped members outside the newest 1000 rows.
Scope the query to the collection's members via NodeFilter::with_ids (bounded) and
apply offset/limit in memory after the membership filter; short-circuit empty
collections.

store.delete_node (each its own autocommit), so the Nth failing left the first N-1
committed. Add a transactional store.bulk_delete (single tx, FK cascade, one
Deleted event per node post-commit) and route the service through it.

and wholesale-REPLACED (un-normalized) properties, diverging from single-update
and silently no-opping property-change automation. Normalize + deep-merge like
update_node, validate the merged candidate, persist the merged value, and emit
the real changed_properties (compute_property_changes).

Tests: collection pagination over members vs global set; transactional multi-delete;
bulk_update merge + non-empty changed_properties. Updated the existing
partial-fields test to the new merge+normalize contract. Full core suite green;
free-users 7/7.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The previous `with_ids` was a no-op — `NodeQuery` had no `ids` field, the
NodeFilter→NodeQuery conversion dropped the plural `ids`, and `query_nodes`
built no `id IN (…)` clause. Combined with dropping the SQL limit for the
collection case, that made a collection-scoped query a `SELECT * FROM node`
full-table scan (correct only because of the in-memory membership filter) —
a regression versus the old bounded over-fetch.

Honor ids end to end:
- add `ids: Option<Vec<String>>` to `NodeQuery`;
- carry `NodeFilter.ids` through the NodeFilter→NodeQuery conversion;
- build a chunked `id IN (?, …)` clause in `query_nodes` (chunked at 900 to
  stay under SQLite's bound-parameter ceiling; order_by + limit/offset are
  applied in memory by the caller, so per-chunk order is irrelevant).

The collection query is now bounded by the member set, not the whole table.
Corrected the misleading "(bounded)" / "re-intersect defensively" comments
(the in-memory intersect is now a genuine defensive double-check). New test
`test_collection_query_returns_members_despite_many_newer_nonmembers` asserts
members are still returned with 25 newer non-members present — it fails under a
capped-global-limit approach and the old fixed-1000 over-fetch.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Review addressed — you were exactly right on #1430. with_ids was a no-op (no ids on NodeQuery, dropped in the conversion, no id IN in query_nodes), so the collection query was an unbounded SELECT * FROM node.

Fixed end-to-end:

  • added ids: Option<Vec<String>> to NodeQuery;
  • carry NodeFilter.ids through the NodeFilter→NodeQuery conversion;
  • query_nodes now builds a chunked id IN (?, …) (chunk size 900, under SQLite's bound-param ceiling; order_by + limit/offset applied in memory, so chunk order is irrelevant).

The collection query is now bounded by the member set, not the whole table. Corrected the misleading "(bounded)"/"defensively" comments. New test test_collection_query_returns_members_despite_many_newer_nonmembers (3 members + 25 newer non-members → all 3 returned) fails under a capped-global-limit approach and the old fixed-1000 over-fetch, catching the scope/bound bug the prior test missed.

Rebased onto current main (your #1453/#1457/#1458 landed). Verified: core lib 964, event_emission 11 (both collection tests), clippy --tests -D warnings + fmt clean. #1433/#1434 unchanged. Ready for re-review.

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (re-review @ 888fe68)

The #1430 blocker is fully resolved — you took Option 1 and wired real id-scoping end-to-end. Verified:

  • NodeQuery now carries ids: Option<Vec<String>> (packages/nodespace-types/src/node.rs) and the NodeFilter→NodeQuery conversion propagates it (query.rs:58 ids: filter.ids.clone()).
  • query_nodes builds a chunked id IN (…) (db/sqlite_store.rs:1206-1235) at ID_CHUNK = 900 — under SQLite's bound-param ceiling exactly as flagged, so a large member set can't overflow. The query is now bounded by the member set, not a full-table scan.
  • Pagination is stable. The ids-path returns member rows unordered, then NodeService::query_nodes applies order_by (CreatedDesc) via in-memory sort (query.rs:38-42), and node_ops applies skip(offset)/truncate(limit) over that sorted member set (node_ops:493+). Correct ordering before the slice → no page overlap/skip.
  • Comments corrected: the "(bounded)" claim and the "re-intersect defensively" note now accurately describe that the SQL is id-scoped and the in-memory member_ids.contains is a genuine double-check.

And the test gap is closed with the exact regression I asked for: test_collection_query_returns_members_despite_many_newer_nonmembers (tests/event_emission_test.rs:203) — members must surface despite many newer non-members, which "FAILS under a capped-global-limit approach … and under the old fixed-1000 over-fetch." Plus test_collection_query_paginates_members_not_global_set covers offset/limit + non-member exclusion.

#1433 (transactional bulk_delete) and #1434 (bulk_update merge) were already correct in the prior pass. Clean — good to merge.

@mstomar125
mstomar125 merged commit d32725b into NodeSpaceAI:main Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant