Skip to content

fix(conversations-v3): commit live-appended sources and deliver created webhooks for derived rows - #25661

Merged
Git-on-my-level merged 7 commits into
mainfrom
lane/v3-beta-harden
Nov 18, 2026
Merged

Git-on-my-level merged 7 commits into
mainfrom
lane/v3-beta-harden

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

Hardens conversations v3 for the live TestFlight (CONVERSATIONS_V3_STAGE=beta) cohort. Two fixes.

1. Live capture no longer starves the owner's projection

Since listen runs v3 (2026-11-18 ~05:35Z), about half of backend-sync /v1/conversations-v3/reconcile calls returned HTTP 500 with Conflict('source_changed'), and an owner who is actively recording got zero derived rows. The commit fence (database/conversations_v3.py commit_projection) compared every loaded source recording's exact update_time. A live recording appends speech every few seconds, so every pass failed, each 500 spent a Cloud Tasks attempt (10 max) and a slot on the 8-slot queue, and the continuation enqueue after the commit never ran.

  • The loader records a source fence for each recording (deleted, deleted_spans, sync_merged_into, data_protection_level, is_locked, started_at, claims, recording, v3_derived). In the commit transaction, a recording whose revision moved while those fields stayed the same counts as "received more speech": appended segments, audio files, finished_at/status, pending or manual-end markers. The pass then:
    • commits the windows it planned from its snapshot;
    • merges claims onto the re-read document. It writes only claims, v3_pending=True and v3_pending_since, so no concurrent field is clobbered;
    • leaves v3_pending owed for the new speech and skips the audio-purge decision.
  • commit_projection returns the moved IDs. reconcile counts omi_conversations_v3_races_total{reason="source_moved"} and enqueues a follow-up wake at the next minute through the existing named task (one name per owner per minute, coalesced, never the executing task's name). It does not re-pass immediately, which would race the same live recording again.
  • The strict fence still applies to derived rows, to deleted, merged or locked sources, to a privacy-level change, to claims changed by another writer, and to any source loaded without a fence. The mid-batch readback in multi-batch commits uses the same rule.
  • Remaining source_changed / lease_lost races on the live builder now return outcome raced (HTTP 200), count RECONCILES{outcome="raced"} and RACES{reason}, and enqueue the same next-minute wake. If the wake cannot be scheduled, the original Conflict is still raised, so Cloud Tasks retries as before. Backfill (derive) still raises. BLOCKED handling is unchanged.

2. Conversation-created webhooks are delivered for v3-derived conversations

Source finalization (recording=True) suppresses the legacy fanout in routers/conversations.py and utils/conversations/finalizer.py, and the derived worker never called it. Zapier, Notion CRM, Dropbox, pCloud and other conversation-created integrations therefore received nothing for v3 captures.

  • Arm: settle_processing(..., notes=True) (the full notes path in _process and run_external for Retry/reprocess) sets v3_notes_written. In the same transaction it arms v3_created_pending when the row qualifies: it is v3_derived, visible, status == completed, and none of these: recording, deleted, discarded, locked, backfilled (silent backfill), terminal_no_derived_effects (free-tier minimum, same suppression as legacy), failed, or already delivered. Short, media and background windows never write notes, so they never arm. A hidden row with notes that becomes visible on a rebuild without a re-note arms in the reconcile plan.
  • Deliver: at the end of drain_processing, utils/conversations/v3/created.py drains the owner's markers (per-owner query, limit 8). Each claim is a transaction with a 5-minute lease and an attempt fence, and it drops the obligation if the row stopped qualifying. The row is re-read and passed to the existing trigger_external_integrations with X-Omi-Idempotency-Key: v3-created:<id>, require_delivery=True, and last_delivery_attempt after 5 attempts. That function already applies the user's enabled apps, account deletion, lock and discard rules, webhook health, the SSRF guard and redaction. On failure the claim is released and the owner is woken in 5 minutes. On success v3_created_delivered_at is set.
  • Exactly once: planner.build spreads the prior row and processing persists with merge writes, so the markers survive rebuilds, adoption, re-notes and late rewrites, none of which deliver again. A replay after a lost acknowledgement reuses the stable idempotency key, as the legacy durable finalizer does. run_external wakes the owner after an armed settle, so a successful explicit Retry delivers.

Scoping note

I considered keeping the strict fence and relying only on the reschedule. The coordinator's 05:58Z evidence (an active recorder had 0 derived rows) showed that a reschedule alone keeps losing to a source that appends continuously. This PR therefore relaxes the fence for speech-only moves and keeps it strict everywhere else.

Tests

New and updated hermetic unit tests use the strict Firestore fixture.

  • tests/unit/test_conversations_v3_live_capture.py:
    • Speech appended during a pass: the derived in-progress row is committed, the recording stays v3_pending, the writer's transcript and manual-end marker are preserved, and claims are merged.
    • An unmoved source still settles.
    • Every non-speech source change, a changed derived row, and a fence-less source still conflict.
    • A manual end during a pass gives an in-progress row, then a processing row (v3_process_pending, manual_end) on the single follow-up wake.
  • tests/unit/test_conversations_v3_commit_conflicts.py:
    • source_changed and lease_lost return raced with one next-minute wake and metrics.
    • A failed wake still raises.
    • A backfill race still raises.
  • tests/unit/test_conversations_v3_created_delivery.py:
    • Arming rules for each suppression.
    • The short path owes nothing.
    • Exactly once across re-drains and re-notes.
    • A failure stays owed and wakes later with the same key.
    • The final attempt drops.
    • A row that becomes ineligible drops its obligation.
    • The claim lease and attempt fence hold.
    • Attempts are bounded.
    • A hidden row becomes visible: owed only with notes and when not yet delivered.
    • An explicit-Retry settle wakes the owner.
  • tests/support/firestore_conversations_v3_drivers.py registers the new pending_created query driver.

Local runs (backend/.venv, each file in its own process): all test_conversations_v3_* suites, test_record_close_v3_contract, test_lifecycle_state_table_writers, test_batch_census_registry, test_firestore_query_shapes, test_firestore_query_contract, test_firestore_index_* and test_reconcile_firestore_indexes pass. scan_async_blockers, check_module_stub_pollution and scan_import_time_side_effects are clean. Not exercised against a live service or the emulator.

Review follow-ups (omi-panel review-20261118t062408-80cf)

  • Payload eligibility recheck. Eligibility is checked again on the payload actually sent. A row that became private, hidden, locked or deleted after its claim is dropped and never fanned out.
  • Unreadable payload. A payload that reads back empty stays owed and is retried; it is not counted as delivered.
  • Wake failure. A delivery retry or continuation wake that cannot be scheduled fails the task, so Cloud Tasks retries it. No sweep owns this marker.
  • Fallback telemetry. The Retry and on-open wake-deferred branches now call record_fallback.
  • Drain test. A test pins the drain-to-delivery wiring.
  • Declined: per-owner race backoff (F5). With the speech-append fence fix, races are rare and transient, and a race never clears the obligation. They are capped at one coalesced wake per owner per minute, the same cadence as the live continuation, and RACES{reason} is metered.

CI note

main #25610 added an unpatched conversation_tombstones.is_deleted call at the top of delete_conversation. This branch's selection runs test_delete_conversation_cancels_task_reminders.py, which then reached a real Firestore client under CI's placeholder credentials. That helper now stubs is_deleted.

Rollout and risk

Both changes are on by default and need no new flag; CONVERSATIONS_V3 / stage remain the kill switch for new intake.

The fence relaxation is limited to source recordings whose protected fields are unchanged. Derived rows keep the strict revision check.

After the deploy, check:

  • reconcile 5xx below 1%;
  • RECONCILES{outcome=committed} above 0 for owners who are recording;
  • RACES{reason} and CREATED_DELIVERIES{outcome} series appear;
  • an owner's live capture produces a live tile, and a processing row after a double-tap.

Product invariants affected

none

Failure-Class: FC-content-write-omits-implied-obligation

🤖 Generated with Claude Code

Git-on-my-level and others added 3 commits November 18, 2026 13:09
…ed webhooks for derived rows

Live capture: the projection commit fenced every loaded source recording on its
exact update_time, so an owner who was still recording failed every reconcile
pass with source_changed (HTTP 500, a burned Cloud Tasks attempt) and got no
live tile or derived conversation while wearing the device. A source that only
received more speech (fence fields unchanged: deletion, merge, privacy, lock,
claims, identity) now commits the windows planned from the snapshot, merges its
claims onto the re-read document, stays v3_pending and wakes the owner at the
next minute. Derived rows and any other source change keep the strict fence.
Remaining source_changed/lease_lost races answer the task with outcome 'raced'
and a coalesced next-minute wake instead of raising (raise only if the wake
cannot be scheduled).

Webhooks: source finalization suppresses the legacy conversation-created
fanout and the derived worker never called it. A notes settle on a visible,
completed, unsuppressed derived row (or a hidden row with notes that becomes
visible) arms a durable v3_created_pending marker; the builder drain delivers
it once through trigger_external_integrations with a stable idempotency key,
require_delivery and a bounded attempt budget.

Failure-Class: FC-content-write-omits-implied-obligation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rain pages, keep private rows out

Scope-panel follow-ups: the on-open summary write arms the same single
conversation-created obligation; a saturated delivery page schedules a
continuation wake; private-level rows never arm; the final delivery attempt is
counted apart from a clean delivery; the eligibility predicate lives in the pure
v3 policy module.

Failure-Class: FC-content-write-omits-implied-obligation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eader

Failure-Class: FC-content-write-omits-implied-obligation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-18T06:24:02.563358Z
We couldn’t complete this review. Comment @codex review to try again.
6bcc7f6 PR opened
ℹ️ 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Git-on-my-level and others added 4 commits November 18, 2026 13:34
… the drain

process_conversation imports the v3 service at import time; a top-level import
of the webhook fanout pulled app_integrations and its LLM graph into that graph
and broke test_selfheal_recovery's stubbed import (CI shard 3/8).

Failure-Class: FC-content-write-omits-implied-obligation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…elete-reminders suite

#25610 made delete_conversation read conversation_tombstones.is_deleted first;
this suite never patched it, so it reached a real Firestore client and failed
in CI (no ADC) once selected.

Failure-Class: FC-content-write-omits-implied-obligation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nt payload

Panel review follow-ups: drop a claimed row that turned private/hidden/locked
before fanout, keep an unreadable payload owed instead of counting it delivered,
fail the task when a delivery wake cannot be scheduled, record fallback telemetry
on deferred Retry/on-open wakes, and pin the drain-to-delivery wiring.

Failure-Class: FC-content-write-omits-implied-obligation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 70f8681 into main Nov 18, 2026
75 of 77 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/v3-beta-harden branch November 18, 2026 07:23
Git-on-my-level added a commit that referenced this pull request Nov 21, 2026
…ersations-v3 first (SCA-2967) (#25713)

## What changed and why

SCA-2967. Activating conversations-v3 for TestFlight on 2026-11-17
needed several services to move in a fixed order: backend Cloud Run,
then llm-gateway, then pusher, then listen. Nothing encoded that order,
and each gap was found in prod or by luck:
- llm-gateway was two weeks stale and had no v3 lanes;
- pusher lacked the `SYNC_TASKS_PROJECT`/`SYNC_TASKS_LOCATION` that
listen sets;
- pusher's image was 8 days old (version skew);
- the `conversations-v3` queue and the v3 scheduler jobs did not exist.

KB evidence: `evidence/2026-11-17-v3-testflight-activation-escapes.md`
(#7, #8) and `2026-11-17-delivery-debt-from-v3-rollout.md` (D1, D8).

This PR adds a feature activation manifest (data) and a read-only tool
that checks it against live serving state. The first manifest is
conversations-v3. **The tool is not wired into any gate.**

- `backend/deploy/activation/conversations-v3.yaml` lists:
- the services and the commits each must contain (ancestry, not an exact
SHA);
  - the order they must move in;
- env keys that must be set, and equal across runtimes where that
matters;
  - gateway lanes, the queue and the scheduler jobs.

Each entry has a `why` that points at the code or incident behind it.
The format is in `backend/deploy/activation/README.md`.
- `backend/scripts/activation_check.py` is pure: manifest + state JSON
in, verdict out. Each requirement is `satisfied`, `missing`, `unknown`
or `deferred`.
- Exit codes: `0` READY; `1` BLOCKED (a controlled requirement is
missing); `2` UNKNOWN (nothing missing, but a controlled requirement
could not be read); `3` invalid input.
  - `unknown` never counts as satisfied.
- Some requirements are owned elsewhere: anything marked `controlled:
false` (the backfill queue), and anything listed under `not_checked`
(Firestore indexes, owned by the index readiness gate). They are always
reported, and the report says who owns them, but they never change the
exit code.
- `--before <service>` checks only the requirements due before that
service moves.
  - The verdict prints the state's `collected_at`.
- `backend/scripts/activation_collect.py` reads prod metadata only:
- Cloud Run: only the revisions receiving traffic, from
`status.traffic`, never the spec.
- GKE: the Deployment template env, with ConfigMaps resolved, and the
image digests of running pods.
  - Cloud Tasks queues and Scheduler jobs: one `list` call per location.

Serving identity comes from the image: its OCI
`org.opencontainers.image.revision` label, else its commit tag. The prod
pusher digest is looked up in the dev registry it was promoted from.
`OMI_BACKEND_RELEASE_SHA` is only recorded, as `release_env`: env merges
never remove a value, so it can name a release the revision does not
serve.

The collector never reads Secrets and records only the env keys the
manifest names. The checker's report prints key and runtime names, never
values.

### v3 requirements

| Kind | Requirement |
| --- | --- |
| Order | 1. `backend`, `backend-sync`, `backend-sync-backfill`,
`backend-integration`, `desktop-backend` → 2. `llm-gateway` → 3.
`pusher` → 4. `backend-listen` → lever (`CONVERSATIONS_V3_STAGE` /
`CONVERSATIONS_V3`) |
| Contains | Writers (`backend`, `backend-integration`,
`backend-listen`): #25500, #25588, #25658, #25661. Builder hosts
(`backend-sync`, `backend-sync-backfill`): the same plus #25691.
`llm-gateway`: #25500 (v3 lanes). `pusher`: #25500 (v3-aware
finalization), #25658 (admission) |
| Gateway lanes | `omi:auto:conversation-v3-outline`, `-summary`,
`-summary-open`, `omi:auto:conv-action-items` |
| Env | `v3-task-binding`: `SYNC_TASKS_PROJECT`/`LOCATION`/`INVOKER_SA`
set and equal on the six writers.<br>`v3-task-target`:
`CONVERSATIONS_V3_TASKS_URL` or `SYNC_TASKS_HANDLER_URL`.<br>`v3-stage`:
`CONVERSATIONS_V3_STAGE` equal on the writers and desktop (code default
`beta` for an absent key).<br>`v3-kill-switch`: `CONVERSATIONS_V3`
equal.<br>`v3-gateway-endpoint`: `OMI_LLM_GATEWAY_URL` on `backend` and
`backend-sync`; the placeholders `http://127.0.0.1:9` and `:9080` count
as unset |
| Queues | `conversations-v3` (controlled); `conversations-v3-backfill`
(`controlled: false`) |
| Scheduler | `conversations-v3-sweep`, `conversations-v3-legacy-users`
(ENABLED) |
| Not checked | Firestore composite indexes (index readiness gate) |

### How Release calls it (not in this PR)

Before each step of the train, and before a stage or kill-switch move:
1. `source ~/.local/bin/gcp-agent-env.sh ro-prod && git fetch origin`.
2. `python3 backend/scripts/activation_collect.py --manifest
backend/deploy/activation/<feature>.yaml --cluster prod-omi-gke
--promoted-from-gcloud-config ~/.config/gcloud-agent/ro-dev --out
state.json`.
3. `python3 backend/scripts/activation_check.py --manifest … --state
state.json --before <service|activate> --json`.
4. On exit 1, stop and name the missing requirements. On exit 2, a human
reviews the unknowns. On exit 0, proceed.

Only controlled requirements affect the exit code, so the check trips
only on signals the activation controls. The meta-repo train
(`omi-deploy-prod` / `train.sh`) can call these two scripts from its
release checkout; that wiring is a separate change.

## Product invariants affected

none

## How it was verified

- `backend/.venv/bin/python -m pytest -q
backend/tests/unit/test_activation_manifest.py`: 38 passed.
- **2026-11-17 fixture**
(`backend/tests/unit/fixtures/activation/state-2026-11-17.json`):
`verdict=BLOCKED`, exit 1, satisfied=63, missing=14, unknown=1. Missing:
- stale gateway: `service:llm-gateway:contains:012329830a9e`, plus the
three lanes `lane:omi:auto:conversation-v3-outline` / `-summary` /
`-summary-open`;
- old pusher image: `service:pusher:contains:012329830a9e` and
`:156b50921d7e`;
- pusher task binding: `env:v3-task-binding:pusher:SYNC_TASKS_PROJECT`
and `:SYNC_TASKS_LOCATION`, with their two `env-equal` results;
- infra: `queue:conversations-v3`,
`scheduler-job:conversations-v3-sweep`,
`scheduler-job:conversations-v3-legacy-users`;
  - the backfill queue (advisory).

The one unknown is the advisory Firestore-index item. With `--before
backend-listen`, the gateway, pusher and infra gaps still block, and
listen's own 10 requirements are deferred.
- **Correct-state fixture** (`state-ready.json`): `verdict=READY`, exit
0, satisfied=77, missing=0; the only unknown is the advisory
Firestore-index item.
- **Current prod, collected 2026-11-18T19:24:59Z** with the read-only
`ro-prod` identity, plus `ro-dev` for the dev-registry tag only.
Metadata reads only, no writes.
- `verdict=READY`, exit 0: satisfied=77, missing=0, unknown=1 (advisory
`external:firestore-indexes`).
- All 9 services resolved to a source commit, all 4 lanes are served,
all env requirements are met and equal, the `conversations-v3` queue is
RUNNING, and both v3 jobs are ENABLED.
- The first manifest draft required #25691 on `backend-listen`, and prod
(listen serving 44d0a4f) reported it missing. Short-task extraction runs
only on the sync task handler, so that requirement now applies to the
builder hosts only.
- `scripts/pr-preflight --pr-body-file` passed, and so did `python3
.github/scripts/check_release_rings.py` (the scope panel warned against
reusing the forbidden "release ring" names).

### Panels

- **Scope** `scope-20261118t174316-a7fd`: only glm-flash completed; luna
failed to launch (journal busy) and deepseek failed. Taken from it:
  - `activation` naming;
- CLI and tests only, with no checks-manifest entry or cross-service
invariant (check budget);
  - queue and scheduler ownership (ops_train, scheduler_reconcile);
- keep the manifest from drifting away from `runtime_env` (handled by a
drift test).

Two of its claims were contradicted by live reads, and I resolved them
that way:
- It said `OMI_BACKEND_RELEASE_SHA` is the true marker. Image identity
is used instead, per the documented env-merge misread.
- It said prod pusher's digest has no live source. The dev-registry tag
does resolve it.
- **Review** `review-20261118t185330-8905` (FIX-FIRST; deepseek and
glm-flash; luna failed to launch):
  - Accepted and fixed in d204e36: F1, F4–F17.
- F2/F3: the PR body first posted was another lane's (SCA-2966), because
a scratch file was shared between sessions. It has been replaced with
this one.

## Tests

`backend/tests/unit/test_activation_manifest.py` covers:
- **Fixtures:** each 11-17 escape is reported by name; the correct state
passes.
- **Unknown handling:** an unreadable service, ancestry or lanes gives
UNKNOWN (exit 2), never satisfied; missing beats unknown; uncontrolled
requirements never change the exit code; split traffic (every serving
revision must contain the commit); an env-equal result with one
unreadable unit is unknown.
- **Env values:** stage skew, code defaults versus an explicit empty
value, the placeholder URLs, `any_of` and Secret refs.
- **Order and input:** order deferral; invalid YAML, manifest and state
exit 3.
- **Collector, with fakes:** reads `status.traffic` and never the spec;
never reads Secrets; resolves ConfigMap and `envFrom`; resolves promoted
digests; failed reads become unknown; pod digest counting; container
choice; `Registry.source` (label, index, tag fallback, ambiguity); only
Google registry hosts.
- **Drift:** queue, job and lane names are parsed exactly from
`ops/prod.yaml`, `scheduler/jobs.yaml` and
`generated_route_overrides.yaml`. Every required env key is declared for
each runtime in the composed prod `runtime_env.yaml`; this would have
caught pusher's missing task binding at PR time.

## UI evidence

UI-Evidence: none -- backend tooling, no UI

## Failure class (fixes)

Failure-Class: none

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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