fix(releaseupdate): address review findings on the #1725 canary change
- one shared UpdateStateDir() resolver for daemon and dashboard, instead of two copies that could drift - the recovery path for a committed/rolled-back journal writes installed.json too, so a crash after the outcome phase cannot lose the install record - JudgeCanaryNow is the explicit signals-only entry point for promoting without the window, replacing the zero-install-time sentinel - canary version comparisons use IssuedAt, matching Promote's replay rule, so semver/issued-at divergence cannot wedge check red; queuedBehind reuses the judgeable predicate instead of a looser check - promote prints the channel/pin; promote.yml cancels superseded runs - canary card: no duplicated elapsed rendering, channel row waits for the settings resource instead of showing a default, agent fallback '?' - rehearsal script bounds its docker build/push/run calls task check passes on this tree.
This commit is contained in:
11 files changed
+90
-44
No files matched your search
@@ -14,6 +14,7 @@ on:
|
||||
|
||||
concurrency:
|
||||
group: promote
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
+3
-2
@@ -114,8 +114,9 @@ not the moving `next` tag:
|
||||
at `next` (clearing any rollback pin) and then installs `V` — unless the
|
||||
canary is already judging a release newer than stable that isn't `V`, in which
|
||||
case `V` is **queued** behind it and the canary keeps running what it judges.
|
||||
`-force` installs regardless. After a promotion, the next `check` picks up the
|
||||
newer `next` itself, so a queue drains one release per window.
|
||||
`-force` installs regardless. A `check` that promotes (or finds nothing to
|
||||
judge) installs the newer `next` in the same run, so a queue drains one
|
||||
release per promotion.
|
||||
|
||||
### Subcommands
|
||||
|
||||
|
||||
@@ -8,10 +8,8 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
"oras.land/oras-go/v2/errdef"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/distribution"
|
||||
@@ -120,9 +118,6 @@ func readCanaryRun(ctx context.Context, dashboard releaseupdate.CanaryDashboard,
|
||||
return run, err
|
||||
}
|
||||
run.version, run.installedAt = version, installedAt
|
||||
if version == "" {
|
||||
return run, nil
|
||||
}
|
||||
release, found, err := fetchChannel(ctx, source, releaseupdate.Tag("exact-pin", version))
|
||||
if err != nil {
|
||||
return run, err
|
||||
@@ -134,13 +129,11 @@ func readCanaryRun(ctx context.Context, dashboard releaseupdate.CanaryDashboard,
|
||||
return run, nil
|
||||
}
|
||||
|
||||
// newerRelease reports whether version a is a strictly newer release than b.
|
||||
func newerRelease(a, b string) bool {
|
||||
return semver.Compare(canonVersion(a), canonVersion(b)) > 0
|
||||
}
|
||||
|
||||
func canonVersion(version string) string {
|
||||
return "v" + strings.TrimPrefix(version, "v")
|
||||
// newerIssued reports whether release a was issued after b. IssuedAt, not
|
||||
// semver order: Promote refuses a release issued before the one stable names,
|
||||
// so the judge must agree with that replay rule.
|
||||
func newerIssued(a, b releaseupdate.Release) bool {
|
||||
return a.Statement.IssuedAt.After(b.Statement.IssuedAt)
|
||||
}
|
||||
|
||||
func displayVersion(version string) string {
|
||||
@@ -324,25 +317,25 @@ func startCanary(ctx context.Context, dashboard releaseupdate.CanaryDashboard, s
|
||||
}
|
||||
|
||||
// queuedBehind reports whether version must wait: the canary already follows
|
||||
// next, runs a release newer than stable (the one being judged) and version is
|
||||
// a different release.
|
||||
// next and is still judging the release it runs (a judgeable one), which is a
|
||||
// different release from version.
|
||||
func queuedBehind(ctx context.Context, dashboard releaseupdate.CanaryDashboard, source distribution.Source, channel, version string, out io.Writer) (bool, error) {
|
||||
if channel != "next" {
|
||||
return false, nil
|
||||
}
|
||||
installed, _, _, err := dashboard.Installed(ctx)
|
||||
run, err := readCanaryRun(ctx, dashboard, source)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if installed == "" || installed == version {
|
||||
if run.version == version {
|
||||
return false, nil
|
||||
}
|
||||
stable, hasStable, err := fetchChannel(ctx, source, "stable")
|
||||
channels, err := fetchChannels(ctx, source)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if hasStable && newerRelease(installed, stable.Statement.Version) {
|
||||
fmt.Fprintf(out, "%s is queued behind %s, which the canary is still judging\n", version, installed)
|
||||
if judgeable(run, channels) {
|
||||
fmt.Fprintf(out, "%s is queued behind %s, which the canary is still judging\n", version, run.version)
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
@@ -405,12 +398,12 @@ func checkCanary(ctx context.Context, dashboard releaseupdate.CanaryDashboard, s
|
||||
}
|
||||
|
||||
// judgeable reports whether the installed release is one the canary judges: a
|
||||
// published, non-prerelease release newer than stable.
|
||||
// published, non-prerelease release issued after stable's.
|
||||
func judgeable(run canaryRun, channels publishedChannels) bool {
|
||||
if !run.found || run.release.Statement.Prerelease {
|
||||
return false
|
||||
}
|
||||
return !channels.hasStable || newerRelease(run.version, channels.stable.Statement.Version)
|
||||
return !channels.hasStable || newerIssued(run.release, channels.stable)
|
||||
}
|
||||
|
||||
func judgeInstalled(ctx context.Context, dashboard releaseupdate.CanaryDashboard, source distribution.Source, run canaryRun, channels publishedChannels, latest []string, checkout string, window time.Duration, out io.Writer) (int, error) {
|
||||
@@ -450,7 +443,7 @@ func pickupNext(ctx context.Context, dashboard releaseupdate.CanaryDashboard, ch
|
||||
if !channels.hasNext || channels.next.Statement.Version == installed {
|
||||
return 0, nil
|
||||
}
|
||||
if channels.hasStable && !newerRelease(channels.next.Statement.Version, channels.stable.Statement.Version) {
|
||||
if channels.hasStable && !newerIssued(channels.next, channels.stable) {
|
||||
return 0, nil
|
||||
}
|
||||
if err := dashboard.Install(ctx, channels.next.Statement.Version, canaryInstallWait); err != nil {
|
||||
@@ -579,6 +572,11 @@ func promoteCanaryNow(ctx context.Context, dashboard releaseupdate.CanaryDashboa
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
channel, pin, err := dashboard.Channel(ctx)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
fmt.Fprintf(out, "channel: %s\n", channelDisplay(channel, pin))
|
||||
if expectVersion != "" && expectVersion != run.version {
|
||||
return 1, fmt.Errorf("the canary runs %s, not %s", displayVersion(run.version), expectVersion)
|
||||
}
|
||||
@@ -590,9 +588,7 @@ func promoteCanaryNow(ctx context.Context, dashboard releaseupdate.CanaryDashboa
|
||||
if err != nil {
|
||||
return 1, fmt.Errorf("read canary signals: %w", err)
|
||||
}
|
||||
// A zero install time makes the judge skip its settle and window waits,
|
||||
// so only the signals decide — exactly what promoting now asks for.
|
||||
verdict := releaseupdate.JudgeCanary(run.version, time.Time{}, now, window, signals)
|
||||
verdict := releaseupdate.JudgeCanaryNow(run.version, now, window, signals)
|
||||
printVerdict(out, run.version, verdict)
|
||||
if verdict.Decision == releaseupdate.CanaryRollBack {
|
||||
fmt.Fprintln(out, "refusing to promote: the canary's signals fail")
|
||||
|
||||
@@ -295,10 +295,7 @@ func hasConfigSection(document map[string]any, section string) bool {
|
||||
}
|
||||
|
||||
func updateStateDir() string {
|
||||
if dir := os.Getenv("ARCHIE_UPDATE_STATE_DIR"); dir != "" {
|
||||
return dir
|
||||
}
|
||||
return configuration.DefaultUpdateStateDir()
|
||||
return configuration.UpdateStateDir()
|
||||
}
|
||||
|
||||
// resumeUpdate hands an interrupted transaction to the frozen watchdog and
|
||||
|
||||
@@ -52,3 +52,13 @@ func DefaultUpdateStateDir() string {
|
||||
}
|
||||
return filepath.Join(dir, InstanceName(), "update")
|
||||
}
|
||||
|
||||
// UpdateStateDir is the one resolution of the host's update state directory:
|
||||
// ARCHIE_UPDATE_STATE_DIR when set, else the default. The daemon's
|
||||
// transactions and the dashboard's update snapshot must read the same one.
|
||||
func UpdateStateDir() string {
|
||||
if dir := os.Getenv("ARCHIE_UPDATE_STATE_DIR"); dir != "" {
|
||||
return dir
|
||||
}
|
||||
return DefaultUpdateStateDir()
|
||||
}
|
||||
@@ -62,6 +62,13 @@ type CanaryVerdict struct {
|
||||
Reasons []string
|
||||
}
|
||||
|
||||
// JudgeCanaryNow decides from the current signals alone, for an operator
|
||||
// promoting without waiting out the window: the settle and window waits are
|
||||
// skipped by construction, every hard and relative check still applies.
|
||||
func JudgeCanaryNow(version string, now time.Time, window time.Duration, s CanarySignals) CanaryVerdict {
|
||||
return JudgeCanary(version, now.Add(-(window + canarySettle)), now, window, s)
|
||||
}
|
||||
|
||||
// JudgeCanary decides what to do with a release, given when it was installed
|
||||
// on the canary host. Once the release has settled, a failed hard check rolls
|
||||
// it back at any time. Error and park rates are judged against the baseline
|
||||
|
||||
@@ -63,3 +63,27 @@ func TestJudgeCanary(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Judging "now" skips the settle and window waits but still applies every
|
||||
// hard and relative check.
|
||||
func TestJudgeCanaryNow(t *testing.T) {
|
||||
healthy := CanarySignals{
|
||||
Installed: "1.1.0", Ready: true,
|
||||
Baseline: CanaryWindowSignals{Finished: 20, Bad: 2, Errors: 10, Covered: CanaryWindow},
|
||||
Canary: CanaryWindowSignals{Finished: 20, Bad: 2, Errors: 12, Covered: CanaryWindow},
|
||||
}
|
||||
now := time.Date(2026, 1, 2, 12, 10, 0, 0, time.UTC)
|
||||
if got := JudgeCanaryNow("1.1.0", now, CanaryWindow, healthy); got.Decision != CanaryPromote {
|
||||
t.Fatalf("healthy now = %s, want promote (%v)", got.Decision, got.Reasons)
|
||||
}
|
||||
degraded := healthy
|
||||
degraded.Ready = false
|
||||
if got := JudgeCanaryNow("1.1.0", now, CanaryWindow, degraded); got.Decision != CanaryRollBack {
|
||||
t.Fatalf("degraded now = %s, want roll back (%v)", got.Decision, got.Reasons)
|
||||
}
|
||||
breached := healthy
|
||||
breached.Canary.Bad = 10
|
||||
if got := JudgeCanaryNow("1.1.0", now, CanaryWindow, breached); got.Decision != CanaryRollBack {
|
||||
t.Fatalf("park breach now = %s, want roll back (%v)", got.Decision, got.Reasons)
|
||||
}
|
||||
}
|
||||
@@ -192,6 +192,17 @@ func (t *Transaction) Run(ctx context.Context, recovering bool) error {
|
||||
if err := t.startUnits(ctx, j, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
// A crash between the outcome phase and recordInstall must not lose
|
||||
// the install record, so the recovery path writes it too.
|
||||
version := j.Version
|
||||
if j.Phase == phaseRolledBack {
|
||||
version = j.Previous[ComponentDaemon]
|
||||
}
|
||||
if version != "" {
|
||||
if err := recordInstall(t.StateDir, version, time.Now().UTC()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return t.remove()
|
||||
default:
|
||||
return t.rollback(ctx, j)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -531,10 +530,7 @@ func (s *Server) handleChatUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
// daemon does, so the dashboard reads the installed.json its transactions
|
||||
// write.
|
||||
func updateStateDir() string {
|
||||
if dir := os.Getenv("ARCHIE_UPDATE_STATE_DIR"); dir != "" {
|
||||
return dir
|
||||
}
|
||||
return configuration.DefaultUpdateStateDir()
|
||||
return configuration.UpdateStateDir()
|
||||
}
|
||||
|
||||
func (s *Server) handleChatUpdateDefer(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -72,10 +72,10 @@ reg_port=$1 pg_port=$2 web_port=$3 state_port=$4 gw_port=$5 daemon_port=$6 healt
|
||||
# --- registry and PostgreSQL -------------------------------------------------
|
||||
|
||||
echo "== starting local OCI registry on 127.0.0.1:$reg_port and PostgreSQL on 127.0.0.1:$pg_port"
|
||||
docker run -d --name "$name-registry" -p "127.0.0.1:$reg_port:5000" registry:2 >/dev/null ||
|
||||
timeout 300 docker run -d --name "$name-registry" -p "127.0.0.1:$reg_port:5000" registry:2 >/dev/null ||
|
||||
die "could not start registry:2 (is the image pullable?)"
|
||||
containers="$containers $name-registry"
|
||||
docker run -d --name "$name-pg" \
|
||||
timeout 300 docker run -d --name "$name-pg" \
|
||||
-e POSTGRES_USER=archie -e POSTGRES_PASSWORD=archie -e POSTGRES_DB=archie \
|
||||
-p "127.0.0.1:$pg_port:5432" postgres:18 >/dev/null ||
|
||||
die "could not start postgres:18 (is the image pullable?)"
|
||||
@@ -118,10 +118,10 @@ seed=$(cat "$work/seed")
|
||||
# A real agent image in the local registry, so the install's image pull by
|
||||
# digest succeeds. The Dockerfile stamps the agent with the release version.
|
||||
echo "== building and pushing the archie-agent test image (this takes a few minutes)"
|
||||
docker build -q -f "$repo/Dockerfile" --build-arg RUNTIME_VERSION="$release_version" \
|
||||
timeout 1200 docker build -q -f "$repo/Dockerfile" --build-arg RUNTIME_VERSION="$release_version" \
|
||||
-t "127.0.0.1:$reg_port/archie-agent:v$release_version" "$repo" >/dev/null ||
|
||||
die "docker build of the agent image failed"
|
||||
docker push -q "127.0.0.1:$reg_port/archie-agent:v$release_version" >/dev/null ||
|
||||
timeout 600 docker push -q "127.0.0.1:$reg_port/archie-agent:v$release_version" >/dev/null ||
|
||||
die "docker push of the agent image failed"
|
||||
agent_image=$(docker image inspect -f '{{range .RepoDigests}}{{println .}}{{end}}' \
|
||||
"127.0.0.1:$reg_port/archie-agent:v$release_version" | grep "^127\.0\.0\.1:$reg_port/" | head -1)
|
||||
|
||||
@@ -59,7 +59,8 @@ const now = ref(Date.now());
|
||||
let timer: ReturnType<typeof setInterval> | undefined;
|
||||
let alive = true;
|
||||
|
||||
const settings = computed(() => (store.stateFor(KIND).resource?.value ?? {}) as UpdateSettings);
|
||||
const settingsResource = computed(() => store.stateFor(KIND).resource);
|
||||
const settings = computed(() => (settingsResource.value?.value ?? {}) as UpdateSettings);
|
||||
const channel = computed(() => settings.value.channel || "stable");
|
||||
const pin = computed(() => settings.value.pin || "");
|
||||
const pinned = computed(() => channel.value === "exact-pin");
|
||||
@@ -101,13 +102,15 @@ function elapsed(ms: number): string {
|
||||
|
||||
const rows = computed(() => {
|
||||
const list: { label: string; value?: string; mono?: boolean }[] = [
|
||||
{ label: "Channel", value: channelLabel[channel.value] ?? channel.value },
|
||||
// The settings resource loads asynchronously; until it arrives the channel
|
||||
// is unknown, not "stable".
|
||||
{ label: "Channel", value: settingsResource.value ? (channelLabel[channel.value] ?? channel.value) : "loading…" },
|
||||
{ label: "Installed", value: daemon.value?.Installed || "unknown", mono: true },
|
||||
{ label: "Installed at", value: installedAt.value ? "" : "not recorded" },
|
||||
{
|
||||
label: "Available",
|
||||
value: available.value.length
|
||||
? available.value.map((c) => `${c.Label || c.ID} ${c.Installed} → ${c.Available}`).join(", ")
|
||||
? available.value.map((c) => `${c.Label || c.ID} ${c.Installed || "?"} → ${c.Available}`).join(", ")
|
||||
: "none",
|
||||
mono: true,
|
||||
},
|
||||
@@ -164,7 +167,7 @@ onUnmounted(() => {
|
||||
<span class="font-mono">{{ pin }}</span>
|
||||
</template>
|
||||
<template v-else-if="row.label === 'Installed at' && installedAt">
|
||||
<Timestamp :at="installedAt" /> · {{ elapsedText }} ago
|
||||
<Timestamp :at="installedAt" absolute /> · {{ elapsedText }} elapsed
|
||||
</template>
|
||||
<template v-else>{{ row.value }}</template>
|
||||
</template>
|
||||
|
||||
Reference in new issue
Block a user