Repository navigation
fix(sync): receipt stored rule discards so admitted first-summary wakes stop looping - #23092
Conversation
…es stop looping Intake stores rule-settled review fragments with discarded=True. When the first-summary wake for such a row runs, _reprocess_conversation_after_update re-derives the discard verdict and calls discard_by_relevance, which returns False because the row is already hidden. The callback then returned None without a discard receipt, and with FIRST_SUMMARY_PRESERVE_ADMITTED_ENABLED (prod since #22099, 2026-10-18) reprocess.run raised FirstSummaryCallbackPending: a 409, a Cloud Tasks retry with backoff, and the same result on every attempt. After the attempt cap the sweep re-created the wake. Before the flag the same path silently deleted the obligation. On 2026-10-21 backend-sync logged ~3,000 callback_pending retries per hour (2,990 of 3,000 sampled enrichment outcomes), every non-OK response on sync-jobs-fresh was an sr- task on its 4th-10th attempt, and the outbox held 4,839 fresh-lane and 4,792 backfill-lane obligations overdue for 4h+ with no lease and no deferral. Those retries share the queue that carries every real first summary. The read predicate derives `discarded` for every uncurated review row, so the callback cannot tell a stored discard from a refused write by looking at the row. database.conversations.rule_discard_outcome now reports the write's own outcome: `discarded` on a write, `already_discarded` for a stored hide (no cache or index side effects), else `refused`. discard_by_relevance keeps its True-only-on-write contract for the relevance backfill script. The pipeline receipts both `discarded` and `already_discarded`; a refusal (revised, curated, deleted) still leaves the obligation for the next attempt to re-read.
Codex Review SummaryThis 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: 4c7ccd0c64
ℹ️ 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".
| if current.get('discarded'): | ||
| return 'already_discarded' |
There was a problem hiding this comment.
Check the revision before accepting an existing discard
When a worker reads revision N and a concurrent writer advances the conversation to N+1 while leaving discarded=True—for example, update_conversation_segments adds fresh live speech but only bumps sync_content_revision—this branch returns already_discarded before checking expected_sync_content_revision. The pipeline then records a terminal discard receipt for a stale transcript, allowing the reprocess obligation to settle without reassessing the newly added speech. Apply the status, curation, and revision fences before returning already_discarded so a changed generation is reported as refused and retried.
Useful? React with 👍 / 👎.
Summary
Sync intake stores rule-settled "review" fragments with
discarded=True. When the first-summary wake for such a row runs,_reprocess_conversation_after_updatere-derives the discard verdict and callsdiscard_by_relevance, which returnsFalsebecause the row is already hidden. The callback then returnedNonewith no discard receipt, and withFIRST_SUMMARY_PRESERVE_ADMITTED_ENABLED(prod since #22099, 2026-10-18)reprocess.runraisedFirstSummaryCallbackPending→ HTTP 409 → Cloud Tasks retry with backoff → the same result on every attempt; after the attempt cap the 2-minute sweep re-created the wake. Before the flag the same path silently deleted the obligation. On 2026-10-21 backend-sync logged ~3,000callback_pendingretries/hour (2,990 of 3,000 sampled enrichment outcomes), every non-OK response onsync-jobs-freshwas ansr-task on its 4th–10th attempt, and the outbox held 4,839 fresh-lane + 4,792 backfill-lane obligations overdue ≥4h with no lease and no deferral. Those retries share the queue that carries every real first summary (P44 write-up:data/run-2026-10-13-two-lane-nemotron/first-summary-finished-at-2026-10-21.mdin the workspace repo).The read predicate derives
discardedfor every uncurated review row, so the callback cannot tell a stored discard from a refused write by looking at the row; only the write's own outcome can.database.conversations.rule_discard_outcomenow reportsdiscarded(a write; cache/index side effects run),already_discarded(stored hide; no side effects) orrefused(deleted, revised, curated, non-completed, missing).discard_by_relevancekeeps its True-only-on-write contract forscripts/conversation_relevance_backfill.pyandtest_people_stats_cache. The pipeline receipts bothdiscardedandalready_discarded(the relevance metric is recorded only for a real write); a refusal still leaves the obligation for the next attempt to re-read, as before.Lane / contract
Lane first-summary (P44 brief, two-lane program); contracts: none. No other lane's files edited.
Product invariants affected
none (no locked path touched).
Verification
Layer: unit (synthetic fixtures), m5,
nice -n 19,BACKEND_PYTEST_WORKERS=4, viabackend/test.shwithBACKEND_UNIT_TEST_FILE_LIST:test_sync_reprocess_coalesce.py(91; +3 new: the pipeline receipts an intake-discarded fragment without a second write, with and without a process context; an admitted obligation on such a row settlesprocessedthrough the real callback instead of raisingFirstSummaryCallbackPending; the existing persistence test now also asserts the relevance metric count),test_rule_discard_visibility.py(44; +2 new: the real DB function against the strict Firestore fake receipts a stored discard without rewriting it, andrule_discard_outcomedistinguishesdiscarded/already_discarded/refusedwith exactly one cache invalidation),test_owner_recognition_telemetry.py(23),test_people_stats_cache.py(52, unchanged contract).test_sync_v2, summary delivery, summary persistence.scripts/backend-python-format --checkclean on all six files.database/conversations.pychanged), integration/emulator suites, and any live layer. No deploy; the fix is dark until the next train.Rollback
Revert. No flag: the new tri-state is internal to the discard write;
discard_by_relevanceis unchanged for its callers.Failure-Class: FC-permanent-write-rejection-retried-forever
Line-Count-Exception: backend/database/conversations.py | 4475 -> 4501 | rule_discard_outcome must live beside discard_by_relevance: the strict-store tests monkeypatch this module's db, cache and index seams, and the relevance backfill keeps the bool wrapper
Line-Count-Exception: backend/utils/sync/pipeline.py | 3644 -> 3647 | the rule-discard branch of the callback that owns it now branches on the write outcome