Skip to content

fix(lead cap): K = 1 waits for a fixed window of global steps; deterministic give-up tests - #914

Merged
michaellchung merged 4 commits into
mainfrom
fix/verl-lead-cap-flake
Nov 26, 2026
Merged

michaellchung merged 4 commits into
mainfrom
fix/verl-lead-cap-flake

Conversation

@michaellchung

@michaellchung michaellchung commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Four commits:

  1. fix(lead cap): the first product fix for the verl parity lead cap flake (superseded by commit 3, kept for the history of the review).
  2. tests: a separate, unrelated flake in tests/test_sync_lead_cap.py, made deterministic with an injectable clock.
  3. fix(lead cap): K = 1 waits for a fixed window of global steps: replaces the K = 1 rule of commit 1 after review found two holes in it.
  4. tests(lead cap): review follow-ups (tests that guard the window wait, the window alignment and K >= 2; the give-up clock in the docs).

Problem

tests/test_verl_miles_parity.py::test_the_lead_cap_holds_a_fast_verl_island_to_the_slow_one failed on CI with AssertionError: (11, 8). The bound counts local rounds, not wall-clock time, so the product broke the guarantee: with --rl-sync-max-local-rounds-ahead 1 and a fixed roster, a fast island must stay at most one local round ahead of the slowest island.

Root cause on origin/main: RolePairing.wait_for_lead answered every PULL that arrived during the wait from the cut it had already pushed. With K = 1 such a pair is itself a lead blocker, so on the slow island each merge opened a new round, the wait answered it, and the new pair held the wait again, while the fast island trained a round per merge. Fault injection (the slow island's broadcasts 60 ms late) fails origin/main 21 of 100 runs.

Why commit 1 was not enough

Commit 1 stopped the wait from opening pairs that would hold it. Review showed two holes:

  • H1, crossed PULL orders: a sharded head merges the PULLs of its shards in no fixed order. When island A sees step 2 first and island B sees step 1 first, each wait pushes one step and holds the other, so each island waits for a push the other makes only after training. Both waits escape at half the wait timeout.
  • H2, PULLs that arrive in order but late: each wait answers only the push it waits for and defers the rest to the next boundary, from the newer cut. The fast island then merges a step with the slow island's push from an older cut, and the lead grows linearly with the run.

Fix: a fixed window of global steps per local round (K = 1)

Options considered, in the requested order:

  • (a) Use contributor progress from the syncer: not available. A broadcast carries only the fragment id and its version; PUSH carries local_step, but the syncer never sends it back.
  • (b) A protocol change: an old syncer rejects an unknown HELLO extension flag when it parses the session, so an old syncer cannot fall back to the current logic with a warning. The change would also be larger than 150 lines.
  • (c) A bound that holds by construction, documented: chosen.

The rule (RolePairing.lead_window):

  • The global steps 1..total are cut into fixed windows of P consecutive steps, P = --rl-sync-fragment-pipeline (the effective pipeline depth). The last window ends at the last step.
  • At each local round the island takes the window of the smallest step not closed yet (applied or staged) and keeps it for that round.
  • It pushes every PULL of that window from this cut, at the boundary and while it waits, so a PULL that arrives late or out of order is still answered from this cut. It holds every other PULL until a later boundary (not materialized ahead).
  • It trains the next round only once every step of the window closed.

Bound, fixed roster: every step needs every island's push. An island pushes at most one window per local round, and a window can close only after it pushed it, so the window it takes at round r has index at most r: every island pushes window b from a cut of round b or later. When an island starts round b + 1, window b closed, so every other island trained at least b rounds. A fast island is at most one local round ahead of the slowest, for any order and delay of PULLs and broadcasts, and on a sharded head (step t merges fragment (t - 1) mod F on every shard, and a fragment's version is the step that last merged it). Every island waits for the same window, so no wait can hold a step another island needs: crossed orders cannot lock.

