Skip to content

fix(batch): hold any poison chain head and redrive restored record targets - #23948

Merged
Git-on-my-level merged 7 commits into
mainfrom
lane/wedge7-poison
Oct 29, 2026
Merged

Git-on-my-level merged 7 commits into
mainfrom
lane/wedge7-poison

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

What

Two stacked pieces on top of #23946 (per lead ruling 0babf0 — no duplication
of its seam-level payload-contract hold):

  1. 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: any
    non-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_held receipt, audio retained, watermark advanced — and the
    chain 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_rows and the sweep's page rows alike.

  2. 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 to pending with
    projection_redriven_at and assignment re-runs. A redriven unit persists
    without 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/BatchPrivacyBlocked keep their
existing 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_segment arms cleanup only for projection_state in {ready, projected, completed} (utils/batch_pipeline/retention.py:269);
    quarantine_held rows never receive expiry receipts, and
    cleanup_completed_artifacts deletes only due or erasure-requested
    artifacts.
  • The held disposition holds the job (recovery_state=held) in the same
    transaction as the receipt; quarantine_job documents "quarantine never
    deletes encrypted source material".
  • complete_held performs "no retention: held audio stays for a reviewed
    redrive".
  • The release redrive touches only receipt/disposition fields; audio_uri
    is untouched (asserted in tests).

Notes for the lead

Tests

  • classification matrix: availability errors retry (incl. BadGateway), bugs
    and contract violations hold
  • generic poison head (TypeError at the head) holds, advances the watermark,
    later rows project; held rows never arm retention; sweep page rows same
  • transient retries within the bound; stamp written once per episode; past
    the bound the same failure holds
  • fresh awaiting-writer conflict keeps waiting, then holds at the bound
  • release: refuses still-discarded/deleted/unfinalized targets and every
    non-held shape; resets a restored target (receipt, lineage fence, bound
    stamp cleared; job released; audio untouched; watermark unmoved);
    idempotent; scan cursor wraps
  • redriven re-assignment persists without regressing the watermark
  • test(batch): CI invariants for the 10-28 wedge classes (poison head, taxonomy, shard spread, boundary geometry, real claim) #23946's poison-head matrix, taxonomy and boundary-geometry invariants stay
    green with this rule composed in (verified on the merged branch)

Local: 10-file merged shard via test.sh green; 21+6-file shards green
pre-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

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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-10-29T08:00:09.723745Z e3e07c1 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.

…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.

@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: 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".

Comment on lines +885 to +886
def commit(transaction):
row = self.store.ref('results', segment_id).get(transaction=transaction).to_dict() or {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +911 to +912
session = self.store.session(segment_id, binding, self.clock(), policy=policy)
persist_disposition(session, quarantined=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +204 to +205
# google-cloud-firestore's exhausted commit retry: contention, not content.
return type(error) is ValueError and isinstance(error.__cause__, api_exceptions.Aborted)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +285 to +289
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +285 to +289
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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.
Sync #23948 with #23946 (simtests ce20e1b) and main after its delta
review, per lead ruling 5233f3: merge, no rebase.
Git-on-my-level added a commit that referenced this pull request Oct 29, 2026
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.
Second sync: main advanced past ce20e1b with #23931 (occasion
merge-first) and the adapter lane; GitHub reported mergeStateStatus
DIRTY at 07:43Z. Merge commit, no rebase, per lead rules.

@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: 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".

Comment on lines +99 to +101
if entry.get('projection_parts'):
reset['projection_parts'] = {}
reset['projection_part_count'] = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 5b70664 into main Oct 29, 2026
58 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/wedge7-poison branch October 29, 2026 08:06
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