Skip to content

fix(batch): advance projection scans past blocked ready results - #22194

Merged
Git-on-my-level merged 7 commits into
mainfrom
lane/sol-projector-deadlock
Oct 18, 2026
Merged

Git-on-my-level merged 7 commits into
mainfrom
lane/sol-projector-deadlock

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

The projector repeatedly selected the oldest 100 unfinished results. When those rows were ready but waiting for pending siblings outside that page, neither assignment nor asynchronous follow-ups could reach the work needed to complete them.

Advance independent, bounded keyset cursors for assignment and follow-ups, using committed timestamp plus document ID and wrapping at exhaustion. Retain each follow-up page until all its queued entries launch. Transactional privacy, predecessor ordering, all-sibling completion, replay and paid-intent fences stay unchanged.

Ships on. Kill switch: BATCH_PIPELINE_PROJECTION_PAGINATION_ENABLED=false restores first-page discovery. The query uses the existing declared prod/dev results index (projection_state, committed_at, __name__); no new index or production index changes.

Validation: real Firestore emulator regression with 101 ready results blocked on a pending sibling beyond the first page, plus later actionable content; independent follow-up progress, restart/replay, timestamp ties and deleted cursor anchor. Existing emulator tests cover ordering, concurrent replay, privacy and atomic sibling completion. Passed: 75 real-Firestore emulator tests, 546 selected unit/query-contract checks, and 119 focused scheduler/privacy/paid-recovery/follow-up tests (file-isolated). All local tests ran at nice 19 through the workspace heavy-command gate. Production index metadata was checked through ro-prod: the exact existing results composite is READY. The hermetic pre-deploy check also passes all 320 tests, and the serving-only cohost declaration passes. Backend typecheck reports zero errors. The ordinary pre-push hook remains enabled.

After deployment, the existing accepted-work serving loop automatically rediscovers committed pending/persisted/ready debt. No one-time kick is needed for this deadlock. Genuine quarantine_held debt still requires ordinary fenced recovery; this change never resets a paid intent.

Failure-Class: new

Product invariants affected

  • INV-MEM-4: runtime declarations add only the projection-discovery kill switch. Canonical intake, consolidation admission, and outbox acknowledgement rules are preserved.

View guided diff Turn on auto-fix

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-18T16:28:28.560772Z c5ad517 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: 2ab9352972

ℹ️ 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 59 to 61
segments = await run_blocking(db_executor, self.candidates)
if self.after in segments:
offset = segments.index(self.after) + 1

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 Badge Serialize concurrent follow-up scheduling

When the serving supervisor overlaps with POST /reconcile or GET /metrics, both invocations use the same cached projector and can enter schedule() while pending is empty. Because the page query and queue replacement span an await without a lock, one invocation can fetch page N, another can advance discovery to page N+1, and then the second self.pending = ... can discard most of page N before it launches. Those durable rows are not retried until the cursor wraps and can starve under sustained backlog, recreating the blocked-result delay this change is meant to remove; serialize scheduling or merge each fetched page into the existing queue.

Useful? React with 👍 / 👎.

