Skip to content

fix(sync): receipt stored rule discards so admitted first-summary wakes stop looping - #23092

Merged
Git-on-my-level merged 1 commit into
mainfrom
lane/first-summary
Oct 21, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
lane/first-summary

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Sync 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 with no discard receipt, and with FIRST_SUMMARY_PRESERVE_ADMITTED_ENABLED (prod since #22099, 2026-10-18) reprocess.run raised FirstSummaryCallbackPending → 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,000 callback_pending retries/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 + 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.md in the workspace repo).

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; only the write's own outcome can. database.conversations.rule_discard_outcome now reports discarded (a write; cache/index side effects run), already_discarded (stored hide; no side effects) or refused (deleted, revised, curated, non-completed, missing). discard_by_relevance keeps its True-only-on-write contract for scripts/conversation_relevance_backfill.py and test_people_stats_cache. The pipeline receipts both discarded and already_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, via backend/test.sh with BACKEND_UNIT_TEST_FILE_LIST:

  • Directly affected files, 210 passed: 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 settles processed through the real callback instead of raising FirstSummaryCallbackPending; 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, and rule_discard_outcome distinguishes discarded / already_discarded / refused with exactly one cache invalidation), test_owner_recognition_telemetry.py (23), test_people_stats_cache.py (52, unchanged contract).
  • Neighbouring consumers, 720 passed: relevance backfill, free-tier matrix, mobile client journeys, owner-identity telemetry, sync cross-job assignment, enrichment custody, fragment visibility, lineage allowlist/dedupe/recording, minimal redrive, test_sync_v2, summary delivery, summary persistence.
  • scripts/backend-python-format --check clean on all six files.
  • NOT run locally: the full backend unit suite (CI selects it because database/conversations.py changed), 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_relevance is 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

View guided diff Turn on auto-fix

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T19:36:39.719923Z 4c7ccd0 PR opened
ℹ️ 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: 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".

Comment on lines +2837 to +2838
if current.get('discarded'):
return 'already_discarded'

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

@Git-on-my-level
Git-on-my-level merged commit 777c152 into main Oct 21, 2026
65 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/first-summary branch October 21, 2026 19:45
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