Skip to content

test(batch): pin projection discovery read budget and gate batch owners - #24786

Merged
Git-on-my-level merged 1 commit into
mainfrom
claude/project-thread-3azebv
Nov 6, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
claude/project-thread-3azebv

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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:

  • Read-budget contract tests (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.
  • CODEOWNERS entries that route batch pipeline, job store, and batch worker chart changes to a named reviewer. These paths drive most of the unit cost, and concurrency or discovery changes there multiply reads across every serving instance.

Product invariants affected

none

How it was verified

  • pytest tests/unit/test_batch_pipeline_read_budget.py tests/unit/test_batch_pipeline_projection_discovery.py from backend/ on Python 3.11: 40 passed. The new file is 4 tests; the discovery file's 36 are unchanged.
  • scripts/pr-preflight --suggest run on the branch; the selected invariants were reviewed.
  • Not run: the full backend unit suite and make preflight. Those are left to CI.
  • No runtime path changed, so no prod read-rate effect is claimed.

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

View guided diff Turn on auto-fix

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
@Git-on-my-level Git-on-my-level self-assigned this Nov 6, 2026

@cubic-dev-ai cubic-dev-ai 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.

2 issues found across 2 files

Confidence score: 4/5

  • .github/CODEOWNERS only covers the exact batch_pipeline.py path, leaving sibling batch-policy modules outside the same ownership gate. Use /backend/config/batch_pipeline*.py.
  • test_batch_pipeline_read_budget.py can pass despite unexpected per-row store reads, so it may not catch a regression in the read budget. Use spec_set or 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')

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

Comment thread .github/CODEOWNERS
/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

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

@Git-on-my-level
Git-on-my-level merged commit 517273b into main Nov 6, 2026
64 checks passed
@Git-on-my-level
Git-on-my-level deleted the claude/project-thread-3azebv branch November 6, 2026 12:11
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.

2 participants