Skip to content

test(branch): evaluate the default branch - #1999

Merged
yyhhyyyyyy merged 34 commits into
mainfrom
hui/branch-default-eval
Nov 23, 2026
Merged

yyhhyyyyyy merged 34 commits into
mainfrom
hui/branch-default-eval

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

This adds the runner support and the scenarios that evaluate the default branch before any change to its policy texts.

The scenario runner can now move the default branch mid-run, as model-prompts §9.8 describes: a scenario names a switch target by role (latest_tool_line) or by id, and the runner calls session.branch_set_default at that line's first turn/start, retrying briefly while the line is not registered yet, then submits the scenario's next input. The target is fixed once that turn has started, so a tool line opened afterwards does not redirect the move, and the move and the next input are bounded by the same absolute deadline as the run's wall clock: a reply that never comes ends the run on that budget instead of holding it open.

A run that stops on that budget fixes one cleanup deadline at that moment, and everything after it runs under that deadline: the Session close, the remaining budget stops, the deferred window read, the Timeline export, the judge, and the run child's served App Server join. A close that does not settle keeps the timeout outcome and is not judged: the run writes no export, and its record says not_asked with the reason. An export that does not finish inside the deadline writes no partial export either: the run keeps its seconds stop and its error, is not judged, and its record says not_asked with "the Timeline export did not finish within the cleanup grace after the run stopped on its wall clock". A judge that has not finished by the deadline is recorded as a failed call with the reason "the judge did not finish within the cleanup grace after the run stopped on its wall clock", and it gets only what is left of the budget. A failed turn in the export does not replace that stop either: a run that stopped on its wall clock keeps seconds.

The child prints its outcome and exits either way, and the parent returns the run's slot once it has read the child's output within its bound and parsed the record. The parent's hard bound on each child is the run's wall clock, a 120-second startup bound, the larger of the cleanup budget and a 600-second judge phase budget, and the output-read grace. A complete outcome line the child printed before that bound is in hand stands: the run keeps its stop, export and judgment, and the teardown failure is attached as an error. A child the bound ends before a complete line is a supervisor failure recorded as error, failed and not_asked with no export, unless the child reported the run's own wall-clock stop before it stalled, in which case that stop and its timed-out flag are kept.

The parent's read of the child's output tells EOF from a deadline cut. A complete line already collected when the deadline cuts the read is accepted; a deadline cut before a complete line is one run's supervisor failure, recorded as above with no export, and the evaluation continues with its next scheduled run instead of cancelling it. A read that reaches EOF still surfaces a missing or malformed line as an error, as it did before. The read is cancellable too, and the child's group is killed after the read or the bound, so no member outlives the harness. The deferred read cannot replace the run's outcome either: a successful read records the window, while an error or a different window leaves the seconds stop and its error in place. A judge that has not answered within a run's 600-second phase budget is recorded as a failed call and keeps the run's stop and export, and every served App Server join is bounded, so a run that does not stop on its wall clock keeps its outcome and its slot is released.

session.submit no longer names main: an input without a branchId lands on the Session's default branch, and the switch scenario that needs the root sends "branchId": "main" explicitly. A scenario without a switch runs as before.

The set now holds the sixteen scenarios of Timeline branches §12.3: the eight existing ones, identity-after-compaction, and seven added here: long-work-and-a-flaky-test, refactor-and-a-pasted-report, same-file-tradeoff, background-command-not-branch, switch-continue-directly, switch-then-open-lines and root-opens-after-switch. Each new directory declares a 131,072-token window and carries its own workspace and probes.

Three of the new scenarios use the switch step: switch-continue-directly and switch-then-open-lines send the next input to the new default branch, and root-opens-after-switch sends it to the root so the root must open a line after another line holds the role.

The no-model tests read every committed scenario, pin the branch set's windows, switches and the delegation probe of switch-then-open-lines, and cover the runner's switch trigger, its move before the next input, its single fire, its error path, the bounded unknown_branch retry, the run outcome when the target never appears, the target staying fixed once it has started, both switch calls stopping on the scenario deadline when a reply never arrives, a timed-out run closing within its bounded grace while the peer withholds both the move and the close, a timed-out run keeping seconds when its deferred window read fails after the timeout, a two-scenario evaluation at one job whose first scenario's timed-out runs cannot close or shut their servers down and still return their records while the second scenario runs and is judged on the same slot, a child that leaves a member holding its standard output stopping at the parent's read bound and freeing the job slot, a successful child leaving no member of its group behind, a timed-out run whose close settles exporting its Timeline and being judged, its record taken before the served App Server's join and kept under 20 seconds, and a timed-out run whose judge never answers being recorded as a failed call while the next scenario is judged on the slot it frees. Two more cover the whole cleanup deadline: a timed-out run whose close settles and whose export never finishes is recorded as not judged with no export while the next scenario runs and is judged on the same slot, and a child that blocks after its wall clock is killed at the parent's bound with no process or group left behind, after a marker proves it reached the stall. The supervisor's endings are pinned one by one: a child that exits before its outcome line while a member holds its output leaves the next scheduled run intact and judged, while a child that exits without an outcome, or with a line that is not JSON, still fails the evaluation; a child stuck before its outcome is a supervisor failure with no export; a child that printed its complete outcome and then cannot exit keeps its stop, export and judgment with the teardown failure attached; and a run whose judge outlives its phase budget keeps idle and its export with a failed judge call while the next scenario runs.

Evaluation

These are smoke runs, not a regression gate: five runs per arm and scenario are under the twenty-run floor of model-prompts §8.1, so the results are inconclusive and none of them is a no-regression conclusion.

Both arms serve the same shipped text: the candidate arm receives a byte-identical copy of the branch tool description, so the smoke exercises the runner and the scenarios on a real model rather than comparing two texts.

No gate is run for this change because the sentences it covers are protocol text, which model-prompts §8.2 excludes from evaluation and leaves to the flow tests that change with them; the runner's current arm also always serves the text shipped in the checkout under test, so an arm that wanted the pre-change text would measure a different mechanism, not the same one with different text.

The three switch scenarios ran thirty sessions: all thirty switched successfully, and each default branch moved 2 to 78 ms after the target line's first turn/start and before its first turn/end. Every probe the smoke ran passed in all five runs of both arms, no run failed, and no run needed the unknown_branch retry.

Runs opened one to four lines; the peak number of counted tool lines, meaning open tool lines other than the default branch and its ancestors, was two, and branch_not_opener and branch_limit_reached were answered zero times. On the switch path, the root opened one line in all ten root-opens-after-switch runs and the new default branch opened none; the new default branch opened two to three lines in nine of the ten switch-then-open-lines runs and none in the tenth, and the root opened none in all ten. No run opened lines on both sides. The cap of four was never reached, so this smoke cannot re-check it, and the behavior after a refusal is covered only by the flow test with a fake model.

The delegation probe of switch-then-open-lines was added after this smoke, so the probe counts above are the ones the scenarios carried at that point. The tenth run named above, which opened no line on the new default branch, would not satisfy it; the other nine would.

The compact scenario ran ten sessions at a 29,000-token window with an 8,192-token output cap. Four of them opened a line, and in all four both main and every line completed a compaction; no step reached the output cap. The other six opened no line and are counted separately: the identity-after-compaction probe is absent in those six and present in the other four, two of five per arm, so they are recorded as an unmet probe rather than left out. Of those six, five never called branch and made both changes on the main line; in the sixth, a branch create was rejected for an unknown title field, and the run made both changes on the main line instead. Three main-line compactions among the six were skipped with nothing_to_compact, which is a designed skip rather than a failure.

An earlier smoke ran the fifteen branch scenarios, without the compact scenario: 150 sessions ended 118 times on idle, 2 times on the wall-clock budget and 30 times with an error before an ended switch target became its own outcome. A separate thirty-session rerun of the three switch scenarios on that code stopped as switch_target_ended in all thirty because the target line had ended itself before the move; that smoke ran before the trigger moved to turn/start.

A switch run used about 1.1M prompt and 35k completion tokens on average, and the thirty sessions took 33 minutes at four jobs. The ten compact sessions took 6.5 minutes and about 280k prompt and 10k completion tokens each. The runner and the judge are from the same model family, which is a measurement limitation.

A scenario may name a switch: the line to move to, by the latest tool line or by id, and the input to send afterwards. The runner calls session.branch_set_default after the target line's first turn/end and then submits the input, which names a line only when the scenario does.

session.submit no longer pins branchId to main, so an input after a switch reaches the default branch. A scenario without a switch runs as before.

The runner's two new unit tests cover the switch step and an input that names no line.
Add the seven scenarios for the default branch's opening and switching roles: two should-open, two boundary and three switch scenarios, each with a 131,072-token window. Two switch scenarios and root-opens-after-switch use the runner's new switch step.

The committed-set test now reads all sixteen scenarios and pins their windows and switches. The design pages name the added set and the runner's mid-run move.
A pending switch now keeps the run open, so a target line that never
appears or never finishes its first turn is not mistaken for an idle
run. A switch still pending when the loop ends stops the run as
`switch_target_not_reached`, with the target in the reason and its own
place in the failed-run count.

A target whose line ended before the move answers `branch_ended`; the
run stops as `switch_target_ended` instead of a harness error, and the
reason names the line.

The switch's order, single fire and error path are covered by a
recording client: the default branch moves before the next input, a
second trigger sends nothing, and a refused move sends no input. Both
the swapped order and a switch that fires twice make the test fail.
The switch-then-open-lines message also asks the former default, the
root, to check README.md, and the root may open lines whatever the
default branch is. The probe now names the files the new default
branch owns, so the root's own README work is not a violation.
The Chinese scenario table gains the two switch rows the English table
has and drops its duplicated row. model-prompts §9.4 names the sixteen
scenarios instead of the original eight.
A line that ends itself commits `branch/end` during its turn, so the
move that follows the turn's end answers `branch_target_protected`
rather than `branch_ended`. Both refusals now stop the run as
`switch_target_ended`, with the tree's message, instead of recording a
harness error; the test covers both codes.
rustfmt wraps the call-count assertion; no behavior changes.
The first turn can start before the line is marked ready, so the
move now runs at the target's `turn/start` and retries a bounded
number of times when the tree answers `unknown_branch`. A line that
never becomes ready ends the run as `switch_target_unknown`; the
runner records its retry count.

