Skip to content

feat(episodes): extend variant F to synced and late joins - #24828

Merged
Git-on-my-level merged 8 commits into
mainfrom
claude/project-thread-fb5dp4
Nov 7, 2026
Merged

Git-on-my-level merged 8 commits into
mainfrom
claude/project-thread-fb5dp4

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Requested by David · project thread

What changed and why

Variant F decided only live joins. Synced (WAL) conversations and late live batches joined the recorded-time owner by time alone, so F never saw them. Since streaming was retired on 11-04, most conversations arrive through sync intake, so at the 5% ramp F saw almost no decisions.

A sync or late conversation whose join to an admitted live owner is ambiguous (a 2 to 30 minute gap after the owner's last speech) now asks F with its full transcript before it is placed:

  • Moved on: the owner closes where the conversation begins (moved_on), and the conversation opens its own occasion. The split uses the same member guard as the live path.
  • Anything else keeps today's join: outside the cohort or killed (checked before any owner read), too little speech, a short gap, a conversation already placed, a member that attached meanwhile, or any error. Errors report through the shared episode_f_join fallback.

Two guards from review:

  • Privacy: every candidate and its predecessor pass the same predicate (f_join.may_feed_llm: locked, discarded, deleted, deferred, local-only or held conversations, another owner's conversation, any missing required field, and private cloud sync consent that is not an explicit true on the row). The candidate is checked on intake before any name lookup. The last reads before the Jev question are, in order: the candidate's stored document, then the user's current private cloud sync toggle (users/{uid}), which fails closed when the document or field is missing. A lock, deletion, discard or consent change in between keeps today's join.
  • Reads: the window query for F reads at most 2 conversations and keeps control placement when full. The candidate is named only over the spec's first 8,000 characters of speech and at most 2 voices, and the predecessor names at most 2 voices. A sync decision is capped at 24 document reads. Measured on this head: 12 on continue, none and timeout paths in the default configuration and 13 in the optimization-off and owner-reuse-off configurations (the non-close assertion is 13 pending lead2's ruling on the bound), and 21-24 on the close path. One Jev call across all placement retries.

Admission runs before the owner lookup, so users outside the cohort add no candidate query on sync attach.

The flag, thresholds and Jev lane are unchanged from #24730 (episode_f_join, MOVED_ON_THRESHOLD = 0.2).

Known gap: a late attach through _attach_once (not the synced intake) still skips F. Late live batches go to the sync intake, so they are covered. The late _attach_once path has no transcript, and no moments follow it, so there is nothing to ask about.

Line-Count-Exception: backend/utils/episodes/service.py | 2037 -> 2217 | F for synced and late joins; the F logic lives in utils/episodes/f_join.py

Product invariants affected

none

How it was verified

Repository BasedHardware/omi, branch claude/project-thread-fb5dp4 on origin/main (head f74c0d34b3: a5bed255b9, plus the row-level consent and ordering fix, plus the user-level consent read). Backend venv (Python 3.11), unit layer (hermetic, StrictFirestore fakes):

  • tests/unit/test_episode_f_join.py, test_episode_f_join_guards.py, test_episode_attach_cost.py, test_episode_attach_review.py, test_episode_live_integrity.py, test_episode_finalize_owed.py, test_late_audio_recorded_time.py, test_people_generation_inventory.py → 368 passed. test_episode_f_join.py alone → 107 passed.
  • The eight new regression tests (no consent, predecessor without consent, locked, deleted or consent-off during the predecessor reads) fail on a5bed255 and pass here.
  • The user-level consent tests (missing user document, missing field, off, and off while the predecessor is read) fail on the previous code and pass here.
  • The episode and inventory set (above, with the new tests): 372 passed.
  • Wide episode/sync set (44 files that import the episodes, timeline or sync-attach modules): 112 failures and errors, identical to the same run on untouched origin/main (test_sync_v2.py, test_sync_reprocess_coalesce.py, two wave2 tests fail on main too). No new failures.
  • scripts/backend-python-format --check on the three changed files: clean.
  • pyright utils/episodes/service.py utils/episodes/f_join.py: 0 errors. The warnings are pre-existing partially-unknown types outside the changed lines.
  • check_product_file_line_count_ratchet.py against origin/main: passes with the exception above.

Not run here: make preflight, the full backend unit CI, the emulator suites, and a live rollout. CI on this PR covers the first two.

Tests

  • Synced path: each excluded class (locked, discarded, deleted, deferred, processing-deferred, local-pending, client-processing, local-only, held, another owner, failed status, unknown protection level, private cloud sync off) never reaches Jev, and today's join stands (a discarded or deleted conversation is refused by placement itself, as before).
  • Consent: a candidate with the consent field missing or false is never named or asked, and a predecessor without consent is never sent to Jev.
  • Ordering: a candidate that becomes locked, deleted or consent-off during the predecessor and name reads never reaches Jev.
  • Live path: the same excluded classes never reach Jev at settle, and a candidate whose document is missing fails closed.
  • Reads: a 40-voice candidate names at most 8 voices and only its first 8,000 characters; candidate_head keeps the spec head and drops names beyond the limit.
  • Earlier: moved-on opens its own occasion; same-occasion stays one episode; killed, outside-cohort, short speech, short gap and later member each keep today's join; a failing decision keeps the join and reports the fallback; a split refused by the member guard keeps the join; an already placed conversation is never asked about again.
  • Existing cost and live-integrity guards still pass: unchanged attaches make no owner or candidate reads.

UI evidence

UI-Evidence: none -- backend only; no product UI changes.

Failure-Class: none

🤖 Generated with Claude Code

Variant F decided only live joins. Sync and offline (WAL) conversations,
and late live batches, joined the recorded-time owner without it, and
most conversations now arrive through sync intake.

A sync or late conversation whose join to a live owner is ambiguous (2 to
30 minutes after the owner's last speech) now asks F with its full
transcript before it is placed. A moved-on answer splits it into its own
occasion under the same member guard as the live path. Every other outcome
keeps today's join: outside the cohort, killed, too little speech, a short
gap, an already placed conversation, or any error.

Admission is checked before the owner lookup, so users outside the cohort
add no candidate read on sync attach.

Line-Count-Exception: backend/utils/episodes/service.py | 2037 -> 2111 | F for synced and late joins; the F logic lives in utils/episodes/f_join.py

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWxzjTgBhSMjSKfALVqL
@Git-on-my-level Git-on-my-level self-assigned this Nov 7, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 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-07T12:08:28.218083Z 7d9fe67 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.

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 3 files

Confidence score: 4/5

  • Retries in backend/utils/episodes/service.py still perform the recorded-episode read and boundary evaluation before the guard returns. Move the guard ahead of those checks to avoid the extra work.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/utils/episodes/service.py">

<violation number="1" location="backend/utils/episodes/service.py:1482">
P2: The already-placed guard runs after owner lookup and `f_join.uncertain`, so retries still pay the recorded-episode read and boundary evaluation before returning. Check conversation membership immediately after the admission and short-speech gates, before `episode_owning_recorded_time` and `uncertain`.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread backend/utils/episodes/service.py Outdated
marker = f_join.uncertain(uid, owner, conversation_id, source, started, firestore_client=c.firestore_client)
if marker is None:
return None
if episodes_db.get_episode_for_conversation(uid, conversation_id, firestore_client=c.firestore_client) is not None:

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: The already-placed guard runs after owner lookup and f_join.uncertain, so retries still pay the recorded-episode read and boundary evaluation before returning. Check conversation membership immediately after the admission and short-speech gates, before episode_owning_recorded_time and uncertain.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/episodes/service.py, line 1482:

<comment>The already-placed guard runs after owner lookup and `f_join.uncertain`, so retries still pay the recorded-episode read and boundary evaluation before returning. Check conversation membership immediately after the admission and short-speech gates, before `episode_owning_recorded_time` and `uncertain`.</comment>

<file context>
@@ -1453,6 +1453,73 @@ def _rejoin_closed_synced(
+    marker = f_join.uncertain(uid, owner, conversation_id, source, started, firestore_client=c.firestore_client)
+    if marker is None:
+        return None
+    if episodes_db.get_episode_for_conversation(uid, conversation_id, firestore_client=c.firestore_client) is not None:
+        # Already placed (a retry or a changed re-attach): F answers only a first placement, and nothing moves.
+        # Checked after the cheap gates, so only an admitted, ambiguous join pays this read.
</file context>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed in this PR. Moving the already-placed check before the owner read broke test_episode_attach_cost, which counts reads. The guard only runs on lost-CAS retries, and the extra read is paid only by an admitted, ambiguous join. Leaving this thread open for a reviewer to decide.


Generated by Claude Code

Comment thread backend/utils/episodes/service.py Resolved
…und its reads

F sent a synced candidate's speech to Jev without the conversation
privacy gate that already guarded its predecessor, so a locked, deferred,
local-only, held or another owner's candidate could reach the model. The
candidate is now checked before any name lookup or model call, and it
fails closed when its document is missing.

The candidate's voices were looked up for its whole transcript, one per
voice. Naming now covers only the spec's first 8,000 characters of speech
and at most 8 voices, the same bounds the predecessor already has.

Failure-Class: none

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWxzjTgBhSMjSKfALVqL

@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: 83ef1d7aa0

ℹ️ 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 thread backend/utils/episodes/service.py Resolved
Comment thread backend/utils/episodes/service.py Resolved
Comment thread backend/utils/episodes/service.py Resolved
…le inventory

The privacy gate renamed the call in f_join.previous_transcript, a
People-reader body pinned in backend/docs/people-generation-writers.json.
The pin changed without any change to what is checked, which failed
test_current_people_scopes_match_the_reviewed_writer_enumeration.

The public gate is unchanged. The private name stays as an alias, so the
pinned body is byte-identical to main.

Failure-Class: none

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWxzjTgBhSMjSKfALVqL
sync_attach re-runs an attach after a lost CAS, and each run asked Jev
for the variant F verdict again, up to three questions per conversation.
One sync attach now shares its answer across attempts: a retry places the
conversation the way the first answer decided, and the owner closes at
most once. Adds tests that a retried attach asks Jev once and keeps the
same placement for both a moved-on and a same-occasion answer.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWxzjTgBhSMjSKfALVqL
Git-on-my-level added a commit that referenced this pull request Nov 7, 2026
…ore Features pins (#24848)

<!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} -->
_Requested by **David**_

## What changed and why

Restores main to green. `test_committed_inventory_is_current` in
`backend/tests/unit/test_monitoring_gmp_shadow.py` failed on main at
a767a4b, because the Core Features dashboard changed in #24833
without the committed migration inventory being regenerated. That also
blocks shard 5/8 on #24828.

This PR regenerates
`backend/charts/monitoring/gmp-query-migration-inventory.json` with the
repo's own command, `python3 backend/scripts/monitoring_gmp_shadow.py
--inventory`. The diff is limited to the `job="..."` pins on the Core
Features journey panels, which is what #24833 changed.

## Product invariants affected

None. The inventory is a generated, read-only record.

## How it was verified

- `backend/tests/unit/test_monitoring_gmp_shadow.py`: 35 passed, in the
task worktree's backend venv.
- The regeneration command above is read-only and makes no datasource or
rule change.

## Tests

`test_committed_inventory_is_current` passes.

## UI evidence

Not applicable.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/24848?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/24848?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24848&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. -->
claude and others added 4 commits November 7, 2026 15:53
…join on close failures

Codex review on the synced F path found four issues on the head:

- The candidate's privacy gate used the intake snapshot. A conversation
  locked, discarded or deleted after intake scheduled the attach could
  still reach Jev. The candidate is now read from the stored document
  right before the model call, and it fails closed when that document is
  missing.
- The owner was chosen over the whole candidate span, so a closed episode
  overlapping the span could hide an ambiguous join from F. The owner is
  now the episode attachment itself would choose: the candidate's start
  point, over the same window.
- An unexpected error while closing the owner escaped the fallback. It now
  reports synced_failed and keeps today's join, as every F failure does.
- AGENTS.md requires a change note for conversation-lifecycle changes;
  backend/docs/listen_pusher_pipeline/changes/2026-11-07-f-synced-joins.md
  records the split behaviour, the flags and the verification.

Tests: a locked-after-intake candidate never reaches Jev, and a failed
close keeps the join. Both fail on the previous service code.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWxzjTgBhSMjSKfALVqL
Apply the existing processing admission predicate to the incoming transcript.
Bound F-only names, timeline windows, ownership lookups and the close, and skip
F after the first sync placement attempt. Exercise exclusions and aggregate
read/call budgets through the close and retry loop.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d before Jev

Luna's delta review of a5bed25 found two gaps in the synced F path.

- may_feed_llm did not check private_cloud_sync_enabled, so a candidate or
  predecessor whose user had not opted in could reach Jev. The gate now
  requires an explicit True on the row and fails closed otherwise, the same
  opt-in rule as the batch attach gate.
- The candidate's stored privacy was read before the predecessor and name
  reads, so a lock, deletion, discard or consent change during those reads
  still reached Jev. settle now reads the predecessor and names first and
  re-reads the candidate as the last step before the question.

The candidate query was already capped at 2 documents. Measured reads on
a5bed25 are 10-11 on continue, none and timeout paths and 19-22 on the
close path, with the 24-read budget test unchanged. Eight regression tests
fail on a5bed25 and pass here.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWxzjTgBhSMjSKfALVqL
…efore Jev

The synced F path checked only the row-level private_cloud_sync_enabled
snapshot. A user who turned the toggle off after the row was written, or
whose user document has no value, still reached Jev. The user-level toggle
is now read as the last read before the question. A missing user document
or field is not permission.

The read adds one document read. Measured on this head: 12 non-close reads
in the default configuration and 13 in the optimization-off and owner-reuse-off
configurations; 21-24 on the close path. The non-close assertion is 13 until
lead2 rules on the bound.

Adds tests: a missing user document, a missing field, and an off toggle each
keep today's join without a question, and a toggle turned off while the
predecessor is read is never asked about. The new consent tests fail on the
previous code. The strict fixture allows the one-field consent read.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWxzjTgBhSMjSKfALVqL
@Git-on-my-level
Git-on-my-level merged commit bb49c94 into main Nov 7, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the claude/project-thread-fb5dp4 branch November 7, 2026 15:00
Git-on-my-level added a commit that referenced this pull request Nov 9, 2026
<!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} -->
_Requested by **David**_

## What changed and why

Synced episode F retries ran the recorded-episode read and boundary
evaluation before the guard returned
(`backend/utils/episodes/service.py`). The guard now runs first, so a
retry that should be skipped does no recorded reads. This is the
follow-up to Cubic's P2 review on #24828, which was never opened.
Source: dropped-work triage item K4.

Pre-push file budget was raised to 3600s
(`BACKEND_UNIT_FILE_BUDGET_SECONDS`) because host load was around 70;
every test still runs and must pass.

**Follow-up (4da90f9, lead2 ruling on the Luna Minor race).**
Moving the guard earlier widened a race. A concurrent attach could place
the candidate after the owner snapshot and before `f_join.uncertain`,
and nothing re-checked ownership before the Jev call. The early
placed-retry guard stays. The candidate's placement is now re-checked
before settlement and again immediately before `ask_same_occasion_f`,
and the existing post-call check is kept. The documented read budget
rises from 24 to 26 including close (13 to 15 without close). This
narrows the window; it is not a cross-request at-most-once guarantee.

## Product invariants affected

none

## How it was verified

- `backend/.venv/bin/python -m pytest tests/unit/test_episode*.py
tests/unit/test_episodes_*.py tests/unit/test_episode_f_join.py -q` via
`bin/omi-heavy`: 1000 passed, 381s, rc=0.
- `backend/.venv/bin/python -m pytest
tests/unit/test_firestore_query_shapes.py -q` alone: 557 passed (470s).
The pre-push run exceeded the 900s file budget under load; the budget
was raised for this push.

- 4da90f9: 33 episode test files, 896 passed;
`test_episode_f_join.py` rerun, 118 passed. Both run through
`bin/omi-heavy`. Pyright: 0 new errors.

## Tests

Regression tests in `tests/unit/test_episode_f_join.py`: the
already-placed retry does no recorded reads, and a deterministic
concurrent attach committed after the owner snapshot and before
`uncertain` yields no settlement and no Jev call.

## UI evidence

UI-Evidence: none -- backend change only

## Failure class (fixes)

Failure-Class: none

Line-Count-Exception: backend/utils/episodes/service.py | 2217 -> 2222 |
the five lines are the ownership re-check before settlement that closes
the race lead2 ruled FIX-FIRST; splitting service.py is out of scope for
this follow-up

Rollback: `git revert` of the commit.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/24892?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/24892?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24892&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. -->
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.

2 participants