Repository navigation
fix(desktop): stop from-segments 422s stranding recordings with blank session ids (#15500) - #23886
Conversation
… session ids (#15500) Every macOS desktop upload carrying a blank persisted client id has been rejected with a 422 and retried with identical bytes forever: measured 16-18k 422s/day on /v1/conversations/from-segments since 2026-10-06 (the stable rollout of v0.12.447 scaled a long-standing ~200/day failure ~80x; ~670 sessions stuck on the hourly retry cadence), response bodies fingerprint-matching blank client_session_id values under the model's alias keys. The Sep-26 wave was #19353 (finalization reasons); this is the second, still-live wave of the same report. The id is optional metadata whose only job is retry dedupe, and every caller already handles its absence, so a blank value is now treated as absent instead of rejecting the only copy of a transcript. The desktop side never uploads a blank stored id either: the chunked continuation upload requires a real session id, so localClientConversationId trims the stored value and falls back to the derived id when blank. Stuck sessions drain without user action: after the backend deploy the next hourly retry of identical bytes lands; chunked-cohort sessions drain once the desktop fix ships. Failure-Class: new (FC-optional-client-metadata-fails-closed — ingestion of the only copy of user data must degrade broken optional metadata to absent, never 422; guard: test_blank_client_session_id_is_treated_as_absent)
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: d250a25a8f
ℹ️ 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".
| if isinstance(value, str) and not value.strip(): | ||
| return None |
There was a problem hiding this comment.
Instrument the blank-session-ID fail-open path
When an upload supplies a blank session ID, this branch now silently admits it without retry deduplication. Neither this validator nor the downstream ingestion handler calls the shared fallback helper, so the disappearance of 422s cannot distinguish repaired clients from requests still relying on degraded ingestion. backend/AGENTS.md explicitly requires new fallbacks to call utils.observability.fallback.record_fallback. Record this normalization with bounded dimensions and an appropriate outcome, without including the session ID or transcript.
AGENTS.md reference: backend/AGENTS.md:L320-L320
Useful? React with 👍 / 👎.
…n ids (#15500) Luna review of #23886 (P1): mapping a blank client_session_id to None moved the stuck blank-id cohort from a 422 onto the unkeyed create path, so a lost 200 followed by the client's byte-identical retry would fork a duplicate conversation. A blank id that was actually sent now derives a deterministic server-side id (derived:<sha256> over uid + source + started/finished_at + language + geolocation + segments) and runs the normal keyed idempotency path; an id that was never sent keeps the public create-path contract, and null stays absent. Routing fields a retry may legitimately resend differently (folder, calendar context, client projection, finalization reason) are excluded from the digest so retries land on the first attempt's row. Chunked continuations still require a real id and are documented in the PR: per-chunk payloads differ, and metadata-only keys could collide two recordings into one chunk namespace (409). That cohort recovers via the desktop fallback id. Failure-Class: new (FC-optional-client-metadata-fails-closed, defined in this PR)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf84fb4aea
ℹ️ 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".
| let stored = session.clientConversationId?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" | ||
| return stored.isEmpty ? "macos-local-\(sessionId)-\(startedAtMs)" : stored |
There was a problem hiding this comment.
Preserve retry identity across the desktop update
If an old desktop client uploads a blank-ID recording after the backend deploy, the server saves it under derived:<sha256>. If that response is lost and the desktop updates before retrying, this function instead sends macos-local-<row>-<timestamp> for the same recording. _ingest_conversation_from_segments only derives an identity for blank IDs, so the retry now creates a second conversation and reruns processing. The local-segments retry path calls uploadLocalSegments directly without reconciliation. Add a reconciliation mechanism between these two fallback identities so an app update cannot invalidate the new retry deduplication.
Useful? React with 👍 / 👎.
| if request.client_session_id is None and request.sent_blank_client_session_id: | ||
| request = request.model_copy(update={'client_session_id': _derived_client_session_id(uid, request)}) |
There was a problem hiding this comment.
Document the changed segment-upload lifecycle contract
backend/AGENTS.md requires conversation-lifecycle changes to update backend/docs/listen_pusher_pipeline.mdx in the same PR, but this commit leaves that document unchanged. Its “Segment-upload processing shape” section distinguishes session-ID uploads from uploads without IDs without documenting the new sent-blank exception. Update it to explain derived retry identities, omitted/null IDs retaining the unkeyed path, and blank-ID chunked uploads still returning 422; these distinctions determine which stranded recordings recover after the backend deploy versus requiring a desktop update.
AGENTS.md reference: backend/AGENTS.md:L163-L163
Useful? React with 👍 / 👎.
…3904) Playback merges reject unchanged source chunks when late encoded uploads cover the last raw fragment: the listing switches from the sample clock back to rounded filename timestamps, invalidating the stamped hash. One affected conversation's bounded read-only metadata reproduces this for 266 of 267 current stamps; the remaining stamp stays fail-closed. Keep identity listings on the sample clock and verify old-clock stamps against their exact generation/checksum hash. Resolve reordered listings and same-timestamp groups by hash, pin stamped downloads to their paths/buckets/generations, and refuse a true changed source without publishing bytes or exhausting attempts. Legitimate growth preserves the unchanged selected manifest and proceeds; fresh groups get stable stamps through the existing creator. Failed merges recover on next access after a 15-minute cooldown, with one deduped task per unavailable-marker generation. `PLAYBACK_MANIFEST_RECOVERY_ENABLED=false` stops new recovery enqueues (default on); already queued jobs drain through the existing handler. Missing/empty/source-changed verdicts stay terminal. No source audio is deleted and no raw storage layout changes. Failure-Class: FC-derived-audio-identity-churn Line-Count-Exception: backend/routers/sync.py | 4084 -> 4124 | Keep terminal source-change classification next to both existing merge task handlers and their shared destructive-operation deferral. Line-Count-Exception: backend/utils/other/storage.py | 2693 -> 2779 | Keep source-clock listing, exact manifest-path and generation-pinned reads, and marker-generation retry inspection at their existing storage authority; no new module or storage API owner. Validation: - 394 distinct tests passed across 14 isolated files (17 platform skips) via selected files through `BACKEND_UNIT_TEST_FILE_LIST=... BACKEND_PYTEST_WORKERS=1 bin/omi-heavy run -- nice -n 19 bash backend/test.sh` (workspace heavy wrapper). CI repair delta rechecked 192 cases through `/Volumes/Ephemeral/scratch/pbmerge/ci-fix-tests.txt` on current main. - Coverage includes growth during merge, reordering, true replacement before/during merge, generation-pinned downloads, permanent marker reasons, kill switch, and 230-file retry fan-out across hourly task names. - Hermetic backend E2E: 174 passed, 3 skipped, 2 xfailed via the same heavy wrapper and `nice -n 19 bash backend/testing/e2e/run.sh`. - Local preflight: all 37 selected checks passed (including registry, Firestore guards, async/import/route checks and runtime source closure). Full push hooks, including whole-backend Pyright and the bounded unit shard, passed again at repair head `7584afe3772f154108f28aa93eba22a7b9f78e10`. - Luna read-only full review round 1 at source head `7799c759c7527b7d4fc90edaba473e3f3077c7d7`: **SHIP**, no findings. Round 2 at final head `7584afe3772f154108f28aa93eba22a7b9f78e10`: **SHIP**, no findings; the reviewer independently verified the explicit trust-boundary allowlist, both storage fixtures, and zero playback production diff since round 1. The test results above are local execution evidence. Lead merge requires terminal-green GitHub checks on the final head; the live Checks tab owns CI status. Test-only old-contract updates: `test_audio_merge_tasks.py` replaces the blanket source-text prohibition on unavailable retries with a behavioral assertion that permanent markers never enqueue; `test_sync_playback_service.py`, `test_conversation_playback_artifact.py` and `test_sync_silent_failure.py` add the new storage seam to their import-isolated fixtures; `test_audio_durable_outbox.py` explicitly constructs a historical filename-clock stamp so the compatibility canary still covers old persisted handles after new listings use the sample clock. `test_client_processing_trust_boundary.py` pins the reviewed serialization site introduced by upstream #23886: `_derived_client_session_id` explicitly includes only recording facts and excludes client projection fields. New regression cases extend existing `test_repeat_work_cuts.py` and `test_playback_idempotency.py`. The first CI run identified the missing stub in `test_sync_silent_failure.py` and the upstream #23886 serialization pin. This **fixes main pin from #23886**, specifically the reviewed `_derived_client_session_id` dump. Both repairs are covered by the standing test-only contract-update grant and explicit lead ruling 70d04a; the upstream owner was notified. Current main was integrated without force-push; playback production code is identical to the full-reviewed source head. No CI rerun or skip was used to hide either failure. Operator evidence: ro-prod only, one conversation's `audio_files` metadata plus GCS object metadata, aggregate output only. Exact fields: name/generation/size/timeCreated/updated/md5Hash/crc32c; v2_start/v2_samples/v2_sample_rate/v2_playback_start/capture_start/capture_end/gap_count/channels/codec/source_layout. No audio bytes, transcripts, profiles or production writes. The mask included four extra raw descriptor keys (gap_count/channels/codec/source_layout) beyond the explicitly named span/capture keys; disclosed to lead. No further prod reads. Report: `omi-workspace/data/run-2026-10-13-two-lane-nemotron/swarm/state/refs/1028-pbmerge-report.md`. Backend Cloud Run deployment belongs to the lead; this lane neither merges nor deploys. Follow-up owner lead, by 2026-10-29T02:00Z: evaluate post-train remaining unmatched-source errors. No claim of production playback acceptance. Scope correction approved by lead ruling 6fa5ba: actual module `backend/utils/cloud_tasks.py` replaces the nonexistent `backend/utils/other/cloud_tasks.py` from the brief. Lead ruling 853171 also permits only the kill-switch registry entry and regenerated catalog in `config/feature-flags.yaml` and `backend/docs/feature-flag-registry.md`. No workflow or runtime-env changes.
What changed and why
Fixes #15500 (still-live wave). macOS desktop recordings were stranded
locally with HTTP 422 on every upload retry: the from-segments wire model rejected a
blank/whitespace
client_session_id(under any accepted alias) as a hard 422, and clientsthat persisted a blank id retried identical bytes forever — measured ~16–18k 422s/day on
/v1/conversations/from-segmentssince 2026-10-06 (stable rollout of desktop v0.12.447scaled a long-standing ~200/day baseline ~80×; ~670 sessions stuck on the hourly retry
cadence). The id is optional metadata whose only job is retry dedupe, so a blank value is
now treated as absent instead of rejecting the only copy of a transcript. The desktop
client also no longer uploads a blank stored id (the chunked continuation path requires a
real id), so both sides are closed.
A blank id additionally no longer falls into the unkeyed create path (Luna review of this
PR): these clients resend byte-identical requests, so if the first attempt's 200 is lost
while its row lands, a plain create path would fork a duplicate conversation on retry.
The server now derives a stable retry identity (
derived:<sha256>over uid + therecording's own facts — source, started/finished timestamps, language, geolocation,
segments) and runs the normal keyed idempotency path with it. Fields a retry may
legitimately resend differently (folder, calendar context, client projection,
finalization reason) stay out of the hash, so a retry lands on the first attempt's
conversation. An id that was never sent keeps the public create-path contract unchanged;
nullcounts as absent, not blank. The derived id never appears in the OpenAPI schema.Chunked uploads (recovery boundary)
Chunked continuation uploads still require a real session id and keep their 422 when the
id is blank: each chunk carries different segments, so a per-request payload hash is not
stable across chunks of one recording, and a metadata-only hash (the only cross-chunk
input) would key two distinct recordings that share timestamps into one chunk namespace
(409 content conflict). The chunked blank-id cohort therefore recovers only after the
desktop release ships the client-side fallback id
(
desktop/macos/Desktop/Sources/ConversationFinalizationService.swift:873, derived fromthe persistent SQLite row id +
startedAt, stable across retries and app restarts); thelocal retry queue keeps retrying on capped hourly backoff, so those sessions drain once
the update is installed. Non-chunked blank-id sessions drain on their next hourly retry
after the backend deploy alone.
Product invariants affected
none
How it was verified
daily 422 counts on the route 2026-09-01→10-28; response-size fingerprints of the
failing bodies matched locally-generated validation errors for blank
client_session_idvalues (aliases
client_session_id/session_id/client_id, whitespace lengths 2–8);failing UAs are desktop builds 12402→12541; failing requests are 3KB–638KB real
transcript payloads (not truncations).
backend/test.shwithBACKEND_UNIT_TEST_FILE_LIST=tests/unit/test_developer_from_segments_idempotency.py tests/unit/test_client_segment_continuation.py tests/unit/test_openapi_contract.py tests/unit/test_client_processing_acceptance.py(unit layer), including thereplay test below.
TranscriptionFinalizationStateMachineTests/testLocalClientConversationIdNeverUploadsABlankStoredIdviascripts/dev-feedback.py --once swift(unit layer).retry sends the identical bytes and now lands (200 → markSessionCompleted → drained, no
user action). Chunked-cohort sessions drain after the app update ships the fallback id.
Retry-forever policy (fix(desktop): never strand local-segments conversations after five failed uploads #19613) confirmed on main:
.permanentfailures stay queued athourly cadence and the recovery query includes rows old builds stranded at
retryCount ≥ 5.
Tests
test_blank_client_session_id_gets_server_derived_retry_identity(parametrized 4aliases × 4 blank shapes): posts blank ids through the real route and asserts the
keyed idempotency path runs with a
derived:session id instead of a 422 — this testfails on main.
test_byte_identical_blank_id_retry_returns_first_conversation: the stuck cohort'sretry shape (first attempt's 200 lost, row landed, identical bytes resent) returns the
first conversation and never reprocesses — the exact duplicate-conversation gap from
the review.
test_blank_id_different_recordings_stay_separate: different recording facts derivedifferent ids and still create two conversations.
test_sent_blank_flag_distinguishes_sent_blank_from_absent: omitted andnullidsstay on the create path; only a sent blank string derives.
test_client_session_id_with_content_still_strips_and_dedupes: real ids still stripand keep the idempotency path.
testLocalClientConversationIdNeverUploadsABlankStoredId: nil/empty/whitespace storedids fall back to the derived id; padded ids still strip.
UI evidence
UI-Evidence: none -- backend validation and upload-id derivation only; no visible UI changed
Line-Count-Exception: backend/routers/developer.py | 2830 -> 2862 | derived blank-id retry identity helper sits beside the existing from-segments idempotency helpers it extends
Failure-Class: new
Failure-class transition narrative
FC-optional-client-metadata-fails-closed(definition added in this PR).degrade broken optional client metadata to absent, never 422 — a retrying client
resends identical bytes, so a hard 422 strands the recording forever. Evidence:
~16–18k 422s/day on
/v1/conversations/from-segmentssince 2026-10-06 from desktopbuilds 12402→12541, ~670 sessions stuck on the hourly retry cadence ([community-signal] transcription-quality: 103 min of speech, zero transcripts (/v4/listen 1011 loop) #15500), caused
by blank
client_session_idvalues hitting the model'scannot be emptyraise.Noneat the wire model, and a sent-blankid derives a stable server-side retry identity so the byte-identical retry is an
idempotency hit, never a duplicate conversation. The parametrized regression test
posts blank ids under every accepted alias through the real route and asserts the
keyed path runs with the derived id instead of a 422; the replay test pins the
lost-200 retry to one conversation.
fix(desktop): accept newer desktop finalization reasons in from-segments (#19328) #19353 finalization-reason guard for the same endpoint. Distinct from
FC-server-bound-excludes-client-design-range (server range excludes valid client
design values): here the client metadata itself was broken and the server's job was
to degrade, not to widen a bound.