Skip to content

fix(backend): declare the action-items due-range Firestore index (#10777) - #10778

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/issue-10777-action-items-due-index
Jul 28, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/issue-10777-action-items-due-index

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

Bug

Every due-date-filtered action-item read fails in prod with
google.api_core.exceptions.FailedPrecondition: 400 The query requires an index.

  • Chat's get_action_items tool returns Error retrieving action items (traceback from
    utils/retrieval/tools/action_item_tools.py → database/action_items.py:_stream_action_items_bounded).
  • GET /v1/action-items with due_start_date/due_end_date hits the same path.
  • Prod Cloud Run backend: 55 occurrences in the 7 days to 2026-07-28, 50 of them in the last 24h.

Root cause

_apply_action_item_date_filters orders due_at ascending whenever a due range is
requested (a bounded prefix must match the soonest-due-first product sort), and
get_action_items then adds the completed == equality filter. That composite needs a
Firestore index on (completed ASC, due_at ASC).

The only deployed action_items composite was (completed ASC, due_at DESC), which serves
the reverse ordering and not this query. The index was never declared in
firestore_index_registry.py, so nothing caught the gap — firestore.indexes.json had no
action_items entry at all.

Fix

Declare (completed ASC, due_at ASC, __name__ ASC) for action_items (COLLECTION scope) in
the registry and regenerate firestore.indexes.json.

The index is already created and READY in based-hardware and based-hardware-dev, so the
deploy-time reconcile_firestore_indexes.py --check-only gate stays green on merge; this PR
adds no serving-schema mutation of its own.

Tested

  • Reproduced against prod Firestore before the index existed: the exact production query
    (completed == False, due_at range, order_by due_at ASC) raised
    FailedPrecondition: 400 The query requires an index.
  • Same query after index creation: returns rows, no error — the failing path now works.
  • backend/test.sh over the index + action-item read files
    (test_action_items_due_range_index_contract.py, test_firestore_indexes.py,
    test_firestore_query_contract.py, test_action_items_pagination_order.py,
    test_reconcile_firestore_indexes.py, test_bounded_firestore_list_reads.py): 6 files pass.
  • The new regression test builds the query through the production get_action_items seam,
    derives the Firestore index signature from it, and asserts the manifest declares it. It
    fails when the registry entry is removed (verified) — so flipping the order direction
    without declaring the matching index breaks here, not in prod.

Product invariants affected

none

Failure class (fixes)

Failure-Class: none

🤖 automated by hourly watchdog — tested and merged

Closes #10777

Review in cubic

Every due-date-filtered action-item read builds `completed ==` plus an ascending
`due_at` order, but the only deployed composite was (completed ASC, due_at DESC),
which serves the reverse ordering. Prod therefore raised
`FailedPrecondition: 400 The query requires an index` on every such read — the chat
`get_action_items` tool returned "Error retrieving action items" and GET
/v1/action-items with due filters 500'd (55 occurrences in the 7 days to 2026-07-28,
50 of them in the last 24h).

Declares (completed ASC, due_at ASC, __name__ ASC) in the index registry and
regenerates firestore.indexes.json. The index is already created in
based-hardware and based-hardware-dev, so the deploy-time reconcile check-only
gate stays green.

Verified:
- reproduced against prod Firestore before the index existed: the exact query
  (completed == False, due_at range, order_by due_at ASC) raised FailedPrecondition
- after index creation the same query returns rows with no error
- backend/test.sh over the index + action-item read files: 6 files pass
- new regression test fails when the registry entry is removed

Failure-Class: none
@kodjima33
kodjima33 force-pushed the watchdog/issue-10777-action-items-due-index branch from a15afc1 to e897aeb Compare July 28, 2026 16:01
@kodjima33
kodjima33 merged commit 867cf7b into main Jul 28, 2026
36 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-10777-action-items-due-index branch July 28, 2026 16:16
undivisible added a commit that referenced this pull request Jul 29, 2026
Index declaration already landed via #10778/#10786; keep the behavioral
regression test and FC-undeclared-serving-query-index failure class.
undivisible pushed a commit to Archit-lal/omi that referenced this pull request Jul 29, 2026
…edHardware#10778)

Every due-date-filtered action-item read builds `completed ==` plus an ascending
`due_at` order, but the only deployed composite was (completed ASC, due_at DESC),
which serves the reverse ordering. Prod therefore raised
`FailedPrecondition: 400 The query requires an index` on every such read — the chat
`get_action_items` tool returned "Error retrieving action items" and GET
/v1/action-items with due filters 500'd (55 occurrences in the 7 days to 2026-07-28,
50 of them in the last 24h).

Declares (completed ASC, due_at ASC, __name__ ASC) in the index registry and
regenerates firestore.indexes.json. The index is already created in
based-hardware and based-hardware-dev, so the deploy-time reconcile check-only
gate stays green.

Verified:
- reproduced against prod Firestore before the index existed: the exact query
  (completed == False, due_at range, order_by due_at ASC) raised FailedPrecondition
- after index creation the same query returns rows with no error
- backend/test.sh over the index + action-item read files: 6 files pass
- new regression test fails when the registry entry is removed

Failure-Class: none
@undivisible undivisible added the AI label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Action items with a due-date filter 500 in prod: missing (completed ASC, due_at ASC) Firestore index

2 participants