Repository navigation
fix(backend): add batch boundary chunking and deduplication in database action_items - #19450
Conversation
b4155a1 to
8c76bf9
Compare
|
Thanks @brandonstensby-dotcom — this is a solid, well-scoped fix for the Firestore batch-boundary and duplicate-contention issues you filed in #19449, and the hermetic test coverage is genuinely thorough (the 501-item 499+2 commit boundary assertions are exactly right). Per-file notes:
Two minor observations, neither blocking: (1) the chunk size for db.get_all reads is a defensive choice rather than a documented hard Firestore limit — harmless, and it also caps per-RPC payload size; (2) the new ValueError on empty/whitespace uid is a behavior change for any internal caller passing a blank uid — the router path always supplies an authenticated uid, so this should only surface real bugs. Because this touches the user-data batch deletion path (Firestore deletes, Pinecone cleanup, and the locked-item paid-plan preflight), leaving for human maintainer review before merge. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
aryanorastar
left a comment
There was a problem hiding this comment.
On 8c76bf9, backend/database/vector_db.py delete_action_item_vectors_batch catches Exception and only logs, so a failed vector delete is treated as success. Let it raise.
Closes #19449
Summary
Hardens batch operations in
backend/database/action_items.py,backend/database/vector_db.py, andbackend/routers/action_items.pyagainst Firestore commit size limits and multi-operation document contention under high-volume workloads.Aligns directly with INV-MEM-5: Universal memory and task authority.
Failure-Class: none.
Root Causes & Structural Remediation
delete_action_items_batchandbatch_set_sync_requested, passing duplicate IDs causes Firestore write batches to abort withInvalidArgument: 400 Multiple operations on document in a single commit.list(dict.fromkeys(...))before constructing batch mutation operations.delete_action_items_for_conversation,retire_action_items_for_conversation,batch_set_sync_requested, andget_action_items_by_idspreviously iterated or batched without chunking, failing when operations exceeded Firestore's hard 500-operation ceiling.get_all, ensuring conversations or batch sync requests with >500 items (tested at 501 items) commit safely across multiple transactions.backend/database/vector_db.py:delete_action_item_vectors_batch, Pinecone network timeouts previously caused unhandled exceptions after Firestore documents were already deleted.try...except Exception as exc: logger.warning(...)to guarantee best-effort cleanup without aborting callers.backend/routers/action_items.py:batch_delete_action_items, deduplicated incomingrequest.idsbefore both the locked-item preflight check and database calls, eliminating redundant Firestore reads and batch write operations.uidin all modified functions to reject blank or whitespace arguments immediately with descriptive errors.Testing & Verification
backend/tests/unit/test_database_action_items_batch_resilience.py:test_delete_action_items_batch_boundary_chunking_501: Verified 501 items split into 2 commits (499 + 2).test_delete_action_items_batch_deduplicates_and_cleans_ids: Verified duplicate IDs and whitespace are sanitized.test_delete_action_items_for_conversation_boundary_chunking_501: Verified conversation deletion chunks over 500 items.test_retire_action_items_for_conversation_boundary_chunking_501: Verified conversation retirement chunks over 500 items.test_batch_set_sync_requested_chunking_and_deduplication: Verified sync requested chunking and deduplication.test_get_action_items_by_ids_chunking_and_order_preservation: Verified chunked queries at 500 ops while preserving exact input ordering.test_delete_action_item_vectors_batch_handles_pinecone_failure_gracefully: Verified vector store failure degradation.test_router_batch_delete_deduplicates_and_protects_locked: Verified router deduplication before lock preflight and DB execution.test_delete_action_items_batch_invalid_uid_raises: Verified empty UID rejection.Ran 9 tests in 0.084s - OK.Designated Payout Rails
0xbB9686b9684421A8e326AC0F8B3eCf88Df975120[email protected]