The design sentence in model-prompts §9.8 follows the new trigger.
Tests cover the trigger, the retry, the exhausted budget and the
pending-switch outcome at a run's budget.
Declare 29,000 for identity-after-compaction and update its window
assertion and the design text in both languages. The window is chosen
so the compaction trigger sits below the request peaks the scenario
reaches.
The wrap-up after a run stopped on its turn or wall-clock budget did
not tell an untriggered switch from a triggered one: a move that kept
answering `unknown_branch` while its retries were unspent was reported
as "the first turn did not start", which the target's own
`turn/start` contradicts. Report the unfinished move instead.

The test drives a scripted peer whose target line starts and ends its
first turn and whose `session.branch_set_default` answers
`unknown_branch`, and stops the run on its turn budget with retries
left. It fails on the previous wording with that reason.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 318d81eb. The switch runner and scenarios are useful, and the identical-arm smoke is correctly described as an instrument check, not a no-regression result. Two issues can make a future policy measurement count the wrong behavior:

  1. [P2] Keep the switch trigger tied to the line that started. PendingSwitch::notice replaces line for each tool branch/create without clearing triggered. If A starts, the first move returns unknown_branch, and B's create notice is consumed next, the retry can promote B and submit the follow-up before B has started. Pin A once its start triggers the switch, or make B wait for its own start if retargeting is intended. Add a fake-peer case with A start → A retry → B create (no B start) and assert B is not promoted.
  2. [P2] Score the branch-opening behavior in switch-then-open-lines. Its probes require the fix, both additions, and no work by the former default, but never require the new default to open either line. The smoke already exhibits the false positive: one of ten runs opened no line on the new default, yet every probe passed. Add a positive delegation probe, ideally backed by branch/create events attributed to the promoted line, so doing both additions inline cannot satisfy this scenario.

These are source and reported-smoke findings. I did not rerun the live model. Exact CI was still running.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 318d81eb6be3044628cd3b2538be1c4f9da6541d on d757f7813a3e9ac9886ceb715521e72193ed2c72.

[P2] Apply the scenario deadline to the branch switch and follow-up submit. drive waits for fire_switch before checking the wall-clock budget. The switch and follow-up use Client::rpc, which can keep waiting while a connection stays open. A stalled reply leaves the run without a timeout result and occupies a worker slot. Apply the same absolute scenario deadline to both RPCs, and have a delayed mock reply verify that the runner records a timeout and releases the worker. This finding is from source inspection.

Eleven targeted no-model tests passed on the exact merge tree. Eric's switch-target and probe findings are separate; the target issue also failed in a local mock. Exact CI passed macOS; Linux was running when checked. No live model calls were made.

A switch names its target by role, which moves to each tool
`branch/create` until the target's first `turn/start`. A run could meet
`unknown_branch` on the first move, then read a later line's create and
promote that line before its own first turn, sending the scenario's next
input to a line with another purpose.

The line whose first turn started now keeps the switch: a later create no
longer renames the target, so the retry and the next input stay with the
line the scenario meant. The test starts A, retries the move, then reads
B's create and asserts the retry promotes A.
`switch-then-open-lines` asks for two independent additions after the
move, but its probes only checked that both were done and that the former
default branch left them alone: a run that did both on the new default
branch itself passed. The new `new-default-opens-a-line` probe requires
that line to open a line for one of the two additions.

The scenario set test pins the probe, and §12.3 gains a row naming what
the scenario watches for, in both languages.
The run called `session.branch_set_default` and submitted the next input
before it checked its wall clock. Both calls go through `Client::rpc`,
which waits on an open connection, so a reply that never came left the
run without an outcome and held its worker indefinitely.

The switch now runs inside the same absolute deadline the budget check
uses, counted from the first submission. When that deadline passes first,
the run records `seconds` with an error naming the line, instead of
waiting on the connection.

The scripted peer gains two stalling scripts, a move that never answers
and a submit that never answers; the test asserts both stop on the
deadline and return.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1999 (review)

Fixed in 591ae8b and 01e5b2a.

The switch stays on the line that started. Once the target line's first turn/start has triggered the switch, a tool branch/create read afterwards no longer renames the target: the retry of the move and the next input stay with the line the role picked before it started, and a newer line waits for its own start. scenario_eval::tests::a_retried_switch_stays_on_the_line_that_started runs A's start, A's move answered by unknown_branch, then B's create with no B start, and asserts that the retry promotes A and that B's create leaves the target unchanged.

switch-then-open-lines scores the delegation. The scenario carries a positive must_show probe, new-default-opens-a-line: after the switch, the new default branch must open at least one line for one of the two additions, --leeway in cli/login.py or CSV output in audit/exporter.py, so doing both additions on the new default branch itself no longer satisfies the scenario. scenario_eval::tests::the_committed_scenario_set_parses_and_its_shared_premises_stay_equal pins the probe, and §12.3 of the design gained a row naming what the scenario watches for, in both languages. The probe was added after the smoke, so it has no judge verdicts: from the saved timelines, nine of the ten switch-then-open-lines runs opened two to three lines on the new default branch and the tenth opened none, so that run would not satisfy the new probe.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1999 (review)

Fixed in 631feba.

The switch and its follow-up are bounded by the scenario deadline. The switch now runs inside the same absolute deadline as the wall-clock budget, counted from the first submission, so session.branch_set_default and the session.submit after it both stop waiting at that instant. When the deadline passes first, the run records seconds with an error naming the line and returns instead of waiting on the connection. scenario_eval::tests::a_stalled_switch_call_stops_on_the_scenario_deadline scripts the peer to answer neither the move (one case) nor the submit after the move (the other), and asserts that each run stops on its deadline with that error; the run is also held to a guard, so a runner that waits on the reply fails the test instead of hanging it.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed 631febaf. The retry now stays with the line whose start triggered it, and the new delegation probe means a run doing both additions inline can no longer pass every probe. The probe was added after the smoke, so the prior results are not new judge verdicts. The timeout now covers both switch RPCs inside drive.

[P2] Bound cleanup so a switch timeout can actually free the evaluation worker. When drive returns seconds, drive_once immediately sends an unbounded session.close on the same connection before it can return the result. A dropped client wait isn't a cancelled server-side move: the tree's admitted default change keeps settling until publication, and tree close awaits those tasks. So if a move stalls on publication, cleanup can still wait behind the operation that just timed out. The new test only calls drive and doesn't exercise this path.

Give post-timeout cleanup a bounded grace and preserve the timeout outcome if cleanup cannot settle, using the isolated run child's supervision to release the worker if needed. Extend a fake-peer or child test to withhold the move and then the close reply, asserting that the caller receives a timeout outcome and the worker slot is released. Source finding; no live model run. Exact CI was still running.

A run that stops on its wall clock gives its cleanup a bounded grace:
the Session close, the remaining budget stops and the deferred window
read, and the child's served App Server join. Cleanup that cannot settle
within that grace keeps the timeout outcome; the child still prints it,
so the parent's worker is released. The normal path is unchanged.

Driven.timed_out records the wall-clock stop, because a pending switch
renames the stop to switch_target_not_reached.

The new scripted-peer test withholds the move reply and then the close
reply, and drives both deadlines on a paused clock.
The deferred window read is cleanup for a run that stopped on its wall
clock. If it answers with an error other than the deferral, or with a
window that does not match, the run keeps `seconds` and the error that
ending carries instead of turning the stop into `error`. A read that
succeeds still records the window. A run that did not time out takes the
same path as before.

The test scripts a peer whose first window read is unavailable and whose
deferred read answers `session_reloading`, and the scenario's budget is
zero, so the test waits on no clock. The assertions are the `seconds`
stop, the peer's two window reads and the read's error not becoming the
run's error. On 67a9a85 it fails with the stop recorded as `error`.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1999 (review)

Fixed in 67a9a85, with the deferred window read corrected on top.

Cleanup after a wall-clock stop is bounded, and the timeout outcome stands. When a run stops on its wall clock, its cleanup now runs under the same 30 second settle bound the harness already gives cancelled siblings: the session.close after the run, the remaining session.stop calls and the deferred context-window read in drive, and the served App Server's join in the run's child. If a wait does not settle in that grace, the run keeps the seconds stop and its error, and the child prints that outcome and exits, so spawn_child releases the run's slot. The close result is ignored as before, so a refused or timed-out close cannot replace the outcome. The deferred read is cleanup as well: a read that answers after the timeout records its window when it succeeds, and an error or a different window leaves the seconds stop and its error in place. Runs that do not stop on the wall clock take the same unbounded path as before.

Driven.timed_out records the wall-clock stop when it happens, because a pending switch later renames the stop to switch_target_not_reached; the cleanup paths read that flag rather than the stop's spelling.

scenario_eval::tests::a_timed_out_run_closes_within_a_bounded_grace scripts a peer that answers the run up to the move, then withholds both the move reply and the close reply. It drives the run's and the cleanup's deadlines on a paused clock and asserts that the run returns seconds with its original error and that the peer read the close. On 631feba the same test fails with "the run kept waiting for cleanup after its timeout".

scenario_eval::tests::a_timed_out_run_keeps_its_outcome_when_the_deferred_window_read_fails scripts a peer whose first context-window read answers context_usage_unavailable and whose deferred read answers session_reloading, with a zero wall-clock budget so the test waits on no clock. It asserts that the run still stops as seconds, that the peer read the window twice and that the read's error did not become the run's error. On 67a9a85 the same test fails with the stop recorded as error and Context window check failed: the Session is reloading.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 22, 2026 08:22
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1999 (review)

Fixed in b2e13c6, with the parent's read bounded in 2c7b46a, the stdout-holder test's guard and scope set in e3dbd75, and a timed-out run's judge bounded in 4a5851b.

drive_once now reads the close's result instead of discarding it. On a wall-clock stop, a close that answers Ok is a settled Session, and the run exports and is judged as before. A close that times out or errors is not settled: the run keeps the seconds stop and its error, writes no export, and asks no judge. Its record says not_asked with the reason "the Session did not close within the cleanup grace after the run stopped on its wall clock", and no run-N.timeline.jsonl is written.

I omitted the export rather than writing a bounded snapshot marked incomplete. A Session that has not closed is still settling the move the run stopped on, so its export is not the settled record the report reads, and an incomplete marker would add a record field and another bound for a run that already failed and is already outside every probe rate.

After the timeout the path is: the remaining session.stop calls and the deferred window read (bounded, outcome ignored), the close (bounded, its result now decides), the export and the judge (skipped when the close did not settle; the judge bounded when it did), the child's server.shutdown and server.join (bounded), the child printing its record and exiting, and the parent returning the --jobs slot once it has read the child's output within its bound and parsed the record. The parent's read of the child's output after the child exits is bounded and cancellable too: a member the child left behind can keep the write end of its stdout open, so the read gets the same cleanup grace (30 seconds, or the 200 ms a test hook sets) and the evaluation's cancel ends it at once. When the grace runs out the child's process group is killed and the outcome is read from what the child printed before it exited; a child that printed no outcome is the existing "printed no outcome line" failure. On a successful exit the group is killed after the read as well, so no member outlives the harness. Nothing the run's own stop reaches waits without a bound, and nothing after the timeout enters the export or the judge unless the close settled.

A timed-out run that did close gives its judge the same cleanup grace: 30 seconds, or the shorter grace a test hook sets. The judge then reads the view of a failed run, whose verdicts enter no probe rate, so a judge that has not finished inside the grace is not waited for: its record is a failed judge call with the reason "the judge did not finish within the cleanup grace after the run stopped on its wall clock", the run keeps its seconds stop and its error, and the child prints the record and exits. A run that did not stop on its wall clock judges exactly as before.

scenario_eval::tests::a_timed_out_run_whose_cleanup_stalls_frees_its_worker runs two scenarios at one job through the real child and supervisor. The first scenario's model answer is held until its wall clock of 0.2 seconds stops the run, and a test hook makes the wait after the close and after the server shutdown never return while shortening the cleanup grace to 200 ms. The test asserts that both arms of that scenario return records with seconds, failed, not_asked and the reason above, that neither leaves an export, that the second scenario's two runs still stop idle and are judged, and that only those two runs reach the judge. On 0bcc797, with the test and its hook but the old close handling, the same test fails after 30 seconds with the evaluation still waiting on the first run. scenario_eval::tests::a_timed_out_run_that_closes_is_judged covers the other half: the run stays open on a steer that is not due, reaches its wall clock with an idle Session, the close settles, and the record stops seconds, is failed, exports its Timeline and is judged. Changing the close result in drive_once to a constant false makes it fail with not_asked and no export.

scenario_eval::tests::a_timed_out_run_whose_judge_never_answers_frees_its_worker covers the bounded judge: two scenarios at one job through the real child and supervisor, a test hook setting the judge's deadline to one second, and a provider holding the first scenario's judge answer for a minute. Both arms of the timed-out scenario stop seconds, are failed, record call_failed with the reason above and keep their exports; the second scenario's runs stop idle and are judged, so the first runs' children freed the slot. With the deadline wrapper reverted, the test fails after its 60-second guard with the evaluation still waiting on the first run.

scenario_eval::tests::a_child_that_leaves_a_stdout_holder_stops_at_the_read_bound has a child exit successfully while a member of its group keeps its stdout open, at one job over both arms: the evaluation returns, both arms keep idle and judged records, and every member is gone. Without the bounded read it waits out its 60-second guard, the evaluation still waiting on the first arm. scenario_eval::tests::a_successful_child_leaves_no_group_member covers the exit that reaches EOF: the child's member is gone when evaluate returns, which the old disarmed group left running.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 22, 2026 12:20

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed 615f2b8c. A failed or timed-out close now skips export and judge, and the judge and inherited stdout waits have bounds. The real child/supervisor tests are a meaningful improvement over the previous fake-peer case.

[P2] Bound the settled-export path before declaring that wall-clock stops release the worker. If close succeeds, drive_once still awaits an entire SQLite timeline export before it reaches the bounded judge or server join. The exporter pages through all branches; a per-query SQLite timeout is not an end-to-end deadline. The parent waits for child exit before the stdout grace even starts. A slow export can therefore still hold the only worker after the scenario's deadline. Either omit export/judge for wall-clock failures, or apply the remaining cleanup budget to export and preserve seconds with no partial export on expiry. Cover successful close followed by stalled export in the one-worker regression. If the contract is a hard process bound, enforce it in the supervisor too, since a child stuck in blocking work may never reach exit.

Static review. Exact CI is still running overall; the dependencies job has already failed on the url 2.5.8 advisory (RUSTSEC-2026-0592), separate from this finding.

A run that stops on its wall clock now fixes one cleanup deadline at
that moment, and every step after it runs under that deadline: the
remaining session.stop calls, the deferred window read, the close, the
Timeline export, the judge, and the child's server shutdown and join.
An export that misses the deadline leaves no partial export, keeps the
stop and the error it reached, and the run records no judgment.

The parent now gives each serve child a hard bound: the run's wall
clock, the startup before it, the cleanup budget after it, and the
grace to read its output. A child stuck in blocking work may never
reach its own cleanup, so the bound kills its process group and the
run keeps the wall-clock stop without an export or a judgment.

