Skip to content

fix(backend): declare the (completed, due_at) action-items composite index - #10781

Merged
undivisible merged 2 commits into
mainfrom
issues-improver/10777-action-items-due-at-index
Jul 29, 2026
Merged

undivisible merged 2 commits into
mainfrom
issues-improver/10777-action-items-due-at-index

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

What

Declares the action_items composite index (completed ASC, due_at ASC, __name__ ASC) in backend/database/firestore_index_registry.py, regenerates firestore.indexes.json from it, and adds the regression test that would have caught its absence.

Why

Every due-date-filtered action-item read was 500ing in prod (#10777): 55 FailedPrecondition: 400 The query requires an index in the 7 days to 2026-07-28, 50 of them in the last 24h. Both the chat get_action_items tool and GET /v1/action-items?due_start_date=… take the same path — _apply_action_item_date_filters orders a due range ascending, get_action_items adds the completed == equality, and the only deployed composite was the descending twin (completed ASC, due_at DESC), which does not serve that ordering.

Nothing declared any action_items index in the registry, so the generated manifest had no action_items entry at all and no gate could catch the gap.

Failure class

Failure-Class: new — FC-undeclared-serving-query-index: a serving query's required composite index must be declared in the repository registry, not exist only as a hand-created live index. The guard artifact is the new behavioral test below, which derives the required signature from the production query builder instead of restating it.

What I tested

  • Live reproduction against prod Firestore (read-only, non-existent probe uid, so no user data touched) with the exact chain the issue reports — due_at >=/<=, order_by due_at ASC, completed == False:
    400 The query requires an index. That index is currently building and cannot be used yet. The index Firestore demands is exactly the one this PR declares; gcloud firestore indexes composite list --project=based-hardware shows it as CREATING (hand-created during the incident) and the other five action_items composites as READY.
  • New regression test drives the real read path. test_due_date_filtered_action_item_reads_have_a_declared_composite_index monkeypatches database.action_items.db with a recorder, calls the production get_action_items for a due range (parametrized over completed=None/False/True), derives each executed equality+ordering chain's required index signature, and asserts the generated manifest declares it.
  • It fails without the fix. Stashing only the registry + manifest change: 3 failed, with ('action_items', 'COLLECTION', (('completed','ASCENDING'), ('due_at','ASCENDING'), ('__name__','ASCENDING'))) not in declared — the same signature Firestore's error hint names.
  • backend/tests/unit/test_firestore_query_contract.py → 11 passed (.venv/bin/python -m pytest, Python 3.11.15).
  • python3 backend/scripts/generate_firestore_indexes.py → manifest matches the registry; firestore_query_coverage.py --check-ratchet and check_firestore_model_read_boundary.py → exit 0.
  • make preflight with this diff → 23 checks passed (including firestore-index-manifest, firestore-query-coverage, failure-class-protocol). black --line-length 120 --skip-string-normalization → unchanged.
  • Touching the registry selects the full backend unit suite (774 files); ran it via test.sh. Everything passes except the local fast-unit CPU-time guard tripping under parallel load (CI uses the 1.0s ceiling) and test_sync_v2.py::TestAsyncCoordinatorBehavioral::test_inline_renew_errors_cancel_before_capacity_admission_without_releasing_retry_material, which fails identically on origin/main — pre-existing, unrelated to this change.

Follow-up (not in this PR)

GET /v1/action-items also accepts conversation_id alongside a due range, and those combinations (conversation_id ASC, due_at ASC, plus the completed triple) are neither declared nor deployed — same failure class, but provisioning two more composites on a hot collection is a separate call. Filed as #10780 rather than widened here.

Fixes #10777

Failure-Class: new

Auto-generated from issue feedback by the mini issues-improver — tested and merged.

…index

_apply_action_item_date_filters orders a due-date range ascending and
get_action_items adds the completed== equality, so every due-date filtered
read needs (completed ASC, due_at ASC). Only the descending twin was ever
deployed, and no action_items index was declared in the registry at all, so
the generated manifest could not catch the gap and prod returned
FailedPrecondition for both the chat get_action_items tool and
GET /v1/action-items.

Declare the index, regenerate the manifest, and guard it with a test that
derives the required signature from the production query builder instead of
restating it.

fixes #10777

Failure-Class: new
@kodjima33
kodjima33 force-pushed the issues-improver/10777-action-items-due-at-index branch from d17968d to c733eb9 Compare July 28, 2026 15:22
Index declaration already landed via #10778/#10786; keep the behavioral
regression test and FC-undeclared-serving-query-index failure class.

@undivisible undivisible left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good after resolving the main conflict.

The production fix for #10777 already landed via #10778 (and conversation-scoped indexes via #10786). This PR still adds real value: the behavioral query→manifest regression test and FC-undeclared-serving-query-index. Conflict resolution kept main’s index declarations (no duplicate registry entry) and retained those guardrails.

@undivisible undivisible left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good after resolving the main conflict.

The production fix for #10777 already landed via #10778 (and conversation-scoped indexes via #10786). This PR still adds real value: the behavioral query→manifest regression test and FC-undeclared-serving-query-index. Conflict resolution kept main’s index declarations (no duplicate registry entry) and retained those guardrails.

@undivisible undivisible left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Index already on main via #10778/#10786; this PR lands the regression test + failure class after conflict resolution.

@undivisible
undivisible merged commit 8192ecb into main Jul 29, 2026
36 checks passed
@undivisible
undivisible deleted the issues-improver/10777-action-items-due-at-index branch July 29, 2026 04:35
undivisible added a commit to Archit-lal/omi that referenced this pull request Jul 29, 2026
…index (BasedHardware#10781)

_apply_action_item_date_filters orders a due-date range ascending and
get_action_items adds the completed== equality, so every due-date filtered
read needs (completed ASC, due_at ASC). Only the descending twin was ever
deployed, and no action_items index was declared in the registry at all, so
the generated manifest could not catch the gap and prod returned
FailedPrecondition for both the chat get_action_items tool and
GET /v1/action-items.

Declare the index, regenerate the manifest, and guard it with a test that
derives the required signature from the production query builder instead of
restating it.

fixes BasedHardware#10777

Failure-Class: new

Co-authored-by: Max Carter 祁明思 <[email protected]>
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.

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

2 participants