Repository navigation
fix(batch): explicit one-call operator repair for language-guard words units - #23775
Conversation
…s units Lead ruling 7fa3d2. Units settled failed_held because Modulate words met zero strict CPU VAD (payload_validation/invalid_payload) and whose capped Soniox call answered empty get one explicit, digest-approved Modulate call under their bound worker VAD receipt (paid epoch 4, --language-guard-repair, exact unit IDs). The repair is its own route: the spent recovery intent and both recognizer receipts stay verbatim, independent_attempted is never consulted or bypassed, the shared epoch-2/epoch-3 plans are unchanged, one repair intent per unit (prepare refuses any other plan once a marker exists), audio is capped at the independent-recovery 60 s bound, and the call is receipted on the marker. Retention accepts only a running epoch-4 Modulate result for an eligible unit. Accounting stays acoustic through the fixed words_payload. Failure-Class: FC-empty-asr-without-evidenced-disposition Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 04baeae1a4
ℹ️ 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".
| bound worker VAD receipt measured speech. Its operator repair buys exactly one | ||
| explicit Modulate call; the spent intent and both receipts stay untouched. | ||
| """ | ||
| from utils.batch_pipeline.contracts import worker_vad_speech |
There was a problem hiding this comment.
Remove the function-local import from the eligibility helper
The new function-local import violates the explicit import rule in backend/AGENTS.md: “All imports at module top level — never inside functions.” Simply moving it to the top would introduce a circular import because utils.batch_pipeline.contracts already imports this configuration module. Extract the shared worker-VAD validation into a dependency-neutral module, or relocate the eligibility helper so both modules can retain top-level imports without a cycle.
AGENTS.md reference: backend/AGENTS.md:L165-L173
Useful? React with 👍 / 👎.
| '--language-guard-repair', | ||
| action='store_true', | ||
| help='Lead 7fa3d2: one Modulate call per guarded words unit, epoch 4; exact unit IDs required', |
There was a problem hiding this comment.
Document the new epoch-4 transcription repair contract
This adds a new paid transcription route without the same-change update to backend/docs/listen_pusher_pipeline.mdx required by backend/AGENTS.md. Its “Independent language-guarded batch recovery” section still says guarded results may register only under an epoch-3 Soniox intent, with epoch 2 retained for legacy redrive; the new epoch-4 Modulate exception makes that operational contract inaccurate. Update the section with the repair eligibility, explicit approval, one-call limit, and replay behavior.
AGENTS.md reference: backend/AGENTS.md:L163-L163
Useful? React with 👍 / 👎.
…n malformed jobs Luna r1 on #23775: the 60 s cap read the declared duration while decoded audio may run 0.1 s longer, and the eligibility predicate could raise inside the retention transaction for a job missing audio_uri. Cap and admit the repair on the decoded duration before dispatch, and fail eligibility closed on malformed jobs. Failure-Class: FC-empty-asr-without-evidenced-disposition Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lead ruling a3af50 approves one bounded Modulate call for every guarded unit whose Modulate words were rejected for zero strict CPU VAD under bound worker VAD speech, whether its spent Soniox call answered empty or words. Same route: paid epoch 4, provider modulate, one intent per unit, 60 s decoded cap, no independent_attempted bypass, same marker, receipts and acoustic accounting. Both-empty, Soniox-error, unbound or sub-frame receipts and any unit already carrying a repair intent stay refused; a failed repair is ledgered failed_held with audio retained and never buys another call. Failure-Class: FC-empty-asr-without-evidenced-disposition Co-Authored-By: Claude Opus 5.5 <[email protected]>
repair and #23795 duration-limit Reconciles the operator script's four modes (epoch-2 default, epoch-3 independent, epoch-4 words repair from main, epoch-1 prepared take-over from this lane) and keeps every existing plan digest byte-stable. Also extends the prepared take-over to the exact failed_held shape that #23795's hold_duration_limit refusal settles without ever starting the intent: RecoveryStore.start_duration_limited reopens only that shape (never a spent intent) in one fenced transition into the running take-over, so a concurrent sweep cannot re-settle the refusal between reopen and start.
…r language guards (#23812) ## Summary Two reviewed capabilities for the 5-r1027b language-guarded held set (lead ruling 0f7cec on op1 900ca2; partition in `selector/proposal-14z.md`, option A design in `selector/proposal-soniox18.md`): 1. **Scoped operator recovery for language-guarded `prepared` units above the 60s bound (option A).** A new `--prepared-independent` mode in `backend/scripts/batch_pipeline_speech_redrive.py` accepts an explicit sealed id list (`--unit-ids-file`, exact ids required) and takes over the **existing** epoch-1 prepared intent via `RecoveryStore.start` — the same at-most-once token fence; no new marker intent is created and custody is preserved. It then runs independent Soniox recovery for those ids only, up to a scoped `--max-seconds` that must exceed the runtime 60s bound. Dry-run by default; the plan sha (`paid_digest`) binds the seal census, `max_seconds` and `usd_cap`; the closed cost estimate (`ESTIMATED_USD_PER_AUDIO_HOUR`) must fit `--usd-cap` or the plan refuses. The owner allowance is rechecked against Soniox exactly as the runtime independent route (`sync_allowed`, `DispatchPath.QUARANTINE`) — the take-over never bypasses it. 2. **Guarded terminal outcome.** A language-guarded unit may settle `no_recoverable_speech` only when every recognizer returned a **validated empty receipt** (modulate and soniox, `word_count == 0`) and independent recovery was attempted; the payload records `LANGUAGE_GUARD_EMPTY_EVIDENCE`. The existing refusal (`independent recovery required`) stands whenever recovery was not attempted or any receipt is non-empty (words/error/refused). Guarded silence and the guarded canary route keep refusing in the terminal tool. ## Reconciliation with #23795 (duration-limit refusal) and #23775 (words repair) Main moved under this lane; the branch merges origin/main and reconciles the operator script's four modes (epoch-2 default, epoch-3 independent, epoch-4 words repair, epoch-1 prepared take-over) with every existing plan digest byte-stable. #23795's `hold_duration_limit` settles the sealed population's no-CPU-span subset as `failed_held` with an `independent_duration_limit` refusal — **without ever starting the intent** (no provider call, receipt, provider or failure). Once that fix train serves, those units are no longer `prepared`, so the take-over extends to exactly that shape: - `config.batch_language_recovery.duration_limited(job)` recognizes only the exact refusal shape #23795 writes; a spent intent (real failure) never matches. - `RecoveryStore.start_duration_limited` mirrors `hold_duration_limit`'s fence and performs one atomic transition refusal→running (provider `modulate`, fresh `started_at`, refusal and its `settled_at` removed). Going straight to running closes the race where a concurrent sweep could re-settle the refusal between a reopen and a `start()`. - The sealed plan's fingerprint freezes `(token, epoch, privacy_generation, prepared_at)`, none of which the refusal settlement touches — so one frozen cohort covers each unit in whichever state the runtime has left it (`prepared`, refusal-settled, or already spent by this plan). ## What is deliberately unchanged - The global runtime 60s independent bound (`MAX_AUDIO_SECONDS`) and `allowed()` — the env can still only lower it. The runtime's new #23795 settlement behavior is preserved verbatim (test `test_runtime_duration_limit_still_settles_without_a_provider_call`). - `held_result_allowed` / the runtime settle fence — a guarded unit still cannot settle `no_recoverable_speech` through the runtime; only the reviewed terminal tool path gains that outcome. - An empty or failed operator take-over settles `failed_held` through the same Soniox receipts as the runtime independent route. It never fabricates the unattempted Modulate receipt that the independent silence contract (`validate_independent_silence`) requires, so a take-over cannot settle silence. - Existing epoch-2/3/4 plan digests are byte-stable (the new knobs are only bound into prepared-mode digests). ## Fences (per unit) `prepared_eligible`: owner pin, quarantined in window, `worker_failed`, language-guarded, epoch 1 with token and no `started_at`/receipts, `prepared` (unsettled) **or** the exact duration-limit refusal shape, no result and no `speech_redrive`/`silence_disposition`/`terminal_disposition` marker, and `60 < duration <= max_seconds`. Every id in the sealed file must be eligible (`unit_not_eligible` otherwise); the cohort manifest freezes ids and per-unit fingerprints; `checked_prepared` revalidates seal identity, eligibility and ledger debt in a read-only transaction before any apply step; `RecoveryStore.checked` gains an opt-in `allow_completed_recovery` ledger path (default off, no existing caller changes) so a settled unit replays after projection completes. `start_duration_limited` refuses everything except the exact refusal shape (wrong token, foreign audio uri, sub-bound duration, spent intent). ## Tests New: `tests/unit/test_batch_pipeline_prepared_independent.py` (30) — sealed-selection fence matrix (including the refusal shape and a spent-failure negative), dry-run read-only and no-audio-download, spend cap, scoped bound (both > max and <= 60 refused), runtime bound identity (flag on + env 190 still refuses >60s), #23795 runtime identity, refusal reopen through the take-over, `start_duration_limited` shape-fence negatives, words recovery through worker-VAD word clocks, empty/error settle `failed_held` with soniox-only receipts, allowance recheck, at-most-once (`already_applied`, `running_held`, artifact-only reconcile), fingerprint stability across refusal settlement and spend, digest binding incl. legacy byte-stability. `tests/unit/test_batch_pipeline_guarded_terminal.py` (17) — guarded terminal settle with recorded evidence + replay, negative controls for each missing/non-empty receipt condition, guarded silence and canary still refused, dry-run read-only, and the live runtime→terminal integration (runtime records both empty receipts, plan settles the unit). Existing suites for every touched module (12 files incl. main's repair/duration-limit suites) pass unchanged. ## Operator runbook (after lead grant by plan sha) Dry-run from the pinned train image, RO tier: `--stage prod --prepared-independent --unit-ids-file <sealed 18 file> --cohort-file <new> --quarantined-after/-before <window> --expect-count 18 --expect-speech-count 18 --paid-epoch 1 --max-seconds 190 --usd-cap 3`. Then apply with `--apply --approve-plan-sha256 <plan sha> --apply-limit 18` under prod-operator. Sealed snapshot: `prepared-snapshot-124022.json` (sha256 bfc0e6d5…, 18 ids, 60.02–181.02s, 1458.57s total ≈ $0.04 estimated). The plan covers each unit whether the runtime has left it `prepared` or #23795-refusal-settled. Note for the run: on an empty Soniox answer these units settle `failed_held` (soniox-only receipt). The terminal tool then requires padded-retry evidence they do not carry, so empty answers stay held — words are what releases them. The 6 guarded failed_held with both empty receipts (and padded evidence) settle through `scripts/batch_pipeline_terminal_empty.py` as `no_recoverable_speech`. Failure-Class: none
What changed and why
Lead ruling 7fa3d2 covers the 16 language-guarded units that settled
failed_heldwithpayload_validation/invalid_payloadwhile recognizers had returned words. Root cause and fix are in #23770, and the RCA is at/Volumes/Ephemeral/scratch/op1/langguard-rca-0210.md. Stacked on #23770 (baseop1/words-without-vad-worker-evidence): this PR uses #23770's worker-VAD placement and acoustic accounting inwords_payload. Merge #23770 first.This PR adds an explicit, operator-invoked repair path:
--language-guard-repair,--paid-epoch 4, exact unit IDs, dry run first.Rulings
Lead a3af50 (binding, supersedes 7fa3d2 items 1-2): "APPROVED one bounded Modulate call each for the 16 (cap 1/unit, audited, same #23775 fences, cost trivial). If Modulate fails, ledger as failed_held with audio retained; no further calls without me. Order: merge+deploy #23775, dry run, then 14+16. The 4 stay held until a worker-acoustic terminal contract exists."
The failed attempts' recognizer words were never persisted, so no zero-call re-settle exists:
words_payloadraisedWordsWithoutVadbefore any payload existed.recognizer_attemptdiscarded the Soniox words.persist_recovery_resultruns only on success.record_recognizerstores only{provider, outcome, word_count, vad_speech_seconds}.Eligibility (
words_repair_eligible). All of the following must hold:modulate;payload_validation/invalid_payload;wordswithword_count > 0;emptywithword_count == 0, orwordswithword_count > 0;audio_uripresent;Refused, with no spend:
empty_asr);error,refusedor missing;--independent-language;Fences:
speech_redrivemarker carriespaid_epoch: 4andprovider: modulate, andexpected_route()keeps it distinct.independent_attemptedis never consulted or bypassed, and the shared epoch-2/3 plans are unchanged (tested).preparerefuses any other plan, and a replay never calls again.repair_budget_held) before start, andsync_allowedis admitted on the decoded duration. The company allowance is always rechecked, there is no BYOK shortcut, and a provider-environment check runs before spend.prior_recoveryverbatim (the spent intent and both receipts),plan_digest,token,privacy_generationand a claimedrecognizers.modulatereceipt (started->words|empty|error,word_count).failed_heldwith a closed failure. The job staysquarantined/failed_heldwith its audio retained and no result, and it never buys another call.The 4 both-empty units stay held until a worker-acoustic terminal contract exists (a3af50). Nothing here closes them.
Dry run (op1, after #23770 and #23775 are merged and deployed; ro-prod, read-only, per owner)
Prod reconciliation (op1) found 16 Soniox-words and 14 Soniox-empty units. All are
invalid_payload/WordsWithoutVadwith Modulate words and worker VAD speech. Another 4 are both-emptyempty_asr, and 2 are unrelated.mode: dry_run,operation: language-guard-words-repair-v1,provider: modulate;units: N,strict_vad: {worker_vad_speech: N};speech_epoch1_failures: {payload_validation/invalid_payload: N};maximum_additional_paid_calls: N,max_audio_seconds_per_unit: 60;paid_stt_calls: 0,firestore_writes: 0.{"outcome":"refused","reason":"unit_not_eligible"}, so keep them out of the ID files.not_failed_held:terminal()fences;completed_ledger: the content ledger no longer owes held units;policy_unpinned: no pinned policy and no--server-flags-file;cohort_changed.prod-operator), with the same flags plus--apply --source-census-sha256 <census> --approve-plan-sha256 <plan_sha256>. Run--apply-limit 1first as a canary, then the full count. The CLI pins one owner per run.Luna review (one round)
The review returned CHANGES REQUIRED with two P2s, both fixed in
fix(batch): bound the words repair on decoded audio...:repair_budget_held, before start and spend) when decoded audio is over 60s, and it admitssync_allowedon the decoded duration.words_repair_eligiblecould raiseKeyErrorinside the retention transaction for a job missingaudio_uri. It now fails closed on malformed jobs.Both have a test:
test_words_repair_bounds_decoded_audio_and_fails_closed_on_malformed_jobs. Luna confirmed the other fences were intact: one call per unit, no epoch-2/3 change and receipts preserved. The a3af50 widening (Soniox-words eligible) came after Luna's single round. bramp3 reviews that delta.Product invariants affected
backend/deploy/runtime_env.yaml). This PR itself changes no memory promotion behavior.How it was verified
tests/unit/test_batch*.py+test_silent_batch_redrive.py+test_cross_service_deploy_contract.py+test_backend_runtime_env_validator.pythrough pytest: 2481 passed, 5 skipped. After the a3af50 widening,test_batch*.py+test_silent_batch_redrive.pypassed 2322 with 2 skipped. After the Luna fixes,test_batch*.py+test_silent_batch_redrive.pypassed 2316 with 2 skipped.black --checkis clean.Tests
In
backend/tests/unit/test_batch_language_recovery.py(synthetic, deterministic).settled_words_without_vadreproduces the exact prod settlement through the real recovery code (pre-fix worker VAD ignored), for both Soniox empty and Soniox words.test_words_repair_buys_one_modulate_call_for_soniox_empty_or_words_units, parametrized over Soniox empty/words and multilingual on/off:recovered, and a replay givesalready_applied;recoveryis unchanged;test_words_repair_refuses_every_other_unit_without_spend[no_receipt|subframe_receipt|independent_plan|both_empty|soniox_error|epoch4_marker]: each givesrepair_not_eligible(orProjectionBlockedfor an existing epoch-4 intent), with no new marker and no call.test_words_repair_is_capped_at_one_call_per_unit: a Modulate empty answer givesfailed_held, receiptedempty/0, with closed failureresponse_validation/empty_asr. The job staysquarantined/failed_heldwith audio retained and no deletes. A replay makes no call, and a new plan raisesProjectionBlocked.test_words_repair_bounds_decoded_audio_and_fails_closed_on_malformed_jobs(Luna P2s).test_words_repair_leaves_shared_redrive_plans_unchanged: epoch 2 still givesindependent_plan_required, and epoch 3 still givesalready attempted.test_operator_repair_census_selects_the_modulate_words_cohort: covers CLI eligibility (Soniox empty and words eligible, both-empty and marked units refused) and a distinct plan digest.In
backend/tests/unit/test_batch_pipeline_speech_redrive_retention.py:test_running_words_repair_registers_only_its_eligible_result: the real retention transaction accepts Soniox-empty and Soniox-words units (multilingual on and off) and rejects both-empty.In
backend/tests/unit/test_batch_redrive_scope.py:checked_jobstub signature now acceptsrepair.UI evidence
UI-Evidence: none -- backend operator recovery path only.
Failure class (fixes)
Failure-Class: FC-empty-asr-without-evidenced-disposition
🤖 Generated with Claude Code