Skip to content

fix(sync): keep phone uploads the server cannot byte-match as durable receipts instead of refusing them forever (admission off by default) - #25444

Merged
Git-on-my-level merged 13 commits into
BasedHardware:mainfrom
Git-on-my-level:lane/q12-wal-handoff
Nov 16, 2026

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What broke

Native-owned phone WAL uploads repeatedly returned record_capture_pending / audio_coverage_unproven. Exact decoded-PCM equality cannot generally identify independently decoded Opus files or reconcile phone/server clocks, and a WAL can contain audio never sent live. Retrying the same bytes did not create a durable recovery obligation.

Change

Before conversation/coverage refusal memos and decoding, scoped admission rechecks the existing batch_live_v1 owner, source/device, consent, privacy generation and deletion intent. It validates every original WAL, creates encrypted immutable originals under the existing account/conversation archive owner, and verifies generation, stored length/CRC32C and plaintext length/SHA-256. Create collisions verify the complete original identity, including metadata; encryption retries reuse the first ciphertext generation.

One transaction commits a versioned all-file receipt, the record upload revision, stable per-file entries, pending obligations and outbox wakes. Rebundled files reuse their obligations. Object-only interrupted attempts stay unaccepted; committed-reply loss replays the same handle without recopying. Originals and outstanding metadata have no routine TTL. Erasure discovers the dedicated media prefix, crash orphans and the new rows in the existing intake receipt collection. The retention contract forbids lifecycle age deletion of record-wal/ originals.

The existing 202 wire contract returns a stable bp_wh_ polling handle. Its durable status remains processing / source_alignment_pending, independent of a completed native job. It never returns an empty covered 200 or completion for these new originals. The existing token-lease wrapper clears its optional fence without scheduling a partial recovery from this receipt. Phase 1 does not decode audio or create paid STT work.

Custody argument

A 202 follows verification of every original and the atomic receipt/work/wake commit. Failure on file two, malformed framing, changed bytes, checksum/generation/metadata conflict, fence loss or a privacy race cannot accept a partial bundle. Privacy changes during or after storage recheck authority and remove invalidated writes; authoritative deletion overrides retention. Current clients keep their local files at 202. Clearing upload-stall eligibility proves upload progress, not recovered transcript or phone disk reclamation.

Rollout and rollback

RECORD_WAL_HANDOFF_ENABLED is a default-off config_switch. Unset, false,
0, off, no and unknown values keep admission off, including intervening main or
image-only deployments. Accepted receipts, headerless status readers and erasure
remain live with admission off. Only true/1/on/yes admit new handoffs.

Release owns this proposed rollout; the quality lead reviews its evidence. No
activation or deployment is authorized by this PR:

  1. 2026-11-16 UTC: deploy this receipt-capable artifact everywhere with
    admission off, including every sync/status and erasure-serving revision.
    Verify image/source identity and Cloud Run status.traffic, not the
    service spec: every revision receiving sync/status traffic must be capable.
    Complete synthetic staging custody, headerless polling and conversation/
    account erasure checks. Leave admission off if any serving reader is old.
  2. 2026-11-17 UTC, only after step 1: the existing release owner sets
    RECORD_WAL_HANDOFF_ENABLED=true on backend-sync only, using a revision
    of the same artifact. Start with synthetic staging/internal test capture,
    then ramp 1%, 10%, 50%, 100% of backend-sync traffic against the capable
    admission-off base. Each step requires a full clean 60-minute lookback;
    quality lead reviews before expansion. Finish or explicitly stop the ramp
    by 2026-11-18 00:00 UTC; no automatic expansion or flag promotion.
  3. Every step requires custody violations = 0 (no 202 without all bytes,
    no missing known handle, no premature completed status), no unexpected paid
    work, fresh pending samples, pending bytes below 80% of the 4 GiB global
    cap and oldest pending age below 6 hours. Sync 5xx must not increase over
    the preceding admission-off 60-minute baseline. Watch pending file counts,
    omi_record_wal_handoff_pending_bytes, oldest_age_seconds,
    sampled_at_seconds, fixed-scope capacity_refusals_total{scope=owner|global}
    and sync 5xx. A capacity refusal keeps phone custody but stops expansion.
    Stop new admission immediately on a custody/status/erasure violation,
    stale metrics, 5xx regression or an age/volume breach. By 2026-11-18 UTC
    Release and the quality lead review every outstanding hold; any oldest age
    reaching 24 hours requires admission off and a phase-2 recovery plan.

