Skip to content

fix(pipeline): wire the first live writers into the in-flight ledger (C1b-1) - #25125

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/c1b1
Nov 15, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/c1b1

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

C1b-1: wire the first live writers into the in-flight ledger

pipeline_ledger.advance() had zero production callers on main, so C2's
census read an empty collection and P2 had nothing to wake on. This lands the
preserved C1a2 live-transition hooks as one source PR so the ledger gets its
first real writers.

Head: 258d96283a12af569ebe6aadfb6bc6a1f47b21e0

Line-Count-Exception: backend/database/conversations.py | 4969 -> 5056 | thread the ledger's first-durable-summary noted and done hooks through the two existing lifecycle writers and delete the sibling ledger row with its conversation; the split of this oversized file is separate debt, not this change

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

Why this class: the ledger is an operator measurement surface (the C2 census
reads users/{uid}/pipeline_ledger), and it was a read path over a collection
that no active writer maintained. The census returned a well-formed
empty/UNKNOWN aggregate rather than a missing-sample error, which is exactly
the "reader without a writer" failure. It is adjacent to
FC-state-deadline-without-reader-exit, but the defect here is the missing
entry writer, not a missing exit reader: the stage table already declared
deadlines and exits; nothing ever entered a stage.

What changed

  • Seal hook (backend/database/record_audio.py): capturing -> sealed on
    the seal that actually closes the recording. Admission is a durable
    per-capture fact (record_admitted_at) written inside the seal transaction,
    so a reconnect that re-opens and re-seals the row does not count a second
    admission, increment attempt, or reset the deadline. A partial-seal repair
    does not count a second admission either.
  • failed:upload_failed terminal (backend/database/record_audio.py):
    end_type=unknown, end_at is record_upload_failed_at falling back to the
    observation time — never last speech, never the ledger-write time.
    mark_record_upload_failed now persists record_upload_failed_at.
  • First-durable-summary noted hook (backend/database/conversations.py,
    both upsert_conversation_with_lifecycle and
    persist_processing_result_with_lifecycle): accepts
    reason in {'summary', 'accept_unknown'} and still excludes discarded and
    local_only.
  • done terminal (backend/database/conversations.py, the same Home-ready
    point as the noted hook): the first durable summary is the Home-ready
    moment, so the row advances noted -> done immediately. This is the missing
    terminal writer: without it every noted row sat past its 1800s deadline and
    the stuck alert paged forever.
  • Source/owner deletion-race fence (backend/database/pipeline_ledger.py):
    advance() accepts source_ref/owner_ref; the ledger transaction reads
    both and refuses to create a row when the source is missing or deleted or the
    owner document is gone. Fail-open for the already-committed transition.
  • Ordered revision / reopen (backend/database/pipeline_ledger.py):
    source_revision() derives the revision from the source snapshot's
    update_time using integer seconds plus microseconds, so two distinct
    commits cannot collapse to one revision at 2026 epochs. Seal and notes
    callers pass it with reopen=True, so a proof repair can close a
    failed:upload_failed recording and a stale failure hook loses.
  • Retention (backend/database/pipeline_ledger.py,
    backend/deploy/batch-pipeline/retention.json,
    .github/actions/sync-backfill-lifecycle/action.yml): terminal rows keep the
    26h TTL; nonterminal rows now carry a bounded 7-day max lifetime, refreshed on
    every transition, so a stalled row cannot live forever. The reviewed
    retention declaration and the platform provisioning step now include the
    pipeline_ledger collection group.
  • Deletion (backend/database/conversations.py,
    backend/utils/conversations/merge_conversations.py): the sibling
    users/{uid}/pipeline_ledger/{conversation_id} row is deleted with the
    conversation, including the merge-source delete path.
  • Portability export (backend/services/users/data_export.py) and the
    recursive-erasure inventory (backend/database/user_data_deletion.py) for
    the now-live collection.
  • Change note
    backend/docs/listen_pusher_pipeline/changes/2026-11-10-pipeline-in-flight-ledger.md.

P0: the stuck alert

The ledger previously had no terminal writer for a normal capture, so every
noted row crossed its 1800s deadline and
max by (stage)(omi_pipeline_ledger_stuck_rows) > 0 paged at critical forever.
This PR does both halves:

  1. done writer at the Home-ready point (the first durable summary, the
    same place home_ready_at is known). noted -> done is a forward
    transition.
  2. Stuck alert downgraded from critical/page to warning/agent in
    backend/charts/monitoring/alerts/pipeline-ledger.json. The alert is not
    deleted and the signal is not hidden. Its rearm_condition annotation names
    the re-arm condition: C1b-2 (transcript landed) and C1b-3 (remaining
    terminals) merged and serving, plus one full lookback.

Write amplification

One document per capture, at most five transitions, 26h terminal TTL, 7-day
nonterminal max lifetime, fail-open on every ledger error. The cost is not
zero: every advance() runs its own Firestore transaction that reads the
owner, the source and the ledger document (three reads) plus 0–1 write, and the
notes hook fires on every processing persist. The ledger write is one extra
small transaction after the real commit — never a per-frame or per-request
read.

Scope split

  • C1b-1 (this PR): the unfenced half — seal, upload-failure terminal, notes,
    done, source/owner fence, ordered revision/reopen, retention, deletion,
    portability, erasure inventory.
  • C1b-2 (outstanding): admission (utils/batch_pipeline/live.py) and
    transcript landed (database/batch_pipeline_projection.py), still fenced by
    fix(batch,sync): explicit backlog state machine with owners, deadlines and attempt budgets #24893.
  • C1b-3 (outstanding): episode composed, no_speech/noise terminals, true
    admission denominator.

This PR alone does not reach G2's 99.5% coverage; that needs C1b-2. It does
make C2's census return non-zero coverage for new captures instead of
0/UNKNOWN.

Kill switch and rollback

PIPELINE_LEDGER via pipeline_ledger_enabled(), default on when absent
(existing flag, no new env name, no flag-budget slot). Off stops ledger writes
and leaves capture behavior unchanged. Rollback is a revert: the ledger is
write-only and fail-open, no read path and no transition depends on it, so a
revert restores today's behavior exactly. Rows already written expire on their
terminal TTL or nonterminal max lifetime.

Allowlist follow-up (needs approval)

The preserved patch also removed the backend/database/pipeline_ledger.py
entry from .github/scripts/dead_code/backend.allowlist.json. That guarded path
needs David's specific approval, so this PR leaves the entry in place and does
not touch .github/. The exact proposed hunk (path, base head, four removed
lines) is recorded in
data/run-2026-11-08-pipeline-refactor/c1b1-allowlist-hunk.md. The dead-code
ratchet still passes at this head; it reports the entry as an advisory
"no longer dead" note, not a failure.

Product invariants affected

  • INV-MEM-3 — the portability export gains a content-free pipeline_ledger
    section only. It reads a per-user subcollection directly (as the existing
    export inventory does for memory_review_data, jit_data, etc.), does not
    bypass MemoryService for memory content, and does not touch the intake-pause
    or deletion paths. The recursive account wipe still erases the collection.

Tests

Unit (hermetic):

  • backend/tests/unit/test_pipeline_ledger.py — table invariants, transitions,
    fail-open, privacy, retention and revision ordering.
  • backend/tests/unit/test_record_audio_seal.py — reconnect re-seal admits
    exactly once, record_upload_failed_at is persisted, and the only non-PATH
    writes target the ledger collection.
  • backend/tests/unit/test_record_token_lease.py — the seal transaction is
    selected by payload, not by [-1].
  • backend/tests/unit/test_summary_persistence.py,
    test_audio_durable_outbox.py,
    test_conversation_persistence_transaction_expiry.py.
  • backend/tests/routers/test_users_export_streaming.py,
    backend/tests/services/users/test_data_export.py,
    test_data_export_streaming.py.
  • Flag-budget, reason-enum, index, lifecycle-writer inventory and
    monitoring-contract suites.

Emulator (loopback Firestore, FIRESTORE_EMULATOR_HOST=127.0.0.1:8085):

  • backend/tests/integration/test_pipeline_ledger_firestore.py — seal,
    duplicate seal, reconnect re-seal (attempt == 1, one sealed transition),
    upload-failure terminal and end_at fallback, source-delete fence, stale
    revision, notes, delete-conversation sibling cleanup, account erasure, and
    the census window. Added to backend/scripts/run-emulator-proofs.sh so it
    runs in CI.

Full pre-push gate: see the push log.

The C1 in-flight ledger shipped its stage/deadline contract with zero
production callers, so the C2 census read an empty collection and reported a
well-formed 0/UNKNOWN instead of a missing sample.

Add the seal (capturing -> sealed, admission counted once per capture, not per
partial-seal repair), failed:upload_failed (record_upload_failed_at as end_at,
falling back to the observation time), and first-durable-summary noted hooks.
Seal and notes callers pass an ordered source revision with reopen=True, so a
proof repair can close an upload failure and a stale failure hook loses. A
delayed post-commit write reads the source and owner inside the ledger
transaction and refuses to create a row after deletion or erasure, fail-open
for the already-committed transition.

The ledger is write-only, fail-open, and never read on the hot path: one
document per capture, at most five transitions, 26h terminal TTL. Off stops
ledger writes and leaves capture behavior unchanged. Portability export and the
recursive account wipe now cover the collection.

The dead-code allowlist entry for the module is left in place; the prepared
removal hunk needs separate approval.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-12T01:06:39.225841Z 258d962 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.

@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: 90742e6ccb

ℹ️ 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 +376 to +380
if owner_ref is not None:
owner = owner_ref.get(transaction=transaction)
if not getattr(owner, 'exists', False):
observed['outcome'] = 'deleted'
return 'deleted'

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 Fence ledger writes against an account wipe in progress

If a delayed hook runs during account erasure after the ledger collection has been swept but before its source conversation is removed, both existence checks still pass and the hook can recreate the ledger row. purge_user_subtree() in backend/database/user_data_deletion.py sweeps subcollections before deleting the user document, so checking only owner/source existence does not fence this interval; deleting those documents afterward does not cascade to the recreated row. Check the durable account-deletion or privacy-purge authority inside this transaction, as assert_batch_write_allowed() already does, so an in-flight hook cannot leave user data behind after a successful wipe.

Useful? React with 👍 / 👎.

Comment on lines 37 to +41
def commit(tx):
row = ref.get(transaction=tx).to_dict() or {}
nonlocal admitted, source_revision, failed_at
snapshot = ref.get(transaction=tx)
row = snapshot.to_dict() or {}
source_revision = pipeline_ledger.source_revision(snapshot)

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 Reset admission state on every transaction attempt

When two seal calls contend, an initial attempt can set admitted = True and then lose its commit. If the retry observes the other caller's successful seal, it returns without updating the conversation, but admitted remains true from the aborted attempt. The post-transaction code consequently counts another admission and submits another SEALED transition with the newer snapshot revision, inflating the coverage denominator and resetting the stage deadline despite no new seal. Reset admitted at the beginning of each callback attempt so only the successful attempt determines the post-commit effects.

Useful? React with 👍 / 👎.

Add the done writer at the Home-ready point so noted rows reach a terminal, and downgrade the stuck alert to warning with a named re-arm condition. Count admission once per capture with a durable record_admitted_at marker, stamp a bounded expires_at on nonterminal rows, declare and provision the pipeline_ledger TTL, and delete the sibling ledger row with its conversation. Fix the lifecycle inventory and token-lease test, reset per-attempt observations, and use integer-microsecond source revisions.

@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: 258d96283a

ℹ️ 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".

nonterminal row would otherwise survive until its max-lifetime TTL.
"""
try:
db.collection('users').document(uid).collection('pipeline_ledger').document(conversation_id).delete()

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 Use an injectable Firestore client for ledger deletion

This new database helper uses the legacy db proxy and provides no firestore_client injection point, contrary to the database convention in backend/AGENTS.md. Consequently, callers and tests cannot explicitly bind this cleanup to their selected client without replacing module-global state; the new integration test already has to monkeypatch conversations.db. Resolve get_firestore_client() at call time, accept a keyword-only client override, and forward the selected client from callers.

AGENTS.md reference: backend/AGENTS.md:L180-L180

Useful? React with 👍 / 👎.

Comment on lines +2674 to +2675
except Exception:
logger.warning('pipeline ledger cleanup failed conversation=%s', conversation_id)

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 Instrument the ledger-cleanup fail-open path

If the Firestore delete fails, this branch allows conversation deletion to report success while retaining the sibling ledger row, potentially until its seven-day TTL. It emits only a warning, so the shared fallback telemetry does not report this degraded cleanup. backend/AGENTS.md explicitly requires new fail-open paths to call utils.observability.fallback.record_fallback; record a bounded degraded outcome here if cleanup is intentionally best-effort.

AGENTS.md reference: backend/AGENTS.md:L322-L322

Useful? React with 👍 / 👎.

Git-on-my-level added a commit that referenced this pull request Nov 12, 2026
…2) (#25143)

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


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/25143?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/25143?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25143&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->



Closes SCA-1761
Git-on-my-level added a commit that referenced this pull request Nov 15, 2026
…nd a tunable notes hold (#25304)

# Capture lifecycle spine: ledger writers for every summary outcome, and
a tunable notes hold

Supersedes #25125 and #25129 (both folded in by merge, history kept).
Tracking: SCA-1760, SCA-1762,
SCA-1766. Design note: the `DESIGN:` comment on SCA-1760.

The in-flight ledger (`users/{uid}/pipeline_ledger/{capture_id}`) had
two production writers on `main`
(`capturing`, `transcribed`), so no capture ever reached a terminal and
the end-to-Home gate had nothing to
read. This gives every normal outcome a writer, and makes the 600 s
notes hold tunable without a release.

Line-Count-Exception: backend/database/conversations.py | 4971 -> 5020 |
thread the ledger's summary-outcome hook through the two existing
lifecycle writers and delete the sibling ledger row with its
conversation; splitting this oversized file is separate debt

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

Why this class: the census reads a collection no writer maintained past
`transcribed`, and returned a
well-formed empty aggregate instead of an error. The defect is the
missing writers.

## What changed

From #25125, unchanged in behaviour:

- **Seal** (`database/record_audio.py`): `capturing -> sealed` on the
seal that closes the recording;
  admission counted once per capture.
- **`failed:upload_failed` terminal**, with `end_type=unknown` and
`end_at` the observed failure time.
- **Deletion fence** in `pipeline_ledger.advance()`: the ledger
transaction reads the source conversation
and the account-deletion marker (`account_deletions/{uid}`) and writes
nothing for a deleted source or an
account being wiped. The marker, not the user document, is the
authority: the user document outlives its
subcollections during a wipe (review finding 1). Every writer here
passes both references, the operator
  closes included (finding 2).
- **Conversation deletion removes the sibling ledger row and fails if
that delete fails** (finding 3); the
  delete is idempotent, so the caller's retry completes it.
- **Retention, deletion and erasure inventory** for the now-live
collection. The ledger is not added to the
portability export (removed under the goal owner's ruling of 23:37Z: the
only approved readers are the
  census routes).

New in this PR:

- **`noted` and `done` in one ledger transaction**
(`pipeline_ledger.advance(..., then=(DONE,))`). #25125
used two transactions at every summary commit; this is one read set and
one write.
- **`noise` terminal for a receipted relevance discard.** Before, a
discarded capture sat at `transcribed`
until its 30-minute deadline and counted as stuck. A later real summary
re-opens it with a higher revision.
- **`no_speech` and `noise` terminals on the two operator closes**
(`utils/conversations/lifecycle.py`),
written after the real close commits. A restore needs no ledger undo:
the restored capture's next real
  transition re-opens the row.
- **`SYNC_PROCESSING_QUIET_SECONDS`** (`utils/sync/processing_hold.py`):
the arrival-quiet window before
full notes processing is read per call. Default 600, clamped to
120..600, malformed keeps the default. The
outbox due time and the budget-denial reschedule follow the same value.
**No behaviour change at the
  default.**

- **`omi_sync_content_arrival_gap_seconds`** histogram: seconds between
content arrivals on one held
conversation. The share above a candidate quiet window is the late
re-run rate that window would buy.
- **Ledger metrics kept in the sync scrape**
(`deploy/cloud_run_gmp_sync.yaml`): the keep rule dropped every
`omi_pipeline_ledger_*` family on the services where seal and summary
ledger writes run.

Not carried over from #25125: its downgrade of the ledger stuck alert.
That rule set is owned by #25284 and
the downgrade no longer met the alert tier contract on `main`.

## Reads and writes

Each fenced ledger write is one transaction: three document reads
(account-deletion marker, source, ledger
row) and at most one write. A normal capture costs about 12 reads and 4
writes across its life (seal, summary, and the two
existing writers), against 15 reads and 5 writes if #25125 had merged as
it was. No query, scan, per-frame or per-request
read. Rows carry an expiry time; the TTL policy that acts on it is not
enabled by this PR.

## What this does not do yet, and how to read it

- Every terminal row still has `end_type=unknown` and no `end_at`: the
end writers are the next PR, stacked on
this one. Until that serves,
`omi_pipeline_ledger_unknown_end_type_total` is not a health signal.
- Done check, after serving: of captures **admitted after the serving
timestamp**, the share reaching `done`,
with `noise`, `no_speech` and `failed:*` reported beside it, and no row
past its stage deadline. "Any
terminal" is not the pass. Rows already at `transcribed` before serving
get no writer, expire on the 7-day
  nonterminal lifetime, and are excluded and named as excluded.
- The hold's 120 s floor is a safety bound (the recorded-time gap at
which a conversation splits), not a
proposed value. The first candidate value is 300, chosen from the
arrival-gap histogram.

## Kill switches and rollback

- `PIPELINE_LEDGER=off` (existing, default on) stops every ledger write.
Nothing reads the ledger on a
  serving path, so a revert restores today's behaviour exactly.
- `SYNC_PROCESSING_QUIET_SECONDS` unset or `600` is today's behaviour.

## Needs the owner's eye

- **Not in this PR:** enabling the Firestore TTL policy on the
`pipeline_ledger` collection group. #25125 did
it by editing `.github/actions/sync-backfill-lifecycle/action.yml`; that
edit is removed here and waits for
the owner's explicit yes as its own change. Until then ledger rows carry
`expires_at` but nothing deletes
them on a timer; conversation deletion and account erasure still remove
them.
- The hold value itself is not changed here. Lowering it is a separate
config decision.

## Tests

- `tests/unit/test_pipeline_ledger.py`: one-write chain keeps both
transitions; a duplicate first stage still
lands the follow stage; a follow stage never re-opens a terminal;
receipt-to-stage mapping; noise terminal
  and re-open by a later summary; deleted source writes nothing.
- `tests/unit/test_lifecycle_ledger_terminals.py` (new): both operator
closes write their terminal; a refused
  close writes none.
- `tests/unit/test_sync_processing_hold.py`: per-call read, clamp,
malformed values, outbox due time.
- `tests/unit/test_summary_persistence.py`,
`test_conversation_persistence_transaction_expiry.py`: one ledger
  transaction per summary commit.
- `tests/unit/test_lifecycle_metrics_are_scraped.py` (new): ledger and
hold families survive the sync keep
rule; arrival-gap observation is covered in
`test_sync_processing_hold.py`.
- Inherited from #25125: `test_record_audio_seal.py`,
`test_record_token_lease.py`, erasure tests,
and the emulator proof
`tests/integration/test_pipeline_ledger_firestore.py`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@Git-on-my-level
Git-on-my-level merged commit 5b313b3 into main Nov 15, 2026
65 of 69 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/c1b1 branch November 15, 2026 01:15
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