Skip to content

ci(backend): rebalance unit shards by wall weight, LPT slices, one typecheck - #23796

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/shardbudget
Oct 27, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/shardbudget

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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 perf(notes): draft exact capture dedupe pending synthetic model parity #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.

test_registered_runtime_image_sources_are_closed staged and AST-walked all
18 registered runtime image contracts in one pytest process: ~183s of CI
wall, the single heaviest file in the unit suite, unlisted in the shard
weights table and capable of serializing a shard lane's final quarter (PR
#23789 shard 3, 724s against the 720s budget). The walk now runs as the same
test in two files, split by parity of the sorted contract name, so every
contract is still checked exactly once, a newly registered contract lands in
exactly one half by construction, and the deal can spread the halves across
shards. Measured on this checkout: halves 33.6s / 33.8s. The moved node IDs
inherit their fast-unit duration-guard allowlist entry.
…pecheck

Four near-misses against the 720s shard budget tonight (#23767 754/740s,
#23771 762s, #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.
@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-27T08:07:09.322604Z e0fc220 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.

…ecks

Review round 1 (Luna, SHIP with one minor): the 360s deal reservation for
shard 1's type check also applied to changed-files runs where
needs-typecheck.sh skips the check entirely, handing shard 1's capacity to
its siblings for nothing (projected max ~570s vs ~556s on such runs). The
boundary decision is now made once before the deal and both the reservation
and the typecheck step key off it.
@Git-on-my-level
Git-on-my-level merged commit be29e91 into main Oct 27, 2026
60 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/shardbudget branch October 27, 2026 08:17
Git-on-my-level added a commit that referenced this pull request Nov 2, 2026
…parse off the CPU guard (#24406)

## What

Root fixes for the two CI guards that tripped on main run 41468678725
(2026-11-02, no pytest failures):

1. **Backend unit shard 1 wall 730s over the 720s budget.** The deal's
p90 wall table (`backend_unit_shard_weights.tsv`) was five days stale
(2026-10-27, PR #23796): 302 files added to main since were priced at
the 1.66s `DEFAULT_WEIGHT`, including
`test_batch_vendor_outage_drills.py` at a measured **74.7s p90**, so the
deal leveled on fiction. Shard 1's pyright reservation was also
under-measured: shipped 90s, remeasured over 16 main runs at median 96s
/ p75 100s / max 113s.
- Regenerate the table from the last 20 main runs
(41386368018..41438174663): 2259 entries, 302 newly priced.
- Raise the typecheck reservation to the measured 100s (deal load offset
360 → 400).
   - `DEFAULT_WEIGHT` 1.66 → 1.70 (fresh mean below the 2s floor).
- Projection (same simulator as PR #23796): worst shard **687s, level
across all six** (702s under the stale table).

2. **Backend unit shard 6 fast-unit CPU guard:**
`test_translation_config.py::test_prod_binds_no_nllb_translation_endpoint`
measured 1.03s CPU against the 1.00s limit (all 40 tests in the file
passed). The `backend/deploy/runtime_env.yaml` parse under
`yaml.SafeLoader` costs ~0.33s CPU locally and ~1s on a CI runner. This
applies the autouse `CSafeLoader` fixture that
`test_backend_runtime_env_validator.py` already ships for large
manifests — same safe YAML schema, measured **0.044s** locally (~7x
cheaper). Locally the test now measures 0.15s CPU.

## Measured evidence

- Wall weights: p90 of per-file walls over 20 main-branch runs (parser +
simulator from PR #23796, scratch `shardbudget/scripts`). Typecheck
delta: per-run shard-1 overhead minus sibling median, 16 runs with
parseable spans.
- YAML parse CPU (M-series, `process_time`, best of 3): SafeLoader
0.326s → CSafeLoader 0.044s for the 4592-line runtime_env.yaml.
- Local CI shard (exact CI envs: WARN 0.1 / FAIL 1.0, file isolation, 4
workers): `test_translation_config.py`,
`test_backend_unit_ci_runner.py`, `test_workflow_contracts.py` — all
pass, no fail-limit offenders.

## Residual risk (owner decision, not this PR)

A perfectly leveled deal still projects ~687s against the 720s budget
with roughly ±45s observed runner variance (green-run shard walls
433–698s; the failing run 730s), so occasional overage remains
structurally possible — the suite has grown past what 6 shards × 4 lanes
fits comfortably at this budget. The 7th-shard / budget-raise lever and
splitting the 74.7s `test_batch_vendor_outage_drills.py`
(runtime_image-split precedent) stay deliberate owner decisions, tracked
on card `margin50-variable-margin`.

Failure-Class: none

Both guards were measurement-staleness flakes on green tests; no product
failure class applies.
MichaelC001 pushed a commit to MichaelC001/omi that referenced this pull request Nov 3, 2026
…parse off the CPU guard

Two independent guards tripped on main run 41468678725 (2026-11-02), no pytest failures:

1. Shard 1 wall 730s over the 720s budget. The deal's p90 wall table was
   five days stale (2026-10-27, PR BasedHardware#23796): 302 files added since were
   priced at the 1.66s default, including test_batch_vendor_outage_drills.py
   at a measured 74.7s p90, so the deal leveled on fiction; and shard 1's
   pyright reservation was under-measured (shipped 90s; remeasured over 16
   main runs 2026-11-02: median 96s, p75 100s, max 113s). Regenerate the
   table from the last 20 main runs (41386368018..41438174663), raise the
   reservation to the measured 100s (load offset 360->400), and move
   DEFAULT_WEIGHT to the fresh 1.70s mean. Projected worst shard: 687s,
   level across all six (702s under the stale table). A perfectly leveled
   deal still projects ~687s against 720s with about +/-45s observed
   runner variance, so residual overage risk is structural (the suite has
   grown past 6 shards x 4 lanes at this budget); the 7th-shard/budget
   lever stays a deliberate owner decision on card margin50-variable-margin.

2. Shard 6 fast-unit CPU guard: test_prod_binds_no_nllb_translation_endpoint
   measured 1.03s CPU against the 1.00s limit with all 40 tests passing.
   The runtime_env.yaml parse under SafeLoader costs ~0.33s CPU locally and
   ~1s on a CI runner; apply the autouse CSafeLoader fixture that
   test_backend_runtime_env_validator.py already ships for large manifests
   (same safe schema, measured 0.044s locally, ~7x cheaper).
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