Repository navigation
feat(pipeline): fail-open in-flight ledger with the C2 read and coverage contract - #25047
Merged
Git-on-my-level merged 9 commits intoNov 10, 2026
Merged
Conversation
Add a storage-neutral stage contract and fail-open store helper under database/pipeline_ledger.py. One document per capture records stage, entered_at, deadline_at, attempt, reason, end_type, end_at, the last 16 transitions, and a terminal TTL. Every nonterminal stage has a deadline and an exit; advance() is idempotent and refuses backward transitions. Instrument the seal transaction (database/record_audio.py) and the first durable notes transaction (database/conversations.py). The ledger read and plan happen before the real transaction, so the real transaction stays write-only; a ledger error returns None and the real transition proceeds unchanged. PIPELINE_LEDGER defaults on and off stops all ledger writes. Admission and transcript landed are deferred to C1b because BasedHardware#24893 still owns those files.
…contract Rewrite the ledger around a post-commit CAS transaction so a ledger failure can never fail the real transition, and a concurrent writer cannot overwrite a newer stage. Add the C2 census fields (schema version, identity, owner key, admission/created/updated clocks, revision, terminal, speech basis, Home and episode clocks), stage+revision idempotency with explicit late-append and retry re-open, a closed reason vocabulary, and a bounded read-only iter_window / census_window helper. Instrument seal, first durable notes and the upload-failure terminal. Add the independent admission counter, write outcome/failure counters, transition and stage gauges, and the unknown-end-type counter. Include the ledger collection in the portability export inventory and the recursive account wipe. Admission and transcript landed remain C1b because BasedHardware#24893 owns those files.
…roup index Add the iter_window/census_window driver entries and the pipeline_ledger admitted_at collection-group single-field index so the Firestore query-shape guard can serve the C2 read helper.
…counts Route the ledger outcome and failure labels through reason_label with new closed enums, and update the export-section and transaction-count assertions that the new ledger write and export section change.
Move the seal/notes/upload-failure hooks, their tests, the change note, the portability/erasure wiring and the trigger->end-type mapping into the preserved C1a2 patch. C1a-core keeps the storage-neutral ledger contract, CAS/idempotency/revision semantics, bounded read helper, counters, flag, index and metric inventory. Core has no live transition writes.
- expires_at is a UTC timestamp for the Firestore TTL policy - census reads are owner-scoped, projected, and fail closed before any prefix - failed:<text> collapses to the closed failure vocabulary - stage labels are bounded; raw capture/conversation ids leave the row body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
C1a-core: storage-neutral in-flight ledger contract (dormant, no live hooks)
Failure-Class: FC-state-deadline-without-reader-exit
Line-Count-Exception: backend/database/firestore_index_registry.py | 2342 -> 2343 | one collection-group single-field index for the C2 ledger window read helper.
Size (measured, not estimated)
git diff --numstat 720f078b33dde3872f5156fb87a961ffec2300c7...HEADoutsidebackend/tests/**:526 changed non-test lines (526 additions, 0 deletions), 26 over the
500-line cap. The C1 fix batch itself is 77 changed non-test lines (56
additions, 21 deletions) in
backend/database/pipeline_ledger.py, under the200-line fix cap. The 26-line overage is the fix batch on top of the 491-line
split; the alternative was to leave the pre-review findings open. Total
including tests: 1,073 additions / 2 deletions.
The one
.githubchange is the dead-code allowlist entry the ratchet itselfprescribes for a dormant module (same mechanism as
backend/utils/batch_pipeline/vendor_health.py). It is a data file, not aworkflow. C1a2 removes the entry when the first caller lands.
Base and head
720f078b33dde3872f5156fb87a961ffec2300c7(origin/mainat branchcreation; still the merge base).
d84481d96c321e0c4c62ea4cfc90662beb88fd5e(push 3/3).This is push 3/3 for #25047. Push 2/2 (
d9efc6ce) was the mechanical contentsplit that brought the dormant core under the cap. Push 3/3 is the C1 fix
batch for the three
28a41fapre-reviews. The live seal/notes/upload-failurecallers are still not in this PR; they remain in
evidence/c1a2-live-transition-hooks.patch(C1a2).C1 fix batch — finding by finding
The three pre-reviews were written against
28a41fa, which still carried thelive callers. The split moved those callers to the preserved C1a2 patch, so
the P1 caller findings are fixed there, not in this dormant core head. The
core findings are fixed in this head.
advance()acceptssource_ref/owner_ref; the ledger transaction reads both and refuses to create a row when the source is missing/deleted or the owner document is gone. Fail-open for the already-committed source transition. Emulator testtest_delayed_ledger_write_does_not_recreate_after_source_deletepauses beforeadvance(), deletes the source, and asserts no row.pipeline_ledger.source_revision()derives an ordered revision from the source snapshot'supdate_time; seal and notes pass it withreopen=True, so a proof repair can close afailed:upload_failedrecording and a stale failure hook loses. Emulator testtest_late_event_from_an_older_revision_is_refused.expires_atis a UTCdatetime(Firestore timestamp), not a numeric epoch.test_expires_at_is_a_utc_timestamp_not_an_epochasserts the serialized type.mark_record_upload_failedpersistsrecord_upload_failed_at; the seal hook passes it asend_at(falling back to the observation time), never last speech or the ledger-write time.notedpredicate acceptsreason in {'summary', 'accept_unknown'}while still excludingdiscardedandlocal_only.iter_window()/census_window()requireuidand queryusers/{uid}/pipeline_ledger; no cross-owner read. Emulator testtest_census_window_never_reads_another_owner.capture_id/conversation_idare no longer stored in the row body; the document path is the documented key. The census projects bounded fields only.LedgerWindowTruncatedwithout handing the caller a prefix.test_iter_window_yields_no_prefix_before_truncation.failed:<text>bypasses validationplan_advance()normalizes anyfailed:stage throughfailed_stage(), so only the closed failure vocabulary is stored; unknown text collapses tofailed:other.test_arbitrary_failed_reason_collapses_to_the_closed_enum.backend-emulator-proofs.ymlalone would not run the suite: the workflow invokesbackend/scripts/run-emulator-proofs.sh, which does not listtest_pipeline_ledger_firestore.py. The one-line trigger addition is therefore insufficient; the follow-up is to add the suite to that script (and then the trigger path). No workflow change is made in this PR.What C1a-core is
A storage-neutral ledger contract plus its declared inventory. It has no live
transition hooks: nothing in the product calls
advance(). It is dormantobservation/schema infrastructure, and this PR does not claim otherwise.
backend/database/pipeline_ledger.py(new, 462 lines): stage table with adeadline and exit per nonterminal stage;
plan_advance()pure transitionrules;
advance()in its own Firestore transaction that reads the documentbefore writing it (CAS);
iter_window()/census_window()bounded,owner-scoped read helper; content-free document shape; counters/gauges/histogram.
backend/utils/observability/reasons.py: closedPipelineLedgerOutcomeandPipelineLedgerFailureReasonenums and thePIPELINE_LEDGERreason family.backend/config/refactor_modes.py+config/feature-flags.yaml+backend/docs/feature-flag-registry.md:PIPELINE_LEDGERviadefault_on.backend/charts/monitoring/metric-inventory.prod.json: the seven declaredmetric names.
firestore.indexes.json+backend/database/firestore_index_registry.py:the
pipeline_ledger.admitted_atcollection-group index retained for thefuture global aggregate; the per-owner read helper uses the automatic
single-field index.
Stages:
capturing,sealed,transcribed,noted,done; terminalsno_speech,noise,failed:<reason>with a closed reason vocabulary.advance()is idempotent for the same stage+revision, refuses backwardtransitions, loses a stale revision, and re-opens a terminal only with an
explicit higher revision. Terminal rows carry
expires_atclamped to[26h, 7d](PIPELINE_LEDGER_TERMINAL_TTL_SECONDS, default 93600).What core proves
duplicate, stale revision, late-append and retry re-open, terminal finality,
max-16 history, bounded reason/end type, TTL clamp, schema fields and
content-free shape,
owner_keytruncated hash, closedfailed:vocabulary.advance()is fail-open on a store error, silent when the flag is off, andwrites the planned document with a read-before-write CAS in its own
transaction. A stale advance cannot overwrite a newer stage (emulator).
window, projects bounded fields, and fails closed with
LedgerWindowTruncatedbefore yielding a prefix.text).
What core does not prove
failure, admission, transcript landed, episode composed and the remaining
terminal exits are not wired. There is no production coverage claim; the
99.5% target is measured only after those transitions land.
contract is that a ledger write is a separate transaction after the real
commit, so it is not atomic with it; a crash between them loses that row and
the independent admission counter makes the loss visible. That statement is
inherited from the reviewed design and is not exercised here.
core, so there is nothing to export or erase. The export inventory and
recursive account wipe move to C1a2 with the first live write, so no window
exists where rows are written without erasure.
claimed as proven by this PR's tests.
Default, rollback, metric honesty
PIPELINE_LEDGERdefaults on, but with no call sites it writes nothing.The default is inert in this PR.
PIPELINE_LEDGER=offchanges nothing becausenothing calls
advance(). No data deletion is needed.is flat:
admit_totalis never incremented,rowsnever moves,stage_secondsnever observes, andwrite_total/write_failures_total/transition_total/unknown_end_type_totalonly move when a test callsadvance()directly. Do not read these as coverage.C1a2 allocation (preserved, not rewritten)
Moved to
evidence/c1a2-live-transition-hooks.patchin the run directory(
data/run-2026-11-08-pipeline-refactor/evidence/), withevidence/c1a2-handoff.md. The patch now applies to this head(
d84481d9) and carries the P1 caller fixes plus findings 4, 5 and 10.backend/database/record_audio.py(seal +failed:upload_failed, revision, firing clock, admission)backend/database/conversations.py(first-summarynoted, revision/reopen)backend/database/pipeline_ledger.py(end_type_for_trigger, source/owner fence,source_revision)backend/utils/observability/reasons.py(DELETEDoutcome)backend/services/users/data_export.py(portability)backend/database/user_data_deletion.py(wipe inventory)backend/docs/listen_pusher_pipeline/changes/2026-11-10-pipeline-in-flight-ledger.md.github/scripts/dead_code/backend.allowlist.jsonC1a2 also carries the moved tests: seal, summary persistence, durable outbox
transaction count, conversation transaction expiry, export inventory, the two
test_pipeline_ledger.pycases, and the emulator hook cases including thedeletion-interleaving and revision-ordering tests. C1a2 lands as a separately
reviewed PR after C1a-core merges, and it removes the
backend/database/pipeline_ledger.pydead-code allowlist entry.Tests (this head)
Run with the worktree venv and GCP credential env vars unset, through
bin/omi-heavy:tests/unit/test_pipeline_ledger.py(31 passed): table invariants,legal/illegal/duplicate/stale/terminal transitions, late-append and retry
re-open, max-16 history, bounded reason/end type, TTL datetime, closed
failed:vocabulary, schema/redaction, firing-clock separation, fail-open,disabled switch, owner-scoped read helper, truncation-before-prefix,
content-free metrics.
tests/integration/test_pipeline_ledger_firestore.py(4 passed, loopbackemulator): stale advance cannot overwrite a newer stage, disabled ledger
writes nothing, census window reads committed rows, census never reads
another owner.
test_firestore_field_indexes.py,test_reason_label_enums.py,test_config_refactor_w6.py,test_monitoring_telemetry_contract.py,test_flag_budget.py,test_firestore_outside_query_contract.py.test_data_export.py,test_data_export_streaming.py,test_users_export_streaming.py,test_batch_pipeline_privacy.py,test_delete_account_purge_storage.py,test_record_audio_seal.py,test_summary_persistence.py,test_audio_durable_outbox.py,test_conversation_persistence_transaction_expiry.py.temporary worktree at this head with the updated patch applied; the patch
applies cleanly to
d84481d9.authority).
Product invariants affected
Scope split
end-type mapping, portability export, recursive erasure, change note, and
the P1 caller fixes.
utils/batch_pipeline/live.py) and transcript landed(
database/batch_pipeline_projection.py), blocked by the fix(batch,sync): explicit backlog state machine with owners, deadlines and attempt budgets #24893 ownershipfence; episode composed; remaining terminal exits; true admission
denominator.
iter_window()/census_window().No admission live.py/projection fence, episode composition, Jev/E1, C2
endpoint, prod data/config, UI,
.githubworkflow, credentials, model names,deploy or merge in this PR.