Skip to content

fix(backend): deduplicate action item batch mutations - #20729

Closed
edvinas1573 wants to merge 1 commit into
BasedHardware:mainfrom
edvinas1573:fix/action-items-batch-safety
Closed

edvinas1573 wants to merge 1 commit into
BasedHardware:mainfrom
edvinas1573:fix/action-items-batch-safety

Conversation

@edvinas1573

@edvinas1573 edvinas1573 commented Oct 5, 2026 •

Copy link
Copy Markdown

Repeated action-item IDs currently consume multiple Firestore writes, repeat proactivity cleanup, inflate the batch-delete response, and repeat its lock-preflight reads. Deduplicate IDs in first-occurrence order before the delete and sync writers chunk them, and before the batch-delete lock preflight. Keep document IDs verbatim.

Refs #19449. This is an independent, focused alternative for the remaining duplicate-ID problem discussed in #20724. Current main already chunks conversation deletion, retirement, and sync at 499 writes. This PR preserves the router's existing 500-item read preflight and does not change Pinecone error handling: account deletion must still surface required vector-cleanup failures. It does not claim to resolve every item in #19449.

Validation on Python 3.11.15 with dependencies from backend/pylock.windows.toml:

  • Before the fix, 10 new duplicate-ID regression cases failed; after the fix, python -m pytest tests/unit/test_action_items_batch_chunking.py -q passes all 16 cases. The recording fake enforces one write per distinct ID and at most 499 writes per commit; cases cover 0, 1, 499, 500, 998, and 1200 unique IDs.
  • python -m pytest tests/unit/test_action_item_ids_endpoint.py -q: 14 passed, including an HTTP request through the production FastAPI router and real DB writer with fake external services. Four requested IDs (a2,a1,a2,a1) produce two writes, two returned IDs, and one vector/notification cleanup per distinct ID. Existing 500/500/200 preflight and locked-item rejection tests still pass.
  • Repository-pinned Black 26.5.1 formatting checked.
  • Full backend Pyright: 0 errors. Runtime image source-closure check passed. The repository's file-isolated pre-push runner also passed both changed test files (30 tests).
  • OpenAPI export, released-client compatibility, generated Dart/TypeScript/Swift contract checks, module-isolation scan, and changed-scope async-blocker scan pass. The bounded pre-push gate passes with the explicitly recorded full-preflight exception above.
  • Related sync regression suites also pass in separate pytest processes: test_action_item_sync_batch_reminder.py (3) and test_task_sync_batch_isolation.py (11), for 44 focused tests total.
  • The mandatory Firestore guard exposed an existing Windows runner problem: its generated list used CRLF, so Git Bash passed trailing carriage returns in pytest filenames. Write that generated list with explicit LF; this affects only the check runner, not application behavior.
  • Metadata preflight passes all four metadata checks. Full local preflight is not green: the unrelated query-driver guard rejects Windows asyncio's internal loopback socketpair, and a daily-summary profile cannot resolve its IANA timezone in the guard environment. These errors occur outside the changed action-item paths. Submit as a draft pending Linux CI; no release-eligibility proof is claimed.
  • Used the repository's documented PRE_PUSH_SKIP_PR_PREFLIGHT=1 hatch for this draft after recording the guard failures; its mandatory failure-class guard-artifact ratchet still passed. On a push retry, already-passed typecheck, unit tests, and source closure were not repeated. Full query-guard execution was stopped after more than 12 minutes with the above failures already recorded.
  • Full offline server startup was attempted with OMI_ENV_STAGE=offline PROVIDER_MODE=offline python -m uvicorn main:app --host 127.0.0.1 --port 18081; startup rejected the default Soniox STT chain without its key. Full emulator-backed curl testing is not yet verified. The HTTP regression uses dependency overrides and is not a live Firestore test.

Failure-Class: none
No existing registry class specifically covers repeated IDs within the same requested document mutation; this change adds behavioral guards at the current batch boundary.

Line-Count-Exception: backend/database/action_items.py | 1633 -> 1636 | Deduplicate the existing batch writer inputs and document unique deletion results without introducing another persistence owner.

AI assistance: implemented and tested with OpenAI Codex.
Compensation: no bounty amount or payment has been confirmed by the maintainers; this contribution is submitted for technical review.

Review in cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @edvinas1573 — this is a nicely scoped fix for the duplicate-ID slice of #19449, and the test discipline is above the usual bar. Reviewed all five changed files against current main:

  • backend/database/action_items.py — list(dict.fromkeys(...)) in delete_action_items_batch and batch_set_sync_requested dedupes in first-occurrence order before the empty-check and before the existing 499-write chunking, so chunk boundaries and commit counts stay deterministic. Docstring updates match the new behavior.
  • backend/routers/action_items.py — deduping request.ids before the 500-item locked-preflight also removes repeated preflight reads for duplicated IDs; the second dedup inside the DB writer is harmless. One client-facing note: deleted_count/deleted_ids now report unique deletions, so a client that submits duplicates and compares counts against its own list length will see a mismatch — that's the intended fix (the old response inflated counts), just worth knowing the response semantics changed.
  • backend/scripts/run_firestore_index_guard.py — the newline='\n' addition is unrelated to the dedup concern but small and correct (keeps the generated tests.txt byte-identical across platforms); fine to keep, just noting the scope addition.
  • backend/tests/unit/test_action_item_ids_endpoint.py — the new HTTP-boundary test drives the real FastAPI route and DB writer with faked externals and pins the exact response shape, the single deduped preflight call, and one vector/FCM cleanup per distinct ID. Good coverage of the router+writer seam.
  • backend/tests/unit/test_action_items_batch_chunking.py — _StrictBatch rejecting repeated documents and oversized commits, parametrized over 0/1/499/500/998/1200 unique IDs with whitespace-preserved document IDs, locks the invariant down exactly the right way.

As a narrower alternative to #20724 that keeps the router preflight at 500 and leaves Pinecone error handling untouched, the scope choice looks sound. Since this is a draft, no CI check summary exists yet — once it's marked ready, the backend suites will validate the claims. Leaving for human maintainer review before merge (maintainers will also want to pick between this and #20724).


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution backend Backend Task (python) labels Oct 5, 2026
@edvinas1573

Copy link
Copy Markdown
Author

Thanks for the detailed review. The unique-ID response semantics are intentional: duplicate requested IDs produce one deletion and one cleanup per document, and the HTTP regression asserts the exact returned IDs and count.

One CI clarification: workflows were created for the current head f03290c, but they are completed with action_required, including Backend Unit Tests, OpenAPI Contract, and Repo Checks. There are no executed CI results yet; the draft flag alone does not explain the missing check summary.

Could a human maintainer approve the pending fork workflow runs and, when appropriate for full review, add ci:full and re-run all jobs on this head as described in the contribution guide? The PR body records 44 passing focused local tests and the Windows-only full-preflight limitations. I am keeping the draft status until the required Linux validation is available.

AI assistance: this follow-up was prepared with OpenAI Codex.

@Git-on-my-level

Copy link
Copy Markdown
Member

This draft has been quiet for a while. No pressure at all — if you're still planning to finish it, push a commit or comment within 7 days and it stays open. Otherwise we'll close it to keep the queue tidy; reopening a draft is one click when you're ready.

@Git-on-my-level Git-on-my-level added the stale-candidate Candidate for kind stale follow-up label Oct 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @edvinas1573 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution stale-candidate Candidate for kind stale follow-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants