Skip to content

fix: recover unsealed no-job batch captures with digest-gated backfill - #24104

Merged
Git-on-my-level merged 17 commits into
mainfrom
lane/sealbackfill
Oct 30, 2026
Merged

Git-on-my-level merged 17 commits into
mainfrom
lane/sealbackfill

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

Completed batch-live captures without a deterministic job can remain unsealed and never reach transcription. Add a one-time operator tool that scans at most 128 conversation references per resumable page, proves retained tails and dead producers, and atomically seals each eligible row with canonical record_pending registration.

Dry-run accepts ro-prod or prod-operator; apply requires prod-operator and a fresh --approve-plan-sha256. Output contains aggregate counts, closed dispositions and the plan digest. Private cursor files stay in 0700 Ephemeral scratch directories and are written as 0600. Explicit serving-role admission flags prevent operator environment settings becoming a stored job policy. Failed uploads and privacy-excluded rows stay untouched.

The flags file must provide both current batch and retirement ramps; incomplete, nonfinite or non-nested values are refused before planning. An empty discovery page resets the private output cursor for another bounded pass. Repeat passes and reconcile aggregate no-job counts before declaring settlement; an empty page alone is not a completion proof.

The finalizer now fails retryably on registration refusal for audio obligations. Proven closed, never-received server captures retain ordinary photo finalization without an audio job; upload failures, pending producers and unknown/unclosed archives retain the strict gate. Silent backfill registers an existing audio obligation before returning its existing processing fence. Intentional-discard retry churn and a restore-aware correction are tracked in #24110 under lead ruling f498ab; the model-only discard prototype was reverted because a concurrent restore could lose the audio obligation.

Validation

  • Targeted integrated backend/test.sh shards: 387 passed, 2 emulator-only tests skipped, including executor/barrier compatibility; through omi-heavy, nice -n 19 and BACKEND_UNIT_TEST_FILE_LIST. Final tree is byte-identical to validated 04e0c76; the discarded prototype's 390-test result is not final-tree evidence.
  • Focused isolated Firestore emulator: 2 passed (real paging and transaction rollback).
  • Hermetic listen/pusher stack and 13 concurrency tests passed at d7a4fbe; exact-head CI passed all runtime gauntlets at bc84bcb. After the documentation-only fix: isolate pusher record-barrier transactions from shared DB workers #24107 integration, two local reruns hit the canonical 20-second service-readiness deadline. Lead 6b0c0d authorizes relying on final exact-head backend CI after that repeated startup timeout; no harness timeout or code changed.
  • Repository preflight and exact-head GitHub checks: results recorded before merge readiness.
  • No production access or data mutation. The rollout lead owns dry-run/apply. Backend deployment is needed for the finalizer fix; the operator tool runs from this reviewed commit.

Failure-Class: FC-split-mutation-authority

Line-Count-Exception: backend/utils/conversations/finalizer.py | 792 -> 812 | Retain audio obligations before terminal fanout and preserve main refusal telemetry, ordinary photo finalization for proven-empty archives, and the silent-backfill processing fence.

The backfill uses canonical registration in the seal transaction and shares the retained-tail proof with the existing repair tool. Regression tests enforce privacy/read-before-write fences and refusal before finalizer terminal fanout.

Add a bounded counts-only operator backfill with fresh digest approval,
dead-producer and retained-tail proofs, and atomic seal plus canonical job
registration. Retain batch obligations before finalizer completion, including
the silent-backfill processing fence.
Require serving-role flags for the operator path, binding them into its
approval digest rather than resolving job policy from the laptop environment.
Bind exact mutable row state only for entries that can be written. Refused
rows retain their scope and disposition in the digest and grant no authority.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-30T12:09:33.950917Z 04e0c76 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.

Address Luna R1: refuse incomplete or invalid ramp maps before planning, and
reset an exhausted keyset cursor so continued bounded runs revisit late matches.
Document pass boundaries separately from aggregate backlog settlement.

@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: 2c086c296b

ℹ️ 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 +422 to +425
if not await run_blocking(
db_executor, register_recording, uid, {**conversation_data, **conversation.model_dump()}
):
raise ConversationFinalizationError('record_registration_refused')

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 Fence intentionally discarded captures instead of failing registration

When processing legitimately marks a batch-owned capture as discarded, process_conversation persists that result before reaching this block. register_recording explicitly returns False for discarded conversations, even if their deterministic job already exists, so this now turns a successful relevance discard into ConversationFinalizationError. The pusher handler consequently reports processing_failed and queues a retry instead of reaching the existing fanout claim, which terminally fences discarded rows. Distinguish intentional registration exclusions from failures to persist a required obligation, or fence discarded captures before this check.

Useful? React with 👍 / 👎.

Git-on-my-level added a commit that referenced this pull request Oct 30, 2026
## Summary

