Skip to content

fix(batch): explicit one-call operator repair for language-guard words units - #23775

Merged
Git-on-my-level merged 3 commits into
mainfrom
op1/language-guard-words-repair
Oct 27, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
op1/language-guard-words-repair

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What changed and why

Lead ruling 7fa3d2 covers the 16 language-guarded units that settled failed_held with payload_validation/invalid_payload while 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 (base op1/words-without-vad-worker-evidence): this PR uses #23770's worker-VAD placement and acoustic accounting in words_payload. Merge #23770 first.

This PR adds an explicit, operator-invoked repair path:

  • Mode: --language-guard-repair, --paid-epoch 4, exact unit IDs, dry run first.
  • What it does: it buys one Modulate call per eligible unit under the unit's bound worker VAD receipt. The fixed validation then places the words and keeps accounting acoustic.

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_payload raised WordsWithoutVad before any payload existed.
  • recognizer_attempt discarded the Soniox words.
  • persist_recovery_result runs only on success.
  • record_recognizer stores only {provider, outcome, word_count, vad_speech_seconds}.
  • Soniox transcripts are DELETEd at the vendor, and Modulate prerecorded keeps nothing.

Eligibility (words_repair_eligible). All of the following must hold:

  • language-guarded;
  • spent recovery on modulate;
  • failure payload_validation/invalid_payload;
  • a Modulate receipt of words with word_count > 0;
  • a Soniox receipt of either empty with word_count == 0, or words with word_count > 0;
  • audio_uri present;
  • duration in (0, 60]s;
  • a bound worker VAD receipt of at least one full frame.

Refused, with no spend:

  • both-empty (empty_asr);
  • Soniox error, refused or missing;
  • an unbound, sub-frame or missing worker receipt;
  • --independent-language;
  • any unit already carrying a speech-redrive marker, including an epoch-4 repair intent.

Fences:

  • Separate route. The speech_redrive marker carries paid_epoch: 4 and provider: modulate, and expected_route() keeps it distinct. independent_attempted is never consulted or bypassed, and the shared epoch-2/3 plans are unchanged (tested).
  • Cap 1 per unit. Once a marker exists, prepare refuses any other plan, and a replay never calls again.
  • 60s cap on decoded audio. The repair refuses (repair_budget_held) before start, and sync_allowed is admitted on the decoded duration. The company allowance is always rechecked, there is no BYOK shortcut, and a provider-environment check runs before spend.
  • Audit receipt. The marker keeps prior_recovery verbatim (the spent intent and both receipts), plan_digest, token, privacy_generation and a claimed recognizers.modulate receipt (started -> words|empty|error, word_count).
  • Failure. If Modulate fails, the marker settles failed_held with a closed failure. The job stays quarantined/failed_held with its audio retained and no result, and it never buys another call.
  • Accounting. Accounting is acoustic (fix(batch): bound worker VAD locates language-guard words that CPU VAD missed #23770, lead ef03d2).
  • Retention. Retention accepts only a running epoch-4 Modulate result for an eligible unit.

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/WordsWithoutVad with Modulate words and worker VAD speech. Another 4 are both-empty empty_asr, and 2 are unrelated.

GCP_AGENT_TIER=ro-prod backend/scripts/batch_pipeline_speech_redrive.py \
  --stage prod --owner-env <OWNER_ENV> \
  --quarantined-after <T0Z> --quarantined-before <T1Z> \
  --unit-ids-file <that owner's IDs from the 30> --cohort-file <new path> \
  --expect-count N --expect-speech-count N \
  --paid-epoch 4 --language-guard-repair [--server-flags-file <serving env json>]
  • Expected across all owners: 30 eligible (16 + 14), with no spend. Per-owner output:
    • 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.
  • Refused: the 4 both-empty and the 2 unrelated. Passing any of their IDs gives {"outcome":"refused","reason":"unit_not_eligible"}, so keep them out of the ID files.
  • Other possible refusals:
    • 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.
  • Apply (prod-operator), with the same flags plus --apply --source-census-sha256 <census> --approve-plan-sha256 <plan_sha256>. Run --apply-limit 1 first 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...:

  1. The 60s cap read the declared duration, while decoded audio may run 0.1s longer. The repair now refuses (repair_budget_held, before start and spend) when decoded audio is over 60s, and it admits sync_allowed on the decoded duration.
  2. words_repair_eligible could raise KeyError inside the retention transaction for a job missing audio_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

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.py through pytest: 2481 passed, 5 skipped. After the a3af50 widening, test_batch*.py + test_silent_batch_redrive.py passed 2322 with 2 skipped. After the Luna fixes, test_batch*.py + test_silent_batch_redrive.py passed 2316 with 2 skipped.
  • black --check is clean.
  • No production read, deploy, config change or paid call was made.

Tests

In backend/tests/unit/test_batch_language_recovery.py (synthetic, deterministic). settled_words_without_vad reproduces 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:
    • repair gives recovered, and a replay gives already_applied;
    • the marker is epoch 4/modulate/completed with its Modulate receipt;
    • the spent recovery is unchanged;
    • the typed contract holds and accounting is acoustic;
    • exactly one extra Modulate call is made, and Soniox is never called again.
  • test_words_repair_refuses_every_other_unit_without_spend[no_receipt|subframe_receipt|independent_plan|both_empty|soniox_error|epoch4_marker]: each gives repair_not_eligible (or ProjectionBlocked for 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 gives failed_held, receipted empty/0, with closed failure response_validation/empty_asr. The job stays quarantined/failed_held with audio retained and no deletes. A replay makes no call, and a new plan raises ProjectionBlocked.
  • 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 gives independent_plan_required, and epoch 3 still gives already 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:

  • The checked_job stub signature now accepts repair.

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

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

chatgpt-codex-connector Bot commented Oct 27, 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-27T04:02:17.228102Z c81513a 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.

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

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

Comment on lines +202 to +204
'--language-guard-repair',
action='store_true',
help='Lead 7fa3d2: one Modulate call per guarded words unit, epoch 4; exact unit IDs required',

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 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]>
Base automatically changed from op1/words-without-vad-worker-evidence to main October 27, 2026 03:42
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]>
@Git-on-my-level
Git-on-my-level merged commit dda3040 into main Oct 27, 2026
61 checks passed
@Git-on-my-level
Git-on-my-level deleted the op1/language-guard-words-repair branch October 27, 2026 13:58
Git-on-my-level added a commit that referenced this pull request Oct 27, 2026
 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.
Git-on-my-level added a commit that referenced this pull request Oct 27, 2026
…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
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