Membership and phases (each has a test):

  • Quorum below the number of islands, or a soft deadline: a step can close without the island. Its window then closes without it and it moves on to the window of the smallest open step. No wait blocks on an island that is not needed and no wait escapes, but the cap bounds no lead across islands then. This is documented in the flag help, docs/CLI_REFERENCE.md and the docstring.
  • An island that leaves: its steps close without it (the same case as above).
  • A joining or relaunched process (also after a spare replacement): it takes the window of the smallest step that its caught-up fragments leave open.
  • Terminal phase or end of data mid-window: any_finalizing ends any wait and lifts the window, so the final cut answers every PULL left, also those past its window. The last rounds' PULLs can start the terminal phase while a wait holds an earlier window. A window filter kept there left both islands waiting on each other; the stress run found this (see below) and it is fixed and tested.
  • A replayed PULL (a redial or a restarted syncer re-sends a round the island already pushed): the retained pair replays its bytes at once, the window does not hold it.
  • The give-up rule is kept: the wait trains on once the oldest pair in flight waited half of --rl-sync-wait-timeout-s (with none in flight, since the island last retained a pair).

Cost of K = 1: one window of P steps is in flight per local round, also on a sharded head whose shards could run P steps each. This is in the flag help and docs/CLI_REFERENCE.md.

K >= 2 keeps the existing lead_blockers / lead_unpushed rule. With the cap off (the default) nothing changes: the window filter returns its input unchanged.

Impact

  • No preset, example or default enables --rl-sync-max-local-rounds-ahead; it needs --rl-sync-full-parameter-rounds async.
  • The customer K3.1 path runs --rl-single-island-no-sync and never builds a RolePairing lead window. Customer gate below.

Tests

Rewritten fake tests, and why:

  • test_with_k_1_the_wait_opens_no_pair_that_would_hold_it (commit 1) is removed. It asserted the rule of commit 1, which is what H1 and H2 break: the wait now does push late PULLs of its window from the current cut.
  • test_the_wait_also_covers_rounds_trained_before_the_next_pull_arrives now uses the lead_clock fixture and the window rule (window 1..2 merges, then the PULLs of window 3..4 arrive late).

New fake tests in tests/test_sync_lead_cap.py:

  • the wait answers its window late and holds the next window;
  • a wait entered before any PULL answers each PULL of its window;
  • crossed PULL orders do not lock two islands (two pairings run together, 0 escapes on both);
  • a step closed without the island closes its window (quorum, soft deadline, leave);
  • a caught-up island takes the window of its first open step (join, relaunch);
  • the last window ends at the last step, and the terminal phase ends a wait;
  • the terminal phase lifts the window, so the final cut answers every PULL;
  • a replayed PULL of a pair in flight is answered during the wait;
  • a held PULL is not materialized ahead;
  • a pair reads the injected clock when it is retained.

tests/test_verl_miles_parity.py, real syncer:

  • the lead cap case is parametrized over four injections: none, late broadcasts (the slow island gets each broadcast 60 ms late), late PULLs (every second step 50 ms late, in order), and crossed PULLs (each island gets the steps of a pair in the opposite order, 80 ms apart). Each asserts that the lead is at most one round from the trace, that no wait escaped, and that the islands finished;
  • quorum 1 of 2 islands: the cap neither locks nor gives up;
  • an island leaves and a new process of it catches up, with the cap on (the dynamic-member cases in tests/test_rl_full_parameter_dynamic_members.py are unchanged).

Mutations: each old or broken variant of full_parameter_sync.py run against the new tests:

variant fake tests failing (of 22; the terminal test was added later) parity lead cap tests failing (of 6)
origin/main 6 0 in one run (flaky: 21 of 100 fail with late broadcasts)
commit 1 + 2 head 9 2 (late PULLs, crossed PULLs)
window without the PULL filter 2 0
window recomputed on every poll 8 6
window that does not answer late PULLs 5 6
window kept in the terminal phase (the first version of commit 3) 0, and the terminal test fails 8 of the first 373 stress jobs failed

