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: an update waits for the unit's daemon; an Orange Pi is told by its board

bubu-dudud1cdfe783faf
diff --git a/cli/src/lib/windowSurfaces.spec.ts b/cli/src/lib/windowSurfaces.spec.ts
index b3e0e8ac0..049902c69 100644
--- a/cli/src/lib/windowSurfaces.spec.ts
+++ b/cli/src/lib/windowSurfaces.spec.ts
@@ -19,6 +19,12 @@ describe('the windows a person has open, per surface', () => {
expect(tuiPresence({ HARNESS_OS: '1' }, files({ [model]: 'Orange Pi 4 Pro\0' }))).toBe('harness-os-pi')
expect(tuiPresence({}, files({ [unit]: '[Unit]', [model]: 'OrangePi 5\0' }))).toBe('harness-os-pi')
expect(tuiPresence({ HARNESS_OS: '1' }, files({ [model]: 'Raspberry Pi 5\0' }))).toBe('harness-os')
+ // Orange Pi's own Debian, as an Orange Pi 4 Pro reads it (2026-10-13): the SoC in `model`.
+ const compatible = '/proc/device-tree/compatible'
+ const release = '/etc/orangepi-release'
+ expect(tuiPresence({ HARNESS_OS: '1' }, files({ [model]: 'sun60iw2\0', [compatible]: 'xunlong,orangepi-4-pro\0arm,sun60iw2p1\0' }))).toBe('harness-os-pi')
+ expect(tuiPresence({ HARNESS_OS: '1' }, files({ [model]: 'sun60iw2\0', [release]: 'BOARD=orangepi4pro\nBOARD_NAME="Orange Pi 4 Pro"\n' }))).toBe('harness-os-pi')
+ expect(tuiPresence({ HARNESS_OS: '1' }, files({ [model]: 'sun60iw2\0' })), 'a SoC alone names no board').toBe('harness-os')
expect(['tui', 'harness-os']).toContain(tuiPresence())
})
diff --git a/cli/src/lib/windowSurfaces.ts b/cli/src/lib/windowSurfaces.ts
index dcab8872f..c1c685169 100644
--- a/cli/src/lib/windowSurfaces.ts
+++ b/cli/src/lib/windowSurfaces.ts
@@ -13,12 +13,15 @@ export const WINDOW_SURFACES: readonly WindowSurface[] = ['desktop', 'tui']
* What the backend counts a `harness tui` window as (`user_daily_client_presence.surface`): the TUI, or
* Harness OS on a PC or an Orange Pi, so where a person comes from is told apart. Harness OS is its
* daemon unit (which sets HARNESS_OS=1, and whose file the OS package ships); the board is the device
- * tree's model.
+ * tree's model or compatible, or Orange Pi's release file.
*/
export type TuiPresence = 'tui' | 'harness-os' | 'harness-os-pi'
export function tuiPresence(env: NodeJS.ProcessEnv = process.env, read: (path: string) => string = readText): TuiPresence {
if (env.HARNESS_OS !== '1' && !read('/usr/lib/systemd/user/harness-daemon.service')) return 'tui'
- return /orange\s*pi/i.test(read('/proc/device-tree/model')) ? 'harness-os-pi' : 'harness-os'
+ // Orange Pi's own Debian names the SoC in `model` ("sun60iw2"); the board is in `compatible`
+ // ("xunlong,orangepi-4-pro") and in /etc/orangepi-release.
+ const board = [read('/proc/device-tree/model'), read('/proc/device-tree/compatible'), read('/etc/orangepi-release')].join('\n')
+ return /orange\s*-?pi/i.test(board) ? 'harness-os-pi' : 'harness-os'
}
function readText(path: string): string { try { return readFileSync(path, 'utf8') } catch { return '' } }
diff --git a/os/live_update.py b/os/live_update.py
index 725849a46..91baa6c2f 100644
--- a/os/live_update.py
+++ b/os/live_update.py
@@ -38,6 +38,8 @@ DOWNLOAD_CHUNK = 1024 * 1024
RESTART_REQUIRED = Path('/run/harness-os-restart-required')
DAEMON_UNIT = 'harness-daemon.service'
DAEMON_STATUS = 'http://127.0.0.1:18473/api/status'
+# How long the unit's restarted daemon has to answer for itself before the update is rolled back.
+RUNTIME_ANSWER_SECONDS = 30
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')
@@ -525,9 +527,15 @@ def restart(cli_changed):
if serving is not None and serving != main:
run('/usr/bin/harness', 'stop', timeout=90)
run('systemctl', '--user', 'restart', DAEMON_UNIT, timeout=180)
- # wait-runtime accepts whichever daemon answers. Activation needs the unit's own.
+ # wait-runtime accepts whichever daemon answers. Activation needs the unit's own, and its
+ # /api/status can lag the socket wait-runtime saw by a few seconds (an Orange Pi answered at
+ # 4 s, after one check at once had already rolled the update back): ask until it answers.
run('/usr/lib/harness-os/wait-runtime')
+ deadline = time.monotonic() + RUNTIME_ANSWER_SECONDS
serving, main = runtime_pids()
+ while (serving is None or serving != main) and time.monotonic() < deadline:
+ time.sleep(1)
+ serving, main = runtime_pids()
if serving is None or serving != main:
raise ValueError(f'The agent runtime is not running under {DAEMON_UNIT}.')
# The terminal surface is separate from the processes that own agent PTYs.
diff --git a/os/tests/test_live_update.py b/os/tests/test_live_update.py
index 317646c3f..b69e7f858 100644
--- a/os/tests/test_live_update.py
+++ b/os/tests/test_live_update.py
@@ -1009,10 +1009,17 @@ class RuntimeSupervision(unittest.TestCase):
('systemctl', '--user', 'is-active', '--quiet', 'hn-screen.service')]
def restart(self, pids, cli_changed=True):
- calls = []
+ """Restart against `pids` in turn, the last repeated, on a clock that only sleeping moves."""
+ calls, answers, clock = [], list(pids), [0.0]
+ ask = lambda: answers.pop(0) if len(answers) > 1 else answers[0]
with patch.object(update, 'run', side_effect=lambda *args, **kwargs: calls.append(args) or ''), \
- patch.object(update, 'runtime_pids', side_effect=pids):
- update.restart(cli_changed)
+ patch.object(update, 'runtime_pids', side_effect=ask), \
+ patch.object(update.time, 'monotonic', side_effect=lambda: clock[0]), \
+ patch.object(update.time, 'sleep', side_effect=lambda seconds: clock.__setitem__(0, clock[0] + seconds)):
+ try:
+ update.restart(cli_changed)
+ finally:
+ self.waited = clock[0]
return calls
def test_the_units_daemon_is_restarted_and_must_serve_afterwards(self):
@@ -1031,6 +1038,15 @@ class RuntimeSupervision(unittest.TestCase):
for after in [(2288, None), (2288, 43000), (None, 43000), (None, None)]:
with self.subTest(after=after), self.assertRaisesRegex(ValueError, 'not running under harness-daemon.service'):
self.restart([(None, None), after])
+ self.assertGreaterEqual(self.waited, update.RUNTIME_ANSWER_SECONDS, 'it gave the daemon its time first')
+
+ def test_a_daemon_that_answers_a_few_seconds_late_is_activated(self):
+ # 2026-10-13, an Orange Pi: wait-runtime was satisfied, /api/status answered 4 s later, and a
+ # single check at once had rolled the update back.
+ calls = self.restart([(1347, 1347), (None, 43000), (None, 43000), (None, 43000), (43000, 43000)])
+ self.assertEqual(calls, [('systemctl', '--user', 'restart', 'harness-daemon.service'),
+ ('/usr/lib/harness-os/wait-runtime',), *self.SCREEN])
+ self.assertEqual(self.waited, 3)
def test_the_unit_bounds_a_stop_and_kills_only_its_main_process(self):
# The restart above waits for the old core to stop; systemd's default 90 s held an update