From a41e3fbd74d9438120c2f5f25dbe1d5a80daa8ee Mon Sep 17 00:00:00 2001 From: Hai Huang Date: Thu, 19 Nov 2026 14:28:10 -0500 Subject: [PATCH 1/2] fix: Keep an RC install from a downgrade, and do not record a "no" as a failure agentop update by hand offered to install v0.9.5 over v0.10.0-rc.1. The automatic update moves an RC only forward, but the manual update compared only for equality with Latest. The manual update now uses the same rule. To move back, give the release with --ref. When the user answered "n" at setup's prompt, setup exited with exitDeclined (3). runUpdate recorded that as a failed update, so the agentop title bar showed "update to v0.9.5 failed". A declined update now returns exitDeclined and does not write the status file. Assisted-By: Claude (Anthropic AI) Signed-off-by: Hai Huang --- cmd/agentop/cmd_update.go | 16 +++++++++++++++- cmd/agentop/cmd_update_test.go | 22 ++++++++++++++++++++++ docs/laptop-service.md | 5 +++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/cmd/agentop/cmd_update.go b/cmd/agentop/cmd_update.go index 6f04ba4bd..d8803b824 100644 --- a/cmd/agentop/cmd_update.go +++ b/cmd/agentop/cmd_update.go @@ -140,14 +140,23 @@ func runUpdate(args []string, stdout, stderr io.Writer) int { _, _ = fmt.Fprintf(stdout, "Already at %s.\n", v) return 0 } + // An RC moves only forward, as in the automatic update: only --ref takes it back. + if v := env.installedVersion; updatestatus.IsRC(v) && updatestatus.IsRelease(latest) && !updatestatus.Newer(latest, v) { + status(updatestatus.ResultCurrent, nil) + _, _ = fmt.Fprintf(stdout, rcAheadNotice+"\n", v, latest) + return 0 + } if err := cpexConfigBlocks(env); err != nil { status(updatestatus.ResultFailed, err) _, _ = fmt.Fprintf(stderr, "agentop: %v\n", err) return 1 } if err := installReleaseFn(env, *ref, updateFlags(env, *ref, yes), stdout, stderr); err != nil { - status(updatestatus.ResultFailed, err) var exit *exec.ExitError + if errors.As(err, &exit) && exit.ExitCode() == exitDeclined { + return exitDeclined // the user said no: not a failure, so the status stays as it was + } + status(updatestatus.ResultFailed, err) if errors.As(err, &exit) { return exit.ExitCode() } @@ -163,6 +172,11 @@ func runUpdate(args []string, stdout, stderr io.Writer) int { const notReleaseNotice = "agentop %s is not a release build, and can be newer than the newest release. Not updated.\n" + "Run agentop update --ref=vX.Y.Z to install a release." +// rcAheadNotice is what update prints for an installed RC that is newer than the +// newest release. The arguments are the RC and that release. +const rcAheadNotice = "agentop %s is a release candidate, newer than the newest release %s. Not updated.\n" + + "Run agentop update --ref=vX.Y.Z to install a release." + // installReleaseFn is what callers use, so tests can replace the installer. var installReleaseFn = installRelease diff --git a/cmd/agentop/cmd_update_test.go b/cmd/agentop/cmd_update_test.go index 0857354c3..db40ce043 100644 --- a/cmd/agentop/cmd_update_test.go +++ b/cmd/agentop/cmd_update_test.go @@ -25,6 +25,8 @@ import ( "testing" "github.com/sigstore/sigstore-go/pkg/root" + + "github.com/rossoctl/cortex/cmd/agentop/updatestatus" ) // fakeInstaller puts a curl on PATH that serves an installer which prints its @@ -74,6 +76,10 @@ func TestUpdateSkipsTheInstallerWhenCurrent(t *testing.T) { {name: "dev build", latest: "v9.9.9", agentop: "#!/bin/sh\necho agentop dev\n", want: fmt.Sprintf(notReleaseNotice+"\n", "dev")}, {name: "main build", latest: "v9.9.9", agentop: "#!/bin/sh\necho agentop main-abc1234\n", want: fmt.Sprintf(notReleaseNotice+"\n", "main-abc1234")}, {name: "dev build pinned", latest: "v9.9.9", release: "v9.9.9", agentop: "#!/bin/sh\necho agentop dev\n", args: []string{"--ref=v9.9.9"}, want: "staged setup\n", code: 7}, + // An RC moves only forward: to its release or a later one, or back by --ref. + {name: "rc ahead", latest: "v9.9.8", agentop: "#!/bin/sh\necho agentop v9.9.9-rc.1\n", want: fmt.Sprintf(rcAheadNotice+"\n", "v9.9.9-rc.1", "v9.9.8")}, + {name: "rc released", latest: "v9.9.9", release: "v9.9.9", agentop: "#!/bin/sh\necho agentop v9.9.9-rc.1\n", want: "staged setup\n", code: 7}, + {name: "rc pinned back", latest: "v9.9.8", release: "v9.9.8", agentop: "#!/bin/sh\necho agentop v9.9.9-rc.1\n", args: []string{"--ref=v9.9.8"}, want: "staged setup\n", code: 7}, {name: "main", latest: "v9.9.9", args: []string{"--ref=main"}, want: "installer: --ref=main\n", code: 7}, // setup repairs a pair that disagree. {name: "cortex behind", latest: "v9.9.9", release: "v9.9.9", cortex: "#!/bin/sh\necho cortex v9.9.8\n", want: "staged setup\n", code: 7}, @@ -172,6 +178,22 @@ func TestUpdateCpexNoticeAfterSetupSucceeds(t *testing.T) { } } +// A "no" at setup's prompt is not a failed update: the title bar must not say "failed". +func TestUpdateDeclinedIsNotAFailure(t *testing.T) { + sc := newDoctorScene(t) + sc.installed(t) + latestIs(t, "v9.9.10") + fakeStagedRelease(t, "v9.9.10", false) + t.Setenv("FAKE_SETUP_EXIT", fmt.Sprint(exitDeclined)) + var out, errb bytes.Buffer + if code := runUpdate(nil, &out, &errb); code != exitDeclined { + t.Fatalf("exit %d, want %d:\n%s", code, exitDeclined, errb.String()) + } + if _, err := os.Stat(filepath.Join(sc.home, ".cortex", updatestatus.FileName)); !errors.Is(err, fs.ErrNotExist) { + t.Errorf("a declined update wrote the status file (stat: %v)", err) + } +} + // addCpexEntry puts a cpex entry first in the outbound pipeline of the config setup wrote. func addCpexEntry(t *testing.T, home string) { t.Helper() diff --git a/docs/laptop-service.md b/docs/laptop-service.md index 2525e8f82..c8d4f5353 100644 --- a/docs/laptop-service.md +++ b/docs/laptop-service.md @@ -331,8 +331,9 @@ A service install (launchd or systemd) updates itself: A release-candidate install (`vX.Y.Z-rc.N`) moves only forward. It installs Latest when Latest is a later version, for example `v0.10.0` over `v0.10.0-rc.1`, after the -same wait. It never moves back to an older Latest. A plain release follows Latest in -both directions, so the maintainers can withdraw a bad release. +same wait. It never moves back to an older Latest. `agentop update` by hand follows +the same rule: to move back, give the release, for example `--ref=v0.9.5`. A plain +release follows Latest in both directions, so the maintainers can withdraw a bad release. It does not change a `dev` or `main-` install. That build has no version order against Latest, and is often ahead of it. `agentop doctor` says so, and the title bar From a62f6973459171a55d28fb1b9fb6297e5e59ef13 Mon Sep 17 00:00:00 2001 From: Hai Huang Date: Thu, 19 Nov 2026 14:38:59 -0500 Subject: [PATCH 2/2] fix: Check the cortex version too before an RC moves back Fixes review: the RC check read only the agentop version; the automatic update also checks cortex Fixes review: agentop update -h did not give the RC rule Fixes review: no test checked that the RC case records current in update.json Fixes review: the decline comment said only "the user said no"; setup also declines with no terminal Files: - cmd/agentop/cmd_update.go - cmd/agentop/cmd_update_test.go Assisted-By: Claude (Anthropic AI) Signed-off-by: Hai Huang --- cmd/agentop/cmd_update.go | 23 +++++++++++++---------- cmd/agentop/cmd_update_test.go | 9 ++++++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cmd/agentop/cmd_update.go b/cmd/agentop/cmd_update.go index d8803b824..a736f4f11 100644 --- a/cmd/agentop/cmd_update.go +++ b/cmd/agentop/cmd_update.go @@ -43,10 +43,11 @@ install that runs the cpex build of cortex to the default build, and says so. --auto what the updater runs: install the newest release only when it is a plain release and update.wait (24h) old; never asks Downloads nothing when agentop and cortex in ~/.local/bin are already at the -release asked for, or when agentop is not a release build (make dev-install, ---ref=main) and there is no --ref. Run agentop doctor to check the rest of the install. +release asked for, or when there is no --ref and agentop is not a release build +(make dev-install, --ref=main) or agentop or cortex is a release candidate newer +than the newest release. Run agentop doctor to check the rest of the install. -Exit status: 0 already current or not a release build, 1 when a download or check fails, else setup's +Exit status: 0 already current, not a release build or a newer release candidate, 1 when a download or check fails, else setup's (or the installer's for --ref=main). ` @@ -141,10 +142,12 @@ func runUpdate(args []string, stdout, stderr io.Writer) int { return 0 } // An RC moves only forward, as in the automatic update: only --ref takes it back. - if v := env.installedVersion; updatestatus.IsRC(v) && updatestatus.IsRelease(latest) && !updatestatus.Newer(latest, v) { - status(updatestatus.ResultCurrent, nil) - _, _ = fmt.Fprintf(stdout, rcAheadNotice+"\n", v, latest) - return 0 + for _, b := range []string{"agentop", proxyBinary} { + if v := installedVersion(filepath.Join(env.binDir, b)); updatestatus.IsRC(v) && updatestatus.IsRelease(latest) && !updatestatus.Newer(latest, v) { + status(updatestatus.ResultCurrent, nil) + _, _ = fmt.Fprintf(stdout, rcAheadNotice+"\n", b, v, latest) + return 0 + } } if err := cpexConfigBlocks(env); err != nil { status(updatestatus.ResultFailed, err) @@ -154,7 +157,7 @@ func runUpdate(args []string, stdout, stderr io.Writer) int { if err := installReleaseFn(env, *ref, updateFlags(env, *ref, yes), stdout, stderr); err != nil { var exit *exec.ExitError if errors.As(err, &exit) && exit.ExitCode() == exitDeclined { - return exitDeclined // the user said no: not a failure, so the status stays as it was + return exitDeclined // not a failure, so the status stays as it was } status(updatestatus.ResultFailed, err) if errors.As(err, &exit) { @@ -173,8 +176,8 @@ const notReleaseNotice = "agentop %s is not a release build, and can be newer th "Run agentop update --ref=vX.Y.Z to install a release." // rcAheadNotice is what update prints for an installed RC that is newer than the -// newest release. The arguments are the RC and that release. -const rcAheadNotice = "agentop %s is a release candidate, newer than the newest release %s. Not updated.\n" + +// newest release. The arguments are the binary, its RC and that release. +const rcAheadNotice = "%s %s is a release candidate, newer than the newest release %s. Not updated.\n" + "Run agentop update --ref=vX.Y.Z to install a release." // installReleaseFn is what callers use, so tests can replace the installer. diff --git a/cmd/agentop/cmd_update_test.go b/cmd/agentop/cmd_update_test.go index db40ce043..db84a10fc 100644 --- a/cmd/agentop/cmd_update_test.go +++ b/cmd/agentop/cmd_update_test.go @@ -67,6 +67,7 @@ func TestUpdateSkipsTheInstallerWhenCurrent(t *testing.T) { args []string want string // stdout code int + result string // the status update.json records, if checked }{ {name: "newest", latest: "v9.9.9", want: "Already at v9.9.9.\n"}, {name: "pinned", latest: "v9.9.8", args: []string{"--ref=v9.9.9"}, want: "Already at v9.9.9.\n"}, @@ -77,7 +78,8 @@ func TestUpdateSkipsTheInstallerWhenCurrent(t *testing.T) { {name: "main build", latest: "v9.9.9", agentop: "#!/bin/sh\necho agentop main-abc1234\n", want: fmt.Sprintf(notReleaseNotice+"\n", "main-abc1234")}, {name: "dev build pinned", latest: "v9.9.9", release: "v9.9.9", agentop: "#!/bin/sh\necho agentop dev\n", args: []string{"--ref=v9.9.9"}, want: "staged setup\n", code: 7}, // An RC moves only forward: to its release or a later one, or back by --ref. - {name: "rc ahead", latest: "v9.9.8", agentop: "#!/bin/sh\necho agentop v9.9.9-rc.1\n", want: fmt.Sprintf(rcAheadNotice+"\n", "v9.9.9-rc.1", "v9.9.8")}, + {name: "rc ahead", latest: "v9.9.8", agentop: "#!/bin/sh\necho agentop v9.9.9-rc.1\n", want: fmt.Sprintf(rcAheadNotice+"\n", "agentop", "v9.9.9-rc.1", "v9.9.8"), result: updatestatus.ResultCurrent}, + {name: "cortex rc ahead", latest: "v9.9.9", cortex: "#!/bin/sh\necho cortex v9.9.10-rc.1\n", want: fmt.Sprintf(rcAheadNotice+"\n", "cortex", "v9.9.10-rc.1", "v9.9.9"), result: updatestatus.ResultCurrent}, {name: "rc released", latest: "v9.9.9", release: "v9.9.9", agentop: "#!/bin/sh\necho agentop v9.9.9-rc.1\n", want: "staged setup\n", code: 7}, {name: "rc pinned back", latest: "v9.9.8", release: "v9.9.8", agentop: "#!/bin/sh\necho agentop v9.9.9-rc.1\n", args: []string{"--ref=v9.9.8"}, want: "staged setup\n", code: 7}, {name: "main", latest: "v9.9.9", args: []string{"--ref=main"}, want: "installer: --ref=main\n", code: 7}, @@ -104,6 +106,11 @@ func TestUpdateSkipsTheInstallerWhenCurrent(t *testing.T) { if code := runUpdate(c.args, &out, &errb); code != c.code || out.String() != c.want { t.Errorf("exit %d stdout %q, want %d %q\n%s", code, out.String(), c.code, c.want, errb.String()) } + if c.result != "" { + if s := readStatus(t, sc); s.Result != c.result || s.Latest != c.latest { + t.Errorf("status %q latest %q, want %q %q", s.Result, s.Latest, c.result, c.latest) + } + } }) } }