The tests use controlled timing: on one worker, a run whose close
settles and whose export stalls frees the slot for the next scenario,
and a child that blocks after its wall clock is killed at the parent's
bound with no process left behind.
A run that does not stop on its wall clock is not under the cleanup
budget: its judge may legitimately spend the failure policy's five
minute wait budget on retries. The parent's hard bound on its child
now takes the larger of the cleanup budget and that wait budget, so a
slow but legitimate judge is not killed and recorded as a wall-clock
stop.
The scenario stops on its wall clock after half a second instead of a
second, and its cleanup budget is one second instead of two, so the
test spends less of its hang guard on waits it does not need. The
shared guards and the other tests' bounds are unchanged.
The flows that run a real serve child through the supervisor take one
outer guard, `SUBPROCESS_EVAL_GUARD` (60 seconds), and the answers and
the stdout member they must outwait take `HELD_PAST_GUARD` (90
seconds), with a compile-time assertion that the second is longer. The
failed-run sibling flow gains the same guard.

The stalled-close, stalled-export and unanswered-judge flows also
assert that their stalled case's record ends under 20 seconds, so an
implementation whose bound is merely too long fails instead of
passing. The 10-second guard of the failed stdout holder is left as it
is.
The timed-out run that closes and is judged runs a real serve child
through the supervisor like the other subprocess flows, so it takes
`SUBPROCESS_EVAL_GUARD` instead of a 30-second guard of its own, and
its records assert that the stop, close, export and judge finish
under 20 seconds. The record is taken before the served App Server's
join, so the join is not part of that bound.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1999 (review)

Fixed in 7747f4f and 72d13a5, with the tests in 4129e21 and 8e61cff. The judged flow's guard and record bound are in 4560a5d. The settled-export path now runs under the same cleanup deadline as every other step after a wall-clock stop, and the parent enforces a hard bound on each serve child, so a run whose child never reaches its own exit cannot hold the --jobs slot.

A run that stops on its wall clock fixes one deadline at that moment: 30 seconds (CLEANUP_BUDGET), the 200 ms the stall_cleanup test hook sets, or the milliseconds a test hook gives. Every step after it runs under that deadline with timeout_at, so the cleanup is bounded as a whole instead of step by step. On the child the steps are: the remaining session.stop calls, one request per line; the deferred session.context.usage read; session.close; the Timeline export; the judge; and the served App Server's shutdown, which only cancels and waits for nothing, followed by its join under the deadline. A close that does not settle keeps its outcome: no export, no judge, not_asked with the reason. An export that reaches the deadline writes no partial export: the run keeps its seconds stop and its error, the judge is not called, and the record is not_asked with "the Timeline export did not finish within the cleanup grace after the run stopped on its wall clock". A judge that reaches the deadline gets only what is left of the budget and is recorded as a failed call with "the judge did not finish within the cleanup grace after the run stopped on its wall clock". The child then prints its record and exits.

The parent gives each serve child a hard bound from the spawn: the run's wall clock, a startup bound of 120 seconds (STARTUP_BOUND, twice the plugin wait), the larger of the cleanup budget and the judge's per-request wait budget (JUDGE_BUDGET, the failure policy's WAIT_BUDGET, which bounds one request's retry sleeps and not the time its reply takes to stream), and the output-read grace. That budget does not bound the whole judge: a provider that streams slowly on every call is not covered by it, so a run that did not stop on its wall clock can still reach the parent's bound, have its child killed, and be recorded as seconds, failed, not_asked, with no export. A child still alive at the bound is killed with its process group, reaped, and its stdout reader is aborted; the record carries "the run's serve child did not exit within the parent's bound of Ns", and the slot returns when that record is built.

So, from the wall-clock stop to the slot return: on the child, the wait in each of the six steps above runs under the one cleanup deadline (the shutdown only cancels; its join is the wait), and the outcome print and process exit have no wait; before the wall clock stops, the child's server start, connect, plugin wait, selections, preflight and session creation have no deadline of their own and are covered only by the parent's hard bound. On the parent, child.wait() runs under the hard bound, the read of the child's output under the read grace and the same hard bound, and parsing the line and building the record have no wait; the slot returns when the run's future returns. The evaluation's cancel can end the wait and the read at any point, and a failed run settles its in-flight siblings under SETTLE_BOUND. I am not claiming that no await is unbounded: a run that did not stop on its wall clock still closes, exports and judges without a cleanup deadline, so the parent's hard bound is the only end to that path; a child that is still working at that bound is killed and its run is recorded as seconds, failed and not_asked, with no export.

