Skip to content

Fence the record gap fill against admission and add the option A retained-copy ack (dark) - #24940

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

Git-on-my-level merged 7 commits into
mainfrom
claude/project-thread-cqxm31

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What changed and why

Follow-up to #24889 (closed-record gap fill, merged dark), built under lead2's be4c23 after David's custody ruling e11df2 (option A). Two parts, race fix first:

  1. Admission fence (lead2's hard condition 9d0efb / ca347f A). The fill now claims the drain's own lease on the record_pending job (available_at = now + 600 s) in the same transaction as the privacy fence, so due and the drain's claim skip the row while the fill writes. A live lease is skipped_busy. After the write, one transaction re-checks privacy and that the job is still record_pending under this exact lease, then releases it; otherwise the outcome is raced (new counter value) and the lease is left to whoever moved the job. Writes stop on a piece boundary 60 s before the lease ends. Any create collision is now always skipped_collision.
  2. Option A retained-copy ack. Behind its own switch RECORD_RETAINED_ACK + RECORD_RETAINED_ACK_PERCENT (both default off), a jobs-missing upload whose fill ended written / skipped_no_gap / skipped_no_audio / skipped_marker with a clean settle gets the existing covered_response() 200 if record_retained_ack.prove passes; the shipped phone then marks those WALs synced and sends the next batch. The proof re-lists chunks/ and counts only lossless single-chunk .bin/.enc objects at 16 kHz in the private-cloud-sync or derived audio bucket, read pinned to the listed generation. Every WAL sample must equal the sample at the same capture time in a counted object, inside [started_at - 1 s, finished_at + 1 s]; privacy is re-checked after the read. Everything else keeps today's 503. The WAL is decoded once and shared by the fill and the proof, because decoding consumes the uploaded files.

Hard condition: RECORD_GAP_FILL stays off until this merges and lead2 re-reviews the fence. The ack rides inside the fill entry, so it is also off until then.

Bucket lifecycle (read-only check via Coordkit): omi-private-cloud-sync only transitions chunks/**.batch.{enc,bin} to Coldline (never counted, and not a delete); the derived bucket has no rules. The batch-pipeline staging bucket (30-day delete) is never listed by list_audio_chunks, and the proof now explicitly refuses to count any object outside the two archive buckets.

Change note: backend/docs/listen_pusher_pipeline/changes/2026-11-08-record-gap-fill-fence-and-retained-ack.md.

Product invariants affected

none

How it was verified

  • pytest tests/unit/test_record_gap_fill.py tests/unit/test_sync_admission_diagnostics.py tests/unit/test_reason_label_enums.py: 117 passed.
  • The 22 unit files that touch live_upload, record_gap_fill, registered_record_response or reason_label: 1265 passed. test_sync_capture_time_skew.py and test_sync_cloud_tasks.py fail 12 tests identically on clean origin/main (pre-existing, unrelated).
  • make preflight and scripts/pr-preflight --pr-body-file: 40 checks passed. scripts/check_feature_flag_registry.py: OK.
  • Hermetic only: nothing here is deployment or live evidence.

Tests

In backend/tests/unit/test_record_gap_fill.py:

  • Fence: lease taken and released on the claim clock; a live lease writes nothing (skipped_busy); live.drain_recordings run mid-fill admits nothing and admits after; a job moved mid-fill (state change or foreign lease) is raced, never acked, and its lease is untouched; a privacy block at the recheck is raced.
  • Option A: ack after a full fill (counter and log carry only the 16-hex record key); retry gets the same answer with no new writes; switch off / 0 % keeps the fill outcome and reads nothing; one differing sample is skipped_bytes_differ; a WAL hole the fill stopped at is skipped_uncovered; gate refusals are never proven; privacy block at the ack recheck is skipped_privacy; a replaced object fails the generation-pinned read (failed); enhanced .enc fill objects count; multi-batch walk (batch 1 already held, batch 2 filled) acks both and admission's tail passes; real decoder on real WAL files; Opus / .opus.enc / batch / raw-live sources never count or get read; WAL outside the record window is refused before any listing; objects outside the archive buckets never count; the call site answers the covered 200 when acked and keeps the 503 otherwise.

UI evidence

UI-Evidence: none -- backend only

Failure class (fixes)

Failure-Class: none


Generated by Claude Code

View guided diff Turn on auto-fix

Tuning

Both knobs are new and only bound the dark retained-ack proof (RECORD_RETAINED_ACK, default off).

  • MAX_LOSSLESS_OBJECTS new: 128. Before: 0 pinned reads per upload, because the proof did not exist. After: at most 128 lossless objects pinned and read per proof. A larger set refuses the proof and keeps today's 503.
  • max_count new: 4096 on the retained-ack archive listing. Before: 0 listings per upload. After: at most 1 listing of up to 4096 objects per proof, the same bound the record seal/orphan repair listings use.

The closed-record gap fill now holds the drain's own lease while it writes,
so no admission lists retained audio mid-fill. A post-write transaction
re-checks privacy and that the job is still record_pending under that lease
before releasing it; otherwise the outcome is `raced`. A live lease is
`skipped_busy`. Any create collision is `skipped_collision`.

Behind RECORD_RETAINED_ACK / RECORD_RETAINED_ACK_PERCENT (default off), a
jobs-missing upload whose fill ended cleanly gets the existing covered 200
once every WAL sample is proven byte-exact against lossless chunks/ objects
in the archive buckets, read pinned to their listed generations. Anything
else keeps today's 503. The WAL is decoded once and shared by the fill and
the proof, since decoding consumes the uploaded files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 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-09T08:22:27.546251Z c7688c7 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.

All reported issues were addressed

You’re at about 99% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

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

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

Comment thread config/feature-flags.yaml Resolved
Comment thread backend/docs/feature-flag-registry.md Resolved

@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: 24d2052ca5

ℹ️ 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".

Measure the write deadline from before the gates take the lease, and bound
each create-only piece upload (per request and across retries) inside the
lease margin, so a slow upload started before the deadline cannot outlive
the fence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
… proof

A cancelled upload cannot stop a storage thread that is still writing, so
the serving entry now leaves the lease to lapse instead of releasing it
under that write. The retained-ack proof reads each object's sample rate
from the listing's span, as admission does. Docs and flag summaries name
the gap-fill prerequisite, the real rollback, and the committed lifecycle
rules.

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

@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: 7257bef787

ℹ️ 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".

…ping sources

The storage write gate does Firestore authority reads with no deadline, so
the chunk writer now re-checks the write deadline just before uploading and
stops the fill on a piece boundary if it passed. The retained-ack proof now
advances by each covering object's matching prefix, so overlapping lossless
objects that together hold every sample are acked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
…-cqxm31

# Conflicts:
#	backend/docs/feature-flag-registry.md
#	config/feature-flags.yaml
Main now requires new kill switches that default off to be config_switch,
and rollout owners to be lanes under the per-owner backlog cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017CeWy3fepTWkruwXu3wafS
@Git-on-my-level
Git-on-my-level merged commit 45436a0 into main Nov 9, 2026
80 of 84 checks passed
@Git-on-my-level
Git-on-my-level deleted the claude/project-thread-cqxm31 branch November 9, 2026 17:32
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