Repository navigation
fix(backend): consolidate Firestore mutation invariants - #8362
Conversation
- add shared deterministic document ID helpers for system folders and calendar meetings - make calendar meeting creates idempotent while preserving created_at - remove speech samples transactionally to keep samples/transcripts aligned - report missing action-item IDs explicitly and only update downstream vectors for successful sync writes - validate folder deletion/reorder targets before mutating Supersedes #8294, #8297, #8298, #8301, #8307, #8316, #8322. Original issue discovery, reproductions, and candidate fixes by @ZachL111. Co-authored-by: Zach <[email protected]>
Keep the legacy mobile happy-path response shape for action-item batch endpoints. Only include detailed batch mutation fields when there is a partial outcome such as missing, no-op, or locked IDs. The hermetic backend e2e harness caught this compatibility regression. Co-authored-by: Zach <[email protected]>
|
Follow-up on the hermetic e2e failure: the harness was right. It caught that the PR changed the mobile happy-path response body for PATCH /v1/action-items/batch from {status, updated_count} to include extra batch detail fields. Even though current Flutter code only checks statusCode, the e2e contract intentionally pins the compatibility shape.\n\nI pushed 59454b3 to preserve the legacy success response and only include detailed fields when there is an actual partial outcome (missing/no-op/locked IDs).\n\nLocal validation after the fix:\n- bash backend/testing/e2e/run.sh -q --tb=short → 73 passed, 6 skipped\n- uv run python -m pytest tests/unit/test_firestore_invariant_helpers.py -q → 3 passed |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b6d7fbfcb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Confidence score: 3/5
backend/database/action_items.pystill has a TOCTOU race: rows can disappear afterget().existsbut beforebatch.commit(), which can cause the entire mutation to fail and break the explicit partial-result behavior for callers. Before merging, move existence handling to commit-time (or catch commit-time missing-row failures) so deletes return partial results instead of aborting the whole request.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Git-on-my-level
left a comment
There was a problem hiding this comment.
Addressed both unresolved review threads.
Changes:
- Updated
TestSyncBatchSkipsLockedso the mockedbatch_sync_update_action_itemsreturns the newBatchMutationResult-shaped contract used by_batch_mutation_response. - Removed pre-read existence checks from action-item partial update helpers. Each Firestore document update is now applied independently and catches
NotFound, so a concurrent delete is reported inmissing_idsinstead of failing the whole mutation after a stale existence read.
Verification:
ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run pytest tests/unit/test_task_sharing.py::TestSyncBatchSkipsLocked::test_sync_batch_skips_locked_updates -q→1 passedENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run pytest tests/unit/test_task_sharing.py -q→29 passedpython3 -m py_compile database/action_items.py tests/unit/test_task_sharing.py→ passed
Summary
This is an aggregated, systematic replacement for ZachL111's Firestore/data-mutation hardening PRs. Rather than merging a set of one-off patches that silently skip missing records, this PR adds explicit invariants and shared helpers:
created_atspeech_samplesandspeech_sample_transcriptsstay alignedBatchMutationResultreporting for action-item batch updates/sync (updated_ids,missing_ids,noop_ids)Supersedes #8294, #8297, #8298, #8301, #8307, #8316, #8322.
Original issue discovery, reproductions, and candidate fixes by @ZachL111 — thank you for surfacing these reliability problems. This PR rewrites them into a smaller shared-contract shape to reduce long-term maintenance cost.
Test plan
uv run --with pytest --with pydantic python -m pytest tests/unit/test_firestore_invariant_helpers.py -qpython3 -m py_compile backend/database/document_ids.py backend/database/_client.py backend/database/folders.py backend/database/calendar_meetings.py backend/database/users.py backend/database/action_items.py backend/routers/action_items.py backend/routers/folders.py backend/models/folder.py backend/tests/unit/test_firestore_invariant_helpers.pyNotes / intentional differences from source PRs
system_folder_doc_id()helper instead of local seed-string construction.calendar_meeting_doc_id()helper. The current public API only exposescalendar_sourceandcalendar_event_idas provider uniqueness dimensions; if provider-account/calendar IDs are added later, this helper is the single extension point.