Rollback sets admission false and retains receipt-capable readers and erasure
at 100% traffic. It never routes known handles to an incapable binary. A capable
revision handles the released app's ordinary headerless status request directly
from Firestore, independently of ordinary jobstore shadow/index adapters.
An incapable revision cannot interpret bp_wh_: it can return 404/unknown-job,
or a legacy reader that treats the receipt as an ordinary intake can error
(500 on missing ordinary-job fields). Neither is a valid processing response;
this is why the traffic proof must precede the first admission.

Validation and limits

Synthetic unit and real loopback Firestore-emulator proofs cover all-file failure injection, encrypted create-only replay, ambiguous committed replies, concurrent rebundles, privacy races, status polling and admission rollback. Related coverage, custody, privacy, erasure, router, metrics and Firestore guard suites are run one file per pytest process. The required premerge guards, CI manifest and installed pre-push dispatcher are run locally; final commands/results are recorded in q12-as-wal-handoff.md alongside this draft.

R27 follow-up verification: 68 handoff unit tests, 16 erasure unit tests,
and 9 real Firestore-emulator cases passed with synthetic audio. The Opus
header helper no longer needs libopus. Ordinary runs skip the emulator file
when FIRESTORE_EMULATOR_HOST is not a loopback address, with the explicit
reason isolated loopback Firestore emulator required; the separately launched
demo-q12-wal run actually exercises it. Storage verification/erasure uses the
local archive adapter; all-generation GCS behavior is covered by SDK doubles,
not a live bucket.

The required slow premerge sweep currently has an unrelated failure already
present on the pinned base: SYNC_FUTURE_CAPTURE_CLAMP_ENABLED passed its
2026-11-15 flag-budget review deadline on the UTC date rollover. This PR does
not invent a renewal for that owner's separate flag. Final manifest/dispatcher
results and exact-head logs are recorded in the implementation report.

No production reads/writes, user audio, pushes, PR creation, merges, deploys or .github/ changes. No staging/device or production improvement is claimed.

Phase 2 adds source-frame overlap/gap proof, original-job and in-flight coverage seeding, same-owner interval reservations, missing-audio recovery/projection and terminal status only when every obligation is settled. Ambiguous audio remains held without paid work.

Bounds and pending-work exit

New handoff limits: MAX_FILES — initial 20 per bundle; MAX_FILE_BYTES — initial 16,777,216 per original; MAX_BUNDLE_BYTES — initial 167,772,160 per request; MAX_FRAMES — initial 200,000 per original. These are defensive admission bounds, not scheduler/provider capacity changes. Above a bound, no partial bundle is accepted and the phone keeps its originals. The exact-request fence initially lasts 600 seconds. The phase-1 pending obligation exits only through explicit privacy erasure; phase 2 adds proved redundancy or committed missing-audio projection as processing exits. No timer silently marks held audio completed.

Capacity is reserved atomically before the first object write, once per
stable original file. The per-owner defaults are 256 MiB (268,435,456 bytes)
and 200 files; the global defaults are 4 GiB (4,294,967,296 bytes) and
10,000 files. Both stage namespaces share the global and owner ledgers in
the existing production intake collection. Limits are configurable through
RECORD_WAL_PENDING_OWNER_BYTES, RECORD_WAL_PENDING_OWNER_FILES,
RECORD_WAL_PENDING_GLOBAL_BYTES, and RECORD_WAL_PENDING_GLOBAL_FILES.
Zero closes new capacity; negative values close it and malformed values refuse
safely. Bytes conservatively include the original length plus 32 bytes for the
current encryption envelope, even for standard protection.

An exceeded owner or global cap returns the existing strict
record_capture_pending 503 before copying any file; the fixed-scope capacity
counter increments and the phone keeps its audio. Exact retries and rebundles
reuse reservations. Object-only crashes remain charged, without expiry, so a
fresh nonce or interrupted write cannot bypass the bound. Media erasure must
succeed before its reservation and counters are released atomically. Failed
attempts can consume capacity until explicit privacy erasure; phase 1 has no
unsafe timer-based reclaim. Pending bytes include these conservative holds.

