Skip to content

fix: data integrity, route matching, namespace filter, vector growth - #970

Merged
ajianaz merged 1 commit into
developfrom
fix/p1-data-integrity-route-namespace
Aug 10, 2026
Merged

fix: data integrity, route matching, namespace filter, vector growth#970
ajianaz merged 1 commit into
developfrom
fix/p1-data-integrity-route-namespace

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

What

Empat perbaikan P1 dari audit cora-code v0.13.0:

  1. crud.rs atomicity β€” insert() sekarang wrap INSERT + tag inserts dalam unchecked_transaction(), konsisten dengan pattern di tags.rs dan documents.rs. Jika tag insert gagal, seluruh operasi rollback.

  2. handlers.rs route matching β€” Query string sekarang di-strip sebelum route dispatch (route_path = path.split("?").next()). Semua handler yang extract query params sekarang pakai path.split("?") bukan p.strip_prefix(...). Menghilangkan 14 clippy redundant_guard warnings.

  3. lib.rs namespace filter β€” graph_data(namespace) sebelumnya no-op (is_none_or(|_| true) selalu return true). Sekarang query memory IDs by namespace, filter nodes by memory_id, dan filter edges untuk consistency.

  4. vector.rs capacity growth β€” Fixed increment +1024 β†’ geometric growth max(current*2, current+4096, 1024). Amortizes to O(1) per insertion untuk dataset besar.

Why

  • crud.rs: Crash di tengah tag inserts meninggalkan memory tanpa tags β†’ data inconsistency
  • handlers.rs: Route matching dengan query string bikin fragile dan redundant guard warnings
  • lib.rs: Namespace filter yang no-op = fitur tidak berfungsi, user tidak bisa filter graph by namespace
  • vector.rs: Fixed increment menyebabkan frequent reallocation pada dataset 100K+ vectors

Changes

  • crates/uteke-core/src/memory/crud.rs β€” unchecked_transaction() wrapper
  • crates/uteke-server/src/handlers.rs β€” route_path variable + literal path matching
  • crates/uteke-core/src/lib.rs β€” Namespace-aware graph node/edge filtering
  • crates/uteke-core/src/memory/vector.rs β€” Geometric capacity growth formula

Testing

  • 476 tests pass, 0 fail, 25 ignored
  • Clippy: 0 warnings
  • Cora review: No issues found

…(#P1)

- crud.rs: wrap insert + tag inserts in BEGIN/COMMIT transaction for atomicity
- handlers.rs: strip query string before route matching, use literal path match
- lib.rs: fix graph_data namespace filter that was a no-op (is_none_or(|_| true))
- vector.rs: geometric capacity growth (2x) instead of fixed +1024 increment

Why: each fix addresses a real correctness or performance issue found in audit.
Tests: 476 pass, 0 fail. Clippy: 0 warnings.
.unchecked_transaction()
.map_err(|e| Error::db("Failed to begin transaction", e))?;

let result = self.try_insert_memory(memory, &embedding_blob, &tags_json, &metadata_json);
@github-actions

Copy link
Copy Markdown

πŸ” Cora AI Code Review

❌ Blocked β€” critical issues found.

πŸ”΄ Error (2)

  • crates/uteke-core/src/lib.rs:1160 β€” The new namespace filtering logic executes a SELECT id FROM memories WHERE namespace = ?1 AND deprecated = 0 query and collects all results into a HashSet<String> on every call to graph_data when a namespace is specified. For databases with a large number of memories in a namespace, this loads potentially thousands of strings into memory just to perform a set membership test for graph node filtering. This is an O(N) memory allocation where N is the total memory count in the namespace, even if the graph only contains a handful of nodes.
  • crates/uteke-core/src/memory/crud.rs:80 β€” The comment states unchecked_transaction is "safe because Store access is serialized via Mutex" β€” however, unchecked_transaction bypasses rusqlite's compile-time safety checks for transaction nesting and does not actually lock the connection. If any other code path calls methods on this Store using a shared &Connection (even read-only methods like prepare/query), those operations will interleave with this transaction and potentially see partial state or cause SQLITE_BUSY errors. The safety depends entirely on the caller holding the Mutex for the entire duration, but Store methods take &self which doesn't enforce this invariant.

Review powered by cora-code Β· BYOK Β· MIT

@ajianaz
ajianaz merged commit 9492f6c into develop Aug 10, 2026
14 of 15 checks passed
@ajianaz
ajianaz deleted the fix/p1-data-integrity-route-namespace branch August 10, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants