Repository navigation
fix(cli): report Ctrl+C during reload readiness wait as canceled, not a shard failure #1154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8158177
04bed36
018cbd8
ddebb13
9cace18
4e6ba69
1c7b866
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package root | |
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "time" | ||
|
|
||
|
|
@@ -207,9 +208,9 @@ func deployShardImages( | |
| // record the instance IDs handed to WaitForShardsReady and return canned | ||
| // ready/expected counts. | ||
| type shardRoller interface { | ||
| shardReadinessWaiter | ||
| PruneOrphanedShards(ctx context.Context) error | ||
| Deploy(ctx context.Context, opts local.DeployOpts) error | ||
| WaitForShardsReady(ctx context.Context, instanceIDs []string, onProgress func(ready, expected int)) (int, int) | ||
| } | ||
|
|
||
| // rollShards recreates the targeted shards' containers, one dashboard row per shard. | ||
|
|
@@ -248,34 +249,63 @@ func rollShards( | |
| if waitReady { | ||
| // Deploy recreates every instance in each targeted pool, so wait for the whole pool. | ||
| waitInstanceIDs := targets.poolInstances(opts.ShardIDs) | ||
| return waitForShardsReadyResult(ctx, sess, rt, waitInstanceIDs) | ||
| } | ||
|
|
||
| var ready, expected int | ||
| waitForShardsReadyRow(sess, func(onProgress func(ready, expected int)) { | ||
| ready, expected = rt.WaitForShardsReady(ctx, waitInstanceIDs, onProgress) | ||
| }) | ||
| return nil | ||
| } | ||
|
|
||
| if ready < expected { | ||
| // Returned, not just shown: the row is already Failed, but the summary and the | ||
| // exit code are what a script or an agent reads, and plain progress has no rows. | ||
| return &shardsNotReadyError{ready: ready, expected: expected} | ||
| } | ||
| // shardReadinessWaiter is the subset of local.Runtime the readiness wait uses; | ||
| // *local.Runtime satisfies it. | ||
| type shardReadinessWaiter interface { | ||
| WaitForShardsReady( | ||
| ctx context.Context, | ||
| instanceIDs []string, | ||
| onProgress func(ready, expected int), | ||
| ) (ready, expected int) | ||
| } | ||
|
|
||
| // waitForShardsReadyResult waits for the targeted instances to serve and | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this comment can just state the invariant: the waiter returns counts without an error, cancellation stays cancellation, and caller deadlines remain readiness failures. The branch-by-branch explanation below repeats the implementation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 8b119d9. Trimmed the comment to the invariant: the waiter returns counts without an error, cancellation stays cancellation (passed through for phasebox to silence at the section boundary), and caller deadlines remain readiness failures.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: keep the counts-only cancellation invariant, but trim the repeated explanation and the interface's testability narration. The row comment below can likewise keep cancellation precedence and the section-lifecycle constraint without walking through the switch. Also, the no-progress guard now handles a documented cancellation path, so calling it defensive is misleading.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 318e645. Trimmed the waitForShardsReadyResult comment to the counts-only/cancellation-stays-cancellation/deadline-stays-failure invariant and dropped the interface testability narration. The row comment keeps cancellation precedence and the section-lifecycle constraint without walking the switch, and the no-progress guard comment no longer calls it "defensive" (it handles a documented cancellation path). |
||
| // classifies the outcome: the waiter returns counts without an error, | ||
| // cancellation returns [context.Canceled], and incomplete counts return | ||
| // shardsNotReadyError (complete counts still succeed with an expired | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a case with complete counts and an expired caller deadline? This comment promises success for that combination, but the current deadline test only covers incomplete counts. It would catch a future blanket
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 1e10f00. |
||
| // deadline). | ||
| func waitForShardsReadyResult( | ||
| ctx context.Context, sess phasebox.Session, waiter shardReadinessWaiter, instanceIDs []string, | ||
| ) error { | ||
| var ready, expected int | ||
| waitForShardsReadyRow(ctx, sess, func(onProgress func(ready, expected int)) { | ||
| ready, expected = waiter.WaitForShardsReady(ctx, instanceIDs, onProgress) | ||
| }) | ||
|
|
||
| if errors.Is(ctx.Err(), context.Canceled) { | ||
| return ctx.Err() | ||
| } | ||
|
|
||
| if ready < expected { | ||
| // Returned, not just shown: the row, if any, is already Failed, but the | ||
| // summary and the exit code are what a script or an agent reads, and plain | ||
| // progress has no rows. | ||
| return &shardsNotReadyError{ready: ready, expected: expected} | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // waitForShardsReadyRow drives the "ready" progress row through WaitForShardsReady | ||
| // to a terminal state. waitForReady performs the actual wait and invokes | ||
| // onProgress for every poll tick (local.Runtime.WaitForShardsReady). The row is | ||
| // set Active on every tick, then closed to Done when ready >= expected or Failed | ||
| // ("timed out …") otherwise. The progressed guard is defensive: WaitForShardsReady | ||
| // always ticks at least once because its counter starts below zero, so it only | ||
| // protects a future waitForReady that could return without reporting anything. | ||
| // to a terminal state. Cancellation takes precedence even when the counts are | ||
| // complete: a Ctrl+C landed after the last probe round is a cancel, not a silent | ||
| // success. The progressed guard handles cancellation before the first completed | ||
| // probe round, where WaitForShardsReady returns (0, expected) without invoking | ||
| // onProgress — the row stays absent rather than rendering a terminal claim with | ||
| // no evidence. | ||
| // | ||
| // Must run before the enclosing section finishes: phasebox drops upserts to a | ||
| // finished section (see Model.upsert), so a terminal update after dash.Run | ||
| // returns would be silently lost and the row would keep rendering its spinner. | ||
| func waitForShardsReadyRow(sess phasebox.Session, waitForReady func(onProgress func(ready, expected int))) { | ||
| func waitForShardsReadyRow( | ||
| ctx context.Context, sess phasebox.Session, waitForReady func(onProgress func(ready, expected int)), | ||
| ) { | ||
| var lastReady, expected int | ||
|
|
||
| progressed := false | ||
|
|
@@ -284,19 +314,24 @@ func waitForShardsReadyRow(sess phasebox.Session, waitForReady func(onProgress f | |
| lastReady, expected = ready, exp | ||
| progressed = true | ||
|
|
||
| sess.UpsertRow("ready", "Waiting for shards ready", fmt.Sprintf("%d/%d", ready, exp), phasebox.Active) | ||
| sess.UpsertRow("ready", "Waiting for shards to be ready", fmt.Sprintf("%d/%d", ready, exp), phasebox.Active) | ||
| }) | ||
|
|
||
| if !progressed { | ||
| return | ||
| } | ||
|
|
||
| if errors.Is(ctx.Err(), context.Canceled) { | ||
| sess.Fail("ready", "Waiting for shards to be ready", ctx.Err()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The canceled readiness row may never reach the terminal: phasebox gives Bubble Tea this same context, and Could we attach TTY output showing this row changing to canceled? The fake-session test proves dispatch, but can't establish that the update renders.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: the row reaching the terminal in dashboard mode — the PR body's "How did you verify?" section already documents the end-to-end dashboard capture (Ctrl+C during |
||
| return | ||
| } | ||
|
|
||
| state, detail := phasebox.Done, fmt.Sprintf("%d/%d", lastReady, expected) | ||
| if lastReady < expected { | ||
| state, detail = phasebox.Failed, fmt.Sprintf("timed out (%d/%d ready)", lastReady, expected) | ||
| } | ||
|
|
||
| sess.UpsertRow("ready", "Waiting for shards ready", detail, state) | ||
| sess.UpsertRow("ready", "Waiting for shards to be ready", detail, state) | ||
| } | ||
|
|
||
| // shardsNotReadyError reports instances that were deployed but never answered. It is its | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: embed
shardReadinessWaiterinshardRollerso the identicalWaitForShardsReadysignature has one declaration to maintain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 0d21203. shardRoller now embeds shardReadinessWaiter, so the WaitForShardsReady signature has one declaration.