From 88d9f51773325e119b8ba4141bf64c6b6b088690 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Fri, 13 Nov 2026 07:39:07 -0500 Subject: [PATCH] Auto-update: check the installed version accepts the config before restarting onto it On 2026-11-12, 0.16.0 rejected accounts.*.usage_login keys that 0.15.2 had accepted. The running server restarted onto it, and launchd then restarted it 128 times: 17 minutes with no jobs, schedules or hosted ingress. The server now runs the installed version's `config show --json` with its own home first. If that version rejects the config, the server logs an error, keeps running and checks again every minute. If the check cannot run (timeout, or node is missing), it restarts as before. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ src/commands/serve.ts | 12 ++++++++++- src/update.test.ts | 27 ++++++++++++++++++++++- src/update.ts | 50 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d17e8a6..bb48975 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to skillhook, newest first. The format follows [Keep a Chang ## Unreleased +- An automatic update no longer bricks the server when the new version rejects the current `skillhook.json`. Before restarting onto a newer version on disk, the server runs that version's `config show --json` against its home. If the new version rejects the config, the server logs `newer version installed but it rejects the current config; keeping this version running` with the error, keeps running, and checks again every minute, so fixing `skillhook.json` lets the restart go ahead. If the check cannot run (it times out, or node is missing), the server restarts as before. On 2026-11-12, 0.16.0 rejected `accounts.*.usage_login` keys that 0.15.2 had accepted. launchd then restarted the daemon 128 times, and it ran no jobs for 17 minutes. + ## 0.16.0 (2026-11-10) - A schedule can be paused without editing the file that declares it: `skillhook schedules pause [--reason …] [--until 2h|]` and `schedules resume `, `POST /schedules//pause` and `/resume` (admin), and the cloud commands `schedule.pause` / `schedule.resume`. While paused nothing fires (the webhook still works); slots that pass are counted as skipped and never caught up. The pause lives in `jobs/.schedules.json`, so a repository pull or a restart keeps it, and `--until` ends it by itself. `schedules list`, `GET /health` and the cloud snapshot show `paused: {at, by, reason, until}`. This lets a repository's `skillhook.yaml` stay the source of truth for schedules while a person can still switch one off from Skillhook Cloud. diff --git a/src/commands/serve.ts b/src/commands/serve.ts index 85577c5..f4fee90 100644 --- a/src/commands/serve.ts +++ b/src/commands/serve.ts @@ -16,7 +16,7 @@ import { Scheduler } from "../scheduler.js"; import { clearServerState, createServer, writeServerState, type ServerControl } from "../server.js"; import { serviceStatus } from "../service.js"; import { errorMessage } from "../util.js"; -import { attemptedRecently, autoUpdateEnabled, checkForUpdate, detectInstall, installedVersion, isNewerVersion, lastInstall, releaseNotesUrl, spawnBackgroundRefresh, UPDATE_CHECK_INTERVAL_MS } from "../update.js"; +import { attemptedRecently, autoUpdateEnabled, checkForUpdate, detectInstall, installedAcceptsConfig, installedVersion, isNewerVersion, lastInstall, releaseNotesUrl, spawnBackgroundRefresh, UPDATE_CHECK_INTERVAL_MS } from "../update.js"; import { VERSION } from "../version.js"; import { DaemonSentry } from "../sentry.js"; import { installDaemonErrorReporting } from "../daemon-errors.js"; @@ -168,6 +168,16 @@ async function runDaemon(ctx: Ctx, sentry: DaemonSentry): Promise { waitingFor = `${installed}:${reason}`; return; } + // A version that rejects this home's config would exit at start and launchd/systemd would restart it in a loop: + // keep running this version and retry every minute (an edit of skillhook.json or a later release clears it). + const check = await installedAcceptsConfig(ctx.paths, { env: ctx.io.env }); + if (shuttingDown) return; + if (check.ok === false) { + if (waitingFor !== `${installed}:config:${check.error}`) logger.error("newer version installed but it rejects the current config; keeping this version running", { running: VERSION, installed, error: check.error }); + waitingFor = `${installed}:config:${check.error}`; + return; + } + if (check.ok === undefined) logger.warn("could not check the installed version against the config; restarting anyway", { running: VERSION, installed, error: check.error }); logger.info("restarting to run the newly installed version", { running: VERSION, installed }); control.restart({ force: false, waitSeconds: 600 }); })(); diff --git a/src/update.test.ts b/src/update.test.ts index 053085d..fdbc185 100644 --- a/src/update.test.ts +++ b/src/update.test.ts @@ -1,8 +1,9 @@ import { createServer, type Server } from "node:http"; import { existsSync, mkdirSync, readFileSync, utimesSync, writeFileSync } from "node:fs"; import path from "node:path"; +import { fileURLToPath } from "node:url"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; -import { acquireUpdateLock, AUTO_INSTALL_RETRY_MS, checkForUpdate, compareVersions, detectInstall, fetchLatestVersion, formatUpdateNotice, installedVersion, isNewerVersion, lastInstall, markInstallAnnounced, parseVersion, planUpdateNotice, readUpdateCache, recordInstall, refreshPlugins, registryUrl as registryUrlOf, releaseUpdateLock, runBackgroundUpdate, spawnBackgroundRefresh, updateCacheFile, updateChecksDisabled, updateStatusFromCache, UPDATE_CHECK_INTERVAL_MS, UPDATE_LOCK_STALE_MS, type InstallInfo } from "./update.js"; +import { acquireUpdateLock, AUTO_INSTALL_RETRY_MS, checkForUpdate, compareVersions, detectInstall, fetchLatestVersion, formatUpdateNotice, installedAcceptsConfig, installedVersion, isNewerVersion, lastInstall, markInstallAnnounced, parseVersion, planUpdateNotice, readUpdateCache, recordInstall, refreshPlugins, registryUrl as registryUrlOf, releaseUpdateLock, runBackgroundUpdate, spawnBackgroundRefresh, updateCacheFile, updateChecksDisabled, updateStatusFromCache, UPDATE_CHECK_INTERVAL_MS, UPDATE_LOCK_STALE_MS, type InstallInfo } from "./update.js"; import type { ToolExecResult } from "./tools.js"; import { tempHome } from "./test-support/helpers.js"; import { VERSION } from "./version.js"; @@ -266,6 +267,30 @@ describe("automatic updates", () => { expect(installedVersion(file)).toBeUndefined(); expect(installedVersion()).toBe(VERSION); }); + + it("asks the installed CLI whether it accepts this home's config before a restart", async () => { + const paths = tempHome(); + const run = (script: string, extra: Parameters[1] = {}) => installedAcceptsConfig(paths, { args: ["-e", script], ...extra }); + // The child sees this home, not the parent's. + expect(await run(`process.exit(process.env.SKILLHOOK_HOME === ${JSON.stringify(paths.home)} ? 0 : 3)`, { env: { ...process.env, SKILLHOOK_HOME: "/elsewhere" } })).toEqual({ ok: true }); + expect(await run(`console.error('Invalid ~/.skillhook/skillhook.json: Unrecognized key "usage_login"'); process.exit(1)`)).toEqual({ ok: false, error: 'Invalid ~/.skillhook/skillhook.json: Unrecognized key "usage_login"' }); + expect(await run("process.exit(2)")).toEqual({ ok: false, error: "exited with code 2" }); + // Unknown is not a rejection: a missing node binary or a hung check keeps the old behaviour (restart). + expect((await installedAcceptsConfig(paths, { execPath: path.join(paths.home, "no-such-node"), args: [] })).ok).toBeUndefined(); + expect(await run("setTimeout(() => {}, 10_000)", { timeoutMs: 200 })).toEqual({ ok: undefined, error: "config check timed out" }); + }); + + it("the real CLI rejects an unknown config key, so the restart is skipped (RA-019)", async () => { + const paths = tempHome(); + const cli = fileURLToPath(new URL("./cli.ts", import.meta.url)); + const args = ["--import", "tsx", cli, "config", "show", "--json"]; + writeFileSync(path.join(paths.home, "skillhook.json"), JSON.stringify({ concurrency: 2 })); + expect(await installedAcceptsConfig(paths, { args, timeoutMs: 60_000 })).toEqual({ ok: true }); + writeFileSync(path.join(paths.home, "skillhook.json"), JSON.stringify({ concurrency: 2, not_a_key: true })); + const rejected = await installedAcceptsConfig(paths, { args, timeoutMs: 60_000 }); + expect(rejected.ok).toBe(false); + expect(rejected.ok === false && rejected.error).toMatch(/not_a_key/); + }, 90_000); }); describe("plugin updates", () => { diff --git a/src/update.ts b/src/update.ts index 237b023..cdd742f 100644 --- a/src/update.ts +++ b/src/update.ts @@ -585,6 +585,56 @@ export function installedVersion(file: string | URL = new URL("../package.json", } } +export type InstalledConfigCheck = + /** The installed version loaded this home's skillhook.json. */ + | { ok: true } + /** The installed version exited non-zero on this home's skillhook.json: restarting onto it would crash-loop. */ + | { ok: false; error: string } + /** The check could not run (spawn error or timeout): nothing is known, so callers keep the previous behaviour. */ + | { ok: undefined; error: string }; + +/** + * Asks the skillhook installed on disk whether it accepts this home's config before a running server restarts onto it + * (a new version can reject keys the running one accepted; 0.16.0 rejected `accounts.*.usage_login` and launchd + * restarted the daemon 128 times). Runs ` config show --json` with this home in SKILLHOOK_HOME. + */ +export function installedAcceptsConfig( + paths: Pick, + options: { cli?: string; execPath?: string; args?: string[]; env?: NodeJS.ProcessEnv; timeoutMs?: number } = {}, +): Promise { + const cli = options.cli ?? fileURLToPath(new URL("./cli.js", import.meta.url)); + const args = options.args ?? [cli, "config", "show", "--json"]; + return new Promise((resolve) => { + let output = ""; + let settled = false; + const done = (result: InstalledConfigCheck) => { + if (settled) return; + settled = true; + clearTimeout(timer); + resolve(result); + }; + let child: ReturnType; + try { + child = spawn(options.execPath ?? process.execPath, args, { env: { ...(options.env ?? process.env), SKILLHOOK_HOME: paths.home }, stdio: ["ignore", "pipe", "pipe"] }); + } catch (error) { + resolve({ ok: undefined, error: (error as Error).message }); + return; + } + const timer = setTimeout(() => { + child.kill("SIGKILL"); + done({ ok: undefined, error: "config check timed out" }); + }, options.timeoutMs ?? 30_000); + // With --json the CLI reports a config error on stdout; a valid config prints the config itself, which is not kept. + const collect = (chunk: Buffer) => { + if (output.length < 4000) output += chunk.toString("utf8"); + }; + child.stdout?.on("data", collect); + child.stderr?.on("data", collect); + child.on("error", (error) => done({ ok: undefined, error: error.message })); + child.on("close", (code) => done(code === 0 ? { ok: true } : { ok: false, error: output.trim().slice(0, 1000) || `exited with code ${code}` })); + }); +} + // --------------------------------------------------------------------------- // The plugin, in Claude Code and Codex // ---------------------------------------------------------------------------