From 9282d35fc1ace541a3fcf83a8c20e2e7d0aff926 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Sat, 5 Dec 2026 06:27:41 -0500 Subject: [PATCH] A release check still running is a wait, never a refused model The hourly check and the step before applying asked blocking(), true for a check still running, a check that didn't finish and a refused model alike, and both gave "a model this release calls was refused; checking again daily", even minutes before the check passed. - check_hold tells the three apart: pending ("waiting for the release check; trying again next hour"), stalled (started again by the next hourly check, which says so) and refused (the reason as before). decide and the step before applying return the reason and its kind as `check`. - notify_blocked never tells a check that is pending or didn't finish; a refused model is still told once. - The next hourly check installs once the check has passed. - Docs: the model check section of updates.md. Incident case xv. - Tests: the three reasons are distinct; no notice for a wait; pending then verified installs at the next hourly check; a stalled check is started again; a refused model is told once. --- docs/incidents/xv_pending_check_is_a_wait.md | 5 + docs/self-host/updates.md | 2 +- lambda/tests/test_updater_check_pending.py | 118 ++++++++++++++++++ lambda/updater/handler.py | 53 ++++++-- .../incidents/xv_pending_check_is_a_wait.rs | 45 +++++++ 5 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 docs/incidents/xv_pending_check_is_a_wait.md create mode 100644 lambda/tests/test_updater_check_pending.py create mode 100644 services/worker/src/passes/incidents/xv_pending_check_is_a_wait.rs diff --git a/docs/incidents/xv_pending_check_is_a_wait.md b/docs/incidents/xv_pending_check_is_a_wait.md new file mode 100644 index 00000000..5538abf8 --- /dev/null +++ b/docs/incidents/xv_pending_check_is_a_wait.md @@ -0,0 +1,5 @@ +# xv. `xv_pending_check_is_a_wait` + +**What happened:** A self-hosted install's hourly check met a new release whose signature was still being checked, so its model check was pending. The check said "a model this release calls was refused; checking again daily", the same as for a refused model, and a few minutes later the release check passed. The hourly check and the step before applying both asked one yes or no question (`blocking`) that was true for a check still running, a check that didn't finish, and a refused model alike, and both gave the refusal's reason. + +**The guarantee:** Why the release check holds an update has three answers (`check_hold`). A check still running is a wait: "waiting for the release check; trying again next hour", nobody is told, and the next hourly check installs once it has passed. A check that didn't finish is started again by the next hourly check, which says so. Only a model the release calls that was refused gives the refusal reason and tells the admins, once. The Python tests in `lambda/tests/test_updater_check_pending.py` replay each one; this case holds the wiring. diff --git a/docs/self-host/updates.md b/docs/self-host/updates.md index 42c16cb7..6665acea 100644 --- a/docs/self-host/updates.md +++ b/docs/self-host/updates.md @@ -97,7 +97,7 @@ An automatic update starts only when all of these hold: auto-update is on, the h ## The model check -Each release lists the models it calls (`models.json`, made from the code and covered by the signed `SHA256SUMS`). The updater reads it only after a read-only build has checked the release's signature and the file's checksum; until then the update waits. Before an update, automatic or from **Update**, the updater asks the worker to make one test call to each, through your current provider (Bedrock or Anthropic keys). If one is refused, the update waits: **Settings, System** and **Setup** say **Update to vX needs your action** with the model, the fix and the AWS console link, and admins get one email. The check runs again daily and the update applies by itself once it passes (with auto-update on). **Re-run the model check** runs it now. CoderHelm never accepts model terms or submits forms for you; see [Model providers](./model-providers.md#bedrock-model-access). +Each release lists the models it calls (`models.json`, made from the code and covered by the signed `SHA256SUMS`). The updater reads it only after a read-only build has checked the release's signature and the file's checksum; until then the update waits, which is never a refusal: the hourly check says it is waiting for the release check, tells no one, and installs at the next hour once the check has passed. A check that didn't finish is started again by the next hourly check. Before an update, automatic or from **Update**, the updater asks the worker to make one test call to each, through your current provider (Bedrock or Anthropic keys). If one is refused, the update waits: **Settings, System** and **Setup** say **Update to vX needs your action** with the model, the fix and the AWS console link, and admins get one email. The check runs again daily and the update applies by itself once it passes (with auto-update on). **Re-run the model check** runs it now. CoderHelm never accepts model terms or submits forms for you; see [Model providers](./model-providers.md#bedrock-model-access). An install on Anthropic API keys (the launch parameter **ModelProvider** `anthropic`) never needs Bedrock: the worker makes the test calls with a team's key, never through Bedrock. Each team adds its own key, so until one exists there is nothing to check with: the check notes it, and nothing holds the update. Once a team adds its key, a model refused with that key holds the update like any other. diff --git a/lambda/tests/test_updater_check_pending.py b/lambda/tests/test_updater_check_pending.py new file mode 100644 index 00000000..949e42ed --- /dev/null +++ b/lambda/tests/test_updater_check_pending.py @@ -0,0 +1,118 @@ +"""A release check that is still running is a wait, never a refusal. The +hourly check said "a model this release calls was refused; checking again +daily" while the release's signature was still being checked, minutes +before the check passed. Pending, stalled and refused now each have their +own reason; only a refused model is told to the admins, and the next hourly +check installs once the check has passed. + +Run: python3 -m unittest discover -s lambda/tests +""" + +import unittest +from datetime import timedelta + +import test_updater as t + +u = t.u +AT = t.SUNDAY_3AM + + +class Reasons(unittest.TestCase): + def test_pending_stalled_and_refused_are_distinct(self): + v = "v1.1.0" + refused = {"version": v, "results": [{"model": "m", "status": "fail", "required": True}]} + self.assertEqual(u.check_hold({"version": v, "pending": True, "results": []}, v), ("pending", u.CHECK_PENDING)) + self.assertEqual(u.check_hold({"version": v, "stalled": True, "results": []}, v), ("stalled", u.CHECK_STALLED)) + self.assertEqual(u.check_hold(refused, v), ("refused", u.CHECK_REFUSED)) + self.assertIsNone(u.check_hold({"version": v, "ok": True, "results": []}, v)) + self.assertIsNone(u.check_hold(refused, "v1.2.0")) + self.assertEqual(len({u.CHECK_PENDING, u.CHECK_STALLED, u.CHECK_REFUSED}), 3) + for wait in (u.CHECK_PENDING, u.CHECK_STALLED): + self.assertNotIn("refused", wait) + self.assertNotIn("daily", wait) + # A refused model only waits for a person when it's a model the release needs. + optional = {"version": v, "results": [{"model": "m", "status": "fail", "required": False}]} + self.assertIsNone(u.check_hold(optional, v)) + + def test_decide_gives_each_its_own_reason(self): + on = dict(t.ON, channel="stable") + for record, kind in (({"version": "v1.1.0", "pending": True, "results": []}, "pending"), + ({"version": "v1.1.0", "stalled": True, "results": []}, "stalled"), + ({"version": "v1.1.0", "results": [{"status": "fail", "required": True}]}, "refused")): + d = u.decide(AT, on, "v1.0.0", [t.rel("v1.1.0")], {}, record) + self.assertEqual((d["action"], d["check"]), ("notify", kind)) + self.assertEqual(d["reason"], dict(pending=u.CHECK_PENDING, stalled=u.CHECK_STALLED, refused=u.CHECK_REFUSED)[kind]) + + def test_notify_blocked_never_tells_a_wait(self): + sent = [] + saved = u.notify + u.notify = lambda *a, **k: sent.append(a[0]) or 1 + self.addCleanup(setattr, u, "notify", saved) + store = u.Store(t.FakeDynamo(), "t") + for record in ({"version": "v1.1.0", "pending": True, "results": [{"status": "fail", "required": True}]}, + {"version": "v1.1.0", "stalled": True, "results": [{"status": "fail", "required": True}]}): + u.notify_blocked(store, {}, dict(record, checked_at=AT.isoformat())) + self.assertEqual(sent, []) + + +class HourlyCheck(unittest.TestCase): + """The hourly check against a release whose signature is still being checked + (ModelCheck's install: auto-update on, a daily window, a fake worker).""" + + releases = t.ModelCheck.releases + tick = t.ModelCheck.tick + + def setUp(self): + t.ModelCheck.setUp(self) + self.db.items.pop(("SYSTEM", "MANIFEST#v1.1.0")) + self.worker.refuse = set() + self.cb = t.FakeCodeBuild() + u._clients["codebuild"] = self.cb + self.addCleanup(u._clients.pop, "codebuild", None) + + def verified(self): + # The release check reports back: signature and checksums verified. + self.store.put("MANIFEST#v1.1.0", {"verified": True, "manifest": t.MANIFEST}) + + def test_pending_is_a_wait_and_the_next_hour_installs(self): + # The beta channel at any hour, so the next hourly check is one that may install. + self.store.put("AUTO_UPDATE", {"auto": True, "channel": "beta", "day": "any"}) + d = self.tick(AT) + self.assertEqual((d["action"], d["reason"], d["check"]), ("notify", u.CHECK_PENDING, "pending")) + self.assertTrue(self.store.get("MODEL_CHECK")["pending"]) + # No refusal: nothing to the admins, and no update started. + self.assertEqual(self.notices, []) + self.assertEqual([b for b in self.builds if b[2] == "update"], []) + # Minutes later the check passes; the next hourly check installs. + self.verified() + d = self.tick(AT + timedelta(hours=1)) + self.assertEqual(d["action"], "update", d) + self.assertIn(("v1.1.0", "auto", "update"), self.builds) + self.assertEqual(self.notices, []) + + def test_a_check_that_didnt_finish_is_started_again_and_says_so(self): + self.tick(AT) + mc = self.store.get("MODEL_CHECK") + mc.update(pending=False, stalled=True) + self.store.put("MODEL_CHECK", mc) + state = self.store.get("UPDATE_STATE") + state["verifying"]["at"] = (AT - timedelta(hours=2)).isoformat() + self.store.put("UPDATE_STATE", state) + checks = len([b for b in self.builds if b[2] == "release-check"]) + d = self.tick(AT + timedelta(hours=1)) + self.assertEqual((d["reason"], d["check"]), (u.CHECK_STALLED, "stalled")) + self.assertEqual(len([b for b in self.builds if b[2] == "release-check"]), checks + 1) + self.assertEqual(self.notices, []) + + def test_a_refused_model_is_still_told_once(self): + self.verified() + self.worker.refuse = {"claude-sonnet-5-5"} + d = self.tick(AT) + self.assertEqual((d["reason"], d["check"]), (u.CHECK_REFUSED, "refused")) + self.assertEqual(self.notices, ["update to v1.1.0 needs your OK"]) + self.tick(AT + timedelta(hours=1)) + self.assertEqual(self.notices, ["update to v1.1.0 needs your OK"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/lambda/updater/handler.py b/lambda/updater/handler.py index 0f68e2ff..e2ce8291 100644 --- a/lambda/updater/handler.py +++ b/lambda/updater/handler.py @@ -374,8 +374,9 @@ def decide(now_utc, settings, current, releases, state, model_check=None, last_i quiet = {"action": "notify" if notify else "none", "version": v} if v in (state.get("failed_versions") or []): return {**quiet, "reason": "this version failed before; an admin can retry it"} - if blocking(model_check, v): - return {**quiet, "reason": "a model this release calls was refused; checking again daily"} + hold = check_hold(model_check, v) + if hold: + return {**quiet, "reason": hold[1], "check": hold[0]} if not settings["auto"]: return {**quiet, "reason": "auto-update is off"} if latest["breaking"] and settings["majors"] == "ask": @@ -1929,11 +1930,34 @@ def invoke_worker(env, payload): return json.loads(r["Payload"].read() or b"{}") +# Why the release check holds an update, by what it is: a wait (the +# release's signature still being checked) passes by itself within minutes; +# a check that didn't finish is started again; only a model the release +# calls that was refused needs a person, and is told once. +CHECK_PENDING = "waiting for the release check; trying again next hour" +CHECK_STALLED = "the release check didn't finish; starting it again, trying again next hour" +CHECK_REFUSED = "a model this release calls was refused; checking again daily" + + +def check_hold(record, version): + """(kind, reason) when the check for `version` holds the update, else + None. kind: "pending" (still checking), "stalled" (didn't finish, started + again) or "refused" (a model the release calls was refused).""" + if not record or record.get("version") != version: + return None + if failures(record, required=True) and not record.get("pending"): + return "refused", CHECK_REFUSED + if record.get("stalled"): + return "stalled", CHECK_STALLED + if record.get("pending"): + return "pending", CHECK_PENDING + return None + + def blocking(record, version): - """True when the check for `version` found a model the release calls - refused, or hasn't run yet because the release's signature is being checked.""" - return bool(record and record.get("version") == version - and (record.get("pending") or record.get("stalled") or failures(record, required=True))) + """True when the check for `version` holds the update (check_hold): a + model the release calls was refused, or the check hasn't finished.""" + return check_hold(record, version) is not None def failures(record, required=None): @@ -2115,7 +2139,9 @@ def checked(record): def notify_blocked(store, env, record): - if record.get("notified") or not failures(record, required=True): + """Tells the admins once that a model the release calls was refused. + Never for a check that is still running or didn't finish: that is a wait.""" + if record.get("notified") or record.get("pending") or record.get("stalled") or not failures(record, required=True): return notify_once(store, f"blocked:{record.get('version')}", checked(record), f"update to {record['version']} needs your OK", blocked_text(record, env), env, what="blocked", version=record.get("version"), @@ -6976,7 +7002,9 @@ def releases(max_age, refresh=False): close_window(env) rel, latest, behind = releases(CACHE_SECONDS) mc = store.get("MODEL_CHECK") - # First sight of a release, and daily while a model is refused. + # A check that didn't finish is started over by this one, and the reason says so. + stalled = bool(latest and mc and mc.get("version") == latest["version"] and mc.get("stalled")) + # First sight of a release, every hour while its check runs, and daily while a model is refused. if latest and not running(state, now) and needs_check(mc, latest["version"], now): mc = model_check(store, env, now, latest["version"], repo, probe) notify_blocked(store, env, mc) @@ -6990,6 +7018,8 @@ def releases(max_age, refresh=False): d = {"action": "none", "version": behind["version"], "reason": behind["reason"]} else: d = decide(now, settings, current, rel, state, mc, last_install=last_install_at(store)) + if stalled and d.get("check") == "pending": + d = dict(d, reason=CHECK_STALLED, check="stalled") if d["action"] in ("notify", "update") and state.get("notified_version") != d.get("version"): # Seen once. No email: Settings, System shows a new release # (a major one too), and the digest sums them up. @@ -6999,10 +7029,11 @@ def releases(max_age, refresh=False): if d["action"] == "update": # Proven again right before applying, whatever the last check said. mc = model_check(store, env, now, d["version"], repo, probe) - if blocking(mc, d["version"]): + hold = check_hold(mc, d["version"]) + if hold: + # Only a refused model is told (once); a check still running is a wait. notify_blocked(store, env, mc) - d = {"action": "none", "version": d["version"], - "reason": "a model this release calls was refused; checking again daily"} + d = {"action": "none", "version": d["version"], "reason": hold[1], "check": hold[0]} else: try: started = begin(store, env, now, d["version"], "auto", "update", scheduled=True) or {} diff --git a/services/worker/src/passes/incidents/xv_pending_check_is_a_wait.rs b/services/worker/src/passes/incidents/xv_pending_check_is_a_wait.rs new file mode 100644 index 00000000..57be9fff --- /dev/null +++ b/services/worker/src/passes/incidents/xv_pending_check_is_a_wait.rs @@ -0,0 +1,45 @@ +//! xv. A release's model check was still pending (its signature was being +//! checked) and the hourly check said "a model this release calls was +//! refused; checking again daily". Minutes later the check passed. One +//! yes or no question (`blocking`) was true for a check still running, a +//! check that didn't finish and a refused model, and every caller gave the +//! refusal's reason. +//! +//! Guarantees: `check_hold` tells the three apart, the hourly check and the +//! step before applying give each its own reason, and only a refused model +//! is told to the admins (`notify_blocked`). The Python replays live in +//! `lambda/tests/test_updater_check_pending.py`; this case holds the wiring. + +const UPDATER: &str = include_str!("../../../../../lambda/updater/handler.py"); + +/// The Python function `name` (up to the next top-level definition). +fn py_fn<'a>(src: &'a str, name: &str) -> &'a str { + let head = format!("\ndef {name}("); + let start = src.find(&head).unwrap_or_else(|| panic!("{name} is gone")); + let rest = &src[start + 1..]; + let end = rest[1..] + .find("\ndef ") + .or_else(|| rest[1..].find("\nclass ")) + .map(|i| i + 1) + .unwrap_or(rest.len()); + &rest[..end] +} + +#[test] +fn a_check_still_running_is_a_wait_never_a_refusal() { + let hold = py_fn(UPDATER, "check_hold"); + for kind in ["\"pending\"", "\"stalled\"", "\"refused\""] { + assert!(hold.contains(kind), "{kind}"); + } + assert!(UPDATER + .contains("CHECK_PENDING = \"waiting for the release check; trying again next hour\"")); + // Both places that hold an update give the reason check_hold gives. + assert!(py_fn(UPDATER, "decide").contains("check_hold(model_check, v)")); + let handle = py_fn(UPDATER, "handle"); + assert!(handle.contains("hold = check_hold(mc, d[\"version\"])")); + assert!(handle.contains("reason=CHECK_STALLED")); + assert!(!handle.contains("\"a model this release calls was refused; checking again daily\"")); + // Only a refused model is told. + let told = py_fn(UPDATER, "notify_blocked"); + assert!(told.contains("record.get(\"pending\") or record.get(\"stalled\")")); +}