Skip to content

fix(batch): retain expired projection holds and re-drive nightly - #24745

Merged
Git-on-my-level merged 5 commits into
mainfrom
lane/lcphase4b
Nov 6, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
lane/lcphase4b

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Assignment-held projection receipts can remain parked indefinitely after their target becomes unrestorable. This adds a seven-day expiry marker and a nightly recovery pass while retaining the receipt in the state that pre-change release code can discover.

  • ProjectionSession.persist stamps held_deadline_at on assignment holds; legacy rows receive a full window at first examination. Over-age, still-unrestorable settled holds retain projection_state=quarantine_held and receive additive held_expired_at / held_expired_reason=held_expired fields. Persisted multipart suffixes and privacy holds never age-expire.
  • The pre-4b release code rejects rows at MAX_RELEASE_ATTEMPTS=3. For capped rows, expiry's transaction saves the count in held_expired_release_attempts and resets the active counter to zero exactly once. The result, receipt and watermark are unchanged. This keeps expired rows recoverable by the unchanged old scan/release code after a full revert, only when the target becomes restorable.
  • Nightly recovery reuses the maintenance leader with 32-row pages, a five-second inter-row budget, five-minute continuation, previous-day cutoff and durable CAS checkpoints. Unfinished pages continue across UTC midnight. The ordinary release scan also recovers marked rows. Its existing durable cursor ordering and budgets are unchanged.
  • Visibility, stock metrics and the existing agent-tier volume alert key on additive markers and the held state. Unrelated legacy stock never counts; no human paging. Two additive age-query indexes are declared for prod/dev and generated in the manifest. Index readiness is a release prerequisite; no index apply or deployment is performed here.

Flag: reuse default-on BATCH_HELD_DEAD_LETTER_ENABLED / batch_held_dead_letter_enabled(). No separate flag, config binding or .github edit.

Rollback: set the flag false to stop new deadline stamps and expiry. Ordinary unmarked flag-off behavior is unchanged. Already expired rows remain discoverable/releasable by the unchanged pre-4b scan and release implementation, including capped rows normalized during expiry. The new nightly helper also continues with the flag off. A full binary revert needs no metadata rewrite or retained helper. Frozen pre-change code from b6b1539c tests this behavior; its scan and release ASTs match that baseline exactly.

Custody: nothing is deleted. Expiry retains the held result/transcript payload, quarantined receipt, proven parts, audio references, job and owner watermark. Each row has a reason and target-gated requeue path. No TTL, privacy/custody fence change, conversation-status writer, BYOK consumer or finalization requeue change.

Validation (offline/synthetic):

  • Isolated 23-file component suite through bin/omi-heavy and backend/test.sh: 2,773 passed, 75 strict expected gaps. No xfails added; the privacy-held deadline gap remains outside scope.
  • Loopback Firestore: seven cases passed, including competing expiry CAS at the cap, competing release, unchanged pre-4b scan/release with flag off (uncapped and capped), payload retention and fresh assignment holds after legacy release with the flag on/off.
  • Query-shape/outside-query and index contract suites: 615 passed. Final delta with loopback Firestore and expiry unit contracts: 31 passed.
  • make preflight: 41 checks passed; scripts/pr-preflight --pr-body-file: 40 passed. Normal pre-push on bd1a6780b73c0e5267d0637842cba9cc5ff3b1ea passed all 41 checks, zero Pyright errors, OpenAPI and selected backend tests. Firestore guard: 162.69s, no timeout. No hook bypass, cap override or force. One initial push attempt was deliberately stopped to clear inherited cloud credential overrides; the successful attempt ran with all four overrides unset. Exact-head GitHub CI is available in this PR's checks.

Review: the final Luna round on b93002a found one blocking rollback-recoverability P1. This inline correction implements the requested additive-marker design and capped-row regression. No additional review round was launched. Earlier required Grok review attempts all timed out without a verdict (exec-buffalo-pulse-bring-system-ranch-truck, exec-similar-stadium-hour-stand-orchard-wash, exec-fantasy-dignity-record-social-frog-reform); each child was reaped. The PR remains draft because that required verdict is unavailable.

Not measured: production stock/dwell, live nightly execution, exporter/alert delivery, index readiness, vendor spend, deployed revision or user-visible recovery. No GCP tier or production access used. No merge or deploy performed.

Product invariant: INV-MEM-4; canonical memory intake/promotion authority is unchanged.
Failure-Class: FC-batch-fault-domain-head-of-line-poison

