Skip to content

fix(batch): re-seed a hinted shard activation right after the admission commits - #24864

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/pipeline-frontier-reseed
Nov 7, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/pipeline-frontier-reseed

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What

Follow-up to #24855 (lead2 c54915 / 45d52f). #24855 reads the owner-activation service frontier outside the admission transaction, to stop the sync 503 storm. Luna correctness found the cost: a pull committing meanwhile can leave a rejoining shard below the true frontier, so it gets served ahead of others by about one pull batch.

This PR restores the bound without bringing back a transactional lock on a hot control doc:

  • activate() stamps p{prio}_frontier_hint with the activation time and notes (shard, priority) on the Firestore transaction view.
  • After the admission commits, FirestoreStore.run calls reseed_hinted_activation. It re-reads the frontier with no transaction, then lifts service = max(own, frontier) in a one-attempt transaction on the shard's OWN control doc, only while the marker is set. RPC deadlines are 1.5 s with no retries, because the upload ack waits on it. Failures are only logged.
  • A pull within 30 s of activation that beats the re-seed lifts the shard itself from a fresh frontier read. A later pull only consumes the marker, so waiting its turn is never charged to the joiner.

Same lever as #24855: admission_frontier_hint set to 0 stamps nothing. Postgres, sim and memory stores have no note hook, so their behavior is unchanged.

Rejected alternative

A pure pull-time clamp (design b) lifted the joiner at its first pull. That charges it for service other shards earned while it waited: test_shards_weight_service_by_active_owner_count_and_preserve_global_priority drifted from 6/6/6 to 5/6/7. This PR keeps that test green.

Review

One Luna round (correctness + prod safety) found two blockers, both fixed in the second commit:

  1. A pull consuming the marker before the re-seed kept the stale credit. Fixed with the 30 s pull-lift window.
  2. The re-seed was unbounded before the upload ack. Fixed: one attempt, 1.5 s deadlines, no retries.

Tests

  • tests/unit/test_batch_admission_frontier_hint.py: 16 tests covering the re-seed lift, no-ops once the marker is consumed or gone, never lowering credit, the activation note behind the lever, a pull beating the re-seed, a late pull consuming only, the post-commit ordering, and isolation from exceptions.
  • Query-shape registry: reseed_hinted_activation and FirestoreStore.run are registered as covered by the existing service_frontier driver, with timeout classified shape-neutral.
  • 745 passed across the scheduler, query shapes, contention and live suites.

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 2 commits November 7, 2026 22:02
…on commits

#24855 reads the owner-activation service frontier outside the admission
transaction; a pull committing meanwhile could leave a rejoiner below the
frontier (served ahead by up to a pull batch). Activation now stamps
p{prio}_frontier_hint and notes the shard; after the admission commits the
store re-reads the frontier (no transaction) and lifts the shard in a small
transaction on its own control doc only while the marker is set. A pull that
reaches the shard first just consumes the marker, so waiting is never charged
to the joiner (a pull-time lift did, drifting the fairness test 6/6/6 to 5/6/7).
Same lever: admission_frontier_hint 0 stamps nothing.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of the post-commit re-seed (one Luna round, two blockers):
- A pull that consumed the activation marker before the re-seed landed kept the
  stale credit. The marker is now the activation time; a pull within 30 s of it
  lifts the shard from a fresh frontier read, later pulls only consume it.
- The re-seed ran unbounded before the upload is acknowledged. It now uses one
  transaction attempt and 1.5 s RPC deadlines with no retries (service_frontier
  gains an optional timeout, classified shape-neutral in the query driver).

Failure-Class: none

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

chatgpt-codex-connector Bot commented Nov 7, 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-07T15:42:50.405054Z e4a3fbd 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.

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

3 issues found across 7 files

