Repository navigation
fix(batch): hold any poison chain head and redrive restored record targets - #23948
Conversation
…rgets The owner-chain walk retries a failing head forever, so any exception the per-exception seams do not catch wedges every later capture behind it (reentry29 10-29: watermark frozen for 6h; the fresh awaiting-writer conflict stream still errors ~500/h after #23932 by design). One generic rule now covers every seam the precise dispositions do not (lead ruling 5d2ae7): a non-transient exception at a chain head takes the held disposition - quarantine_held receipt, audio retained, watermark advanced - and the chain moves on. Transient infrastructure errors and fresh awaiting-writer conflicts keep retrying under a durable bound (projection_blocked_since; 24h) after which they too hold. The walk and the sweep page both apply it. Restore->redrive closes the loop: a bounded maintenance scan re-examines held units and, when the discarded record target is really restored, resets the row to pending (projection_redriven_at) so assignment re-runs. A redriven unit persists without dragging the owner watermark backward, and the predecessor fence accepts its one sanctioned out-of-order re-assignment.
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. |
…poison # Conflicts: # backend/utils/batch_pipeline/projection.py
…ad rule Review r1 P1: a 502 from the API surface is an outage, not content poison — holding a non-record unit for it has no redrive (no record target to restore), so it must retry like every other availability error. Adds the classification matrix test covering the transient/permanent split.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f452c873a4
ℹ️ 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".
| def commit(transaction): | ||
| row = self.store.ref('results', segment_id).get(transaction=transaction).to_dict() or {} |
There was a problem hiding this comment.
Run the blocked-head stamp inside a decorated transaction
When a head encounters a transient failure or fresh awaiting-writer conflict, this callback is passed undecorated to ProjectionStore.run, which delegates to run_transactional and expects an already-@firestore.transactional callable. Consequently, no transaction is begun or committed: the transactional read fails, the exception is swallowed, and projection_blocked_since is never persisted. Such heads therefore keep retrying indefinitely instead of reaching the new 24-hour bound. Decorate this callback and cover the real transaction lifecycle; the new ResultLog.run fake invokes callbacks directly and masks this failure.
AGENTS.md reference: backend/AGENTS.md:L231-L231
Useful? React with 👍 / 👎.
| session = self.store.session(segment_id, binding, self.clock(), policy=policy) | ||
| persist_disposition(session, quarantined=True) |
There was a problem hiding this comment.
Preserve successful multipart follow-ups when holding a failed head
For an async multipart result, if an earlier part has persisted and a later part raises an unexpected non-transient exception, this creates a session without part_index and writes a whole-result quarantine receipt. ProjectionSession.persist leaves the earlier projection_parts receipt in persisted but sets the result to quarantine_held, removing it from ordinary assignment and follow-up discovery. The already-created conversation consequently loses its pending playback/enrichment work, and partial accounting skips its successfully assigned speech. Hold the remaining parts while keeping successful parts discoverable until their follow-ups finish, as the existing per-part quarantine path does.
Useful? React with 👍 / 👎.
| # google-cloud-firestore's exhausted commit retry: contention, not content. | ||
| return type(error) is ValueError and isinstance(error.__cause__, api_exceptions.Aborted) |
There was a problem hiding this comment.
Treat the repository's contention-exhaustion exception as transient
When projection's enabled contention retry exhausts its attempts or deadline, run_with_transaction_contention_retry raises the repository's FirestoreContentionExhausted, a RuntimeError subclass. This classifier recognizes only the SDK's ValueError-from-Aborted exhaustion shape, so the actual outer-retry exception returns false and head_holds_without_retry immediately quarantines the unit. A temporary Firestore contention spike can therefore permanently hold otherwise valid captures on their first failed projection pass instead of applying the intended bounded retry. Include the explicit wrapper exception in the transient classification.
Useful? React with 👍 / 👎.
| if self.entry.get('projection_redriven_at'): | ||
| # A released held unit re-enters projection behind the watermark: | ||
| # its hold already advanced the chain past it, so the erased- | ||
| # predecessor fence must not block the one sanctioned out-of-order | ||
| # re-assignment. |
There was a problem hiding this comment.
Prevent privacy settlement from rewinding a redriven owner's watermark
If a released unit is behind the owner's watermark and its next assignment encounters a recognized privacy refusal, such as a changed privacy generation, this bypass also allows projection_privacy.hold to prepare the out-of-order unit. Release has removed its receipt, so hold sees neither an existing receipt nor an ordering checkpoint and unconditionally updates projection_watermark to this older segment (batch_pipeline_projection_privacy.py:95–96). The new guard in ProjectionSession.persist does not cover that separate write path. Subsequent owner walks then stop on already-terminal successors rather than reaching new captures. Make privacy settlement honor projection_redriven_at as already-settled ordering, too.
Useful? React with 👍 / 👎.
| if self.entry.get('projection_redriven_at'): | ||
| # A released held unit re-enters projection behind the watermark: | ||
| # its hold already advanced the chain past it, so the erased- | ||
| # predecessor fence must not block the one sanctioned out-of-order | ||
| # re-assignment. |
There was a problem hiding this comment.
Prevent privacy settlement from rewinding a redriven owner's watermark
If a released unit is behind the owner's watermark and its next assignment encounters a recognized privacy refusal, such as a changed privacy generation, this bypass also allows projection_privacy.hold to prepare the out-of-order unit. Release has removed its receipt, so hold sees neither an existing receipt nor an ordering checkpoint and unconditionally updates projection_watermark to this older segment (batch_pipeline_projection_privacy.py:95���96). The new guard in ProjectionSession.persist does not cover that separate write path. Subsequent owner walks then stop on already-terminal successors rather than reaching new captures. Make privacy settlement honor projection_redriven_at as already-settled ordering, too.
Useful? React with 👍 / 👎.
… waits Review r2: FirestoreContentionExhausted (the contention retry helper's own RuntimeError) fell through to a first-failure hold, so a contention wave could turn valid units into held work; the taxonomy-declared retryable kinds PermissionError and OSError (storage/authorization waits) must keep waiting under the bound too. Classification matrix extended accordingly.
…ntinel contract CI full-suite: the strict Firestore fixture deliberately retains DELETE_FIELD sentinels (22 assertions across 14 files rely on it); teaching it real field deletes is out of scope for this PR. The release reset now writes falsy tombstones instead (empty receipt map, None stamps, zeroed lineage fence): every consumer reads these fields through truthiness, so the reset semantics are unchanged.
The reviewed replay adapter lacks `store.run()`, which the new bounded projection-head retry path calls to persist its first-failure time. Replaying #23948 against serving91d therefore reports five new AttributeErrors from the adapter instead of exercising that path. This adds a result-only transaction facade to the fixed replay runner. It reuses StrictFirestore's read-before-write/reference checks against a private snapshot, publishing result metadata only after the callback succeeds. Unsupported collection access and nested callbacks fail closed. Keeping the implementation in runner.py includes it in the existing adapter SHA and makes it available when comparing older product snapshots. Production code and the gate's exception comparison are unchanged. This does not simulate retries, contention or multiprocess commits. Validation:21 local cases through backend/test.sh (15 replay +6 transaction regressions) passed. The exact formerly failing comparison now PASSes: candidate12db97806043e44d5eec50205ed95f5e59d594a5 versus serving91d5616fa922e8f77fe02dbea40fa85ef8f45f1e, structure-v3 corpus9a53e11b8ee5aad13f815eaa7784590bd5285837241366012a4a0c9a5aee263c; zero new exception sites, chain blocks, per-unit failures or synthetic failures. Adapter4d1d7c2253679709a3f77cb3741892d3246312698c38f06158b40e4647609259 includes fixed fixture6f1184b7f22682f4d2502958d9e7d24145db32ecd1fdd8e048b4d5824b9f14e4. Existing captured geometry/speech-accounting gaps remain explicit. Commands use omi-heavy and nice-n19; no cloud access or production mutation by this change. Full review found oneP1: selected source snapshots could replace the unpinned strict fixture. The fix loads that fixture from the fixed tool's absolute path for both result and assignment simulation, hashes its bytes, and tests snapshot independence plus identity changes. Round2 delta review says SHIP at8d3fd91c6c9de58296848b93ab202a995de4f0d7. Fresh exact-head CI remains required before merge. Per lead131060, this old-head comparison is diagnostic. Repeat on #23948 after it merges main before its merge. Independent review and exact-head CI are required; lead owns merges and deployment. ## Product invariants affected none Failure-Class: none This repairs a test adapter capability; no production behavior or failing-site suppression is added.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3e07c1724
ℹ️ 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 entry.get('projection_parts'): | ||
| reset['projection_parts'] = {} | ||
| reset['projection_part_count'] = 0 |
There was a problem hiding this comment.
Preserve the expected part count when releasing held records
When a speech-bearing record was held by the per-part assignment path, it has projection_parts even though record-origin results contain only one part. Releasing it here sets projection_part_count to zero, but the next assign_parts attempt creates a session with part_count=1. ProjectionSession.prepare then raises ProjectionBlocked('immutable projection part count mismatch') before reaching the redrive bypass. Consequently, restoring the target leaves the released recording permanently pending, and the release scan cannot retry it because projection_redriven_at is already set. Preserve the original expected count rather than replacing it with zero.
Useful? React with 👍 / 👎.
What
Two stacked pieces on top of #23946 (per lead ruling 0babf0 — no duplication
of its seam-level payload-contract hold):
The generic poison-head rule at the walk/sweep level (lead ruling
5d2ae7), composed with test(batch): CI invariants for the 10-28 wedge classes (poison head, taxonomy, shard spread, boundary geometry, real claim) #23946's
payload_contract_violation: anynon-transient exception that escapes the seams at an owner-chain head
(unknown bugs — TypeError/KeyError/…, contract ValueErrors raised outside
assign_parts' catch, structural conflicts) takes the held disposition —quarantine_heldreceipt, audio retained, watermark advanced — and thechain moves on. Transient failures (Firestore/API contention and
availability: Aborted, ServiceUnavailable, BadGateway, DeadlineExceeded,
TooManyRequests, ResourceExhausted, InternalServerError, GatewayTimeout,
network errors, contention-shaped ValueError) and fresh awaiting-writer
conflicts keep retrying under a durable bound
(
projection_blocked_since, 24h), after which they too hold. Applies at_walk_rowsand the sweep's page rows alike.Restore → redrive (ruling 7a09a7): a bounded maintenance scan (one
page per 15 min tick, keyset cursor, leader-gated) re-examines held units;
when a discarded record target is genuinely restored (mirroring
replace_record's own fences), the row resets topendingwithprojection_redriven_atand assignment re-runs. A redriven unit persistswithout dragging the owner watermark backward onto already-terminal rows,
and the predecessor fence accepts its one sanctioned out-of-order
re-assignment. This is the recovery path for every held unit — fix(batch): hold structural record-target conflicts instead of wedging the owner chain #23932's
conflicts, test(batch): CI invariants for the 10-28 wedge classes (poison head, taxonomy, shard spread, boundary geometry, real claim) #23946's payload holds, and this rule's holds alike.
Deliberate limits:
ProjectionBlocked/BatchPrivacyBlockedkeep theirexisting semantics (shadow refusal must never hold; privacy has its own
machinery). The seam dispositions (#23932 strike rule, #23946 payload
contract) stay; this rule is the floor beneath them.
Why
reentry29 10-29: a discarded record target froze an owner's watermark for 6h;
#23932 fixed that seam, but its fresh-lane keep-waiting design still retries
forever (~500/h live), and #23946 covers only ValueError/InvalidTag at the
assign seams. Post-#23932 readback (owner hash 75235644, 04:2xZ): watermark
12 → 39, zero pending — the wedge shape is gone; this PR makes that
guaranteed for every escaping exception class, bounded, and recoverable.
Held audio is never swept before redrive (extends the 8f792d condition)
expire_completed_segmentarms cleanup only forprojection_state in {ready, projected, completed}(utils/batch_pipeline/retention.py:269);quarantine_heldrows never receive expiry receipts, andcleanup_completed_artifactsdeletes only due or erasure-requestedartifacts.
recovery_state=held) in the sametransaction as the receipt;
quarantine_jobdocuments "quarantine neverdeletes encrypted source material".
complete_heldperforms "no retention: held audio stays for a reviewedredrive".
audio_uriis untouched (asserted in tests).
Notes for the lead
PR's diff then collapses to its own additions.
.github/chart/workflow change. Normal backendtrain; no deploy of mine.
make batch-replay: candidate should show fewer walkexceptions and held heads where the baseline wedged (held heads unblock
followers) — direction of fix, not newly-blocked units.
redrive target) fixed + classification matrix added.
Tests
and contract violations hold
later rows project; held rows never arm retention; sweep page rows same
the bound the same failure holds
non-held shape; resets a restored target (receipt, lineage fence, bound
stamp cleared; job released; audio untouched; watermark unmoved);
idempotent; scan cursor wraps
green with this rule composed in (verified on the merged branch)
Local: 10-file merged shard via
test.shgreen; 21+6-file shards greenpre-merge; broader 477-test batch set green; query-shapes and field-index
tests green with the new driver entries.
Failure-Class: none
Line-Count-Exception: backend/utils/batch_pipeline/projection.py | 1504 -> 1716 | #23946's seam-level payload hold (absorbed into this stacked PR) plus the walk/sweep-level poison-head rule composed with it, and the release scan hook