Repository navigation
fix(backend): retire quiet checks when conversation owners close - #23527
Conversation
Retire merged, deleted and non-live conversation checks with a shared owner fence; register bounded replay workers and document recovery controls. Clear terminal replay indexes instead of renewing no-op debt. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Exercise actual near-ceiling, orphan, deferred and noise-close commits in the isolated Firestore emulator. Re-review the smart-merge query coverage digest for its post-commit document-only retirement. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Close remaining indirect terminal paths and recursive account deletion through the same latest-owner fence. Register the bounded UID-only erasure scan and exercise terminal, merge rollback and multipage erasure behavior. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Make the moved quiet-stop API an explicit export. Align nullable/coercible retrieval inputs with their existing runtime behavior, retain product-query validation without a redundant check, and preserve nullable Wrapped segment handling through the positive-duration filter. These five unchanged-main diagnostics blocked the mandatory full backend type gate. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the existing coercion behavior while separating the normalized string from the object input for the required type gate. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Register the lightweight model-text and result-bound modules inside existing import-isolation scopes so dataclass annotation resolution works while network and heavy parent packages remain stubbed. Failure-Class: new 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: 40783dea01
ℹ️ 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 claimed_status != ConversationStatus.in_progress: | ||
| stop_quiet_check_for_conversation(uid, conversation_id, firestore_client=db) |
There was a problem hiding this comment.
Isolate quiet-check cleanup failures from committed admission
If the new retirement read or transaction fails after the status CAS commits, this function raises even though the conversation is already processing. The synchronous finalize path in backend/routers/conversations.py calls admit_processing before entering processing_admission_guard, so this failure skips both the processor and its rollback. Subsequent requests see an already-processing conversation, and the orphan sweep eventually completes it without running summarization. This also affects conversations without quiet checks because retirement always performs an initial Firestore read. Keep cleanup failures from invalidating a successful admission, relying on the existing quiet-check replay backstop or another retry mechanism for retirement.
Useful? React with 👍 / 👎.
Apply the strict hermetic transaction facade to quiet arm and post-admission retirement reducers. Assert finalization wire requests leave the prior quiet obligation retired and unindexed without weakening reconnect identity or terminal-response checks. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep post-commit retirement failures from invalidating processing admission, terminal transitions or erasure. Log deferred cleanup and retain the indexed replay backstop. Inject read and write failures to prove admission success and subsequent quiet-debt repair. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Model actual due-field deletion for repeated BYOK claims, keep account-erasure outbox cleanup as an explicit collaborator in the tombstone unit seam, and construct isolated payment routers in fixture setup so the existing call CPU guard measures endpoint behavior. Preserve all assertions, thresholds and required suites. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d88674c08d
ℹ️ 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 claimed: | ||
| if claimed_status != ConversationStatus.in_progress: |
There was a problem hiding this comment.
Restore the quiet obligation when processing admission rolls back
When synchronous finalization fails, processing_admission_guard calls rollback_processing_admission, which returns the conversation to in_progress through this same status helper. The new admission cleanup has already marked its quiet check quiet_done and removed reconcile_after_at, but the rollback does not rearm it. Previously scheduled deliveries cannot restore that retired obligation, so a transient processing failure now loses quiet-check recovery and must wait for the slower fallback scan or another client interaction. Rearm the check on a successful processing-to-in-progress rollback, or defer retirement until processing has a durable successor.
Useful? React with 👍 / 👎.
| except Exception: | ||
| # Cleanup must not invalidate an already-committed owner transition. | ||
| # Keep the durable index for the independent quiet replay backstop. | ||
| logger.exception('event=quiet_check_retirement outcome=deferred operation=stop_quiet_check_for_conversation') | ||
| return False |
There was a problem hiding this comment.
Record deferred cleanup through the shared fallback telemetry
When Firestore cleanup fails, this new fail-open branch continues the committed operation and delegates retirement to replay, but emits only an exception log. The equivalent job/account handlers do the same, leaving these degraded outcomes absent from the shared fallback metrics. backend/AGENTS.md explicitly requires new fallbacks to call utils.observability.fallback.record_fallback; instrument these deferred-retirement paths with that helper while preserving their non-throwing behavior.
AGENTS.md reference: backend/AGENTS.md:L316-L316
Useful? React with 👍 / 👎.
Use the boundary-helper fixes now landed in main through #23512 so this focused quiet-lifecycle PR no longer carries competing versions of those files. Preserve published history with a normal follow-up commit. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Restore an existing quiet obligation atomically with the successful processing-to-live CAS, with a new generation and immediate due index. Publish deferred cleanup through shared fallback telemetry without invalidating committed owner results. Guard restoration, stale deliveries, dependency failures and telemetry failures in unit and real Firestore tests. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 58624f1841
ℹ️ 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".
|
|
||
| def _record_deferred_retirement(operation: str) -> None: | ||
| try: | ||
| from utils.observability.fallback import record_fallback |
There was a problem hiding this comment.
Move the fallback telemetry import to module scope
The new deferred-retirement handler imports record_fallback inside the function, contrary to the explicit backend rule, “All imports at module top level — never inside functions.” Move this import to module scope while retaining the exception guard around telemetry emission so telemetry failures still cannot invalidate committed lifecycle operations.
AGENTS.md reference: backend/AGENTS.md:L163-L163
Useful? React with 👍 / 👎.
Keep telemetry failures isolated while complying with the backend import contract. Patch the resolved callable in the failure-injection guard. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
Apply the same backend import rule to the shared fallback counter assertion. Failure-Class: new Co-Authored-By: Claude Opus 5.5 <[email protected]>
#23527 landed a parallel guard fix for this file on main (per-test payment_router fixture calling the old _load_payment_router in fixture setup). Keep its public shape -- tests take a payment_router fixture and alias it locally -- but back it with this lane's module-scoped fixture: one import per file instead of one per test, shared-mock call-state reset between tests, unconditional stub replacement (no real-module attribute mutation in batched sessions), and utils.stripe/utils.subscription parent pinning. Drops main's now-dead per-test fixture. Allowlist entries for this file stay removed.
Summary
Quiet checks were armed at listen setup/reconnect/teardown, but sync-merge donor tombstones, smart merges, deletion and ordinary finalization writers did not retire them. They stayed
waiting_quietuntil replay rediscovered that their owner was gone or terminal. Reconnect reuse already has one deterministic job per conversation; it is not one new row per socket event.Expected inflow change
For the observed mix (~495–498 dead-owner retirements per 500 replay rows), this should eliminate nearly all new dead-owner overdue obligations from the covered paths after rollout, roughly 99% of the sampled avoidable inflow if that mix persists. It does not remove the existing ~134k backlog or reduce legitimate first arms. This estimate is conditional, not a live acceptance measurement.
Current main has replay outcome counters but no arm counter. Add
listen_quiet_check_arm_totalwith committedcreated,rearmed,reused,refusedoutcomes. The deterministic test expects and observes 1 created + 4 reused from five calls, one waiting row; terminal/donor arms are refused and leave zero waiting rows. The runbook separates these from replay retirement and actual per-window lifecycle rates. No production arm-rate measurement is claimed.Product invariants
No path-mandated invariant citations were selected by
scripts/pr-preflight --suggest. Preserve recording-lease, content, account, BYOK, revision and processing/fanout admission fences. Retiring a wake changes no conversation content, capture data or merge ownership. Live reopened owners retain quiet recovery. No language-gate, firmware, production configuration, production data or backfill change is included.Validation
cd backend && BACKEND_UNIT_TEST_FILE_LIST=<selected-file-list> nice -n 10 bash test.sh, throughomi-heavy; lifecycle, sync/smart-merge, executor/replay and Firestore guard coverage.firebase emulators:exec --only firestore --project demo-quiet-retirement "backend/.venv/bin/python backend/scripts/quiet_finalization_replay_emulator_test.py". User/empty deletion, capture_end, completion/discard/failure, processed persistence/upsert, live reopen, orphan/deferred/noise/actual near-1MiB fallback, dead-letter/BYOK/meeting closure, recursive account erasure with multipage cursor, and SDK index deletion; existing cursor/starvation/crash cases retained.scripts/pr-preflight --pr-body-file <body>and repository push gates; GitHub CI required before handoff.Scope and rollback
Focused on owner retirement and the deferred replay-pool/runbook P1s. #23506 owns episode lifecycle reconciliation; this adds no episode policy or new index. Throughput rollback remains limit 100 / concurrency 1. Revert this PR to roll back the source change; existing replay remains the recovery backstop. No merge/deploy is performed by this lane.
Failure-Class: new
Line-Count-Exception: backend/database/conversations.py | 4458 -> 4473 | Wire shared retirement after existing lifecycle commits; broader persistence extraction would expand this focused incident fix.
Line-Count-Exception: backend/database/conversation_finalization_jobs.py | 2949 -> 2976 | Retire quiet ownership after admission and terminal fallback, and clear terminal replay indexes without changing admission semantics.
🤖 Generated with Claude Code