Confidence score: 3/5

  • In batch_pipeline_store.py, the 1.5-second deadline and no-retry policy do not cover transaction begin or commit, so those calls can still hold up the acknowledgment. Apply explicit timeout and retry bounds to them.
  • In batch_pipeline_store.py, reseeding runs synchronously in run(), so the acknowledgment waits for each hinted activation’s sequential RPCs. Move reseeding off the acknowledgment path.
  • In CONTRACT.md, the residual-gap explanation points to the wrong window: pulls before the fresh frontier read are included, and pulls after the marker is set consume it. Clarify that the gap is between the frontier read and setting the marker.

You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

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/utils/batch_pipeline/CONTRACT.md">

<violation number="1" location="backend/utils/batch_pipeline/CONTRACT.md:88">
P3: The residual gap is misplaced. Pulls committed before the fresh frontier read are seen by that read, and a pull on this shard after the marker is set consumes it and lifts. The uncovered window is between the frontier read and the lift commit, so the doc should name that interval.</violation>
</file>

<file name="backend/database/batch_pipeline_store.py">

<violation number="1" location="backend/database/batch_pipeline_store.py:283">
P2: The reseed runs synchronously inside `run()`, so the upload acknowledgment waits for every reseed RPC. This contradicts the PR goal of not holding up the acknowledgment. Each hinted activation adds sequential round trips, up to two 1.5s-bounded calls plus transaction begin and commit. Move the reseed off the acknowledgment path, for example to a background task, or confirm the added latency is acceptable.</violation>

<violation number="2" location="backend/database/batch_pipeline_store.py:981">
P2: The 1.5s deadline and no-retry guarantee cover only the query and the `get`. Transaction begin and commit still use SDK default timeouts and retries, so the reseed can block the acknowledgment path longer than documented. Bound these calls explicitly, or correct the PR description and the code comment that says the operation is bounded.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

view.flush()
return result

result = self._run_committed(client, commit, last_view)

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: The reseed runs synchronously inside run(), so the upload acknowledgment waits for every reseed RPC. This contradicts the PR goal of not holding up the acknowledgment. Each hinted activation adds sequential round trips, up to two 1.5s-bounded calls plus transaction begin and commit. Move the reseed off the acknowledgment path, for example to a background task, or confirm the added latency is acceptable.

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/database/batch_pipeline_store.py, line 283:

<comment>The reseed runs synchronously inside `run()`, so the upload acknowledgment waits for every reseed RPC. This contradicts the PR goal of not holding up the acknowledgment. Each hinted activation adds sequential round trips, up to two 1.5s-bounded calls plus transaction begin and commit. Move the reseed off the acknowledgment path, for example to a background task, or confirm the added latency is acceptable.</comment>

<file context>
@@ -274,6 +280,19 @@ def commit(transaction):
             view.flush()
             return result
 
+        result = self._run_committed(client, commit, last_view)
+        for key, priority in sorted(last_view[0].hinted_activations) if last_view else ():
+            try:
</file context>

)
return True

return lift(client.transaction(max_attempts=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: The 1.5s deadline and no-retry guarantee cover only the query and the get. Transaction begin and commit still use SDK default timeouts and retries, so the reseed can block the acknowledgment path longer than documented. Bound these calls explicitly, or correct the PR description and the code comment that says the operation is bounded.

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/database/batch_pipeline_store.py, line 981:

<comment>The 1.5s deadline and no-retry guarantee cover only the query and the `get`. Transaction begin and commit still use SDK default timeouts and retries, so the reseed can block the acknowledgment path longer than documented. Bound these calls explicitly, or correct the PR description and the code comment that says the operation is bounded.</comment>

<file context>
@@ -934,14 +953,48 @@ def committed_walk(query):
+        )
+        return True
+
+    return lift(client.transaction(max_attempts=1))
+
+
</file context>

logged). The marker is the activation time: a pull that beats the re-seed
within 30 s lifts the shard itself from a fresh frontier read; a later pull only
consumes it (`consume_frontier_hint`), so waiting its turn is never charged to
the joiner. Residual gap: pulls committed between the admission commit and that

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The residual gap is misplaced. Pulls committed before the fresh frontier read are seen by that read, and a pull on this shard after the marker is set consumes it and lifts. The uncovered window is between the frontier read and the lift commit, so the doc should name that interval.

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/utils/batch_pipeline/CONTRACT.md, line 88:

<comment>The residual gap is misplaced. Pulls committed before the fresh frontier read are seen by that read, and a pull on this shard after the marker is set consumes it and lifts. The uncovered window is between the frontier read and the lift commit, so the doc should name that interval.</comment>

<file context>
@@ -77,10 +77,16 @@ record. Live transcription is a preview; the batch result is the record.
+  logged). The marker is the activation time: a pull that beats the re-seed
+  within 30 s lifts the shard itself from a fresh frontier read; a later pull only
+  consumes it (`consume_frontier_hint`), so waiting its turn is never charged to
+  the joiner. Residual gap: pulls committed between the admission commit and that
+  read (milliseconds). Earned credit is never lowered (`max(own, frontier)`).
   A pull stops at a claimed fresh shard only on a pump's first lane. Its other
</file context>

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

ℹ️ 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".

)
return True

return lift(client.transaction(max_attempts=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.

P1 Badge Bound the reseed transaction's lifecycle RPCs

When Firestore is slow or unavailable, this synchronous post-commit step can still delay the upload acknowledgment by tens of seconds despite the 1.5-second read deadlines. In the pinned Firestore 2.20.0 SDK, the transactional decorator invokes begin, commit, and rollback without timeout or retry overrides (SDK implementation); those RPCs retain 60-second timeout/retry defaults (transport configuration). max_attempts=1 only limits transaction attempts, not these RPC policies. Bound the entire reseed lifecycle or remove it from the acknowledgment's critical path.

Useful? React with 👍 / 👎.

Comment on lines +86 to +90
self.doc, self.tx = doc, SimpleNamespace(update=Mock())

def collection(self, name):
assert name == 'batch_pipeline_dev_control'
return SimpleNamespace(document=lambda key: SimpleNamespace(get=lambda transaction=None, **kw: _Snap(self.doc)))

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 Use the required strict Firestore transaction fixture

The new reseed tests exercise document-reference reads and transaction updates through an unrestricted Mock, so they cannot detect Firestore ordering or constraint violations; replacing the transactional decorator with an identity function also bypasses the SDK lifecycle entirely. backend/AGENTS.md explicitly requires StrictFirestore for tests with these operations and emulator coverage for retry/contention behavior. Replace this permissive fake with the prescribed fixture and cover the transaction-lifecycle bounds through an appropriate SDK/emulator test.

AGENTS.md reference: backend/AGENTS.md:L232-L232

Useful? React with 👍 / 👎.

Comment on lines +287 to +288
except Exception as error: # Best effort: the admission already committed.
logger.warning(

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 Record reseed failures through shared fallback telemetry

When reseeding fails, admission continues without the fairness correction, but this new degraded path emits only a warning. Consequently, the shared fallback metrics cannot distinguish healthy admissions from those proceeding with potentially stale service credit. backend/AGENTS.md requires new fallback paths to call utils.observability.fallback.record_fallback; emit a bounded degraded outcome here in addition to the diagnostic log.

AGENTS.md reference: backend/AGENTS.md:L322-L322

Useful? React with 👍 / 👎.

…parity)

The note hook exists only on the Firestore transaction (only Firestore has the
locked frontier query); make it private so the jobstore protocol-parity surface
does not require Postgres/Sim to grow a no-op.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

ℹ️ 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 +974 to +977
if not control.get(marker):
return False
transaction.update(
reference, {service_key: max(control.get(service_key, 0.0), frontier), marker: firestore.DELETE_FIELD}

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 Bind reseeding to the original activation marker

If a shard is pulled, drained, and reactivated between this reseed's frontier query and its document read, the truthiness check accepts the newer activation's marker. The older reseed can then delete that marker using a frontier sampled before the newer admission, causing both the newer admission's reseed and its first pull to skip the correction. This silently preserves the stale service credit this change is intended to repair. Carry the activation's marker value alongside the noted shard and priority, and update only if the stored marker still matches that activation.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 3d3e963 into main Nov 7, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/pipeline-frontier-reseed branch November 7, 2026 15:52
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