Repository navigation
test(batch): pin projection discovery read budget and gate batch owners - #24786
Merged
Merged
Conversation
Keyset discovery is the largest Firestore read amplifier in the batch pipeline: every serving instance re-reads the same oldest-first page each tick. Add contract tests that pin the per-tick query count (one page query plus one startup head read), forbid per-row document reads on the discovery path, and require that striped instances start on distinct pages. Route batch pipeline, job store, and worker chart changes to a named owner in CODEOWNERS. These paths drive most of the unit cost, and concurrency or discovery changes here multiply reads across every serving instance. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_017CeWy2AS88FvyqrGM6WcMM
There was a problem hiding this comment.
2 issues found across 2 files
Confidence score: 4/5
.github/CODEOWNERSonly covers the exactbatch_pipeline.pypath, leaving sibling batch-policy modules outside the same ownership gate. Use/backend/config/batch_pipeline*.py.test_batch_pipeline_read_budget.pycan pass despite unexpected per-row store reads, so it may not catch a regression in the read budget. Usespec_setor assert the complete call list.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/tests/unit/test_batch_pipeline_read_budget.py">
<violation number="1" location="backend/tests/unit/test_batch_pipeline_read_budget.py:21">
P2: This contract test does not actually reject arbitrary per-row store reads. Constrain the mock with `spec_set` or assert the complete call list so unexpected store methods fail the test.</violation>
</file>
<file name=".github/CODEOWNERS">
<violation number="1" location=".github/CODEOWNERS:31">
P2: `/backend/config/batch_pipeline.py` is an exact match, so sibling batch-policy modules remain unowned. Use `/backend/config/batch_pipeline*.py` to keep these pipeline controls under the same gate.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
|
||
|
|
||
| def _page_store(oldest: float = 1000.0): | ||
| store = Mock(name='store') |
There was a problem hiding this comment.
P2: This contract test does not actually reject arbitrary per-row store reads. Constrain the mock with spec_set or assert the complete call list so unexpected store methods fail the test.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_batch_pipeline_read_budget.py, line 21:
<comment>This contract test does not actually reject arbitrary per-row store reads. Constrain the mock with `spec_set` or assert the complete call list so unexpected store methods fail the test.</comment>
<file context>
@@ -0,0 +1,76 @@
+
+
+def _page_store(oldest: float = 1000.0):
+ store = Mock(name='store')
+ store.projection_page.side_effect = lambda *, limit, after, **kw: (
+ ['row'] * limit,
</file context>
| /backend/utils/batch_pipeline/** @Git-on-my-level | ||
| /backend/database/batch_pipeline*.py @Git-on-my-level | ||
| /backend/database/jobstore/** @Git-on-my-level | ||
| /backend/config/batch_pipeline.py @Git-on-my-level |
There was a problem hiding this comment.
P2: /backend/config/batch_pipeline.py is an exact match, so sibling batch-policy modules remain unowned. Use /backend/config/batch_pipeline*.py to keep these pipeline controls under the same gate.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .github/CODEOWNERS, line 31:
<comment>`/backend/config/batch_pipeline.py` is an exact match, so sibling batch-policy modules remain unowned. Use `/backend/config/batch_pipeline*.py` to keep these pipeline controls under the same gate.</comment>
<file context>
@@ -21,3 +21,12 @@
+/backend/utils/batch_pipeline/** @Git-on-my-level
+/backend/database/batch_pipeline*.py @Git-on-my-level
+/backend/database/jobstore/** @Git-on-my-level
+/backend/config/batch_pipeline.py @Git-on-my-level
+/backend/charts/batch-pipeline-worker/** @Git-on-my-level
</file context>
Suggested change
| /backend/config/batch_pipeline.py @Git-on-my-level | |
| /backend/config/batch_pipeline*.py @Git-on-my-level |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by David · project thread
What changed and why
Keyset discovery is the largest Firestore read amplifier in the batch pipeline. Each serving instance re-reads the same oldest-first page each tick, and roughly two-thirds of drain turns end
claim_busy(pipeline limits review, 2026-11-05). This PR adds two things and no runtime behavior change:backend/tests/unit/test_batch_pipeline_read_budget.py). They pin the per-tick query count (one page query plus one startup head read), forbid per-row document reads on the discovery path, keep the legacy kill switch at one query per tick, and require that 40 striped instances start on distinct pages.Product invariants affected
none
How it was verified
pytest tests/unit/test_batch_pipeline_read_budget.py tests/unit/test_batch_pipeline_projection_discovery.pyfrombackend/on Python 3.11: 40 passed. The new file is 4 tests; the discovery file's 36 are unchanged.scripts/pr-preflight --suggestrun on the branch; the selected invariants were reviewed.make preflight. Those are left to CI.Tests
No bug fix; this adds guard tests for the discovery hot path. The contract tests fail if a change re-introduces per-row reads, drops the startup striping, or unbounds the page query.
UI evidence
UI-Evidence: none -- backend tests and CODEOWNERS only
Failure class (fixes)
Failure-Class: none