Repository navigation
backend: make listen conversation lifecycle durable - #9700
Merged
Git-on-my-level merged 23 commits intoJul 14, 2026
Merged
Git-on-my-level merged 23 commits into
Git-on-my-level merged 23 commits into
Conversation
Member
Author
Monitor run summaryFixed 5 hermetic backend E2E test failures caused by the lifecycle guard introduced in this PR. Root cause: The lifecycle guard in
Fixes:
Verification: full hermetic e2e suite passes locally (104 passed, 3 skipped). CI: all checks green including Hermetic Backend E2E. |
Member
Author
|
@cursor address merge conflicts and do a review + fix round |
added 23 commits
July 15, 2026 01:47
Characterizes reconnect reuse of the existing finalization job before lifecycle refactoring. Verification: cd backend && .venv/bin/python -m pytest tests/unit/test_conversation_finalization_jobs.py tests/unit/test_workflow_contracts.py -q (31 passed); cd backend && .venv/bin/python scripts/check_workflow_contracts.py; cd backend && black --check --line-length 120 --skip-string-normalization tests/unit/test_conversation_finalization_jobs.py.
Adds the seeded BasedHardware#9687 reducer contract before routing runtime lifecycle callers through it. Verification: cd backend && .venv/bin/python -m pytest tests/unit/test_finalization_decision.py tests/unit/test_conversation_finalization_jobs.py tests/unit/test_workflow_contracts.py -q (38 passed); cd backend && .venv/bin/python scripts/check_workflow_contracts.py; black --check --line-length 120 --skip-string-normalization utils/conversations/finalization_decision.py tests/unit/test_finalization_decision.py.
Routes lifecycle creation, admission, transitions, finalization handoff, merge, import, and discard through one typed owner; deletes public writer seams and the temporary legacy counter. Verification: cd backend && bash test.sh (583 files passed); cd backend && .venv/bin/python -m pytest tests/unit/test_check_conversation_lifecycle_writes.py tests/unit/test_conversation_lifecycle_contract.py tests/unit/test_conversation_revision_contract.py tests/unit/test_listen_finalization_cloud_tasks.py -q (46 passed); scripts/check_conversation_lifecycle_writes.py; scripts/check_workflow_contracts.py.
Phase 3 of BasedHardware#9687: bind each listen recording to a durable canonical conversation and emit versioned monotonic lifecycle envelopes consumed by macOS. Verification: backend/test.sh (584 unit files); targeted lifecycle suite (59 passed); xcrun swift build/test StopReconciliationTests (40 passed); named omi-durable-recording-sessions bundle launched via automation bridge.
The lifecycle guard introduced by this PR inadvertently blocked:
1. Reprocessing already-completed conversations (persist_processed_conversation
only accepted status in {processing, merging}, fencing out reprocess)
2. E2E test fakes that called update_conversation with lifecycle fields
Production fix: add 'completed' to the expected_statuses set in
persist_processed_conversation so reprocess overwrites are not fenced.
Test fixes: update E2E fake process_conversation functions to respect
the lifecycle boundary — use update_conversation for non-lifecycle fields
and lifecycle_service.complete() for status transitions. Update
upsert_conversation call to renamed upsert_conversation_with_lifecycle.
Verification: full hermetic e2e suite passes (104 passed, 3 skipped).
Firestore server transactions can let empty cleanup terminalize a generation before a late segment or photo write acquires the parent lock. Replay that buffered batch once through a fresh recording generation instead of resurrecting the tombstoned conversation, and persist first-segment started_at atomically with content.\n\nVerification:\n- npm run test:listen-lifecycle:emulator\n- cd backend && .venv/bin/python -m pytest tests/unit/test_live_content_rollover.py tests/unit/test_listen_lifecycle_emulator_harness_wiring.py tests/unit/test_recording_sessions.py tests/unit/test_conversation_finalization_jobs.py tests/unit/test_conversation_lifecycle_contract.py -q\n- cd backend && bash scripts/typecheck.sh (0 errors)\n- make preflight (20 checks)\n- cd backend && ./test.sh (586 test files)
Git-on-my-level
force-pushed
the
codex/durable-listen-lifecycle
branch
from
July 14, 2026 19:02
65a578b to
99ca271
Compare
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.
Summary
Closes #9687
Closes #9516
Closes #9351
This is the one-PR landing requested by #9687. It deliberately supersedes #9516's earlier two-PR landing sequence while retaining the tests-before-refactor contract as strict commit order:
66f13d02f/a825ffbbdcharacterize current admission behavior and add the deterministic finalization-decision ordering fuzzer against unmodified production writes.513e25f04centralizes lifecycle mutation ownership and registers the lifecycle-write static guard in the deterministic checks manifest.2ea541143persists durable recording sessions and routes all session lifecycle operations through that service.d0347f2ad/c2529047f/8f42b84f0/0d8f8e9c9/8e8fbc7d0/8a18d57fe/166cd7d34/b82e6b568/6fbb8a5ad/3443cd43f/ffd55aa95/9040edec6/a435d3746/321f9161b/89e0855close the independent-review race, fanout, rollover, dual-write, envelope-isolation, static-guard, isolation-boundary, fenced-job, atomic fanout-admission, deleted-row, mismatch-envelope, create-vs-processor-write, fenced-completion-signal, legacy-admission-leak, post-fanout deletion-replay, discarded-reconnect, empty-session tombstone-reuse, post-persistence legacy fanout, late-content cleanup, photo-only finalization, and lifecycle-storage API boundary findings without weakening the three phases above.Failure-class closure
513e25f04creates the exclusive lifecycle service; the manifest-enforced AST guard rejects direct lifecycle writes, including generic DB and Firestore transaction forms.c2529047fhardens the checker with bypass regressions.6fbb8a5adseparates explicit idempotent initial creation from fail-closed processing-result persistence.89e0855exposes the storage primitives only as the lifecycle service’s guard-tracked boundary, so strict type checking rejects neither an intentional private escape nor a second owner.a825ffbbdsupplies the ordering fuzzer;c2529047fevaluates its reducer on the transaction snapshot and fences processing/terminal writes with CAS contracts.8e8fbc7d0preserves the transaction result through write preparation, and8a18d57femoves durable acceptance ahead of all derived writes.b82e6b568makes a missing row a fail-closed no-resurrection fence, including the initial finalizer read.3443cd43fpreserves terminalfencedthrough the pusher protocol so a listener retires the request without issuing a false completed envelope.a435d3746also reports a later core-persistence fence back to each legacy endpoint before it can trigger direct integrations.2ea541143introduces immutable(uid, recording_session_id)bindings and ordered envelopes;d0347f2adadds rollover generations, terminal immutability, delayed completion routing, and0d8f8e9c9keeps a dual-write legacy route from borrowing the canonical envelope.b82e6b568ensures that same legacy route keeps delivering processing/completed envelopes on a dual-write mapping conflict, while the canonical binding remains untouched.8e8fbc7d0immediately rolls a terminal reconnect before it can accept audio.ffd55aa95suppresses a discarded terminal reconnect rather than replaying it as completed.9040edec6tombstones an empty session before deleting its row, and any missing bound row forces a fresh recording generation instead of recreating the old conversation ID.d0347f2adpersists a fenced fanout state and stable idempotency key on the finalization job, so replay completes the same fanout boundary before job completion.8a18d57feadds an explicit, lease-fenced terminal no-fanout job disposition for a discarded or superseded processor.166cd7d34moves the conversation’s completed, non-discarded, job-id, and revision checks into the claim transaction itself; interleaving regressions cover both discard and newer-binding fences.3443cd43fgives the legacy finalization endpoint the same fail-closed admission branch, returning its durable winner before processor or integration side effects.ffd55aa95recognizes a durable fanout acknowledgement before fencing a deleted-row replay, allowing the worker to atomically finish without a duplicate delivery.a435d3746atomically tombstones/deletes only an empty parent while segment and photo writes share the parent transaction and sethas_content; a late writer wins the retry and routes durable finalization instead of losing content.321f9161badmits that durable marker so a photo-only conversation reaches its finalization job.Child closure criteria
fenced, except a previously acknowledged fanout is normally completed on deletion replay; neither case can duplicate integration, retry forever, dead-letter, or emit a false listener-completed transition. Both finalization endpoints return the durable winner before derived side effects, including when core persistence loses its later fence.Shipped #9516 ownership matrix
utils.conversations.lifecycleutils.conversations.lifecycle.admit_processingutils.conversations.lifecycleThe static guard scans production backend sources with a zero baseline and rejects both the lifecycle persistence primitives and generic/raw writes of lifecycle fields outside the exclusive owner. Its self-tests include pasted-back direct, anonymized Firestore, generic-API, and finalization-admission escape hatches.
Scope fence
#9355 (sync change feed) is explicitly excluded. It has a separate data/rollback plan and must land independently; this PR neither changes its feed protocol nor relies on it for lifecycle correctness.
Verification
cd backend && PYTHON=.venv/bin/python bash test-preflight.sh— 18 checks passed, 0 failed (the remaining optional integration-provider/service checks are warnings only).cd backend && ./test.sh— 584 backend unit-test files passed after the final review-fix commit.cd backend && .venv/bin/python -m pytest tests/unit/test_conversation_finalization_jobs.py tests/unit/test_listen_finalization_cloud_tasks.py tests/unit/utils/test_listen_pusher_session.py tests/unit/test_conversation_search_date_validation.py -q— 77 targeted finalization, protocol, and legacy-admission tests passed after3443cd43f.cd backend && .venv/bin/python -m pytest tests/unit/test_transcribe_decisions.py tests/unit/test_listen_finalization_cloud_tasks.py -q— 63 reconnect and finalization-replay tests passed afterffd55aa95.cd backend && .venv/bin/python -m pytest tests/unit/test_recording_sessions.py -q— 22 durable binding/tombstone tests passed after9040edec6, including empty-session deletion and reconnect rollover.cd backend && .venv/bin/python -m pytest tests/unit/test_conversation_finalization_jobs.py tests/unit/test_recording_sessions.py tests/unit/test_conversation_search_date_validation.py tests/unit/test_process_conversation_usage_context.py tests/unit/test_transcribe_conversation_cache.py -q— 92 targeted lifecycle and legacy-route tests passed after321f9161b, including photo-only finalization admission, persistence-fence fanout suppression, and late-content empty-cleanup races.cd backend && .venv/bin/python -m pytest tests/unit/test_conversation_lifecycle_contract.py tests/unit/test_process_conversation_usage_context.py tests/unit/test_developer_from_segments_idempotency.py tests/unit/test_listen_finalization_cloud_tasks.py tests/unit/test_recording_sessions.py -q— 91 lifecycle contracts passed, including deleted-row fencing, no derived work, terminal finalization, dual-write compatibility, and fresh/deferred creation.cd backend && bash scripts/typecheck.sh— 0 errors (existing strict-Pyright warnings only) after89e0855.make preflight— deterministic manifest checks passed (existing architecture warnings only).cd desktop/macos && xcrun swift build -c debug --package-path Desktop— passed.cd desktop/macos && xcrun swift test --package-path Desktop --filter StopReconciliationTests— 40 tests passed.omi-durable-recording-sessionsthrough./run.sh --yolo; the non-production automation bridge responded. The seeded named bundle was signed out, so no authenticated live listen session was available; durable lifecycle behavior is exercised by the backend contracts and fuzzer above.The finalization fuzzer runs four checked-in named edge corpus sequences plus 250 seeded randomized sequences (1–32 events each) on every test run. The default seed is
OMI_FUZZ_SEED=9687; failures preserve the seed through the environment variable for deterministic replay.Invariants
No product invariants affected (
scripts/pr-preflight --suggest).