Failure-Class: FC-batch-fault-domain-head-of-line-poison
Failure-Class: FC-batch-fault-domain-head-of-line-poison
Failure-Class: FC-batch-fault-domain-head-of-line-poison
Failure-Class: FC-batch-fault-domain-head-of-line-poison
@Git-on-my-level
Git-on-my-level marked this pull request as ready for review November 6, 2026 03:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T03:40:33.840280Z bd1a678 Draft marked ready
ℹ️ 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.

4 issues found across 26 files

Confidence score: 4/5

  • The xfail reason in test_lifecycle_invariants.py implies the quarantine_held gap is closed, but the clause still fails. Keep the reason aligned with the missing stamped marker and DEADLINE_ENTRIES entry.
  • The release_page digest in firestore_batch_pipeline_drivers.py does not match the current function body. Recompute it from HEAD and update the pin here and in the registry.
  • The change note documents the default-on switch and held_expired markers, but listen_pusher_pipeline.mdx does not. Update the pipeline contract so it matches the behavior described in the note.
  • The alert description says all stock is state=dead, but the metric also counts projection_state=quarantine_held receipts. Change the first clause to say “Job stock is only…” so the scope is accurate.
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/tests/support/firestore_batch_pipeline_drivers.py">

<violation number="1" location="backend/tests/support/firestore_batch_pipeline_drivers.py:432">
P3: The new `release_page` digest does not match the current function body. Recompute it with `function_body_digest` on the HEAD source (currently 315ea28b…) and update the pin here and in `firestore_query_driver_registry.py`. The same applies to the `release_scan_pass` pin. The shape-guard tests should then catch future body drift.</violation>
</file>

<file name="backend/tests/unit/test_lifecycle_invariants.py">

<violation number="1" location="backend/tests/unit/test_lifecycle_invariants.py:344">
P2: This xfail reason now reads as if the gap is closed, but the clause still fails: the `quarantine_held` row in `lifecycle_state_table.py` is not marked `stamped` and has no `DEADLINE_ENTRIES` entry. Keep the reason naming the open gap so the strict xfail documents what remains broken; the privacy-hold policy sentence is not the failing condition.</violation>
</file>

<file name="backend/docs/listen_pusher_pipeline/changes/2026-11-06-projection-held-dead-letter.md">

<violation number="1" location="backend/docs/listen_pusher_pipeline/changes/2026-11-06-projection-held-dead-letter.md:22">
P3: This note cites the pipeline contract for the new default-on `BATCH_HELD_DEAD_LETTER_ENABLED` switch and the `held_expired` markers, but `listen_pusher_pipeline.mdx` is not updated and does not mention either. Per the changes README, the env var, its default, and the new fields belong in that contract section. Add a short section to the contract doc in this PR.</violation>
</file>

<file name="backend/charts/monitoring/alerts/batch-held-dead-letter.json">

<violation number="1" location="backend/charts/monitoring/alerts/batch-held-dead-letter.json:142">
P3: This scope first says all stock is `state=dead`, but the metric also counts projection receipts in `projection_state=quarantine_held`, which are not dead rows. Change the first clause to say “Job stock is only…” so operators do not misread the projection cohort’s alert scope.</violation>
</file>

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

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

Comment on lines +344 to +345
('batch_projection:quarantine_held', 'entry_deadline'): 'Assignment holds stamp held_deadline_at; privacy holds '
'remain explicitly outside phase 4b and must never age-expire. ANX lcinv-lifecycle-invariants',

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: This xfail reason now reads as if the gap is closed, but the clause still fails: the quarantine_held row in lifecycle_state_table.py is not marked stamped and has no DEADLINE_ENTRIES entry. Keep the reason naming the open gap so the strict xfail documents what remains broken; the privacy-hold policy sentence is not the failing condition.

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/tests/unit/test_lifecycle_invariants.py, line 344:

<comment>This xfail reason now reads as if the gap is closed, but the clause still fails: the `quarantine_held` row in `lifecycle_state_table.py` is not marked `stamped` and has no `DEADLINE_ENTRIES` entry. Keep the reason naming the open gap so the strict xfail documents what remains broken; the privacy-hold policy sentence is not the failing condition.</comment>

<file context>
@@ -341,9 +341,8 @@ def assert_clause(row, clause):
-    ('batch_projection:quarantine_held', 'entry_deadline'): 'batch_projection:quarantine_held: missing deadline '
-    'stamped at entry; phase contract follow-up; no fix PR '
-    'yet; ANX lcinv-lifecycle-invariants',
+    ('batch_projection:quarantine_held', 'entry_deadline'): 'Assignment holds stamp held_deadline_at; privacy holds '
+    'remain explicitly outside phase 4b and must never age-expire. ANX lcinv-lifecycle-invariants',
     ('batch_projection:ready', 'entry_deadline'): 'batch_projection:ready: missing deadline stamped at entry; phase '
