Repository navigation
Fix quiet-check replay starvation and backlog throughput - #23500
Conversation
Failure-Class: FC-bounded-discovery-pinned-by-blocked-page Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Failure-Class: FC-bounded-discovery-pinned-by-blocked-page Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the urgent PR on replay progress and accounting; defer arm telemetry to the lead follow-up. Propagate FSR/request context into bounded leaf workers and drain the pool before returning. Failure-Class: FC-bounded-discovery-pinned-by-blocked-page Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Firestore SDK only adds implicit name ordering for snapshot cursors. Explicit name ordering preserves equal-timestamp rows with the persisted value cursor; the real emulator reproduced the omission. Failure-Class: FC-bounded-discovery-pinned-by-blocked-page Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preserve fresh waiting successors, repair unindexed waiting obligations, and retire terminal stale indexes even when their checkpoint is future-dated. Failure-Class: FC-bounded-discovery-pinned-by-blocked-page Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preserve malformed-generation retirement while proving to the pinned type checker that None is never passed to int. Failure-Class: FC-bounded-discovery-pinned-by-blocked-page Co-Authored-By: Claude Opus 5.5 <[email protected]>
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: 204dac7430
ℹ️ 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".
| next_cursor = None | ||
| if len(snapshots) == safe_limit: | ||
| last = snapshots[-1] | ||
| next_cursor = {'reconcile_after_at': (last.to_dict() or {})['reconcile_after_at'], 'job_id': last.id} |
There was a problem hiding this comment.
Bound each cursor sweep so deferred checks cannot prevent wrapping
If a process crashes after reserving a page, those unprocessed jobs can remain behind the cursor indefinitely: subsequent passes use a fresh time cutoff, so a full page of recurring quiet checks can continually move its reconcile_after_at values ahead of the cursor and prevent a short page from ever triggering wrap. For example, with an explicit limit of two, reserve A/B and crash; process C/D on each later minute, with successor task enqueue failing and evaluation deferring them by 60 seconds. Every subsequent page contains C/D, while A/B are never retried. The same failure scales to the configured production limit. Persist a sweep cutoff or otherwise force bounded wrapping so replay cannot chase newly deferred successors forever.
Useful? React with 👍 / 👎.
| with ThreadPoolExecutor( | ||
| max_workers=min(concurrency, len(quiet_candidates)), thread_name_prefix='quiet-replay' | ||
| ) as pool: |
There was a problem hiding this comment.
Use repository-managed executors for quiet-check fan-out
Whenever a pass contains multiple quiet checks, this creates an ad-hoc executor outside the managed executor registry. Consequently, its workers and queued checks are invisible to get_executor_metrics() and are not managed by shutdown_executors(). backend/AGENTS.md explicitly requires the purpose-specific pools and says “Never ad-hoc Thread/ThreadPoolExecutor.” Move this fan-out to async orchestration over an appropriately managed pool, preserving the separation between coordinator and child workers rather than submitting children back to an occupied shared pool.
AGENTS.md reference: backend/AGENTS.md:L264-L269
Useful? React with 👍 / 👎.
| default_limit = 500 if oldest_overdue_age >= 300 else 100 | ||
| try: | ||
| limit = max(1, min(2000, int(os.getenv('LISTEN_FINALIZATION_RECONCILE_LIMIT', str(default_limit))))) | ||
| except ValueError: | ||
| limit = default_limit |
There was a problem hiding this comment.
Update the required lifecycle documentation with replay controls
This changes conversation-lifecycle recovery to use adaptive replay limits, concurrent quiet-check evaluation, and new operator rollback controls, but the commit does not update backend/docs/listen_pusher_pipeline.mdx. backend/AGENTS.md requires conversation-lifecycle changes to update that document “in the same PR.” Document the cursor recovery behavior, the 100/500 default transition, and the limit/concurrency overrides so the owning operational reference describes the recovery path being shipped.
AGENTS.md reference: backend/AGENTS.md:L159-L159
Useful? React with 👍 / 👎.
Persist one cutoff across a cursor sweep so a crashed reserved prefix is revisited even while later checks keep deferring. Qualify the crash-and-recurrence case with unit and real-store emulator regressions. Failure-Class: FC-bounded-discovery-pinned-by-blocked-page Co-Authored-By: Claude Opus 5.5 <[email protected]>
Prebind the fixed aggregate outcome vocabulary and drain fan-out futures through as_completed so request ownership is explicit to both readers and the background-task contract guard. No debt or baseline exemptions. Failure-Class: FC-bounded-discovery-pinned-by-blocked-page Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep #23500 as the single quiet replay authority, including cursor, concurrency, progress repair, backoff and counters. Drop the redundant quiet due query and index while preserving episode segment identities, speech liveness and closed recap recovery. Failure-Class: FC-high-water-cursor-skips-unready-row Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep incoming main's canonical retrieval/wrapped typing, fallback registration and test duration classifications. Preserve the episode lifecycle work and #23500's single quiet replay authority; no custom arming or quiet query/index additions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Quiet replay clamps the oldest due page to 100, runs checks serially, and counts every non-exception return as
requeued. A non-advancing prefix can hide later work; retirement looks like dispatch success, and 100/min cannot drain a queue receiving roughly 110 overdue obligations/min.Evaluate quiet pages with at most 16 independent leaf workers, preserving FSR/request context and joining all work before releasing the pass. Rotate a persisted CAS-fenced timestamp/document-ID cursor with a fixed cutoff per sweep (so recurring successors cannot prevent wrapping after a crash), reserve bounded successor wakes for overdue stale/error checks, retire missing conversations with an updated timestamp, and back off unchanged snapshots without overwriting newer work. Report
requeued,advanced,retired,stale,no_progress, anderrorseparately, plus oldest-overdue-age telemetry and effective database page logs without identities.LISTEN_FINALIZATION_RECONCILE_LIMIToverrides a backlog-aware default (100 normally, 500 once oldest overdue reaches five minutes), capped at 2000.LISTEN_QUIET_REPLAY_CONCURRENCYdefaults to 16 and clamps to 1..16; set it to 1 for serial rollback. The existing interval knob is unchanged. Recording-lease, account, BYOK, and admission semantics stay authoritative.The live missing-conversation sample retired on the current release; no generation type mismatch was reproduced. This PR repairs the proven discovery/throughput/accounting defects and guards stale paths. Arm-amplification telemetry is a separate lead-owned follow-up.
Failure-Class: FC-bounded-discovery-pinned-by-blocked-page
Line-Count-Exception: backend/database/conversation_finalization_jobs.py | 2856 -> 2949 | Keep the incident replay cursor, CAS backoff and oldest-overdue query beside existing replay ownership; avoid an unrelated module migration during recovery.
Product invariants affected
none. Existing recovery admission, recording lease, account cutover, BYOK, and finalization generation fences remain authoritative.
Validation
Exact head
6b317890e99c8dbb247035f7d4c3aa7bc1ed81bcpassed the real Firestore emulator (101-row starvation, deleted cursor, wrap, missing-conversation retirement and crash/recurrence bounded sweep), all 14 selected files through canonical backend/test.sh under nice10 (964 passed, one deselected), all 33 repository preflight checks, metadata validation and the full pre-push hook. Both previously failing GitHub guard files are in that selected suite; no exemptions or baseline changes. GitHub CI is tracked separately and must complete on this head.Review scope
The incident instruction explicitly limits this lane to quiet-check/replay files while the broader episode-lifecycle lane owns adjacent work. The per-pass leaf pool is bounded, propagates context, and joins all futures before the callback exits; it deliberately avoids children on the occupied shared DB pool. Shared executor registry health visibility and the lifecycle reference update are outstanding supporting-file review findings outside that boundary. A request to allow those two narrow edits is pending; no scope expansion or review resolution is implied by CI success.
Read-only
git merge-treeagainst the broader PR23506 ata92f93b2e11c257fc3488b515182e7cf04b0320bconfirms four content conflicts in the quiet evaluator, worker, replay service and query driver. The lead must reconcile that overlapping quiet-query/index design before combining the PRs. This PR itself requires no new index. No branch or worktree was merged during this check.Operator notes
Lead and David own production changes; none were performed by this lane. The local incident handoff includes an unexecuted exact-page CAS mitigation proposal.
Start a temporary drain at
LISTEN_FINALIZATION_RECONCILE_LIMIT=500andLISTEN_FINALIZATION_RECONCILE_INTERVAL_SECONDS=30, with concurrency16. Expand to 1000/15 only while Firestore latency/errors and downstream processing pressure stay clean. The interval also affects other serial recovery sweeps and singleton lease cadence. At 110/min inflow, ideal coverage lower bounds for the 126,473-row snapshot are ~5h25m at 500/60, ~2h23m at 500/30, and ~33m at 1000/15, plus pass duration and other sweeps. At 100/60 the queue never drains; the no-arrival estimate alone is ~21h05m. Remove temporary overrides after oldest age/backlog recovery; adaptive selection returns to100 for a fresh queue. Rollback knobs are limit100/concurrency1, with the acknowledged throughput shortfall.🤖 Generated with Claude Code