scenario_eval::tests::a_timed_out_run_whose_export_stalls_frees_its_worker covers the settled-close, stalled-export case at one job over two scenarios. Both arms of the first scenario stop seconds, are failed, record not_asked with the export reason and leave no run-0.timeline.jsonl; the second scenario's runs stop idle and are judged, so the slot came back. With the export's deadline removed and the rest of the fix kept, the evaluation is still waiting on the first run after its hang guard. scenario_eval::tests::a_child_stuck_after_its_wall_clock_stops_at_the_parent_bound has each child block its thread after the wall clock, so no timer of the child's can fire: with a two-second hook bound both arms are recorded seconds, failed, not_asked, no export, the next arm runs on the freed slot, and the killed child's process and group are gone. With the parent's bound removed, the test waits out its hang guard. scenario_eval::tests::a_timed_out_run_that_closes_is_judged takes the same 60-second guard as the other subprocess flows, and its records must stay under 20 seconds. That record is taken before the served App Server's join, so the join is outside the assertion; the stop, close, export and judge do finish under 20 seconds, while the 30-second default cleanup budget is the one in effect because this test sets no cleanup hook. scenario_eval::tests::a_timed_out_run_that_closes_is_judged and scenario_eval::tests::a_timed_out_run_whose_judge_never_answers_frees_its_worker still pass.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 22, 2026 15:58

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Keep a deadline-limited outcome read local to one eval run. The new watchdog bounds a stalled export, which addresses the previous blocker. There is still a race between child exit and draining stdout: if exit wins just before the deadline and the reader has only part of the outcome, the drain branch aborts the reader and then parses the partial buffer as if it were complete. A missing or truncated result becomes an error that cancels the entire evaluation instead of a timeout for that one run. Drain and parse.

Track whether the reader reached EOF or was stopped by its deadline. If the deadline stopped it, accept a complete result already captured, or record a timeout for that run and continue. Keep surfacing malformed output normally when the read completed. A focused supervisor regression should verify that this branch leaves the next scheduled run intact.

This is a static finding. CI 45041095952 was running on the merge with c347bc34; dependencies passed, Linux and macOS were pending.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed 4560a5d6. The shared deadline now reaches the settled export and judge, and the supervisor can reclaim the slot if the child never exits. The in-memory export also avoids publishing an incomplete Timeline.

[P2] Distinguish a supervisor timeout from the scenario’s own seconds stop. The hard bound starts at spawn and covers startup as well as cleanup and judging. The live-child deadline branch discards collected output and always synthesizes stop: seconds. So a startup stall, an idle scenario followed by a slow judge, and a child that already printed its result but cannot exit all look like the scenario ran out of time. The judge can legitimately make multiple requests, but the hard bound reserves only one request’s retry budget. This is separate from the exit-first partial read noted in the other review.

Keep watchdog expiry a failed run, but record it as a supervisor failure unless the child reported the scenario’s own wall-clock stop. Preserve a complete outcome if one was already captured and attach the teardown failure. Give the judge phase an explicit budget, and have the watchdog test confirm the child reached its intended stall before asserting that the next run gets the slot.

Source review; exact CI passed dependencies and macOS, with Linux still running.

The parent now tracks whether its read of a serve child's output reached EOF or was cut at its deadline, so an exit-first race records a supervisor timeout for that run and leaves the next scheduled run intact, while a malformed completed line still fails the evaluation.

A complete outcome printed before the parent's hard bound stands: the teardown failure is attached as an error instead of replacing the run's stop, export and judgment.

A child the bound ends before its outcome is a supervisor failure with no export and no judgment, unless the child reported the scenario's own wall-clock stop, which is kept.

The non-wall-clock judge phase gets its own 600-second budget for up to four legitimate calls, the parent's hard bound covers it, and every server join is bounded so a finished outcome is printed and its slot released.

A failed turn in the export no longer replaces a run's wall-clock stop, and the stall hooks write a marker the parent's bound counts from, so a slow start cannot spend the bound under test.
The child's first output line carries the test harness's test-name prefix, so the run's reported ending is read from the first line that names it, and the JSON object is parsed from that line's first brace.

The judge phase budget test runs both arms at once, so a loaded host cannot spend the guard on four sequential starts.
The non-wall-clock join is pinned by a_run_whose_server_never_settles_keeps_its_outcome: a new afterShutdown stall point writes the child's marker before the join and never lets the shutdown settle, the join runs under the settle grace, and the run keeps its stop, export and judgment with the teardown failure attached as an error, so the child prints its outcome and the next scenario runs on the same slot. The settle grace is the test hook's shorter grace when the hook is set; a run without the hook still waits the product's 30 seconds.

The export's ending rule is a named function, settle_failed_turn, pinned by a_failed_turn_in_the_export_does_not_replace_a_wall_clock_stop: a failed turn in the export fails a run that did not stop on its wall clock, and a run that did keeps its seconds stop.
The comment on the non-wall-clock judge phase said the run keeps every call recorded so far, but an unfinished phase records a failed call with no calls. The comment now states what the record holds: the run's stop and its export.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

The parent now tracks whether its read of the child's output reached EOF or was cut at its deadline. A completed outcome line already collected when the deadline cuts the read is accepted. A deadline cut before the line is one run's supervisor failure: its stop is error unless the run had reported its own wall-clock stop, judgeOutcome is not_asked, it writes no export, and the evaluation continues with its next scheduled run. A read that reaches EOF still surfaces a missing or malformed line as an error. a_child_that_exits_before_its_outcome_leaves_the_next_run_intact covers the exit-first race and asserts the next scenario is judged on the same slot; a_child_that_exits_without_its_outcome_fails_the_evaluation and a_garbled_outcome_line_fails_the_evaluation pin the completed-read errors.

Fixed in 0e1d2f0.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