Account and conversation erasure sweep every generation of the exact
record-wal/{uid}/{conversation_id}/ prefix (or the owner prefix for account
purge), including crash orphans, before metadata/quota cleanup. The handoff's
sole write target is the configured BUCKET_PRIVATE_CLOUD_SYNC archive bucket;
both purge paths derive that same target. The resumable conversation purge
uses bounded pages and its existing gated, generation-pinned remote deletion
units, re-lists after restart, and cannot acknowledge a failed/unknown erase.
No historical bucket migration or live bucket policy has been verified here.

The existing stage-qualified intake collection stores an explicitly tagged bundle receipt and stable per-file receipt rows. Each file row contains the durable pending obligation and outbox wake in the same write; wal_pending_since is the bounded indexed discovery surface. Ordinary job dispatch does not consume these rows. No new Firestore collection or independent scheduler is introduced. Existing intake erasure discovers both kinds and exact media URIs. Quota reservations are tagged separately until the all-file receipt commits.

Line-Count-Exception: backend/routers/sync.py | 4113 -> 4123 | A lazy archive callback preserves archival before destructive legacy decoding while allowing verified handoff replay to avoid recopying; no new route is added.
Line-Count-Exception: backend/utils/other/storage.py | 2684 -> 2756 | The scoped verified writer shares this module's canonical create-only encryption, tombstone and owner gates; prefix erasure must cover uncommitted crash orphans.

Failure-Class: FC-pre-durability-audio-eviction

🤖 Generated with Claude Code

View guided diff

Git-on-my-level and others added 13 commits November 16, 2026 05:52
Commit verified all-file originals, stable receipts and pending obligations
before returning 202. Preserve privacy erasure and polling across rollback;
leave source alignment and paid processing for phase 2.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Use tagged bundle and per-file intake rows with atomic obligations and
outbox wakes. Existing erasure discovery owns both kinds; no independent
work-state collection or scheduler is introduced. Offload metadata adapters
at the async boundary as required by the blocking-I/O guard.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve existing intake collections through the batch store and keep WAL
orphan cleanup inside its explicit privacy storage purge. Exercise the real
handoff/status with Firestore and local verified originals through restart
and erasure, without production access.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep source-alignment holds on the existing five-minute custody cadence,
including surface-open polling and poll-backoff rollback. The generic
processing adapter must not shorten this pending-only obligation to 20s.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep canonical intake reference construction inside its transaction class
and expose header-only Opus sample counting from the codec module. The WAL
handoff uses public boundaries rather than reaching into private members.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Install the receipt-capable artifact with admission off before enabling
any new handles, then ramp admission on the same artifact. A pre-protocol
binary cannot serve status for accepted WAL obligations.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve archive bucket identity in pure configuration and keep crash-orphan
erasure independent of sync/provider imports. Preserve worker reader policy
and batch-stage snapshot boundaries. Record the fenced base upload revision
alongside the committed revision for subsequent reconciliation.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Use bounded generation-pinned GCS deletion and convergence verification
for the dedicated WAL prefix, matching batch storage erasure. Avoid pulling
account-reader imports into the separately deployed GPU worker.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Use the storage SDK's typed retry policy with a ten-second deadline for
owner-prefix discovery and convergence checks. Deletion stays generation
pinned and one-attempt; failures leave privacy purge retryable.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Default WAL admission off until every serving reader is capable. Route plain
status polling directly to its Firestore receipt independently of jobstore
adapters. Sweep all conversation-original generations before erasing metadata.

Reserve per-owner and global bytes/files before copying originals, including
interrupted attempts; release quota only with retryable privacy erasure. Count
Opus packet duration from framing headers without a native decoder dependency.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pipeline scanner reads all four quota names directly. Reserve helper-backed
registry metadata for names read through registered helpers, keeping the quota
owner and review deadline without broadening the guard's helper allowlist.

Failure-Class: FC-pre-durability-audio-eviction

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e in delete test

The A2 seam test pins exactly one shadow_from_env(FirestoreStore(...)) in
get_durable_job_status; WAL receipt lookups move to a helper that builds the
plain Firestore store. The developer delete test stubs the new WAL storage
sweep (no ADC in unit tests) and asserts the conversation's WAL is erased.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit fbf207a into BasedHardware:main Nov 16, 2026
53 checks passed
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