Skip to content

fix(batch): age proxy keeps skipping allowance holds through unevaluated re-evaluation - #23767

Merged
Git-on-my-level merged 4 commits into
mainfrom
op1/proxy-hold-reeval
Oct 27, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
op1/proxy-hold-reeval

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What (lead ruling 0e021b, follow-up to #23638)

#23638 made the batch uncommitted-age proxy (database/batch_pipeline_store.py:oldest() -> omi_batch_pipeline_oldest_age_seconds -> in-cluster guard uncommitted_job_age_over_30m) skip durable allowance policy holds. In prod the proxy still flaps: 0 at most samples, ~54h at some. The source is priority-1 allowance holds (enqueued 10-24) that, at the flap moment, read state=retry attempt=0 merge_pending=true with no compute_decision, and a minute later carry held/allowance_exhausted again.

Mechanism: Scheduler.defer() on admission_refused=True with no held_reason (an unevaluated admission RPC) deliberately pops compute_decision ("Preserve BLIND instead of a false hold"). So a held job whose re-evaluation comes back unevaluated loses its hold marker until the next evaluation re-holds it; during that gap oldest() measures it as a real commitment and the guard trips falsely.

Fix

  • defer() records a separate durable last_policy_hold = {reason, at} alongside every held compute_decision. The unevaluated path is unchanged: compute_decision is still popped, so outside readers still see BLIND, never a false hold.
  • admission.authorize() pops last_policy_hold in the same transaction that seals an allowed decision; a later hold with a different reason overwrites it.
  • Luna review P2: Scheduler.pull() pops last_policy_hold when it issues a lease the pump will dispatch without admission (same predicate as the pump's required gate: requires_compute_admission false and offline_admission_enabled(owner, 'batch') false, e.g. after offline enforcement is turned off). That lease is a real commitment, so a stale parked hold can never hide it from the proxy.
  • is_allowance_policy_hold() keeps the current decision authoritative whenever one is recorded; only when the decision is absent does it fall back to last_policy_hold.reason == 'allowance_exhausted'. An admitted job that later hits an unevaluated dispatch recheck has no marker and is still measured, so a genuine stuck commitment trips exactly as before.
  • The fix(batch): uncommitted-age proxy skips durable allowance policy holds #23638 scan bound, truncation sentinel, and oldest-hold fallback are untouched.

Tests

New regression tests (tests/unit/test_batch_pipeline_metrics.py, plus case 2 in test_batch_pipeline_admission.py where the admission imports already live, keeping the metrics file under the fast-unit CPU guard):

  1. A held allowance job that goes through an unevaluated defer (decision popped, BLIND preserved) still reads proxy age 0 ~54h later.
  2. A hold replaced by a sealed allowed decision clears the marker; a subsequent unevaluated defer leaves the job measured (1860s -> trip).
  3. A lease that bypasses admission (enforcement off, unit not requiring admission) clears the marker; the job is measured again (1900s -> trip).
  4. Firestore oldest() walk with marker-only holds: skips them, returns the commitment, and the truncation sentinel / exact-bound cases behave as in fix(batch): uncommitted-age proxy skips durable allowance policy holds #23638; the current decision wins over a stale marker.

Tests 1 and 4 fail on main and pass with the fix. Local runs: test.sh over all 78 tests/unit/test_batch_*.py files plus test_incluster_guards.py and test_stt_cap_dispatch.py - all passed (exit 0).

CI shard rebalance (lead ruling cca63f)

Touching batch_pipeline_store.py selects the full backend unit suite (2332 files). backend/scripts/run-unit-ci.sh assigned files to the six shards round-robin over the sorted list, so one inserted file shifts every later file to the next shard. On this PR that left shard walls at 433-754s: shard 4 went over the 720s budget three times (754s, 740s, 725s) with every test passing.

  • Which file controls sharding: backend/scripts/run-unit-ci.sh (the workflow only passes --shard 6/N; .github is unchanged).
  • Change: the runner gives each file a weight from the new backend/scripts/backend_unit_shard_weights.tsv: the mean measured pytest time per file over three full-suite runs (main 40433411631 and PR runs 40435691671 and 40442350301), for the 1293 files at 2s or more. Unlisted files weigh 1.1s, the mean of the rest. Files are dealt heaviest-first to the least loaded shard. The deal is deterministic, so every shard computes the same partition and their union is still exactly the selection. With no weights table every file ties and the deal falls back to round-robin.
  • Why / evidence: shard wall tracks the shard's summed per-file test time (wall ~ 0.45 x test-seconds). In leave-one-run-out checks, round-robin's worst projected shard was 725-757s; the weighted deal's worst was 653-708s. A first version weighted from a single run (611 files at 5s or more) measured 512-722s on CI. That showed single-run weights are too noisy, so the table now uses the three-run mean. Size-based weights without data were tried and rejected: small edits reshuffled them up to ~701s.
  • Remaining margin: the mean shard wall is ~620-680s depending on runner speed, against the 720s budget, so a hot runner can still push one shard near the line even with balanced shards (main's own shards ran 681-682s).
  • Tests: test_backend_unit_ci_runner.py adds a weighted-deal case (heavy files land one per shard, each shard keeps selection order, the partition is exact). The existing round-robin partition test still passes because unweighted files tie. The test_workflow_contracts.py sharding contract now pins the weighted deal and the weights file instead of the awk slice.
  • No budget raise, no skip.

Deploy note

Ships after the batch 5% soak (lead 0e021b); not during the deploy exclusion hold. Rides the batch worker rollout like #23638. Jobs already decisionless today gain the marker on their next held defer.

Failure-Class: none

🤖 Generated with Claude Code

…ted re-evaluation

Scheduler.defer pops compute_decision when an admission re-evaluation comes
back unevaluated (preserve BLIND, never a false hold). An allowance-held job
then read as a decisionless commitment until the next re-hold, so the
uncommitted-age proxy from #23638 flapped to ~54h and tripped the in-cluster
guard falsely.

defer now records last_policy_hold {reason, at} with every held decision;
admission clears it when it seals an allow, and a later hold overwrites it.
is_allowance_policy_hold keeps the current decision authoritative and falls
back to last_policy_hold only when no decision is recorded. The BLIND
contract, scan bound and truncation sentinel are unchanged.

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

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T03:31:50.294901Z da16dde 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.

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

ℹ️ 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_firestore_oldest_skips_a_decisionless_job_with_a_last_allowance_hold():
from database.batch_pipeline_store import OLDEST_POLICY_HOLD_SCAN_LIMIT, is_allowance_policy_hold, oldest

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 Move the new test import to module scope

The new regression test imports database.batch_pipeline_store inside its function, contrary to the explicit import rule in backend/AGENTS.md, which requires all imports at module scope and provides no test exemption. Move these three imports into the module-level import block to keep the added test compliant with the backend convention.

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

Useful? React with 👍 / 👎.

Git-on-my-level and others added 3 commits October 27, 2026 08:55
Review (Luna) P2: with offline enforcement off, a unit that does not
require compute admission is dispatched by the pump without authorize(),
so no allowed seal clears last_policy_hold. If an unevaluated retry had
already popped compute_decision, the stale marker would let oldest() skip
a real in-flight or stuck commitment.

pull() now pops last_policy_hold when it issues such a lease, using the
pump's own required-admission predicate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lead ruling cca63f. The full backend unit suite was sliced round-robin over
the sorted file list, so one inserted file shifted every later file to the
next shard; on #23767 that left shard walls at 433-754s and shard 4 over its
720s budget three times with every test passing.

run-unit-ci.sh now weights each file from backend_unit_shard_weights.tsv
(611 files measured at 5s or more in run 40435691671; unlisted files weigh
the 1.8s mean of the rest) and deals heaviest-first to the least loaded
shard. The partition stays deterministic and exact; with no weights every
file ties and the deal is round-robin. Projected walls on the same
measurements: 611-646s (round-robin ~716-725s).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The single-run weights (run 40435691671, 5s floor) measured 512-722s on CI:
per-file pytest times vary run to run, so one run overfits its noise. The
table now holds the mean over three full-suite runs (main 40433411631, PR
runs 40435691671 and 40442350301) for files at 2s or more, with unlisted
files at the 1.1s mean of the rest. Leave-one-run-out checks cut the worst
projected shard from 725-757s (round-robin) to 653-708s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit f10cbeb into main Oct 27, 2026
64 of 65 checks passed
@Git-on-my-level
Git-on-my-level deleted the op1/proxy-hold-reeval branch October 27, 2026 03:47
Git-on-my-level added a commit that referenced this pull request Oct 27, 2026
…pecheck (#23796)

## What

Backend unit CI shard walls keep grazing the 720s regression budget:
#23767 754/740s, #23771 762s, #23789 724s, with main at ~681s (~5%
headroom). This rebalances the shards to a simulated worst shard of
**607s** (target 640s, 11% headroom) without touching `.github/`
workflows, the 720s budget, or the shard count.

Three causes, each fixed at its layer:

1. **The weights table priced pytest time, not wall time.** Per-file
wall (import/collection startup included) is what the scheduler
consumes. The old table (3-run mean pytest seconds) missed the suite's
heaviest file entirely — `test_runtime_image_contracts.py` at ~183s wall
was unlisted and dealt at the 1.1s default — and underpriced
`test_cross_service_deploy_contract.py` at 36.7s vs a measured 130s.
Rebuilt as **p90 wall seconds over the last 20 main-branch runs** (1982
entries, ≥2s floor), attribution-free from each file's `::group::`
marker to its last path-bearing line +0.7s tail; `DEFAULT_WEIGHT` 1.1 →
measured 1.66.
2. **Slices launched alphabetically**, so heavy files started ~75% into
their shard and serialized the tail (the 183s file capped a lane for the
final quarter on #23789 shard 3). Each shard's slice now keeps deal
order, so `test.sh`'s four worker slots run a longest-processing-time
schedule.
3. **All six shards ran the identical full-tree pyright** (~99s each:
~8m of runner time per main commit, ~99s of every shard's budget). It is
deterministic over the same checkout every shard sees, so only shard 1
runs it now; its failure still fails the workflow for the commit, and
the deal reserves shard 1's extra capacity (`load[0] += 360`) so shards
finish level.

Plus the split the brief asked for: the 183s closure walk
(`test_registered_runtime_image_sources_are_closed`, 18 registered image
contracts staged + AST-walked in one process) becomes the same test in
two files split by parity of the sorted contract name — every contract
still checked exactly once, new contracts land in exactly one half by
construction. Halves measured 33.6s / 33.8s locally. Moved node IDs
inherit their fast-unit duration-guard allowlist entry.

## Evidence

- Harvest + parser + simulation scripts and per-run JSON:
`/Volumes/Ephemeral/scratch/shardbudget/` (20 main runs × 6 shard logs;
per-file p90s are tight across runs, e.g. runtime_image 179.7–185.7s
over 20 samples).
- Variant simulation over all 20 runs (same deal code as shipped):
current setup reproduces at 737s worst; new table + LPT → 701s; + split
→ 679s; + shard-1 typecheck → **607s worst**, per-shard makespans level
at 594-595s (shard 1: 504s + 95s typecheck).
- Shipped-deal check: union of the 6 slices == full selection (2341
files), partition exact.
- Local layer: `backend/test.sh` over the seven changed/pinning test
files — all green (runner pins 94, workflow contracts 14, allowlist pin
2, runtime_image trio 63+1+1).

## Notes for review

- The typecheck dedup is a contract change to a documented invariant
("phases identical across shards"). The guard still gates every commit
exactly once on the same tree; preflight (seconds) still runs on every
shard. If this is rejected, the projected worst shard is 679s — over the
640s target and within 6% of the budget, and the residual fix (a 7th
shard or a budget raise) lives in `.github/`, which this lane does not
touch.
- `test_cross_service_deploy_contract.py` (130s wall, now correctly
weighted) is the next split candidate if walls creep again; not split
here to keep the diff reviewable.
- Failure-Class: none
- UI-Evidence: none -- no UI changes

## Review

- Round 1 (Luna, full): **SHIP** with one minor finding — the 360s
shard-1 reservation also applied to changed-files runs where
`needs-typecheck.sh` skips the check, handing shard 1's capacity to
siblings for nothing (~570s vs ~556s projected max on such runs). Fixed
in e0fc220: the boundary decision is computed once before the deal,
and both the reservation and the typecheck step key off it (verified:
with the check reserved → shard 1 empty in a tiny fixture; without → 7/6
even split; runner pin tests 94 + workflow contracts 14 green locally).
- Empirical CI on this PR (full 2338-file suite through the new deal):
shards green at 422 / 607 / 470 / 533 / 581 / 393s — worst 607s,
matching the simulation, was 718–762s near-misses.
YinkaAdepoju pushed a commit to YinkaAdepoju/omi that referenced this pull request Oct 27, 2026
…pecheck

Four near-misses against the 720s shard budget tonight (BasedHardware#23767 754/740s,
BasedHardware#23771 762s, BasedHardware#23789 724s) with main at ~681s left ~5% headroom. Three causes,
each fixed at its layer, measured from the six shard logs of the last 20
main-branch runs (40333043889..40458587600, per-file wall time from each
file's ::group:: marker to its last path-bearing line + 0.7s tail):

- Weights priced pytest time, not wall time. Per-file import/collection
  startup is what the scheduler actually consumes; the old table missed a
  183s file entirely (unlisted) and underpriced a 130s file at 36.7s and the
  sub-2s default at 1.1s vs a measured 1.66s wall mean. Rebuilt as p90 wall
  seconds (1982 entries); DEFAULT_WEIGHT 1.66.
- Slices launched alphabetically, so heavy files started late and serialized
  their shard's tail. Each shard's slice now keeps deal order, turning
  test.sh's four worker slots into a longest-processing-time schedule.
- All six shards ran the identical full-tree pyright (~99s each; ~8m of
  runner time per main commit, ~99s of every shard's 720s budget). It is
  deterministic over the same checkout every shard sees, so only shard 1
  runs it; its failure still fails the workflow for the commit, and the deal
  reserves shard 1's capacity (load[0] += 360) so all shards finish level.

Simulated over all 20 runs with the shipped deal and scheduler: worst shard
607s (budget 720, target 640, was 718-762 observed; per-shard makespans
594-595s except shard 1's 504s). Runner pin tests updated to the new
contract: shard-1-only typecheck, offset-aware deal, deal-ordered slices.
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