Repository navigation
fix: retain recovered episode speech and reject unsafe scope bindings - #23828
Conversation
Reject mixed unnamed-speaker scopes at the v5 projection binding seam. Apply recovered WAL member speech with transactional content receipts and recheck unapplied member transcripts before closing an episode. Retry attachment conflicts with fresh reads and queue saturated episode hooks for admission when executor capacity returns. Failure-Class: FC-once-only-trigger-dropped-at-capacity
Keep stored segment IDs in recovery prompts and use private slice keys for consumption. Receipt an unplaced source ID only after its last slice lands, so provider failure cannot consume unseen speech and normal finalization does not replay an already recovered unplaced segment. Exercise served and legacy notes rendering, retained speaker evidence IDs, ordinary finalize replay, and provider failure between recovery batches. Failure-Class: FC-once-only-trigger-dropped-at-capacity
Codex Review SummaryThis 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: 0b0e740ae3
ℹ️ 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".
| for moment in recovery.moments(conversation_id, row, now=_now(c), calendar_identity=_calendar_identity(row)): | ||
| outcome = record_moment(uid, moment, c, member_episode_id=episode_id) |
There was a problem hiding this comment.
Release the episode worker between recovery batches
For a long recovered WAL transcript, this loop performs every batch's synchronous notes-model call while retaining the same executor slot. The intake/finalization hooks submit this entire operation to lifecycle_executor(uid, episode=True), which has only two workers in serving mode, and each model call permits a 20-second timeout. Two large recoveries can therefore monopolize the shared episode pool for minutes, delaying unrelated users' live notes and finalization hooks and eventually blocking sync producers when the deferred queue fills. Coordinate recovery asynchronously and borrow a worker per bounded step rather than holding one throughout the transcript; backend/AGENTS.md explicitly requires async coordination for long-running pipelines and prohibits holding a pool slot for more than 60 seconds.
AGENTS.md reference: backend/AGENTS.md:L270-L274
Useful? React with 👍 / 👎.
| if episode is None: | ||
| return outcome | ||
| episode = episodes_db.get_episode_for_conversation(uid, conversation_id, firestore_client=c.firestore_client) |
There was a problem hiding this comment.
Reconcile recovered items after a finalize-time attachment
When a WAL conversation first joins an episode during on_conversation_finalized rather than at intake, episode still contains the pre-attachment lookup result (None). _attach_synced now generates notes and provisional items, but this early return skips _reconcile for those newly created items even though the conversation's normal processing has already saved its tasks. Without another WAL append or repeated finalization, the items remain provisional instead of receiving their saved-task links, and a subsequent episode close drops them. Reload the newly attached owner and continue through reconciliation whenever attachment succeeds.
Useful? React with 👍 / 👎.
| 'recovered_conversation_ids': list( | ||
| dict.fromkeys( | ||
| survivor_id if cid == donor_id else cid for cid in episode.get('recovered_conversation_ids') or [] | ||
| ) |
There was a problem hiding this comment.
Preserve recovery receipts when repointing a merged donor
When an already-recovered WAL member is merged into a survivor, this moves its recovery tracking to the survivor but leaves its consumption receipts under the donor's conversation ID. Sync assignment preserves retained donor segment IDs and text, yet the subsequent _attach_synced recovery reads receipts only for the survivor, so it sends the already-consumed donor speech through the notes model again and charges for every batch again. Repeated intake of that survivor is then idempotent, but each donor merge defeats the new receipt guarantee. Transfer the donor's recovery receipts or include its lineage receipts when checking consumption before recovering the survivor.
Useful? React with 👍 / 👎.
Use the fail-closed binding helper for canonical from-segments input too. Record content-revision receipts for complete live prompts and reuse them for WAL recovery, retaining legacy unplaced receipts and novel earlier gaps. Transfer receipt namespaces with donor membership and retry donor CAS conflicts through the same fresh three-attempt attachment owner. Absorb finalization reads current survivor speech instead of replaying the donor. Record the bounded queue's existing episode-overlay lifetime in the owning background-task inventory and cover it in the local gate set. Failure-Class: FC-once-only-trigger-dropped-at-capacity
Recognize both retry admission APIs in the background-task lifetime ratchet, follow completion ownership through typing casts, and require the episode caller to document its bounded derived-overlay lifetime separately from the executor implementation. Add fail-before scanner coverage for orphaned and returned handles.
|
Addressed the round-one review findings in the correction commit on this PR:
All four review regressions fail at reviewed head The ratchet additionally recognizes both new retry APIs and inventories The lead authorized one delta-only Luna round in ruling 2664ef. CI and that review must pass at final head |
Include absorbed sync callbacks in the existing attachment retry owner, adopt legacy unplaced donor receipts before membership moves, and split large receipt transfers into bounded archives. Add fail-before/pass-after cases for two conflicting absorbed callbacks, legacy proof and 50,000 content receipts.
|
Round-two correction delta for the lead's review. Luna r2 returned FIX-FIRST at
All three regressions fail at Correction commit: |
|
MERGE READY at
Lead owns merge and the backend/listen/pusher release train. No merge, deploy, flag flip, production call, customer-data mutation or GCP tier was used by this lane. Production acceptance remains a release-train responsibility. |
What changed and why
Fix three P1 episode/projection failures identified in #23404 and #23418. Client projection binding now rejects mixed scopes among unnamed voices while preserving hash encoding v5. WAL attachment and sync finalization merge recovered member speech into running notes with transactional content receipts; close rechecks recovered member transcripts for unapplied speech. Attachment retries version conflicts three times with jitter and fresh reads, and saturated episode hooks retain bounded deferred admission until capacity returns.
Recovered text uses bounded batches so prompt truncation cannot acknowledge unseen words. Complete live prompt input and recovery share content-revision receipts, so WAL appended to the same canonical conversation skips proven live speech and preserves novel gaps. Donor repointing transfers receipt namespaces with the membership CAS inside the retry owner; absorb finalization reads the survivor's current transcript. Canonical ingest binding uses the same scope guard as persisted binding. Existing EPISODES and LIFECYCLE flags and defaults are preserved.
Failure-Class: FC-once-only-trigger-dropped-at-capacity
The admission regression is a once-only trigger lost at capacity. Companion tests cover missing scope in v5 binding and recovered speech incorrectly treated as already consumed.
Product invariants affected
INV-TASK-2: episode updates retain provisional items and never write action items, Candidates, or memories. Customer identity and serving-plane authorities are preserved (INV-DATA-1).
How it was verified
BACKEND_UNIT_TEST_FILE_LIST=/Volumes/Ephemeral/scratch/p88fix/regressions.txt BACKEND_PYTEST_WORKERS=1 bin/omi-heavy run -- nice -n 19 bash backend/test.sh(workspacebin/omi-heavy): all 16 targeted files passed again after the round-two corrections, including 78 episode-service cases, ingest trust/idempotency and the background-task inventory ratchet.5f2caea10a6fail on mixed-scope binding, lost recovered notes/close rebuild, two CAS conflicts, and saturated final hooks. The candidate passes those regressions.bin/omi-heavy run -- nice -n 19 make preflight: all 35 repository checks passed (389 seconds), including Firestore guards, runtime source closure, async blocking, import purity, metadata, and file-size gates.bin/omi-heavy run -- nice -n 19 bash backend/scripts/typecheck.sh: canonical full backend type check, zero errors.bin/omi-heavy run -- nice -n 19 bash backend/testing/sync_cloud_tasks_stack/run.sh --only sync --state-dir /Volumes/Ephemeral/scratch/p88fix/sync-stack: hermetic Sync Cloud Tasks gauntlet passed with real local Firestore/Redis and separate admission/worker processes; sanitized evidence retained.2fedac, no third review runs: acceptance is corrected-head CI plus the regression mapping for the lead's delta review. Terminal CI and that mapping will be attached before handoff.These are source, hermetic unit, and local harness claims. Product deployment and production acceptance belong to the lead's release train.
Tests
test_transcript_hash.py: dict/model scope-only attribution correction, legacy unscoped mix, bound owner/person compatibility, v5 unchanged.test_client_processing_finalize.py: router and transactional binding reject the stale digest while finalization fields survive.test_episodes_service.py: recovered speech at attach, idempotent replay, existing member gap behind an applied offset, close after a provider failure, three fresh CAS attempts retaining concurrent members, full long-transcript prompt coverage in served/legacy modes, preserved speaker-evidence IDs, and ordinary-finalize/unplaced-slice failure receipts.test_episodes_finalize_paths.pyandtest_executors.py: saturated final/intake hooks run without another append, context survives, errors surface, cancelled and shutdown work stays bounded.0b0e740ae3cand pass after correction: canonical ingest scope guard, same-row live/WAL consumption, donor receipt transfer, and fresh donor CAS attempts. The merged-survivor finalization test also proves only novel survivor speech reaches the model.test_background_task_ratchet.py: both retry APIs remain subject to caller inventory; returned cast-wrapped futures transfer ownership while done callbacks alone remain detached. The new regression fails before correction; all six scanner cases pass afterward.90f2eff0f13and pass after correction: absorbed callback survives two fresh CAS conflicts, legacy-only donor receipts prevent replay, and transferring 50,000 content receipts bounds every archive to 2,000 IDs while retaining order and all proof.Risks and rollout
Recovery can add notes-model calls for retained WAL snapshots whose prior live consumption cannot be proved. Older placed cursor-only state cannot distinguish an old line from a new gap behind that cursor, so its first recovery conservatively merges the retained snapshot once. Legacy unplaced-ID receipts remain proof; new live content receipts prevent replay. Updates merge into the existing compact state. The deferred queue is process-local like the ordinary executor queue, capped at 64 pending submissions with synchronous producer backpressure when full; shutdown cancels it. Its documented background-task inventory entry retains the existing best-effort episode-overlay lifetime over durable source conversations. No new queue infrastructure or migration is required.
Lead-owned backend/listen/pusher release train required after merge. No production access or mutation was used in this lane.