</file context>
Suggested change
('batch_projection:quarantine_held', 'entry_deadline'): 'Assignment holds stamp held_deadline_at; privacy holds '
'remain explicitly outside phase 4b and must never age-expire. ANX lcinv-lifecycle-invariants',
('batch_projection:quarantine_held', 'entry_deadline'): 'batch_projection:quarantine_held: deadline is not declared as stamped at entry (no DEADLINE_ENTRIES); assignment holds stamp held_deadline_at, privacy holds must never age-expire; '
'ANX lcinv-lifecycle-invariants',

reason='bounded release scan delegates queries to both page builders; resets are document transactions',
expect_observed=False,
body_digest='6585eb78557d3f1f336d97ca78325be4a55146f44f5e21c6c72f11abec183580',
body_digest='ec3dcf9db1840bbee61eed826b815d0bac6a277975dfa5f0c9f7388b3272e397',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The new release_page digest does not match the current function body. Recompute it with function_body_digest on the HEAD source (currently 315ea28b…) and update the pin here and in firestore_query_driver_registry.py. The same applies to the release_scan_pass pin. The shape-guard tests should then catch future body drift.

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/tests/support/firestore_batch_pipeline_drivers.py, line 432:

<comment>The new `release_page` digest does not match the current function body. Recompute it with `function_body_digest` on the HEAD source (currently 315ea28b…) and update the pin here and in `firestore_query_driver_registry.py`. The same applies to the `release_scan_pass` pin. The shape-guard tests should then catch future body drift.</comment>

<file context>
@@ -424,7 +429,7 @@ def entries():
             reason='bounded release scan delegates queries to both page builders; resets are document transactions',
             expect_observed=False,
