Skip to content

fix(pipeline): wire C1 admission and transcript-landed coverage (C1b-2) - #25143

Merged
Git-on-my-level merged 1 commit into
mainfrom
agent/m1-studio-opencode-deepseek-v4/8b40e8c0f4d9
Nov 12, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
agent/m1-studio-opencode-deepseek-v4/8b40e8c0f4d9

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

C1b-2: admission and transcript-landed writers for the in-flight ledger

The write-only, fail-open ledger had no production caller on main for either
end of a fresh capture's middle. Nothing created the admission row, so the C2
census had no capturing cohort; a completed projection never advanced past
sealed, so every transcribed row aged past its deadline. This lands the two
writers that close that gap, on the files the C1b split reserved.

Failure-Class: FC-dashboard-reads-key-no-writer-maintains

What changed

  • Admission (backend/utils/batch_pipeline/live.py): reserve_recording
    offers capturing at the durable admission that gives a capture its batch
    lane — 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.
  • Transcript landed (backend/database/batch_pipeline_projection.py): the
    first durable completion of a capture's projection writes transcribed on
    the completion's own event clock (now), 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 and gets no new durable row.
  • Tests (unit, hermetic): admission is idempotent across replays, never
    rewinds a sealed row, skips an identity-less or deleted capture and cannot
    be 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

  • The seal, upload-failure, notes and done writers and the ledger's
    revision/erasure-fence, deletion, export and retention surface belong to
    C1b-1/C1b-1a (#25125, #25129). This PR stacks no code on either: its
    writers use only advance() as it exists on main, and they keep working
    unchanged when the fenced advance(..., source_ref=..., owner_ref=...)
    signature lands.
  • Episode composed, no_speech/noise terminals and the true admission
    denominator are C1b-3.
  • Partial completions (complete_partial) deliberately do not write
    transcribed: a held partial has not landed the capture's whole transcript,
    and its terminal disposition belongs to C1b-3.
  • This change alone does not prove G2/P2 coverage: that needs the sibling
    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_LEDGER via pipeline_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 on
    a 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 completion
    writes transcribed with the completion clock and completion-summary speech
    seconds; 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 was
not 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.

View guided diff Turn on auto-fix

Closes SCA-1761

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

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T08:36:10.508052Z 8f529bf 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: 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".

Comment on lines +144 to +145
if owner in BATCH_LEDGER_OWNERS:
observe_admitted(uid, conversation)

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 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

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 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)

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

@Git-on-my-level
Git-on-my-level merged commit 5f126d0 into main Nov 12, 2026
72 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/m1-studio-opencode-deepseek-v4/8b40e8c0f4d9 branch November 12, 2026 08:56
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