testbox: approval helper finds a queued box's run (fix deadlock)
Fix for the deadlock in scripts/blacksmith-testbox-approve.sh (from #17129). blacksmith 0.4.64 prints a box's RUN URL only after a runner takes the job, and a runner takes the job only after the gate is approved. The helper therefore waited for a URL that never appears. Two GPUI boxes were lost this way.
The helper now proves the run with the strongest evidence it has, in this order:
- The run title names the box. The warmup workflow gains
run-name: cmux-tui Rust Testbox setup ${{ inputs.testbox_id }}. A run titled with another box is never approved. - The RUN URL, when Blacksmith shows it.
- Exactly one waiting warmup run, with no box id in its title, created between the dispatch time minus 60 s and the dispatch time plus 120 s. The helper lists with
per_page=100. Two or more candidates make it refuse and print them.
The chosen run must also be: the warmup workflow, workflow_dispatch, ref main, status waiting, and triggered by the caller or Blacksmith's app. Any failure approves nothing and exits 3.
Tests: tests/test_testbox_approve.sh covers 7 cases with fake gh and blacksmith. It is red on the first commit (case 1: a queued box with one matching run) and green on the fix. tests/test_ci_testbox_broker_guard.py passes (10 tests). actionlint passes on the workflow. A live success-path run on a real queued box follows in a PR comment.
Changelog
none
🤖 Generated with Claude Code
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Fixes the Testbox approval helper deadlocking on queued boxes. Blacksmith 0.4.64 prints a box's RUN URL only after a runner takes the job, which happens only after approval, so the old helper waited for a URL that never appeared and lost two GPUI boxes.
The helper now approves only a run that is provably bound to the box:
- A run title that names the box. The warmup workflow now sets
run-name: cmux-tui Rust Testbox setup ${{ inputs.testbox_id }}, and a run naming another box is never approved. - The RUN URL, when Blacksmith shows it.
A run found only by its dispatch time is never approved: another operator's run can appear first inside any time window. The chosen run must also be the warmup workflow, workflow_dispatch, on ref main, status waiting, and triggered by the caller or Blacksmith's app. Any mismatch approves nothing and exits 3, and a queued unsigned run with no title is refused. stdout ends with the bare run id; the success message goes to stderr.
Tests
Adds tests/test_testbox_approve.sh with 7 cases using fake gh and blacksmith binaries, run in the CI guard matrix.
Migration
When dispatching a warmup, capture the epoch with date +%s right before blacksmith testbox warmup and pass it as the second argument.
Summary by CodeRabbit
- Reliability
- Testbox warmup runs are matched using run details and dispatch timing. Ambiguous matches, mismatched Testbox titles, and runs that are no longer waiting are rejected.
- Approval checks wait for a matching run for a configurable period, helping accommodate delays in run availability.
- Warmup run titles now display the dispatched Testbox ID.
- Automated Checks
- Added automated coverage for Testbox approval scenarios and included it in CI checks.