Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Harness OS: a system update says to keep the computer on, and counts its steps

bubu-dudu2df53b86339f
diff --git a/os/live_update.py b/os/live_update.py
index ed698ccbe..66832972a 100644
--- a/os/live_update.py
+++ b/os/live_update.py
@@ -36,6 +36,7 @@ FILES = ('harness-tui', 'cli.mjs', 'notify.mjs')
LIMIT = 64 * 1024 * 1024
DOWNLOAD_CHUNK = 1024 * 1024
RESTART_REQUIRED = Path('/run/harness-os-restart-required')
+KEEP_ON = 'Keep the computer on and plugged in until the system update finishes.'
SYSTEM_LOCK = Path('/run/lock/hn-os.lock')
BOOT_ID = Path('/proc/sys/kernel/random/boot_id')
PROC = Path('/proc')
@@ -685,6 +686,8 @@ def update_all():
# Do not reconnect an old session using a new OS package. Its included
# runtime takes effect on reboot; finish any independent public release
# against that new base afterward, under this same explicit approval.
+ # The one stretch where turning the computer off leaves it to recovery: say so first.
+ print(KEEP_ON, flush=True)
subprocess.run(['sudo', '-n', '/usr/bin/harness', 'upgrade'], check=True)
(STATE / 'system.json').unlink(missing_ok=True)
if read(RESTART_REQUIRED, {}).get('status') == 'ready':
@@ -750,6 +753,8 @@ def screen(window, message='', refresh=False, intent=None):
else:
title, choices = 'Harness is up to date.', [('Done', None)]
lines = [*WORDMARK, '', '', status or title]
+ if system_state == 'applying' and not status:
+ lines += ['', KEEP_ON]
if message and not status:
lines += ['', message]
top = max(0, (height - len(lines) - 4) // 2)
diff --git a/os/release_update.py b/os/release_update.py
index 999808145..5807781ba 100644
--- a/os/release_update.py
+++ b/os/release_update.py
@@ -110,6 +110,12 @@ def apply(feed=FEED):
name = manifest['package'].get('name', '')
if not re.fullmatch(r'harness-os-[0-9A-Za-z.+_-]+-x86_64\.pkg\.tar\.gz', name):
raise ValueError('Invalid system package filename.')
+ # How many steps to show: a newer Arch snapshot adds the base upgrade. Read here only to
+ # count; the same checks are made again under the operation lock before anything changes.
+ snapshots = set(re.findall(r'https://archive\.archlinux\.org/repos/(\d{4}/\d{2}/\d{2})/', system.PACMAN_CONFIG.read_text()))
+ base_upgrade = bool(system.pending_update()) or any(system.snapshot_date(manifest['arch_snapshot']) > day for day in snapshots)
+ steps = updater.Steps(5 if base_upgrade else 4)
+ steps('Downloading and checking the update')
(folder / name).write_bytes(verified(release['assets']['package'], feed != FEED))
(folder / 'package-manifest.json').write_text(json.dumps(manifest))
with system.operation_lock():
@@ -129,8 +135,9 @@ def apply(feed=FEED):
if system.pending_update() or date > current:
# This public update was already requested; pacman's extra
# confirmation must not stall the Updates terminal.
+ steps('Updating the Arch Linux base')
system.update(max(current, date), noninteractive=True)
- updater.apply(folder, system, base, installation)
+ updater.apply(folder, system, base, installation, steps)
def main():
diff --git a/os/runtime_update.py b/os/runtime_update.py
index 649add149..5a427016a 100644
--- a/os/runtime_update.py
+++ b/os/runtime_update.py
@@ -246,7 +246,22 @@ def prepare_packages(package, additional=()):
*map(str, additional), str(package)], check=True)
-def apply(folder, system, base, installation):
+class Steps:
+ """`Step 2 of 4 · Saving a recovery point…` in the Updates terminal. A system update showed
+ pacman's output alone, with no sign of how far it was or that turning the computer off
+ then is the one moment that leaves it to recovery."""
+
+ def __init__(self, total):
+ self.total, self.done = total, 0
+
+ def __call__(self, text):
+ self.done += 1
+ self.total = max(self.total, self.done)
+ print(f'Step {self.done} of {self.total} · {text}…', flush=True)
+
+
+def apply(folder, system, base, installation, steps=None):
+ steps = steps or Steps(3)
previous = latest()
if previous and previous['status'] not in ('applied', 'rolled-back'):
raise ValueError('The previous Harness update did not finish. Run rollback first; its checkpoint is retained.')
@@ -276,6 +291,7 @@ def apply(folder, system, base, installation):
kernel = boot.module('t2_update') if kernel_change else None
additional = [incoming / kernel_change['candidate']['package']['filename']] if kernel_change else []
prepare_packages(incoming / source_package.name, additional)
+ steps('Saving a recovery point')
checkpoint = system.checkpoint('before-harness-update')
identity = datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%SZ-') + uuid.uuid4().hex[:8]
saved = STATE / identity
@@ -298,7 +314,9 @@ def apply(folder, system, base, installation):
# The fast user updater must not mix a running old session with newly
# installed OS integration. /run clears this only on a real reboot.
system.write_json(RESTART_REQUIRED, {'status': 'applying', 'package': manifest['package']['version']})
+ steps('Installing Harness')
install_package(incoming / source_package.name, manifest['package']['version'], manifest['runtime'], additional)
+ steps('Preparing the boot files')
boot.restore_firmware()
# Plymouth and other initramfs assets may change without a kernel
# package transaction, so rebuild them on this path as well.
diff --git a/os/tests/test_release_update.py b/os/tests/test_release_update.py
index 78283dfa8..ecd7b8587 100644
--- a/os/tests/test_release_update.py
+++ b/os/tests/test_release_update.py
@@ -1,8 +1,9 @@
import copy
-from contextlib import nullcontext
+from contextlib import nullcontext, redirect_stdout
import hashlib
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
import importlib.util
+import io
import json
import os
from pathlib import Path
@@ -130,18 +131,25 @@ class ReleaseChannel(unittest.TestCase):
system = SimpleNamespace(operation_lock=lambda: nullcontext(), installed=lambda: {'root_uuid': 'fixture'},
snapshot_date=lambda date: date, PACMAN_CONFIG=config, pending_update=lambda: None,
update=lambda date, **options: self.events.append(('system', date, options)))
- def apply(folder, system, base, installation):
+ def apply(folder, system, base, installation, steps):
self.assertEqual((folder / self.manifest['package']['name']).read_bytes(), self.package)
self.assertEqual(folder.stat().st_mode & 0o777, 0o700)
self.events.append(('harness', folder))
+ steps('Saving a recovery point')
return SimpleNamespace(system_module=lambda: system, validate_bundle=Mock(),
- prepare_kernel_bundle=Mock(),
+ prepare_kernel_bundle=Mock(), Steps=update.load_runtime_updater().Steps,
validate_base=update.load_runtime_updater().validate_base, latest=lambda: None, apply=apply)
def test_root_download_is_private_and_full_base_upgrade_precedes_package_application(self):
updater = self.fake_updater()
- with patch.object(update.os, 'geteuid', return_value=0), patch.object(update, 'load_runtime_updater', return_value=updater):
+ shown = io.StringIO()
+ with patch.object(update.os, 'geteuid', return_value=0), patch.object(update, 'load_runtime_updater', return_value=updater), redirect_stdout(shown):
update.apply(self.url + '/metadata.json')
+ # Numbered steps in the Updates terminal, the base upgrade counted when the snapshot moves.
+ self.assertEqual([line for line in shown.getvalue().splitlines() if line.startswith('Step ')], [
+ 'Step 1 of 5 · Downloading and checking the update…',
+ 'Step 2 of 5 · Updating the Arch Linux base…',
+ 'Step 3 of 5 · Saving a recovery point…'])
self.assertEqual(self.events[0], ('system', '2026/10/01', {'noninteractive': True}))
self.assertEqual(self.events[1][0], 'harness')
self.assertFalse(self.events[1][1].exists(), 'Root download is removed after the transaction')