Repository navigation
fix(pipeline): wire C1 admission and transcript-landed coverage (C1b-2) - #25143
Conversation
The write-only in-flight ledger had no production caller on main for either end of a fresh capture's middle: nothing created the admission row, and a completed projection never left `sealed`. The census therefore had no `capturing` cohort and every transcribed row aged past the seal deadline. - Admission (`utils/batch_pipeline/live.py`): `reserve_recording` offers `capturing` at the durable admission that gives the capture its batch lane, including a lane already claimed on the streaming path. The ledger is forward-only and idempotent, so a finalizer replay or reconnect can only produce a duplicate or an illegal-transition refusal, never a second admission. The write is fail-open and a deleted capture gets no row. - Transcript landed (`database/batch_pipeline_projection.py`): the first durable completion of a capture's projection writes `transcribed` on the completion's own event clock, with the immutable completion summary's speech seconds and `speech_basis='transcript'`. A replay (`changed is False`) writes nothing, and a source deletion keeps its erasure fence. - Tests: admission is idempotent across replays and never rewinds a sealed row; a ledger outage cannot block the real admission; the transcription writer uses the completion clock, skips replays, and stays fail-open. Ledger reads and writes stay out of the real transition's transaction; every ledger error is swallowed. `PIPELINE_LEDGER=off` still stops all ledger writes. Failure-Class: FC-dashboard-reads-key-no-writer-maintains
Codex Review Summary: ✅ CompletedThis 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: 8f529bf27b
ℹ️ 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 owner in BATCH_LEDGER_OWNERS: | ||
| observe_admitted(uid, conversation) |
There was a problem hiding this comment.
Write capturing at the streaming admission boundary
For recordings admitted while streaming, this writer does not run until finalization: the only production caller of reserve_recording is utils/conversations/finalizer.py:868, whereas create_in_progress_conversation already persists the batch owner in utils/conversations/lifecycle.py:164–171. Consequently, an actively recording capture has no capturing row, and a capture that never reaches finalization remains absent altogether. The admission timestamp and six-hour capturing deadline also start at finalization rather than admission. Call the observer after the durable streaming admission succeeds, retaining this call for repairs and replays.
Useful? React with 👍 / 👎.
| if not isinstance(capture_id, str) or not capture_id or conversation.get('deleted'): | ||
| return False | ||
| try: | ||
| from database import pipeline_ledger |
There was a problem hiding this comment.
Move the new ledger imports to module scope
Both new production observers import pipeline_ledger inside their function bodies, contrary to the explicit import convention in backend/AGENTS.md: “All imports at module top level — never inside functions.” Move these imports to module scope in both live.py and batch_pipeline_projection.py; the ledger already resolves its Firestore client lazily inside advance(), so this does not require constructing a client at import time.
AGENTS.md reference: backend/AGENTS.md:L166-L168
Useful? React with 👍 / 👎.
| result, changed, seconds = self.run(commit, policy=policy) | ||
| self._mirror(binding) | ||
| if changed: | ||
| self._observe_transcription(binding, now, accounting, result) |
There was a problem hiding this comment.
Add the required pipeline change note
This commit changes capture admission and transcript-completion instrumentation, but its changed-file list contains no pipeline change note. backend/AGENTS.md explicitly requires transcription and conversation-lifecycle changes to add a note under backend/docs/listen_pusher_pipeline/changes/ in the same change. Add a dated note describing the new writers, PIPELINE_LEDGER flag state, and verification evidence so the pipeline's operational documentation includes this change.
AGENTS.md reference: backend/AGENTS.md:L164-L164
Useful? React with 👍 / 👎.
C1b-2: admission and transcript-landed writers for the in-flight ledger
The write-only, fail-open ledger had no production caller on
mainfor eitherend of a fresh capture's middle. Nothing created the admission row, so the C2
census had no
capturingcohort; a completed projection never advanced pastsealed, so every transcribed row aged past its deadline. This lands the twowriters that close that gap, on the files the C1b split reserved.
Failure-Class: FC-dashboard-reads-key-no-writer-maintains
What changed
backend/utils/batch_pipeline/live.py):reserve_recordingoffers
capturingat the durable admission that gives a capture its batchlane — the fresh claim and a lane already claimed on the streaming path. The
ledger is forward-only and idempotent, so a finalizer replay, reconnect or
competing reservation can only produce a duplicate or a forward/illegal
refusal, never a second admission. A capture without an identity or already
deleted gets no row. The write is fail-open: it never changes the returned
owner.
backend/database/batch_pipeline_projection.py): thefirst durable completion of a capture's projection writes
transcribedonthe completion's own event clock (
now), with the immutable completionsummary's speech seconds and
speech_basis='transcript'. A replay(
changed is False) writes nothing, and a source deletion keeps its erasurefence and gets no new durable row.
rewinds a
sealedrow, skips an identity-less or deleted capture and cannotbe blocked by a ledger outage; the transcription writer uses the completion
clock, skips replays, respects the deletion fence, needs a capture identity
and is fail-open.
Not in this change
donewriters and the ledger'srevision/erasure-fence, deletion, export and retention surface belong to
C1b-1/C1b-1a (
#25125,#25129). This PR stacks no code on either: itswriters use only
advance()as it exists onmain, and they keep workingunchanged when the fenced
advance(..., source_ref=..., owner_ref=...)signature lands.
no_speech/noiseterminals and the true admissiondenominator are C1b-3.
complete_partial) deliberately do not writetranscribed: a held partial has not landed the capture's whole transcript,and its terminal disposition belongs to C1b-3.
writers merged and one full serving window. The census denominator is still
every conversation created in the window, not only fresh batch-eligible
captures.
Write amplification
One
advance()per capture admission and at most one per capture completion.Each is its own small Firestore transaction after the real transition; the
ledger is never read on a hot path and no transition depends on it. A duplicate
or refused transition reads the row and writes nothing.
Kill switch and rollback
PIPELINE_LEDGERviapipeline_ledger_enabled()(existing flag, default on).Off stops all ledger writes; capture and projection behavior is unchanged
either way because both calls are fail-open. Reverting the code returns capture
and projection behavior exactly to today's; rows already written keep their
stamps.
Tests
backend/tests/unit/test_batch_pipeline_live.py— admission written once ona fresh claim, replay is a duplicate, a sealed row is never rewound, a ledger
outage leaves the real admission intact, identity-less/deleted captures are
skipped.
backend/tests/unit/test_batch_pipeline_projection.py— first completionwrites
transcribedwith the completion clock and completion-summary speechseconds; a replay writes nothing; a source deletion writes nothing; the
writer is fail-open and needs a capture identity.
Focused run with the repo's Python 3.11 environment:
tests/unit/test_batch_pipeline_live.py,test_batch_pipeline_projection.py,test_pipeline_ledger.py,test_pipeline_ledger_census.py,test_restore_recording_obligation.py,test_batch_record_dead_letter.py,test_phase_shadow_readers.py— 338 passed. The Firestore emulator proof wasnot run in this environment; the changes add no query or index and use only the
existing
advance()contract.Product invariants affected
None. The ledger document is content-free (stage, clocks, bounded reason, speech
seconds, truncated owner hash) and no read path or transition depends on it.
Closes SCA-1761