The parent records a watchdog expiry as a supervisor failure unless the child reported the run's own wall-clock stop before it stalled; the child prints that ending before cleanup, and only then is the reported stop kept. A complete outcome printed before the bound stands with its stop, export and judgment, and the teardown failure is attached as an error so the run is failed. The judge phase of a run that did not stop on its wall clock now has its own 600-second budget for up to four legitimate calls, and the parent's hard bound covers it. The watchdog test now waits for the child's own stall marker before the bound, so a slow startup cannot trigger it: a_child_stuck_after_its_wall_clock_stops_at_the_parent_bound asserts the marker and the kept seconds stop, a_child_stuck_before_its_outcome_is_a_supervisor_failure asserts the supervisor error with no export, and a_child_that_printed_its_outcome_and_blocks_keeps_it asserts the preserved outcome. The second and third also assert that the next scenario is judged on the released slot. a_run_whose_judge_outlives_its_phase_budget_keeps_its_stop pins the judge budget, keeping idle and the export with a failed judge call.

Two more tests pin the rest of the rule. a_run_whose_server_never_settles_keeps_its_outcome covers a run that did not stop on its wall clock: its stall marker proves the child reached the served App Server's shutdown, the join never settles, and the run keeps its stop, export and judgment with the teardown failure attached as an error, so the child prints its outcome and the next scenario is judged on the same slot. a_failed_turn_in_the_export_does_not_replace_a_wall_clock_stop covers a failed turn in a run's export: it fails a run that did not stop on its wall clock, and it does not rewrite a run's seconds stop.

Fixed in 7450169.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at head 7450169.

The runner support is built the right way round: the doc section it implements (§9.8 of model-prompts) came first, and the code follows it rather than the other way round. A scenario names its switch target by role or id, fire_switch moves the default branch through session.branch_set_default and then submits the next input, and the target is fixed at that line's first turn/start so a line opened afterwards cannot redirect the move. The outcomes are told apart by kind rather than by message: branch_ended / branch_target_protected end the run with switch_target_ended, an unknown branch consumes a bounded retry and then ends it with switch_target_unknown, and anything else propagates as a plain error. The switch fires once, and switch.take() on the failure paths means a later event cannot fire it again.

The cleanup half is the part I would have expected to go wrong and it does not: a run that stops on its budget fixes one cleanup deadline at that moment and everything after it — Session close, the remaining budget stops, the deferred window read, the export, the judge, the child's join — runs under that deadline; a close that does not settle keeps the timeout outcome and is not judged, and its record says not_asked with the reason. That is the difference between an evaluation that reports honestly and one that hangs. The tests sit where they should for a runner: fire-once, retry-stays-on-the-line-that-started, refused-switch-propagates-and-sends-no-input, and the timeout path on a paused clock via tokio's test-util in dev-dependencies.

Blocking: none.

Checks are green at this head. I read fire_switch, its caller's outcome match, the retry accounting, the cleanup-deadline assignment, the Cargo.toml dev-dependency and the test names; I did not read the 3580-line scenario_eval.rs delta in full, the scenarios' workspaces, or the doc changes, and ran nothing.

Non-blocking:

  • xtask/src/scenario_eval.rs:5856 — SwitchFire::Retry increments switch_retries and returns to the event loop with no wait shown here. If the loop turns on every bus event, a burst arriving before the line registers can burn UNKNOWN_BRANCH_RETRIES in microseconds and end a run that would have succeeded a moment later. The body says "retrying briefly"; if the delay lives in the loop's own pacing rather than at this call site, a comment saying so would keep the next reader from "fixing" it into a sleep.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed this head. A deadline-limited stdout drain now preserves a complete result if one is available and otherwise records a failure for that run without aborting the rest of the evaluation. Malformed output after a completed drain still surfaces as a harness error. The relevant regressions passed in the exact Linux run, and the required CI gate is green. This approval covers the runner changes, not the separate policy evaluation in #2013.

`SwitchFire::Retry` does not sleep at its match arm: the pass returns to the loop, which waits for the next notice (`wait_time`) before the move is tried again.

The comment points a reader at that pacing so the retry is not changed into a sleep at the call site.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Confirmed: SwitchFire::Retry does not spin on its own. The attempt is paced by the run loop's wait for the next notice (wait_time), and the comment on that match arm in e321f4a says so.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reconfirmed on this exact head: the only change since the previous approval is a comment explaining that the switch retry returns to the notice-receive loop. The implementation and the previously verified timeout fix are unchanged. Current merge CI passed.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at head e321f4a.

The single commit since the head I approved at 7450169e is the answer to the one non-blocking point I raised there, and it settles it in the right place: SwitchFire::Retry does not sleep at its match arm — the pass returns to the loop, which waits for the next notice via wait_time before the attempt — and the comment now says so at the arm. That was the risk I named, that a later reader would "fix" the missing sleep into one and change the run's pacing under the deadline; the note removes the ambiguity without touching behaviour.

Nothing else changed: the preceding review's ground still holds — the switch fires once, the target is fixed at the first turn/start, outcomes are told apart by kind (switch_target_ended, switch_target_unknown, plain error), and the cleanup deadline fixed at a budget stop governs the Session close, the deferred window read, the export, the judge and the child's join, with a close that does not settle recorded as not_asked with its reason.

Blocking: none.

Checks are green at this head. I read the full delta against 7450169e — two lines plus the commit message — and re-relied on the reading recorded at the previous head for the rest; I did not re-read scenario_eval.rs in full or run anything.

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.

3 participants