Repository navigation
fix(attention): expire non-retryable items (bounded replacement for #25055) - #25070
Conversation
Failure-Class: FC-stale-selection-used-as-write-authority
Failure-Class: none
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5682a15bd
ℹ️ 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".
| item['retryable'] = True # Repair items made permanently non-retryable by the old ledger. | ||
| item['retry'] = {'state': operation['state'], 'operation_id': operation['operation_id']} | ||
| if expiry_enabled and expired_non_retryable(item, now): | ||
| if run_transactional(db, firestore.transactional(expire_in_transaction), snapshot, now): |
There was a problem hiding this comment.
Use the supported Firestore client seam for expiry transactions
The new expiry transaction uses the legacy module-level db proxy, contrary to the explicit Database rule in backend/AGENTS.md: new code must obtain get_firestore_client() at call time, and converted helpers must expose an optional keyword-only firestore_client injection parameter. Resolve the client through that supported seam and use it consistently for the expiry reads and transaction; the added tests currently reinforce the retired pattern by monkeypatching store.db.
AGENTS.md reference: backend/AGENTS.md:L180-L180
Useful? React with 👍 / 👎.
| if start_after is not None: | ||
| query = query.start_after(start_after) | ||
| query = query.limit(SCAN_LIMIT) |
There was a problem hiding this comment.
Connect bounded scans to caller-visible pagination
For a user with more than 500 active items that remain unresolved and do not expire, this cap permanently excludes later documents from the existing attention flows. backend/routers/pending_work.py calls list_items(uid) without a cursor for GET attention-items, retry-all, and seen-all, while AttentionItemsPage exposes no continuation cursor. Repeated requests therefore scan the same first 500 documents, so later failures cannot be listed, retried through retry-all, or marked seen through seen-all. Preserve the scan bound, but implement continuation through these callers rather than silently truncating their previously full-set behavior.
Useful? React with 👍 / 👎.
…ounded-attention # Conflicts: # backend/config/flag_budget.json
The 620-item pagination regression ended its first 500-row page on an item that was returned, so a cursor based on the last *returned* item would have passed it too. Resolve the last document of the first page and assert the second page's start_after is that document, protecting the last-scanned cursor in processing_attention._scan_pages. Test-only; no product change.
…ounded-attention # Conflicts: # config/feature-flags.yaml
…ounded-attention # Conflicts: # config/feature-flags.yaml
…ounded-attention # Conflicts: # backend/charts/backend-listen/dev_omi_backend_listen_values.yaml # backend/charts/backend-listen/prod_omi_backend_listen_values.yaml # backend/config/flag_budget.json # backend/docs/pending-work.md # config/feature-flags.yaml
Codex P1 on #25070: the expiry path used the legacy module-level `db` proxy, and the new tests reinforced it by monkeypatching `store.db`. `items_ref`, `_scan_pages`, and `list_items` now resolve `get_firestore_client()` at call time and accept an optional keyword-only `firestore_client` seam. The bounded scan, the conversation/claim reads, and the expiry transaction all use that one client. Tests inject the fake client instead of replacing `db`; `db` remains only for the unconverted claim/finish helpers. No pagination, cursor, or expiry-predicate behavior changed.
What changed and why
Head:
672d873b5aa2322b1e47a112e5e57fe412e5d1e4Replacement for #25055 (which replaced #25028) on current
origin/main7ebd8450b6e023474cfe3275cf3446b28f3a710f, carrying the reviewed attention-expiry patch plus the independent-review FIX-FIRST corrections atEarlier head:e1c309b3e047cbfb15933fb0d2246af8829cd459.Supersedes #25055 because that PR is at its two-push limit and its exact head carries two independent-review FIX-FIRST findings. This replacement starts a fresh branch from current main, carries the same reviewed commits, and fixes both findings:
77a43d).list_itemsno longer streams a user's whole active attention collection. Each query is bounded toSCAN_LIMIT = 500documents, and an optionalstart_aftercursor lets a caller start from a known document. Expiry transactions therefore run only inside a bounded scan.34c935).list_items(limit=0)(and any non-positive limit) returns an empty list before iterating or appending, instead of returning one item.3d2d9d). A full read now pages internally on the last scanned document, not the last returned one, so filtering (resolved or expired rows) cannot repeat a window or omit later items. The 500-row query bound and the non-positive-limit early return are unchanged.Carried non-merge commits from the reviewed head:
329a8b8fa5d— expiry predicate and initial tests.3e0e6f98de1— transaction fencing, tests, config, registry and documentation.7d75d6a5980— pusher literal config snapshot.The carried patch is otherwise behavior-identical: attention expiry, banked/completed/live-debt guards, and the flag registry. No new product behavior beyond the two fixes. No
.github/, UI, credentials/IAM, production data/config, or model changes.Test-only follow-up (push 3)
1252bca525deis a test-only assertion under the driver's third-push allowance. The 620-item pagination regression previously ended its first 500-row page on an item that was returned, so a cursor based on the last returned item would have passed it too. The test now resolves the last document of the first page and asserts the second page'sstart_afteris that document, protecting the last-scanned cursor inprocessing_attention._scan_pages. No product code changed.Firestore client seam (Codex P1
4529060103, lead2f66b9e)672d873b5aa2fixes the review finding that the new expiry path used the legacy module-leveldbproxy, contrary tobackend/AGENTS.md.items_ref,_scan_pages, andlist_itemsnow resolveget_firestore_client()at call time and expose an optional keyword-onlyfirestore_clientparameter; the bounded scan, the conversation/claim reads, and the expiry transaction use that single resolved client. The new expiry tests injectfirestore_clientinstead of monkeypatchingstore.db(the module fixture now supplies the same fake client throughget_firestore_clientso the unconverted claim/finish helpers and HTTP route keep working).dbremains only in the unconverted claim/finish helpers andpending_conversations. Pagination, cursor, and expiry-predicate behavior are unchanged; the delta is 15 non-test changed lines in one file plus the test seam. Merge-main resolutions under1c606eare unchanged from71aff3e888f4e.Merge-main resolutions (lead2
1c606e)This head is a merge-main resolution under lead2
1c606e.71aff3e888f4emerges currentorigin/main(a73632ce0ec9, which carries C2's operator-ledger census read from #25084) into the branch. Six files conflicted, all additive on both sides and resolved by keeping both:config/feature-flags.yaml,backend/tests/unit/test_verify_pusher_config_references.py, and all fourbackend/chartslisten/pusher values (this PR'sPROCESSING_ATTENTION_NON_RETRYABLE_EXPIRY_ENABLEDand main'sSYNC_RECORD_COVERAGE_WAIT_MEMO), plusbackend/config/flag_budget.json, wherecountis reconciled to 271, equal to the 271 names on the merged head.backend/tests/support/firestore_query_driver_registry.pyauto-merged and was then checked against both parents: this PR's attention cursor entries (list_itemswithstart_after,_scan_pagescovered-by) and C2's census entries (pipeline_ledger.iter_global_window,pipeline_ledger.retention_start,pipeline_ledger_census._capture_creates,pipeline_ledger_census.census) are both preserved, and the delta againstorigin/mainis exactly this PR's patch (19 files). No product behavior changed; the reviewed patch is unchanged.Earlier head:5ad54d2f0d8f2mergedorigin/main(8fa2cbd36487b, the main-wide notes prompt-pin fix from #25108); that merge was clean andflag_budget.countwas 270 there.Earlier head:bf6efab1c7bf6mergedorigin/main(8659de6ee98d9, which carries the main-wide messaging flake fix from #25018) into the branch, so the previously red messaging check ran against the fix. Five files conflicted:config/feature-flags.yamland bothbackend/charts/backend-listenlisten values (additive env/flag entries on each side, kept both),backend/config/flag_budget.json(countreconciled to 270, equal to the 270 names on the merged head), andbackend/docs/pending-work.md(narrative paragraphs from both sides merged, keeping theHOME_STEP_PROJECTIONtext and the bounded-attention text). No product behavior changed; the reviewed patch is unchanged.Earlier head:047de1b18fb7merged the priororigin/main(75dc53a81df7) under the same ruling; its only conflict wasconfig/feature-flags.yaml.Product invariants affected
Tuning and rollback
PROCESSING_ATTENTION_NON_RETRYABLE_EXPIRY_ENABLED: default on. Setting the declared value tofalseand recomposing runtime configuration disables new expiry writes. All backend services and matching listen/pusher charts carry the binding.NON_RETRYABLE_ITEM_TTL: seven days fromcreated_at, exclusively forrecovery_structure_unavailableafter retry reconciliation.SCAN_LIMIT: 500 active attention documents examined per query; a full read pages internally on the last scanned document.HOME_STEP_PROJECTION(existing, default on). Turning it off is the L4 rollback.Verification
Fresh checks of head
672d873b5aa2on m5 through/Users/dazheng/workspace/omi/bin/omi-heavy run -- ..., with GCP credential environment variables unset and worktree-local Python 3.11 dependencies:test_batch_pipeline_scheduler.py): 360 passed across the 13 files run;test_pending_work.pyalone: 76 passed, including the strengthened 620-item pagination regression and all expiry tests, now withfirestore_clientinjection.test_firestore_query_shapes.py(now covering both driver sets): 572 passed.flag_budget.count271 equals the 271 names on the merged head).test_verify_pusher_config_references.py: 31 passed. Runtime-env validator: 206 passed. Notes prompt-version nodetest_llm_input_prompt_version.py: 6 passed (includingtest_prompt_sources_match_the_pinned_digest[notes]). Combined five-file run: 839 passed._scan_pagesto advance on the second-to-last page item fails it with[None, 'item-0498'] != [None, 'item-0499'].Evidence is hermetic; real Firestore contention/SDK retries and deployed behavior are not claimed.
UI evidence
UI-Evidence: none -- backend-only expiry on existing API reads; no client or UI change.
Failure class
Failure-Class: FC-stale-selection-used-as-write-authority