From 995f94b99906d16b1775cb7240c5bb269acb3186 Mon Sep 17 00:00:00 2001 From: Archipelago Date: Sun, 15 Nov 2026 23:11:02 +0300 Subject: [PATCH] Resume through the ordinary unit: one stop path and one status --- STATUS.md | 19 +++++++++++++++++++ control/README.md | 5 +++++ control/server.py | 21 ++++++++++++++------- pipeline/release-cycle.py | 36 +++++++++++++++++++++++++++--------- tests/control_portal.py | 14 ++++++++++++++ tests/cycle-recovery.py | 14 ++++++++++++++ 6 files changed, 93 insertions(+), 16 deletions(-) diff --git a/STATUS.md b/STATUS.md index 44e2c99..a440927 100644 --- a/STATUS.md +++ b/STATUS.md @@ -32,6 +32,25 @@ lacked `worker_source_root`, the defect recorded in `deploy/PIPELINE-AUDIT`, so never reached its assertions and its mocked `docker ps` failure path returned no output; both are fixed and the interruption/recovery order passes again. +Verifying the fix exposed the second half of the same 404: `deploy/Caddyfile` had no +route for `/archipelago/arch-repo-snapshot/*`. The container that failed the run still +had one in memory from a file edited on the host, so the views were reachable only +until that file was overwritten and the container restarted — which is exactly what +rolling out this change did to the previously working `2026-11-12` view. The route is +now in `deploy/Caddyfile` (root `/srv/artifacts/arch-repo-snapshot`, outside the +generation symlink `current`), and both dates answer 200 over HTTPS for `core.db` and +`extra.db`, next to the unchanged `/archipelago/`, `v1/releases.json`, +`releases.json`, `pipeline.json`, portal, package and ISO routes. + +A resume is no longer a second unit. `POST /api/control` accepts +`{action:start,resume:true}` and writes a request containing only `resume` and +`requested_at`; `release-cycle.py` turns that into `--resume` and the run keeps the +mode and snapshot it already had, so nothing is pinned twice. Until now a resume ran +as the transient `archipelago-cycle-resume.service`, which the portal's stop button +and status view did not know about; now one ordinary service unit covers starts, +resumes and stops. `resolve_request` in the driver is covered by +`tests/cycle-recovery.py`. + ## A stop takes effect immediately, not after two minutes (2026-11-15) `archipelago-release-cycle.service` was `Type=oneshot`. systemd does not deliver diff --git a/control/README.md b/control/README.md index d6b659e..a078154 100644 --- a/control/README.md +++ b/control/README.md @@ -74,6 +74,11 @@ dates from inside that container, restarts it once when it still has a stale vie drops a date it cannot serve; the portal additionally requires the pinned date to answer HTTP 200 before it writes the request. +`{action: "start", "resume": true}` continues the last failed run under the same +service unit: the request carries only `resume` and `requested_at`, so the run keeps +the mode and the immutable snapshot it was pinned to, and the stop button and the +status view keep describing the unit that is actually running. + Schedule buttons enable or disable the monthly dispatcher timer; the cadence itself (1st of the month, ISO + OSTree) is fixed by the code and is not editable from the portal. diff --git a/control/server.py b/control/server.py index bcf6e00..9bc0646 100644 --- a/control/server.py +++ b/control/server.py @@ -175,13 +175,20 @@ class App: raise ValueError('Pipeline is already running or stopping') if action == 'start': mode = parameters.get('mode', 'iso') - if mode not in ('iso', 'ostree'): - raise ValueError('Неизвестный режим сборки') - # Pin the exact immutable repository before the cycle starts: a - # manual build must never silently reuse a different snapshot. - pinned = self.snapshot_date(parameters.get('snapshot', 'latest')) - parameters = {'mode': mode, 'snapshot': pinned, - 'requested_at': datetime.now(timezone.utc).isoformat()} + request = {'requested_at': datetime.now(timezone.utc).isoformat()} + if parameters.get('resume'): + # Continue the last failed run. It keeps the mode and the + # immutable snapshot it was already pinned to, so this request + # must not pin either again; the run stays one ordinary service + # unit, which keeps the stop button and the status truthful. + request['resume'] = True + else: + if mode not in ('iso', 'ostree'): + raise ValueError('Неизвестный режим сборки') + # Pin the exact immutable repository before the cycle starts: a + # manual build must never silently reuse a different snapshot. + request.update(mode=mode, snapshot=self.snapshot_date(parameters.get('snapshot', 'latest'))) + parameters = request path = self.archive / 'cycle-request.json' path.parent.mkdir(parents=True, exist_ok=True) temporary = path.with_suffix('.tmp') diff --git a/pipeline/release-cycle.py b/pipeline/release-cycle.py index 45c5601..4d118fe 100644 --- a/pipeline/release-cycle.py +++ b/pipeline/release-cycle.py @@ -33,6 +33,25 @@ def atomic(path, value): temp.replace(path) +def resolve_request(candidate, age, resume): + """Return the portal request this run may consume, or None. + + A build request pins a mode and one immutable snapshot date. A resume request + only asks to continue the last run: it carries neither, because that run keeps + its own mode and snapshot identity, and a command-line --resume wins over any + request. Requests older than 900 s are discarded so a scheduled run never + inherits a forgotten manual start. + """ + if resume or candidate is None or age is None or not 0 <= age <= 900: + return None + if candidate.get('resume') is True: + return candidate + if (candidate.get('mode') in ('iso', 'ostree') + and re.fullmatch(r'[0-9]{4}-[0-9]{2}-[0-9]{2}', candidate.get('snapshot', ''))): + return candidate + return None + + def verify_snapshot(snapshot_url): """Refuse to build from a snapshot the public web server does not serve. @@ -100,21 +119,20 @@ def main(): except (OSError, json.JSONDecodeError): candidate = None request_path.unlink(missing_ok=True) - if args.resume: - candidate = None try: age = (datetime.now(timezone.utc) - datetime.fromisoformat(candidate['requested_at'])).total_seconds() except (TypeError, KeyError, ValueError): age = None - if (candidate and candidate.get('mode') in ('iso', 'ostree') - and re.fullmatch(r'[0-9]{4}-[0-9]{2}-[0-9]{2}', candidate.get('snapshot', '')) - and age is not None and 0 <= age <= 900): - request = candidate - elif candidate is not None: - print('ignored stale or invalid portal request', flush=True) + request = resolve_request(candidate, age, args.resume) + if request and request.get('resume'): + # A resume keeps the previous run's mode and snapshot, so the request + # carries neither and the run continues from its own state. + args.resume = True + elif request is None and candidate is not None: + print('discarded portal request (stale, invalid, or superseded by --resume)', flush=True) if args.mode != 'auto': mode = args.mode - elif request: + elif request and request.get('mode'): mode = request['mode'] else: mode = 'iso' if datetime.now(timezone.utc).day == 1 else 'ostree' diff --git a/tests/control_portal.py b/tests/control_portal.py index 5cd35ff..7f7b675 100644 --- a/tests/control_portal.py +++ b/tests/control_portal.py @@ -97,6 +97,20 @@ class Portal(unittest.TestCase): with self.assertRaises(ValueError): app.control('start', {'mode': 'reboot'}) self.assertFalse((app.archive / 'cycle-request.json').exists()) + # A resume keeps the failed run's mode and snapshot: it pins neither, + # so the same ordinary service unit and the same stop button apply. + asked.clear() + control.subprocess.run = lambda argv, **kwargs: subprocess.CompletedProcess(argv, 0, b'', b'') + try: + resumed = app.control('start', {'action': 'start', 'resume': True}) + finally: + control.subprocess.run = original + request = json.loads((app.archive / 'cycle-request.json').read_text()) + self.assertEqual(request.get('resume'), True) + self.assertNotIn('mode', request) + self.assertNotIn('snapshot', request) + self.assertEqual(asked, []) + self.assertEqual(resumed['request'], request) def test_snapshot_listing_uses_the_published_manifest(self): with tempfile.TemporaryDirectory() as directory: diff --git a/tests/cycle-recovery.py b/tests/cycle-recovery.py index b5eaef4..c40c348 100644 --- a/tests/cycle-recovery.py +++ b/tests/cycle-recovery.py @@ -81,4 +81,18 @@ with patch.object(cycle.urllib.request, 'urlopen', return_value=Served(404)), \ assert 'not served' in str(error) and 'core.db' in str(error) else: raise AssertionError('Unserved repository snapshot accepted') + + +# A portal request may pin a fresh build or ask to resume the last run, never both. +build = {'mode': 'ostree', 'snapshot': '2026-11-15', 'requested_at': 'stamp'} +assert cycle.resolve_request(build, 10, False) is build +assert cycle.resolve_request(build, 9 * 60 + 59, False) is build +assert cycle.resolve_request(build, 901, False) is None +assert cycle.resolve_request(build, None, False) is None +assert cycle.resolve_request(build, 10, True) is None +assert cycle.resolve_request({'mode': 'reboot', 'snapshot': '2026-11-15'}, 10, False) is None +assert cycle.resolve_request({'mode': 'iso', 'snapshot': 'latest'}, 10, False) is None +resume = {'resume': True, 'requested_at': 'stamp'} +assert cycle.resolve_request(resume, 10, False) is resume +assert cycle.resolve_request(resume, 901, False) is None print('CYCLE_RECOVERY_ORDER_AND_OWNERSHIP_PASS')