Review follow-ups (commit 4)

  • The core K = 1 rule (the next round waits until every step of its window merged) now has its own test: step 1 merges first and step 2's PULL arrives at the fourth poll. With the K >= 2 blocker rule in place of the window check, the island trains on before step 2 and the test fails; this is the linear lead growth of H2.
  • Window alignment: versions (7, 6) give window 7..8, not 8..9 (fails when the window starts at the first open step).
  • K = 2 keeps the lead_unpushed case: after a merge nothing is in flight, and two rounds trained since the last retained push stop the next round (fails when <= becomes <).
  • The deferred-capture case frees two pipeline slots before the held PULL arrives, so a missing window filter in prepare_submissions materializes the held step (fails without the filter).
  • Flag help, docs/CLI_REFERENCE.md and the wait docstring now say where the give-up clock starts (the last push of the oldest pair in flight; with none in flight, the first pair retained in the island's last retaining round) and that the lead is no longer bounded after a give-up.

Each of the four mutants above fails exactly the new or changed test. The lead cap files (tests/test_sync_lead_cap.py, tests/test_verl_miles_parity.py, tests/test_verl_full_parameter_launch.py) pass on the rebased head: 74 passed. Customer gate on the rebased head: 52 goldens pass, dry-run diff against origin/main none. The stress numbers below were measured on commit 3; commit 4 changes only tests, docs, help text and one docstring.

Verification (local, CPU only)

All under 32 yes processes, 8 parallel shells, host load 100 to 160:

case runs failed
parity lead cap, no injection 200 0
parity lead cap, late broadcasts 200 0
parity lead cap, late PULLs 200 0
parity lead cap, crossed PULLs 200 0
tests/test_sync_lead_cap.py, whole file (fakes and real syncer) 200 0
real-syncer lead cap tests, late broadcasts (all clients of the run) 200 0
real-syncer lead cap tests, late PULLs 200 0
real-syncer lead cap tests, crossed PULLs 200 0
real-syncer capped test with the tightened bound (_max_lead <= 0), no injection and each injection 4 x 200 0

The first version of commit 3 kept the window in the terminal phase. The same run failed 8 of its first 373 jobs: the last rounds' PULLs arrived while a wait held an earlier window, started the terminal phase, and stayed filtered, so both islands waited for each other until the pair timeout. Lifting the window in the terminal phase fixed it (the table above is the fixed code), and test_with_k_1_the_terminal_phase_lifts_the_window_so_the_final_cut_answers_every_pull fails without the fix.

The real-syncer capped test in tests/test_sync_lead_cap.py now asserts the bound of the window rule: the fast island never starts a round before the slow island completed as many (it was "at most two ahead").

max_lead (fast island's started rounds minus the slow island's trained rounds, at every start of the fast island), parity case:

injection runs x rounds max_lead escapes (fast, slow) per quarter of the run (max over runs)
none 30 x 4 1 in 30 of 30 (0, 0) in all 1, 1, 1, 1
late broadcasts 30 x 4 1 in 30 of 30 (0, 0) in all 1, 1, 1, 1
late PULLs 30 x 4 1 in 30 of 30 (0, 0) in all 1, 1, 1, 1
crossed PULLs 30 x 4 1 in 30 of 30 (0, 0) in all 1, 1, 1, 1
none 3 x 16 1 in 3 of 3 (0, 0) in all 1, 1, 1, 1
late broadcasts 3 x 16 1 in 3 of 3 (0, 0) in all 1, 1, 1, 1
late PULLs 3 x 16 1 in 3 of 3 (0, 0) in all 1, 1, 1, 1
crossed PULLs 3 x 16 1 in 3 of 3 (0, 0) in all 1, 1, 1, 1

A max_lead of 1 is the bound itself: the fast island starts round b + 1 right after window b closed, when the slow island has trained b rounds. Both islands train the same number of rounds in every run. An earlier probe of origin/main under load recorded a lead of 4.

Regression: rebased head, no load, every test file that exercises the pairing or the full-parameter sync session (73 files that import full_parameter_sync, full_parameter_stream or build a FullParameterSync), each file in its own process: 1431 passed, 0 failed, 20 skipped (Miles-only cases skip without Miles). The Rust syncer is unchanged.

Customer gate

  • test_k31_customer_plan_golden + tests/golden/breakers: 52 passed, golden files unchanged.
  • customer dry-run diff against origin/main: none. Every examples/k31/run*.json went through yeto run up --dry-run and the pool --dry-run and was compared line by line, with timestamps and --source-sha256 normalized. The trainer launch was rc=0 on both sides. The only failures were the expected offline model_pull and sandbox status checks.

Not merged.

🤖 Generated with Claude Code

@michaellchung michaellchung changed the title fix(lead cap): a K = 1 lead wait opens no pair that would hold the wait itself (verl parity lead cap flake) fix(lead cap): a K = 1 lead wait opens no pair that would hold the wait itself; deterministic give-up tests Nov 26, 2026
@michaellchung
michaellchung force-pushed the fix/verl-lead-cap-flake branch from cc09aa9 to 799c35b Compare November 26, 2026 20:43
@michaellchung michaellchung changed the title fix(lead cap): a K = 1 lead wait opens no pair that would hold the wait itself; deterministic give-up tests fix(lead cap): K = 1 waits for a fixed window of global steps; deterministic give-up tests Nov 26, 2026
michaellchung and others added 4 commits November 27, 2026 06:36
…it itself

The lead wait pushed every PULL that arrived while it polled from the cut
the island had already pushed. With K = 1 that pair is itself a lead
blocker, so each such PULL held the wait one more merge. On a slow island
this chained: its pushes complete the merges a fast island already pushed
to, each merge opens a round whose PULL the slow island answers from inside
its wait, and the fast island trains a round per merge meanwhile. The fast
island's lead was unbounded; the verl parity lead cap case failed on CI
with 11 fast rounds against 8.

A lead wait poll now opens a new pair only where it cannot block the wait
(K >= 2) or for the push the wait waits for (lead_unpushed). Held PULLs are
answered at the next boundary from the newer cut. Replays, harvests,
broadcast applies and peer snapshots are unchanged; the cap off (default)
is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-clock bounds

test_the_wait_for_a_late_pull_gives_up_at_half_the_wait_timeout failed once
on a loaded host (four parallel shards, load about 58): it and
test_the_wait_gives_up_at_half_the_wait_timeout_and_never_times_out_itself
asserted that a wait with real 50 ms polls ends within 0.4 s. A loaded host
stretches real sleeps, so the upper bound fails while the give-up logic is
right.

The pairing module's clock is now replaceable as a whole: the one place
that bound time.monotonic at class definition (PairedSubmission.retained_at)
reads it at construction through the module's time, like every other call.
The default clock stays time.monotonic and is read at the same moment, so
production timing is unchanged. The tests install a clock that only the
module's own sleeps (the wait's polls) advance and assert the give-up time
exactly; the two new K = 1 / K = 2 wait cases use it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The K = 1 rule of the first fix (a wait opens no pair that would hold it)
left two holes. Crossed PULL orders, as a sharded head delivers them, made
two islands each wait for a push the other makes only after training (both
waits escaped at half the wait timeout). PULLs that arrived in order but
late were answered one boundary later, from a newer cut, so the lead grew
with the run.

