fix(cli): report Ctrl+C during reload readiness wait as canceled, not a shard failure
Detail bug report: View on Detail
Screenshot / Recordings
No screenshot or recording attached: the change is in terminal output text (box summary label and error message), verified via before/after terminal captures described in "How did you verify?" below.
What changed
Ctrl+C during world reload's shard readiness wait was reported as a hard shard failure — the box showed "failed", the CLI printed "0/N instances are serving; check world logs", and the process exited 1 — indistinguishable from a genuine crash-loop. A developer who deliberately aborted a slow reload was told their shards failed to come up.
Root cause: WaitForShardsReady returns counts only (no error). On ctx.Err() != nil it returns the last completed count (zero before the first completed probe round) without calling onProgress. rollShards then unconditionally converted ready < expected into shardsNotReadyError without checking ctx.Err(), so a cancel reappeared as a real failure. The phasebox row also showed "timed out (k/N ready)" even though the 2-minute timeout never elapsed.
Fix: After the readiness wait in rollShards, check ctx.Err() and return the bare ctx.Err() on context.Canceled — before converting counts into shardsNotReadyError. Box.Run silences context.Canceled at the section boundary (the box summary shows "canceled") and JoinFailures classifies it as a cancel, not a failure. Only context.Canceled is silent — a caller DeadlineExceeded falls through to shardsNotReadyError. The readiness row is marked canceled through sess.Fail so phasebox owns the "canceled" label, instead of "timed out". Cancellation wins even when the counts are complete.
The readiness wait + error classification was extracted into waitForShardsReadyResult with a shardReadinessWaiter interface seam for unit testing, mirroring the existing shardBuilder pattern. The same fix covers world start, which shares the deployShardImages → rollShards path.
How did you verify?
Unit tests (new): 12 tests in cli/commands/root/reload_internal_test.go covering the three waitForShardsReadyRow terminal states (canceled, timed out, ready), the no-progress edge case, and the waitForShardsReadyResult outcomes (cancel before progress, cancel after progress, cancel after complete counts, timeout→shardsNotReadyError, deadline→shardsNotReadyError, ready→nil), the JoinFailures interaction (a cancel alone stays silent), and a real plain-phasebox section regression. 2 tests in cli/pkg/local/runtime_internal_test.go covering WaitForShardsReady's contract on cancel (returns (0, N) without onProgress) and on a caller cancellation with two controlled endpoints (one serving, one accept-and-close via the shared withFreePorts seam) asserting the partial count survives.
Unit tests (existing): All existing tests in cli/commands/root/ (build, logs, endpoints), cli/internal/errors/ (silent error, JoinFailures), and cli/internal/tui/component/phasebox/ (cancel contract) pass unchanged.
Static checks: go build ./cli/..., go vet, and gofmt all clean. Full go test -count=1 ./cli/... (34 packages) passes.
End-to-end (Docker): Built the CLI and ran it against a live Docker world using the bare-bone-template fixture (whose shard crashes on startup, so the readiness wait is always in progress when interrupted):
- Ctrl+C during
world reloadreadiness wait: box shows"canceled", no"0/N instances are serving"message. Before the fix (old binary): box shows"failed", prints"0/1 instances are serving; check world logs". - Ctrl+C during
world startreadiness wait: box shows"canceled", world stops cleanly, no standalone"0/N instances are serving"error. Before the fix: box shows"failed". - Ctrl+C during
world reload --purgereadiness wait: purge succeeds, box shows"canceled", no failure message. - Genuine timeout (no Ctrl+C):
world reloadwaits the full 2 minutes, shows"failed (2m0s)", prints"0/1 instances are serving; check world logs", exits 1 — no regression. - Successful reload (healthy shard): could not run end-to-end because the fixture's shard crashes on startup; the success path is covered by unit tests (
TestWaitForShardsReadyResult_ReadyReturnsNil,TestWaitForShardsReadyRow_ReadyShowsDone).
Caveats
The exit code on Ctrl+C is still 1 (not 0) because main.go sets exitCode=1 for any non-nil error, including silent ones — this is the existing behavior for all commands and not a regression. The bug was about the misleading failure message and box label, both of which are fixed: the message is no longer printed (silent error), and the box shows "canceled" instead of "failed".
AI Usage
Created with detail-zai/glm-5.2 in opencode. Fully autonomous: the bug report, fix, tests, and verification were all produced by the agent.
Automatic Fixes PRs can be configured here.
Summary by cubic
Fixes world reload and world start reporting Ctrl+C during the shard readiness wait as a shard failure (box shows "failed", the CLI prints "0/N instances are serving", exit 1) instead of a cancel. WaitForShardsReady returns counts only, so a canceled context collapsed into (0, expected) and was misread as not-ready. The wait and error classification moved into waitForShardsReadyResult through a shardReadinessWaiter seam (embedded in shardRoller), which returns context.Canceled before the count check so Box.Run treats it as a cancel. The readiness row is marked canceled through sess.Fail. Only context.Canceled is silent — a caller deadline still reports as "timed out" — and cancellation wins even when counts are complete.
Adds unit tests covering the row terminal states, result outcomes (cancel before/after progress, cancel-after-complete, timeout, deadline, ready, complete counts succeeding with an expired caller deadline), the rollShards cancel path, JoinFailures interplay, a real plain-phasebox section, and WaitForShardsReady's cancellation contract.