fix(releaseupdate): wait for the canary to offer a release before installing (#1716)
Quality / check (push) Successful in 3m14s
deploy / gate (push) Successful in 6m48s
deploy / archied-image (push) Successful in 3m3s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped

This commit is contained in:
sam committed 2026-11-01 02:55:31 +11:00
1 parent c78063eba0
commit efd3eb2854
1 file changed
+42 -22
+42 -22
View File
@@ -229,38 +229,58 @@ func (d CanaryDashboard) Channel(ctx context.Context) (channel, pin string, err
// it reports running it. The install restarts the dashboard, so a dropped
// connection after the request is sent is expected.
func (d CanaryDashboard) Install(ctx context.Context, version string, wait time.Duration) error {
installed, snapshot, err := d.installed(ctx)
if err != nil {
return err
}
if installed == version {
return nil
}
var offered Snapshot
if err := json.Unmarshal(snapshot, &offered); err != nil {
return fmt.Errorf("decode update snapshot: %w", err)
}
if available := offered.Available(); len(available) == 0 || available[0].Available != version {
return fmt.Errorf("canary doesn't offer %s yet", version)
}
_, err = d.call(ctx, http.MethodPost, "/api/chat/update/install", map[string]json.RawMessage{"snapshot": snapshot}, nil)
if _, ok := errors.AsType[statusError](err); ok {
return err
}
deadline := time.Now().Add(wait)
for time.Now().Before(deadline) {
requested := false
for {
installed, snapshot, err := d.installed(ctx)
switch {
case err != nil:
// The dashboard drops off while the install restarts it.
if !requested {
return err
}
case installed == version:
return nil
case !requested:
// The canary caches its registry lookup, so a release just
// published can take a few minutes to be offered.
offered, err := offers(snapshot, version)
if err != nil {
return err
}
if offered {
_, err := d.call(ctx, http.MethodPost, "/api/chat/update/install", map[string]json.RawMessage{"snapshot": snapshot}, nil)
if _, ok := errors.AsType[statusError](err); ok {
return err
}
requested = true
}
}
if !time.Now().Before(deadline) {
break
}
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(15 * time.Second):
}
if installed, _, err := d.installed(ctx); err == nil && installed == version {
return nil
}
}
if !requested {
return fmt.Errorf("canary didn't offer %s within %s", version, wait)
}
return fmt.Errorf("canary didn't report %s within %s", version, wait)
}
// offers reports whether an update snapshot offers version.
func offers(snapshot json.RawMessage, version string) (bool, error) {
var offered Snapshot
if err := json.Unmarshal(snapshot, &offered); err != nil {
return false, fmt.Errorf("decode update snapshot: %w", err)
}
available := offered.Available()
return len(available) > 0 && available[0].Available == version, nil
}
type statusError struct {
code int
body string