K = 1 now cuts the global steps into fixed windows of P (the pipeline depth)
steps. Each local round takes the window of the smallest open step, pushes
every PULL of that window from its cut (also late and out-of-order ones,
during the wait), holds the others, and trains the next round once the
window closed. With a fixed roster every island pushes window b from a cut
of round b or later, so a fast island stays at most one local round ahead
of the slowest for any order and delay of PULLs and broadcasts, and no wait
holds a step another island needs. A window closes without the island when
its steps can (quorum below the island count, soft deadline, an island that
left): no lock and no escape, but no lead bound then. A joining or
relaunched process takes the window of its first open step. The terminal
phase ends any wait and lifts the window, so the final cut answers every
PULL left. K >= 2 and the cap off are unchanged.

Tests: window, crossing, quorum, join, terminal, replay and held-PULL cases
on fakes; the verl parity lead cap case under late broadcasts, late PULLs
and crossed PULLs, with quorum 1 of 2, and with an island that leaves and
catches up. The flag help and CLI reference state the bound and the cost
(one window in flight per local round, also with several syncer shards).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…>= 2

Review follow-ups:
- A fake test for the core K = 1 rule: step 1 merged, step 2's PULL comes
  late; the next round waits until step 2, pushed from this cut, merged.
  The K >= 2 blocker rule trains on there (the linear lead growth).
- Versions (7, 6) give the fixed window 7..8, not 8..9.
- K = 2 keeps the lead_unpushed case (rounds trained after the last retained
  push count once nothing is in flight).
- The deferred-capture case frees two pipeline slots, so a missing window
  filter would materialize the held step.
- The flag help, CLI reference and wait docstring state where the give-up
  clock starts and that the lead is no longer bounded after a give-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaellchung
michaellchung force-pushed the fix/verl-lead-cap-flake branch from 799c35b to 838a0b4 Compare November 26, 2026 22:41
@michaellchung
michaellchung merged commit 1dce78f into main Nov 26, 2026
7 checks passed
@michaellchung
michaellchung deleted the fix/verl-lead-cap-flake branch November 26, 2026 22:58
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