Skip to content

fix(batch): read each projection-finish stamping page in one BatchGet - #25287

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/stamp-page-batch-read
Nov 14, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/stamp-page-batch-read

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Why

The one-time projection-finish stamping pass from #25225 is running in production now (started 2026-11-14 09:44Z, about 527k rows). It reads each row of a 200-row page with its own transactional get, so a page takes about 17 s from the operator host and the pass would finish around 23:15Z. BATCH_PROJECTION_FINISH_BACKOFF_ENABLED stays off until the pass completes, and that lever is the largest Firestore read cut scheduled for today (SCA-2173, SCA-2175).

What changed

  • stamp_page reads the page with one transactional get_all (BatchGet) instead of one RPC per row.
  • An empty page issues no BatchGet.
  • The strict Firestore test fixture accepts a whole-document BatchGet as well as the existing folder-membership mask.

What did not change

  • The documents read inside the transaction, so the conflict fence is the same.
  • The checkpoint comparison, the writes, the shared cursor and the completion marker.
  • A row deleted between the page query and the transaction still reads as empty and is skipped, as before.
  • The pass stays resumable and atomic per page, so the running pass can be stopped and restarted from this commit.

Tests

  • tests/unit/test_batch_projection_finish_backfill.py and test_batch_projection_finish_backoff.py: 30 passed. Two new tests: one BatchGet per page inside the transaction; none for an empty page.
  • Every unit file that calls get_all was run with the fixture change. All pass except test_empty_capture_recovery.py, which fails the same 7 tests on an untouched checkout on this host (no ffmpeg).
  • Not measured: page time against production Firestore. The first pages of the restarted pass will show it.

Rollout

Operator script only; no service deploy is needed for the speed-up. Kill switch for the lever itself is unchanged: BATCH_PROJECTION_FINISH_BACKOFF_ENABLED=false.

Known red, not from this change

Backend emulator proofs fails 6 cases in scripts/provider_merge_emulator_test.py (test_pl585_privacy_revoke_between_probe_and_commit_preserves_custody, test_pl584_a_predecessor_settled_after_probe_cannot_be_skipped, each on sim, emulator and postgres). This PR does not touch the provider merge path; see the check on main below.

Failure-Class: none

🤖 Generated with Claude Code

The one-time stamping pass (#25225) read every row of a 200-row page with
its own transactional get. From an operator host that is about 17 s a
page, so the roughly 527k-row production pass was a 12-hour job and the
finish-backoff lever could not be turned on the same day.

Read the page with one transactional get_all instead. The documents read,
the transaction's conflict fence, the writes and the shared cursor are
unchanged; a row deleted between the page query and the transaction still
reads as empty and is skipped. An empty page issues no BatchGet.

The strict Firestore test fixture now models a whole-document BatchGet as
well as the folder-membership mask.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T10:55:49.525666Z e6a610e PR opened
ℹ️ 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.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

RECOMMENDATION: APPROVE. This is a technical review comment, not a GitHub approval event: GitHub rejected the APPROVE action because the connected reviewer account is also the PR author.

Reviewed head e6a610e.

  1. Yes. With google-cloud-firestore 2.20.0, DocumentReference.get(transaction=tx) routes through Transaction.get to Client.get_all([ref], transaction=tx); this change calls that same Client.get_all path with the full page and same transaction. Both register the same documents with the same transaction, so the read/conflict set is unchanged (lock acquisition timing can differ). The function reads the marker and page before staging any update or set. See the pinned transaction implementation, pinned client implementation, and Firestore contention/transaction semantics.

  2. Yes. In the pinned Python client, BatchGet maps both a found document name and a missing document name back to the original input DocumentReference; therefore snapshot.reference.path == ref.path for both. Missing documents produce snapshots with exists=False and to_dict() is None. projection_page supplies distinct document IDs, so the documented duplicate-reference elision does not omit a requested ref. On a successful completed RPC there is no expected missing map entry. If an RPC/protocol error prevents a complete result, failing before writes and leaving the cursor unchanged is the safe retryable outcome. See the pinned parser and BatchGet API contract.

  3. No fixed 200-read cap. Firestore documents a 10 MiB API request limit and 270-second transaction lifetime (plus 60-second idle expiry); transaction docs also list a 20-second lock deadline. The BatchGet request here carries 200 document names, and the commit stages at most 200 row updates plus the marker. Those general size/time limits still apply to unusually large rows or a slow/contentious page, but 200 itself is not a documented read-count limit. See Firestore quotas and transaction failure limits.

  4. Yes. The fixture's existing folder-membership BatchGet caller still passes field_paths=['folder_id']; None now models the SDK's ordinary full-document read for this new caller. The narrowed fixture continues rejecting unsupported non-null masks.

  5. Yes. stamp_page stages the clock updates and advances the shared after cursor / completion marker in the same transaction. A committed page is skipped on restart; an interrupted or failed page leaves the checkpoint unchanged and is retried. This matches the runbook's per-page atomicity contract.

The focused pytest command could not run in this environment because the selected Python interpreter has no pytest module; the PR description reports 30 passing tests. No production action was taken.

@Git-on-my-level
Git-on-my-level merged commit c13e510 into main Nov 14, 2026
76 of 81 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/stamp-page-batch-read branch November 14, 2026 13:40
Git-on-my-level added a commit that referenced this pull request Nov 14, 2026
…tegration (#25307)

## Why
`BATCH_PROJECTION_FINISH_BACKOFF_ENABLED` is being turned on for prod
backend-integration on the push captain's go (SCA-2222, SCA-2166,
2026-11-14), applied by the release executor as a config-only revision.
Repo config did not declare the lever at all, so the next deploy
rendered from the repo would drop it. That is what happened to five
hand-set Firestore lever values at 13:45Z today (fixed by #25277). This
PR makes the repo say what production is meant to run.

Both conditions of the runbook's re-enable bar that could be met from
code are met:
- the one-time stamping pass completed at 12:46Z (read-only preview:
complete, 0 missing), using #25225 and #25287;
- the finish counters export from backend-integration since Train 1
(#25291): `omi_batch_projection_finish_reads_total` read 46,459 in ten
minutes at 16:44Z with `omi_batch_projection_finish_completed_total` at
0.

## What changed
- `backend/deploy/runtime_env/prod.overlay.yaml`:
`BATCH_PROJECTION_FINISH_BACKOFF_ENABLED: 'true'` (category rollout) for
`backend-integration`, which runs the finish sweep, and for
`backend-sync`, which can reach the same sweep through its authenticated
reconcile and batch metrics routes (review SCA-2270; its finish counters
read 0 in production today, so this is consistency, not a second
saving).
- `backend/deploy/runtime_env.yaml`: regenerated.
- `config/deployment-setting-classification.json`: the binding is
classified as config.
- `backend/docs/feature-flag-registry.md`: regenerated.
- `backend/tests/unit/test_render_backend_runtime_env.py`: the pin moves
from "absent everywhere" to "true on prod backend-integration and
backend-sync, absent on every other service and environment".

## What did not change
No code path. No other service: prod backend and backend-sync-backfill
render an empty `BATCH_PIPELINE_WORKER_AUDIENCE`, so the authenticated
reconcile route that reaches the sweep cannot be invoked on them. No dev
environment. The code default stays off.

## Tests
`tests/unit/test_render_backend_runtime_env.py` and
`tests/unit/test_backend_runtime_env_validator.py`: 364 passed. Both
generator `--check` commands pass.

## Rollout
Rides the next backend train; until then the release executor's
config-only revision carries the value. Proof after the flip, posted on
SCA-2173: finish reads per ten minutes before and after, completions,
fresh commits per ten minutes not below half the 15:12-15:42Z baseline,
and no rise in over-SLA or unfinished projections.

Kill switch: `BATCH_PROJECTION_FINISH_BACKOFF_ENABLED=false` restores
the legacy finish page immediately.

## Product invariants affected

- INV-MEM-4

Named because `backend/deploy/runtime_env.yaml` changes. This PR adds
one batch-projection binding for backend-integration and touches no
memory intake, consolidation, promotion or privacy TTL setting;
INV-MEM-4 behaviour is unchanged.

Failure-Class: FC-deploy-literal-reverts-operator-value

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Git-on-my-level added a commit to Git-on-my-level/omi that referenced this pull request Nov 14, 2026
…tegration

The finish-backoff lever is being turned on for backend-integration, the
only service that runs the projection finish sweep, now that the one-time
stamping pass has completed (BasedHardware#25225, BasedHardware#25287) and the finish counters
export from that service (BasedHardware#25291). Repo config did not declare the lever
at all, so the next deploy would have dropped a hand-set value.

Declare BATCH_PROJECTION_FINISH_BACKOFF_ENABLED=true for prod
backend-integration only, regenerate runtime_env.yaml, and move the
renderer pin: present and true on prod backend-integration, absent on
every other service and environment.

Kill switch: BATCH_PROJECTION_FINISH_BACKOFF_ENABLED=false.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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