-            body_digest='6585eb78557d3f1f336d97ca78325be4a55146f44f5e21c6c72f11abec183580',
+            body_digest='ec3dcf9db1840bbee61eed826b815d0bac6a277975dfa5f0c9f7388b3272e397',
         ),
         CoveredByEntry(
</file context>
Suggested change
body_digest='ec3dcf9db1840bbee61eed826b815d0bac6a277975dfa5f0c9f7388b3272e397',
body_digest='315ea28bf30953ad3395528f321f87a033fdc1560bfc0b397161f86cfd7fcb49',

change is included. Synthetic and loopback tests cover payload retention, CAS,
legacy recovery, entry stamps, backfill and bounded scans. Production stock,
live re-drive and alert delivery were not measured. See the
[pipeline contract](../../listen_pusher_pipeline.mdx).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This note cites the pipeline contract for the new default-on BATCH_HELD_DEAD_LETTER_ENABLED switch and the held_expired markers, but listen_pusher_pipeline.mdx is not updated and does not mention either. Per the changes README, the env var, its default, and the new fields belong in that contract section. Add a short section to the contract doc in this PR.

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/docs/listen_pusher_pipeline/changes/2026-11-06-projection-held-dead-letter.md, line 22:

<comment>This note cites the pipeline contract for the new default-on `BATCH_HELD_DEAD_LETTER_ENABLED` switch and the `held_expired` markers, but `listen_pusher_pipeline.mdx` is not updated and does not mention either. Per the changes README, the env var, its default, and the new fields belong in that contract section. Add a short section to the contract doc in this PR.</comment>

<file context>
@@ -0,0 +1,22 @@
+change is included. Synthetic and loopback tests cover payload retention, CAS,
+legacy recovery, entry stamps, backfill and bounded scans. Production stock,
+live re-drive and alert delivery were not measured. See the
+[pipeline contract](../../listen_pusher_pipeline.mdx).
</file context>

"summary": "Held batch dead letters exceed the retained-stock or new-expiry volume threshold.",
"user_impact": "Recorded audio remains retained but these units have no published transcript.",
"scope": "Stock is only state=dead with reason held_expired, a new explicit cohort; legacy unrelated dead rows never count. Rate counts unique CAS expirations over 30 minutes. Stock requires a sample younger than 15 minutes. Agent tier only. Each replica stock sample is filtered by its own timestamp before max aggregation, so another replica cannot refresh stale stock.",
"scope": "Stock is only state=dead with reason held_expired, a new explicit cohort; legacy unrelated dead rows never count. Rate counts unique CAS expirations over 30 minutes. Stock requires a sample younger than 15 minutes. Agent tier only. Each replica stock sample is filtered by its own timestamp before max aggregation, so another replica cannot refresh stale stock. Projection receipt stock counts only projection_state=quarantine_held with held_expired_reason=held_expired; no legacy quarantine stock counts.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This scope first says all stock is state=dead, but the metric also counts projection receipts in projection_state=quarantine_held, which are not dead rows. Change the first clause to say “Job stock is only…” so operators do not misread the projection cohort’s alert scope.

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/charts/monitoring/alerts/batch-held-dead-letter.json, line 142:

<comment>This scope first says all stock is `state=dead`, but the metric also counts projection receipts in `projection_state=quarantine_held`, which are not dead rows. Change the first clause to say “Job stock is only…” so operators do not misread the projection cohort’s alert scope.</comment>

<file context>
@@ -139,9 +139,9 @@
       "summary": "Held batch dead letters exceed the retained-stock or new-expiry volume threshold.",
       "user_impact": "Recorded audio remains retained but these units have no published transcript.",
-      "scope": "Stock is only state=dead with reason held_expired, a new explicit cohort; legacy unrelated dead rows never count. Rate counts unique CAS expirations over 30 minutes. Stock requires a sample younger than 15 minutes. Agent tier only. Each replica stock sample is filtered by its own timestamp before max aggregation, so another replica cannot refresh stale stock.",
+      "scope": "Stock is only state=dead with reason held_expired, a new explicit cohort; legacy unrelated dead rows never count. Rate counts unique CAS expirations over 30 minutes. Stock requires a sample younger than 15 minutes. Agent tier only. Each replica stock sample is filtered by its own timestamp before max aggregation, so another replica cannot refresh stale stock. Projection receipt stock counts only projection_state=quarantine_held with held_expired_reason=held_expired; no legacy quarantine stock counts.",
       "verification": "Read omi_batch_held_expired_units and omi_batch_held_expired_total, then inspect reasoned rows using an authorized operator read.",
-      "safe_next_action": "Check nightly re-drive and worker failure reasons. Use the private OIDC requeue-quarantined path after resolving the cause. Never delete audio or clear privacy fences.",
</file context>

@Git-on-my-level
Git-on-my-level merged commit 3b09c0c into main Nov 6, 2026
71 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/lcphase4b branch November 6, 2026 03:44
Git-on-my-level added a commit that referenced this pull request Nov 6, 2026
## Change

Projection and held state now have one owned contract before lifecycle
phases 2, 4c and 5. Document the current batch, projection,
finalization, record-audio custody and conversation state tables,
including writers, deadlines, observability, switches and rollback gaps.
Reserve terminal_family and follow-on work as PLANNED.

Pin the retained shapes from #24736 (b6b1539) and #24745 (3b09c0c):
batch merge_pending=true preserves legacy dead-row re-drive; projection
keeps quarantine_held and normalizes the capped release counter once.
Only uicleanup may introduce another held/dead-letter shape through a
CONTRACT.md PR (lead2 2f9297 / PA-1106-01). Dead-lettering never deletes
retained content.

Correct the older Inputs and outputs description: successful recovery is
recovery_state=recovered with state=result_ready, rather than
"completed"; failed_held is a recovery outcome, not an absorbing batch
state.

Add a small offline consistency test comparing table keys to the shared
lifecycle inventory and checking documented flags against runtime
literals/registry, metrics against source (including generated
PhaseMetrics names), expiry metrics against the existing alert, and
required retained-shape spellings in the contract. Existing dedicated
4a/4b runtime tests own CAS behavior. It uses the existing backend
unit-test lane; no additional CI primitive or workflow is needed. It
guards drift in the actual shapes whose pre-change recovery
compatibility needed review fixes in #24736/#24745.

No runtime, deployment, GCP, or .github changes. Pre-existing Flutter
worktree edits are excluded.

## Validation

- Via bin/omi-heavy, new consistency test + lifecycle writer/invariant
suites: 1,909 passed, 75 expected failures (declared lifecycle gaps).
- Final combined run: 1,909 passed, 75 xfailed in 91.73s; the fourth
contract test pins retained-shape text.
- make preflight on final commit: 36 checks passed in 233.17s. Initial
run invalidated by a concurrent commit; rerun against a stable tree
passed.
- scripts/pr-preflight --suggest: no locked invariant citations or
fix-class declaration required. Full --pr-body-file run passed 35
checks; final metadata-only validation passed.
- Normal pre-push hook: PASSED (shared preflight, type check with 0
errors, seven selected backend test files, format and release-contract
checks); normal push succeeded. No bypass, custom cap or force.
- Required Grok review via agentctl-portable and cursor-delegation:
first review exec-jewel-inmate-quick-hurt-live-desert found a misplaced
finalization budget requeue and writer/test gaps. Corrected
leased-to-queued budgeting, privacy/retry/receipt writer citations and
retained-shape doc assertions; follow-up
exec-couple-burger-west-despair-day-boat: no remaining actionable
findings. Both reviews were local read-only Grok through agentctl.

No merge/deploy requested or performed.


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

1 participant