Adds a content-free replay corpus for the pusher **record path** (seal,
sticky upload failure, producer tokens, batch admission barrier) and a
runner that drives each trace through the real `routers.pusher`
websocket handler.

Batch shadow re-runs recognition on stored audio and never exercises
this path. Both 10-29/30 live batch stops and the current unsealed
no-transcript backlog were on it, so a record-path change had no
pre-deploy replay. This gives one: add a trace per incident, in the PR
that fixes it.

- `backend/testing/record_traces/traces/*.json`: `record-trace/1`
fixtures (row seed, websocket sessions as 103/101/104 frames with an
upload outcome, expected end state). Durations and protocol shape only:
no audio, IDs or user content.
- `backend/tests/unit/test_record_traces.py`: replays each trace with
the existing strict-Firestore and recording fakes. Finalize-only traces
run with `AUDIO_DURABLE_OUTBOX_ENABLED` both off and on. Traces with
audio run legacy-only, and the corpus check refuses durable-plus-audio
until an outbox fake exists, so a durable replay can never pass without
exercising custody. It asserts `sealed`, `upload_failed`, `open_tokens`
and whether `require_record_audio_barrier` would admit the row.
- Seven goldens pin main `a05342f`:
- a reconnect that finalizes with no new audio (unsealed-rca path 1),
with and without an earlier audio session;
  - the `batch_sync_v1` owner;
  - a legacy owner that is never sealed;
  - an exhausted upload followed by a clean reconnect;
  - one session that uploads audio and finalizes;
- a drained-pod producer token that blocks the seal, marked `known_gap`
for the sealsweep fix (#24104) to flip.
- Finding pinned by the exhausted-upload trace: the failed session's
producer token stays on the row. This is harmless for admission because
`record_upload_failed` is sticky, but a dead-token sweeper must keep
requiring `record_upload_failed == false`.

Test-only: no runtime code, flags or deploy.

## Test plan

- `cd backend && python -m pytest tests/unit/test_record_traces.py -q`:
11 passed locally (7 traces × their modes, plus the corpus shape check).
- Bounded pre-push gate passed.

Archive listing and tail durability are proved at admission against
storage and are not modeled here.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Require audio registration unless a server archive is explicitly closed and
never received audio, with no failed upload, pending producer or durable bounds.
Keep ordinary photo fanout and the silent-backfill processing fence for that
case, while unknown or unclosed audio obligations remain retryable.
Preserve main's registration refusal counter and content-free warning inside
the reviewed audio-obligation gate, before the retryable refusal. Keep the
counter contract test and assert refused registration cannot claim fanout.
Preserve both adjacent seal operator runbooks after the sweeper merge.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Integration review response at bc84bcba0ac9bdfe63964ea8dd1b13e43e9a21b3:

Grok accepted the production resolution, photo-only obligation guard, retained operator documentation and shared pod-parser compatibility. Its sole FIX-FIRST finding claims test_generic_batch_registration_refusal_is_visible_and_blocks_fanout[True] leaks the harness's RuntimeError instead of the expected ConversationFinalizationError.

That finding is rebutted by the existing outer handler in backend/utils/conversations/finalizer.py:678-720: it catches ordinary exceptions, records the closed failure classification, then raises ConversationFinalizationError('processing_failed') from error. The success parameter intentionally reaches derived work and exercises that wrapper. It additionally asserts that fanout was claimed; the refusal parameter asserts no fanout and the incremented refusal counter/content-free log.

Both parameters passed in the exact-head backend/test.sh shard (350 passed, 2 emulator-only skips). The isolated Firestore emulator tests also passed (2). No source change is justified by this finding. A correction-only reviewer follow-up has been requested from the lead under the review cap. The PR remains unready pending that ruling/review and full exact-head backend CI.

Keep both adjacent backfill and record-barrier operator documentation.
Classify the persisted processing result before requiring registration. Keep
the existing discard and silent fences while retaining revived obligations.
Return to the reviewed finalizer behavior per lead ruling f498ab. Track
intentional discard retry churn and a restore-aware correction separately.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

The intentional-discard finding is tracked in #24110. Lead ruling f498ab explicitly retains the reviewed strict registration behavior for this PR: the observed P2 is bounded retry churn, while skipping registration from a discarded processing model introduces a P1 race if the user restores the durable row before fanout claims it.

The prototype was reverted in bd8110484dbeff22b27077f84d91bc3ef72a9c4a; its final tree is byte-identical to validated 04e0c76de43a7af112225bfefc3e879881899448. The follow-up issue records the reproduction, restore-aware acceptance criteria, rollout-lead ownership and an 18:00 UTC assignment/plan promise. No additional review round is required under the lead ruling. Fresh exact-head CI is still required before merge readiness.

@Git-on-my-level
Git-on-my-level merged commit 14d4195 into main Oct 30, 2026
56 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/sealbackfill branch October 30, 2026 12:49
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