Skip to content

fix(attention): expire non-retryable items (bounded replacement for #25055) - #25070

Merged
Git-on-my-level merged 13 commits into
mainfrom
lane/pipeline-25028-bounded-attention
Nov 11, 2026
Merged

Git-on-my-level merged 13 commits into
mainfrom
lane/pipeline-25028-bounded-attention

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

What changed and why

Head: 672d873b5aa2322b1e47a112e5e57fe412e5d1e4

Replacement for #25055 (which replaced #25028) on current origin/main 7ebd8450b6e023474cfe3275cf3446b28f3a710f, carrying the reviewed attention-expiry patch plus the independent-review FIX-FIRST corrections at Earlier 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:

  • Scan bound (finding 77a43d). list_items no longer streams a user's whole active attention collection. Each query is bounded to SCAN_LIMIT = 500 documents, and an optional start_after cursor lets a caller start from a known document. Expiry transactions therefore run only inside a bounded scan.
  • Zero limit (finding 34c935). list_items(limit=0) (and any non-positive limit) returns an empty list before iterating or appending, instead of returning one item.
  • Scan cursor (finding 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)

1252bca525de is 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's start_after is that document, protecting the last-scanned cursor in processing_attention._scan_pages. No product code changed.

Firestore client seam (Codex P1 4529060103, lead2 f66b9e)

672d873b5aa2 fixes the review finding that the new expiry path used the legacy module-level db proxy, contrary to backend/AGENTS.md. items_ref, _scan_pages, and list_items now resolve get_firestore_client() at call time and expose an optional keyword-only firestore_client parameter; the bounded scan, the conversation/claim reads, and the expiry transaction use that single resolved client. The new expiry tests inject firestore_client instead of monkeypatching store.db (the module fixture now supplies the same fake client through get_firestore_client so the unconverted claim/finish helpers and HTTP route keep working). db remains only in the unconverted claim/finish helpers and pending_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 under 1c606e are unchanged from 71aff3e888f4e.

Merge-main resolutions (lead2 1c606e)

This head is a merge-main resolution under lead2 1c606e.

71aff3e888f4e merges current origin/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 four backend/charts listen/pusher values (this PR's PROCESSING_ATTENTION_NON_RETRYABLE_EXPIRY_ENABLED and main's SYNC_RECORD_COVERAGE_WAIT_MEMO), plus backend/config/flag_budget.json, where count is reconciled to 271, equal to the 271 names on the merged head. backend/tests/support/firestore_query_driver_registry.py auto-merged and was then checked against both parents: this PR's attention cursor entries (list_items with start_after, _scan_pages covered-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 against origin/main is exactly this PR's patch (19 files). No product behavior changed; the reviewed patch is unchanged.

Earlier head: 5ad54d2f0d8f2 merged origin/main (8fa2cbd36487b, the main-wide notes prompt-pin fix from #25108); that merge was clean and flag_budget.count was 270 there.

Earlier head: bf6efab1c7bf6 merged origin/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.yaml and both backend/charts/backend-listen listen values (additive env/flag entries on each side, kept both), backend/config/flag_budget.json (count reconciled to 270, equal to the 270 names on the merged head), and backend/docs/pending-work.md (narrative paragraphs from both sides merged, keeping the HOME_STEP_PROJECTION text and the bounded-attention text). No product behavior changed; the reviewed patch is unchanged.

Earlier head: 047de1b18fb7 merged the prior origin/main (75dc53a81df7) under the same ruling; its only conflict was config/feature-flags.yaml.

Product invariants affected

  • INV-MEM-4: the runtime change only adds attention expiry configuration; canonical memory consolidation and promotion authority retain their existing configuration. Attention expiry is distinct from Short-term memory disposition.

Tuning and rollback

  • PROCESSING_ATTENTION_NON_RETRYABLE_EXPIRY_ENABLED: default on. Setting the declared value to false and recomposing runtime configuration disables new expiry writes. All backend services and matching listen/pusher charts carry the binding.
  • NON_RETRYABLE_ITEM_TTL: seven days from created_at, exclusively for recovery_structure_unavailable after retry reconciliation.
  • SCAN_LIMIT: 500 active attention documents examined per query; a full read pages internally on the last scanned document.
  • Bundle kill switch: HOME_STEP_PROJECTION (existing, default on). Turning it off is the L4 rollback.
  • Rollback is the flag off; no data migration. Expiry is terminal: already-expired documents remain inactive after disabling the switch, and no automatic data restoration is claimed.
  • L4 success metric: no processing rows on past days.

Verification

Fresh checks of head 672d873b5aa2 on m5 through /Users/dazheng/workspace/omi/bin/omi-heavy run -- ..., with GCP credential environment variables unset and worktree-local Python 3.11 dependencies:

  • Attention/pending-work set (13 files, including test_batch_pipeline_scheduler.py): 360 passed across the 13 files run; test_pending_work.py alone: 76 passed, including the strengthened 620-item pagination regression and all expiry tests, now with firestore_client injection.
  • Full query-shape battery test_firestore_query_shapes.py (now covering both driver sets): 572 passed.
  • Flag budget: 24 passed (flag_budget.count 271 equals the 271 names on the merged head). test_verify_pusher_config_references.py: 31 passed. Runtime-env validator: 206 passed. Notes prompt-version node test_llm_input_prompt_version.py: 6 passed (including test_prompt_sources_match_the_pinned_digest[notes]). Combined five-file run: 839 passed.
  • Normal full pre-push hook: PASS, 0 failures.
  • The new cursor assertion was confirmed load-bearing: mutating _scan_pages to 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T13:31:28.963722Z 672d873 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +150 to +152
if start_after is not None:
query = query.start_after(start_after)
query = query.limit(SCAN_LIMIT)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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.
@Git-on-my-level
Git-on-my-level merged commit 631de21 into main Nov 11, 2026
65 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/pipeline-25028-bounded-attention branch November 11, 2026 13:55
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.

1 participant