Comment on lines 46 to 49
return [
sid
for sid in store.store.projection_pending(limit=100)
for sid in self.discovery.next(limit=100)
if (store.ref('results', sid).get().to_dict() or {}).get('projection')

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 Badge Advance discovery only after candidate reads succeed

If any per-result get() in this comprehension fails after discovery.next() successfully returns, the cursor has already advanced past the entire page even though no candidates are scheduled. The next reconciliation therefore starts on a later page instead of retrying the failed one; with a large or continuously growing backlog, actionable persisted receipts on that page can be delayed indefinitely. Commit the cursor only after all candidate reads and queue setup succeed, or restore the previous cursor when candidate construction raises.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit e1fedc6 into main Oct 18, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/sol-projector-deadlock branch October 18, 2026 16:58
Git-on-my-level added a commit that referenced this pull request Oct 19, 2026
## Why

The two-lane rollout found its capacity and ordering failures in slow
production ramps:
- **Serial per-owner burst:** a 365-upload burst on one owner drained at
4.8/min.
- **Summaries behind transcription:** summaries queued behind
transcription on a shared executor.
- **Provider exhaustion:** batch STT exhaustion with Parakeet at its HPA
max produced empty_asr quarantines and recovery tails.
- **Revision replacement:** it killed un-awaited work.

This simulation reproduces each of them in seconds, locally and in the
existing unit CI. A fix shows up as a verdict change before a ramp.

## What

`backend/testing/pipeline_sim/` is a deterministic discrete-event
simulation on a virtual clock.

**Real code, unmodified, on `StrictFirestore`:**
- `admit`, `Scheduler`, `Pump.run`
- `PipelineWorker` (window packing, padded retry, empty-ASR
classification)
- `OrderedMerge`, `Serving.reconcile`
- `QuarantineRecovery.sweep` / `_dispatch` / `recover`, `RecoveryStore`
- the privacy fence `assert_batch_write_allowed`

`Pump` and `Serving` see a virtual `time` through module-attribute
patches that are restored after each run.

**Small named models, each citing the code it mirrors:**
- Parakeet capacity (replicas × concurrency, HPA max, empty and failure
rates, exhaustion windows)
- the paid Modulate fallback (counted)
- Cloud Tasks
- three Firestore query leaves
- the privacy purge
- the `admission.authorize` checks
- projection and first summary
- the shared `sync_executor`
- the legacy per-owner sequencer
- revision drain

**Scorer:** emits a fleet_gate-shaped sample with the same keys the ops
gate's `verdict()` reads, plus a verdict:
- completion
- accept→projection p50/p95
- terminal unrecovered speech
- quarantine→projection p95 with n
- first-summary breaches
- obligations over 15m
- paid calls

**CLI:** `python -m testing.pipeline_sim run <scenario> [--seed N]
[--json] [--param k=v]`.

## Scenarios (seed 1)

| scenario | verdict | key numbers |
|---|---|---|
| `burst_owner_serial_sequencer` K=1 | FAIL `obligation_over_15m` | p95
≈ 9,000 s, one active job per owner |
| same, K=32 | PASS | p95 528 s |
| `mixed_fleet_steady` | PASS | p95 27 s |
| `provider_exhaustion_window` (30 min of empty ASR) | FAIL
`quarantine_projection_p95_over_5m` | 132 quarantines, 132 paid calls,
p95 1,512 s |
| `revision_replacement_mid_run`, background summaries | FAIL
`first_summary_deadline` | 4 units killed |
| same, request-scoped summaries | PASS | nothing request-scoped lost |
| `stale_finalize_targets` | PASS | deleted targets excluded, 0 paid
calls after the fence |
| `privacy_blocked_users` | PASS | 409s, 0 paid calls, reported
separately |
| `summary_behind_transcription` shared | FAIL | 53% breach |
| same, isolated pool | PASS | 0 breaches |

The tests pin verdicts and orderings, not absolute latencies, which
depend on the profiles. The same seed gives byte-identical JSON.

## Findings in real code (for the owners; not changed here)

1. **Recovery dispatch is capped per serving instance.**
`QuarantineRecovery.sweep` breaks after one dispatch per queried cohort
(`queued` included). When all owners are admitted, that means one
dispatch per `Serving` tick (20 s), so about 3 per minute per
integration instance. There is no leader, so the fleet rate scales with
instances. A quarantine burst faster than that grows the
quarantine→projection tail.
2. **`skipped_oversize` units that get an empty Modulate response settle
`failed_held`, with no automatic exit.** The terminal-empty disposition
requires `padded_empty(job)`, and `speech_redrive` excludes
`padded_skipped`.

## Scope

- Test and harness code only. No production behavior change, no new
workflow.
- A `batch_pipeline_capacity_sim` workflow contract selects the sim
tests when the scheduler, pump, serving, merge, recovery, disposition,
admission or worker change.

## Verification

Local, m5, `nice -n 19`, on `origin/main` e1fedc6 (after #22194):
- The 3 sim files: 29 passed in 5.8 s, also under `test.sh` with the
fast-unit CPU guard (scenarios run in module fixtures).
- With `test_workflow_contracts.py` and
`test_backend_unit_selector_output.py` added: 128 passed.
- `check_workflow_contracts.py` passes.
- pre-commit is clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


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