Repository navigation
SCA-2072: fix(batch): fresh-first pick reads the settle instant; probe reads past one page - #25243
Conversation
…nd restarts Failure-Class: none Co-Authored-By: Claude Fable 5.2 <[email protected]> (cherry picked from commit 86685d1)
…o it Failure-Class: none Co-Authored-By: Claude Fable 5.2 <[email protected]> (cherry picked from commit d985b1f)
…st one page A ready fresh provider row without ready_at could never pass an unready earlier fresh row: the pick measured its wait only from ready_at, and the probe saw 32 rows. 2026-11-13: 15 owners with a vendor-held fresh unit in front committed nothing, 7,784 ready fresh units. The pick now uses _ready_since, and the probe reads up to four pages while a full page holds no ready row. The newest-commits discovery read records its fallback. Failure-Class: FC-backlog-release-shares-lane-with-fresh-work Co-Authored-By: Claude Fable 5.2 <[email protected]>
The Firestore query-shape registry covers fresh_pending; a separate paging helper was an unregistered querying function. Same behaviour. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Review round 1: a probe of several pages is not one view, so a fresh row admitted behind its cursor could be passed by a later one. The pick from such a probe is bound to the owner revision the strict transaction saw. One fallback log per failed newest-commits read instead of two. Failure-Class: FC-backlog-release-shares-lane-with-fresh-work Co-Authored-By: Claude Fable 5.2 <[email protected]>
…tches Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ready row Rollout lead's ruling after review round 2: the probe paging carried an open consistency finding and is not what unblocked owners. The stores and the query go back to main. The settle-instant pick stays. A full probe page with no ready row is now logged so the one-page limit is visible. Co-Authored-By: Claude Fable 5.2 <[email protected]>
#25224 and #25226 each added a name; the merged file declared 277. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… probe line logs Review of ebd1af0: the wait is the longest among ready rows on the page and the row picked is the earliest ready one, so a provider row's settle instant can make an earlier ready row (a GPU row included) the one picked. The log line is per commit attempt, not per drain. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Nothing drained such an owner again: the merge writes no hold marker for a held-backlog head and the global ready page is full of held backlog rows. 2026-11-13: 23 owners, about 3,400 ready fresh rows, no commits. The merge now writes the existing durable marker when a call commits nothing while ready fresh rows sit on the probe page, or when a drain spends its commit budget with such rows left. release_hold keeps the marker until a drain finds none. Fenced owners are not marked. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… re-offer marker Rollout lead's conditions for folding the re-offer into this PR: BATCH_PIPELINE_FRESH_REOFFER_MARKER_ENABLED (unset = on), one log line per marker written for this reason, and a bound so an owner whose ready fresh row never commits is not re-offered on every maintenance pass for good. Co-Authored-By: Claude Fable 5.2 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50ec632a5f
ℹ️ 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".
| marked = self._fresh_marked.get(key) | ||
| if marked is not None and time.monotonic() - marked < FRESH_REOFFER_MARK_SECONDS: | ||
| return |
There was a problem hiding this comment.
Invalidate the marker cache when releasing an owner's hold
If maintenance clears an owner's marker and another drain needs to re-mark that owner within 30 seconds, this cached timestamp suppresses the write even though the durable marker is now false. release_hold never invalidates _fresh_marked. For an owner whose fresh rows are hidden behind the held-backlog global page, this can lose the only maintenance wake after a budget-limited drain or a drain inside the head wait. Invalidate the cached entry when clearing the marker rather than treating the timestamp as proof that the marker still exists.
Useful? React with 👍 / 👎.
| wait; only the recovered unit also passes the catch-up depth hold. The | ||
| body, late marking and chain are the same as every other commit.""" | ||
| key = owner_key(owner_id) | ||
| self._fresh_waiting.discard(key) |
There was a problem hiding this comment.
Preserve the re-offer marker when the fresh probe fails
When maintenance re-offers a marked owner and fresh_pending raises a transient GoogleAPICallError, the existing exception handler substitutes an empty page. Because commit_next now unconditionally discards _fresh_waiting here, that failed probe leaves the owner classified as having no waiting fresh rows; reoffer_marked then calls release_hold and clears its durable marker when below the depth cap. If the global ready page is occupied by held backlog and no further units settle, the fresh rows lose their retry path indefinitely. Preserve the marker on an unsuccessful probe and clear it only after a successful read establishes that no ready fresh rows remain.
Useful? React with 👍 / 👎.
| finds no ready fresh row. ``false`` stops new marker writes for this reason; markers already | ||
| written are cleared by maintenance like any hold marker. | ||
| """ | ||
| from config.policy import kill_switch |
There was a problem hiding this comment.
Move the new kill-switch import to module scope
The new fresh_reoffer_marker_enabled helper imports kill_switch inside its function body, contrary to the explicit backend import rule: all imports must be at module scope, never inside functions. Move this dependency to the module-level imports to comply with the scoped repository convention.
AGENTS.md reference: backend/AGENTS.md:L166-L168
Useful? React with 👍 / 👎.
Full review of 50ec632: the marker write could raise into a drain; a row-level privacy refusal suppressed the marker; a re-offer marker could be kept by the depth check after no ready fresh row was left; the give-up bound could end before a configured head wait; the prune cleared every owner's clock. Docs and PR text corrected for the probe log line and the tests. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…; text corrections Confirmation on 1fde83a: evicting the least recently seen owner restarted its give-up clock, so with more than 4,096 waiting owners the bound did not hold. The table now evicts only owners unseen for the gap and otherwise does not track (or mark) a further owner. Four statements in the docs corrected. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…owner marked Two findings from the automated PR review, both stall risks: a 30-second in-memory throttle could skip re-marking an owner whose marker another process had cleared, and a transient fresh-probe error let a maintenance visit clear a marker held for waiting rows. Co-Authored-By: Claude Fable 5.2 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c10dbb5d4
ℹ️ 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".
|
|
||
| def test_a_full_table_does_not_evict_owners_still_waiting(world, monkeypatch): | ||
| """Evicting an owner that is still being seen would restart its clock and undo the bound.""" | ||
| import utils.batch_pipeline.merge as merge_module |
There was a problem hiding this comment.
Move the new test imports to module scope
The new tests import utils.batch_pipeline.merge inside their function bodies here and in test_a_re_offer_marker_is_not_kept_by_the_depth_cap_and_a_depth_hold_replaces_it. The applicable backend/AGENTS.md explicitly requires all imports at module scope, with no exception for tests. Move the shared merge_module import alongside the existing module-level imports.
AGENTS.md reference: backend/AGENTS.md:L168-L168
Useful? React with 👍 / 👎.
| ready_left = sum(row.get('state') == 'result_ready' for row in pending) - (1 if entry is not None else 0) | ||
| if ready_left > 0 and fenced is None: |
There was a problem hiding this comment.
Reset the stall clock when the last ready row commits
For an owner receiving isolated ready fresh rows behind an unready fresh head, each successful commit leaves ready_left == 0, so this condition skips _fresh_left_waiting and never records those commits in _fresh_stalled. If successive waiting episodes are less than ten minutes apart, the original stall timestamp survives indefinitely; after head wait plus 30 minutes, subsequent episodes immediately hit fresh_reoffer_gave_up despite the owner's regular successful commits. Maintenance then clears the marker while the new row is still inside its head wait, removing its durable retry path when held backlog hides it from the global ready page. Reset or remove the stall record on every successful commit, including commits that empty the probe's ready rows.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b285472e2
ℹ️ 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".
| wait; only the recovered unit also passes the catch-up depth hold. The | ||
| body, late marking and chain are the same as every other commit.""" | ||
| key = owner_key(owner_id) | ||
| self._fresh_waiting.discard(key) |
There was a problem hiding this comment.
Preserve fresh re-offer markers during query backoff
When fresh_pending raises FailedPrecondition, its handler recursively calls commit_next with the fresh probe disabled for 300 seconds. This discard removes the owner's waiting state, and the recursive call cannot restore it because it skips the probe. Maintenance then calls release_hold and clears the durable fresh re-offer marker without establishing that the ready rows are gone. The same happens to other marked owners visited during that process-wide backoff. If held backlog fills the global ready page and no more units settle, those owners remain stranded even after the index becomes available. Preserve their markers until a successful fresh probe confirms that no ready rows remain.
Useful? React with 👍 / 👎.
Rollout lead's ruling 2026-11-14: the marker produced repeated code findings in review (last: a thread race in its give-up table). It moves to its own PR (branch lane/fresh-reoffer-marker). This PR is back to the settle-clock pick, the probe-full log line and the recorded discovery fallback. The change note no longer claims the probe line repeats only after a commit. Co-Authored-By: Claude Fable 5.2 <[email protected]>
What
Follow-up to #25213 and #25226. Three small things in the batch pipeline, backend only. No store, query or index change, and no new setting.
ready_at. It now uses_ready_since, which the head-wait path already uses:ready_at, or for a provider row while provider merge membership is on,provider_intent.settled_at.event=batch_merge outcome=fresh_probe_full_no_ready. The probe itself is unchanged (one page of 32).record_fallback(recent_discoverytomain_cursor). This was the valid P1 from the automated review on fix(batch): projection reaches newly committed owners first; backlog owners yield #25213.Also carries two docs-only commits for #25213's change note that were written after it merged (wording about replicas, restarts and what the main cursor guarantees), cherry-picked from the then-deleted branch.
Why
Production, 2026-11-13, job metadata and counts only: 15 of 71 owners with fresh provider units committed none of them. Each had a fresh unit held on a rate-limited vendor at the front, and the ready fresh rows behind it had no
ready_at(settled while the stamp was off, or removed by an operator script that day). The pick could never measure their wait, so the probe returned nothing on every drain. 7,784 ready fresh units were affected; they were released by restoringready_atwith a reviewed operator script (7,375 rows written). This change removes the dependency on that field for provider rows.Risk and cost
BATCH_PIPELINE_PROVIDER_BACKLOG_RELEASE_ENABLEDis off, the default).ready_atnow supplies its settle instant. So such a row can now pass an unready earlier fresh row, and it can also make an earlier ready fresh row on the same page eligible, including a GPU row that has noready_atof its own. That is the intent for provider rows. The skipped unready row appends later as a late capture, as before.Known limits
Not in this PR: nothing re-offers an owner whose drain left ready fresh rows waiting. An owner drains when one of its units settles, when maintenance finds one of its rows on the global ready page, or when it carries a hold marker. Since the provider backlog hold the ready page holds only held backlog rows and no marker is written for a held-backlog head, so an owner that goes quiet with ready fresh rows inside the head wait is not drained again (2026-11-13: 23 owners, about 3,400 rows). A merge change for this was written and reviewed in this PR and then cut by the rollout lead's ruling after repeated code findings; it goes to its own PR. Until then an operator script re-offers such owners.
A fresh unit held on a vendor still waits for the vendor.
The probe still reads one page of 32. If an owner's first 32 pending fresh rows are all unready, ready rows behind them are not seen; the new log line reports it. An earlier version of this PR read further pages; review found that a probe of several pages is not one consistent read, and the rollout lead ruled to cut it. A pick that sees past one page, made inside the transaction, is recorded as a requirement of the metered release work.
The probe is a hint read outside the transaction, on main and here alike: a row it did not return that becomes ready between probe and transaction can be passed by the picked row, and then commits on a later drain as a late capture. Unchanged by this PR.
A GPU row's own settle time is not read: only a provider row supplies a settle instant. A ready GPU row without
ready_atstill cannot start the wait by itself, but, as stated under Risk and cost, a later provider row's settle instant can now make it the row picked.The settle instant is the provider intent's
settled_at. A recovered provider unit normally carriesready_atfrom recovery; if that were removed, the pick could use an earlier attempt's settle instant and so shorten the wait behind an unready row. The row must still beresult_readyto be picked.A persistent failure of the newest-commits read logs one fallback warning per tick per instance, unthrottled.
Deploy
backend-integration and the GPU batch worker, both of which run the merge. Never roll either below f3902ec: older code releases the held provider backlog through rows that carry
ready_at. Off switch: none of its own;BATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLED=falseremoves the settle-instant fallback with the rest of membership.Must stay clean after deploy: no non-fresh provider commits; share of under-1h fresh captures unprojected at 10 to 20 minutes;
fallbackevents withfrom_mode=recent_discoverynear zero;fresh_probe_full_no_readylines near zero.Tests
test_batch_provider_merge_membership.py: the production shape end to end (held backlog head, a fresh unit that never settles, ready fresh rows withoutready_at): nothing inside the wait, both ready rows after it, backlog and held unit untouched. Fails without the fix. Also: a full probe page with no ready row commits nothing and logs the line.test_batch_terminal_poll_skip.py: the pick uses the settle instant for provider rows only and only with membership on.test_batch_pipeline_projection_discovery.py: the failed recent read records the fallback.Not tested here: production behaviour.
Failure-Class: FC-backlog-release-shares-lane-with-fresh-work
🤖 Generated with Claude Code