@crvouga/homelab 0.23.8 → 0.23.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ansible/macos/t3-activate.yml +49 -42
- package/ansible/pyproject.toml +1 -1
- package/ansible/ubuntu/agent-tool.bash +9 -0
- package/ansible/ubuntu/agent-tool.py +113 -0
- package/ansible/ubuntu/policy.json +7 -1
- package/ansible/ubuntu/pressure-guard.py +4 -1
- package/ansible/ubuntu/tasks/resources.yml +45 -3
- package/ansible/uv.lock +4 -4
- package/docs/convergence.md +1 -1
- package/docs/runbooks.md +2 -2
- package/docs/ubuntu-sync.md +45 -0
- package/package.json +2 -2
- package/src/agents/launch.ts +15 -0
- package/src/cli/fleet-sync-forward.ts +3 -1
- package/src/cli/fleet-sync-plan.ts +20 -5
- package/src/cli/fleet-sync-remote.ts +3 -1
- package/src/cli/fleet-sync.ts +3 -0
- package/src/cli/register-fleet.ts +4 -0
- package/src/platform/resource-verify.ts +63 -9
- package/src/t3/manager-desktop.ts +23 -17
|
@@ -3,55 +3,62 @@
|
|
|
3
3
|
hosts: localhost
|
|
4
4
|
connection: local
|
|
5
5
|
gather_facts: false
|
|
6
|
+
vars:
|
|
7
|
+
t3_activation_script: |
|
|
8
|
+
ObjC.import('AppKit');
|
|
9
|
+
ObjC.bindFunction('kill', ['int', ['int', 'int']]);
|
|
10
|
+
function run(argv) {
|
|
11
|
+
const [bundleId, path, version, convergePid] = argv;
|
|
12
|
+
// Ansible runs this task under a detached async supervisor when
|
|
13
|
+
// converge itself is running inside the desktop being replaced.
|
|
14
|
+
const pid = Number(convergePid);
|
|
15
|
+
while (pid && $.kill(pid, 0) === 0) delay(1);
|
|
16
|
+
|
|
17
|
+
const running = () => $.NSRunningApplication.runningApplicationsWithBundleIdentifier(bundleId);
|
|
18
|
+
const matches = (app) => ObjC.unwrap(app.bundleURL.path) === path &&
|
|
19
|
+
ObjC.unwrap($.NSBundle.bundleWithURL(app.bundleURL).objectForInfoDictionaryKey('CFBundleShortVersionString')) === version;
|
|
20
|
+
const apps = running();
|
|
21
|
+
if (Number(apps.count) > 1) throw Error('Multiple T3 desktops are running');
|
|
22
|
+
if (Number(apps.count) === 1) {
|
|
23
|
+
const app = apps.objectAtIndex(0);
|
|
24
|
+
if (matches(app)) return;
|
|
25
|
+
if (!app.forceTerminate) throw Error('Could not terminate T3');
|
|
26
|
+
for (let n = 0; !app.isTerminated && n < 100; n++) delay(0.1);
|
|
27
|
+
if (!app.isTerminated) throw Error('T3 did not exit');
|
|
28
|
+
}
|
|
29
|
+
const open = $.NSTask.alloc.init;
|
|
30
|
+
open.launchPath = '/usr/bin/open';
|
|
31
|
+
open.arguments = $([path]);
|
|
32
|
+
open.launch;
|
|
33
|
+
open.waitUntilExit;
|
|
34
|
+
if (Number(open.terminationStatus) !== 0) throw Error('Could not open T3');
|
|
35
|
+
for (let n = 0; n < 15; n++) {
|
|
36
|
+
const live = running();
|
|
37
|
+
if (Number(live.count) === 1 && matches(live.objectAtIndex(0))) return;
|
|
38
|
+
delay(1);
|
|
39
|
+
}
|
|
40
|
+
throw Error('The verified T3 desktop did not start');
|
|
41
|
+
}
|
|
6
42
|
tasks:
|
|
7
|
-
- name:
|
|
43
|
+
- name: Activate and verify the pinned manager desktop
|
|
8
44
|
ansible.builtin.command:
|
|
9
45
|
argv:
|
|
10
46
|
- /usr/bin/osascript
|
|
11
47
|
- -l
|
|
12
48
|
- JavaScript
|
|
13
49
|
- -e
|
|
14
|
-
-
|
|
15
|
-
ObjC.import('AppKit');
|
|
16
|
-
function run(argv) {
|
|
17
|
-
const apps = $.NSRunningApplication.runningApplicationsWithBundleIdentifier(argv[0]);
|
|
18
|
-
if (Number(apps.count) === 0) return;
|
|
19
|
-
if (Number(apps.count) !== 1) throw Error('Multiple T3 desktops are running');
|
|
20
|
-
const app = apps.objectAtIndex(0);
|
|
21
|
-
if (ObjC.unwrap(app.bundleURL.path) === argv[1]) return;
|
|
22
|
-
if (!app.forceTerminate) throw Error('Could not terminate T3');
|
|
23
|
-
for (let n = 0; n < 100; n++) {
|
|
24
|
-
if (app.isTerminated) return;
|
|
25
|
-
delay(0.1);
|
|
26
|
-
}
|
|
27
|
-
throw Error('T3 did not exit');
|
|
28
|
-
}
|
|
29
|
-
- '{{ bundle_id }}'
|
|
30
|
-
- '{{ desktop_path }}'
|
|
31
|
-
changed_when: true
|
|
32
|
-
- name: Open the verified manager desktop
|
|
33
|
-
ansible.builtin.command:
|
|
34
|
-
argv: [/usr/bin/open, '{{ desktop_path }}']
|
|
35
|
-
changed_when: true
|
|
36
|
-
- name: Wait for Launch Services to report the verified desktop
|
|
37
|
-
ansible.builtin.command:
|
|
38
|
-
argv:
|
|
39
|
-
- /usr/bin/osascript
|
|
40
|
-
- -l
|
|
41
|
-
- JavaScript
|
|
42
|
-
- -e
|
|
43
|
-
- |
|
|
44
|
-
ObjC.import('AppKit');
|
|
45
|
-
function run(argv) {
|
|
46
|
-
const apps = $.NSRunningApplication.runningApplicationsWithBundleIdentifier(argv[0]);
|
|
47
|
-
if (Number(apps.count) !== 1 || ObjC.unwrap(apps.objectAtIndex(0).bundleURL.path) !== argv[1])
|
|
48
|
-
throw Error('Waiting for the verified desktop');
|
|
49
|
-
}
|
|
50
|
+
- '{{ t3_activation_script }}'
|
|
50
51
|
- '{{ bundle_id }}'
|
|
51
52
|
- '{{ desktop_path }}'
|
|
53
|
+
- '{{ desktop_version }}'
|
|
54
|
+
- '{{ converge_pid }}'
|
|
55
|
+
async: '{{ 7200 if converge_pid | int else 0 }}'
|
|
56
|
+
poll: 0
|
|
57
|
+
register: t3_activation
|
|
52
58
|
when: not ansible_check_mode
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
changed_when: true
|
|
60
|
+
|
|
61
|
+
- name: Report the detached activation job
|
|
62
|
+
ansible.builtin.debug:
|
|
63
|
+
msg: 'T3 activation job {{ t3_activation.ansible_job_id }}'
|
|
64
|
+
when: not ansible_check_mode and converge_pid | int != 0
|
package/ansible/pyproject.toml
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Managed by personal converge. BASH_ENV runs before a noninteractive Bash
|
|
2
|
+
# command. Re-exec its original arguments in a separately bounded tool scope.
|
|
3
|
+
# The helper clears BASH_ENV only for that job: nested shells stay in its cap.
|
|
4
|
+
if [[ -r /proc/$$/cmdline ]]; then
|
|
5
|
+
mapfile -d '' -t homelab_shell_argv < /proc/$$/cmdline
|
|
6
|
+
exec /usr/bin/python3 -I -B /usr/local/lib/personal-fleet-agent-tool/agent-tool.py "${homelab_shell_argv[@]:1}"
|
|
7
|
+
fi
|
|
8
|
+
printf '%s\n' 'AGENT_TOOL_REFUSED: cannot identify shell command for memory isolation.' >&2
|
|
9
|
+
exit 75
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
"""Admit one shell tool into its own bounded scope; never cap the shared provider."""
|
|
3
|
+
import fcntl
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import signal
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import time
|
|
11
|
+
import uuid
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def available(root, proc):
|
|
15
|
+
info = dict(line.split(':', 1) for line in (proc / 'meminfo').read_text().splitlines())
|
|
16
|
+
headroom = int(info['MemAvailable'].split()[0]) * 1024
|
|
17
|
+
# Include every ancestor, not just the aggregate agent budget.
|
|
18
|
+
group = root
|
|
19
|
+
while group != Path('/sys/fs') and group != group.parent:
|
|
20
|
+
maximum = group / 'memory.max'
|
|
21
|
+
if maximum.exists():
|
|
22
|
+
value = maximum.read_text().strip()
|
|
23
|
+
if value != 'max':
|
|
24
|
+
headroom = min(headroom, int(value) - int((group / 'memory.current').read_text()))
|
|
25
|
+
group = group.parent
|
|
26
|
+
return max(0, headroom)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def limits(policy, capacity):
|
|
30
|
+
mib = 1024 * 1024
|
|
31
|
+
# Small supported workers need a smaller envelope, not a permanent refusal
|
|
32
|
+
# because one default tool budget exceeds the whole agent slice.
|
|
33
|
+
reserve = min(policy['reserveMiB'] * mib, capacity // 4)
|
|
34
|
+
provider = min(policy.get('providerReserveMiB', 1024) * mib, capacity // 4)
|
|
35
|
+
return min(policy['memoryMiB'] * mib, capacity - reserve - provider), reserve
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def reserved(root, budget):
|
|
39
|
+
# Empty scopes are no longer running. Reservations are the unused part of
|
|
40
|
+
# each live tool's hard cap, so simultaneous launches cannot overcommit.
|
|
41
|
+
total = 0
|
|
42
|
+
for group in root.glob('homelab-tool-*.scope'):
|
|
43
|
+
try:
|
|
44
|
+
if 'populated 1' in (group / 'cgroup.events').read_text():
|
|
45
|
+
maximum = (group / 'memory.max').read_text().strip()
|
|
46
|
+
cap = int(maximum) if maximum != 'max' else budget
|
|
47
|
+
total += max(0, cap - int((group / 'memory.current').read_text()))
|
|
48
|
+
except FileNotFoundError:
|
|
49
|
+
pass
|
|
50
|
+
return total
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main():
|
|
54
|
+
policy = json.loads(Path(__file__).with_name('agent-tool-policy.json').read_text())
|
|
55
|
+
runtime = Path(os.environ['XDG_RUNTIME_DIR'])
|
|
56
|
+
own = (Path('/proc/self/cgroup').read_text().strip().split('0::', 1)[1])
|
|
57
|
+
prefix = own.split('/app-t3code-agents.slice/', 1)
|
|
58
|
+
if len(prefix) != 2:
|
|
59
|
+
sys.stderr.write('AGENT_TOOL_REFUSED: shell tool is outside the managed agent budget; run homelab converge.\n')
|
|
60
|
+
return 75
|
|
61
|
+
root = Path('/sys/fs/cgroup' + prefix[0] + '/app-t3code-agents.slice')
|
|
62
|
+
maximum = (root / 'memory.max').read_text().strip()
|
|
63
|
+
if maximum == 'max':
|
|
64
|
+
raise ValueError('agent slice is not bounded')
|
|
65
|
+
budget, reserve = limits(policy, int(maximum))
|
|
66
|
+
# Scope creation and the admission check form one worker-wide critical
|
|
67
|
+
# section. Kernel hard caps enforce every granted reservation afterwards.
|
|
68
|
+
with (runtime / 'homelab-tool-admission.lock').open('a') as lock:
|
|
69
|
+
fcntl.flock(lock, fcntl.LOCK_EX)
|
|
70
|
+
if available(root, Path('/proc')) - reserved(root, budget) < budget + reserve:
|
|
71
|
+
sys.stderr.write('AGENT_TOOL_REFUSED: insufficient unreserved memory for a bounded shell job. Finish other jobs or move work to another worker, then retry.\n')
|
|
72
|
+
return 75
|
|
73
|
+
unit = 'homelab-tool-' + uuid.uuid4().hex + '.scope'
|
|
74
|
+
env = dict(os.environ)
|
|
75
|
+
env.pop('BASH_ENV', None)
|
|
76
|
+
child = subprocess.Popen([
|
|
77
|
+
'/usr/bin/systemd-run', '--user', '--scope', '--quiet', '--collect',
|
|
78
|
+
'--slice=app-t3code-agents.slice', '--unit=' + unit,
|
|
79
|
+
'--property=MemoryMax=' + str(budget),
|
|
80
|
+
'--property=MemorySwapMax=' + str(policy['swapMiB']) + 'M',
|
|
81
|
+
'--property=OOMPolicy=stop', '--property=IOAccounting=yes',
|
|
82
|
+
'--property=TimeoutStopSec=10s',
|
|
83
|
+
'--', '/bin/bash', *sys.argv[1:]], env=env)
|
|
84
|
+
def cancel(signum, _frame):
|
|
85
|
+
subprocess.run(['/usr/bin/systemctl', '--user', 'stop', unit], check=False)
|
|
86
|
+
child.wait()
|
|
87
|
+
sys.exit(128 + signum)
|
|
88
|
+
signal.signal(signal.SIGTERM, cancel)
|
|
89
|
+
signal.signal(signal.SIGINT, cancel)
|
|
90
|
+
deadline = time.monotonic() + 10
|
|
91
|
+
while child.poll() is None:
|
|
92
|
+
try:
|
|
93
|
+
if 'populated 1' in (root / unit / 'cgroup.events').read_text():
|
|
94
|
+
break
|
|
95
|
+
except FileNotFoundError:
|
|
96
|
+
pass
|
|
97
|
+
if time.monotonic() >= deadline:
|
|
98
|
+
# Do not release admission while an unobserved job may start.
|
|
99
|
+
subprocess.run(['/usr/bin/systemctl', '--user', 'stop', unit], check=False)
|
|
100
|
+
child.terminate()
|
|
101
|
+
child.wait()
|
|
102
|
+
sys.stderr.write('AGENT_TOOL_REFUSED: tool scope startup was not observed.\n')
|
|
103
|
+
return 75
|
|
104
|
+
time.sleep(0.02)
|
|
105
|
+
return child.wait()
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
if __name__ == '__main__':
|
|
109
|
+
try:
|
|
110
|
+
sys.exit(main())
|
|
111
|
+
except (OSError, ValueError, KeyError):
|
|
112
|
+
sys.stderr.write('AGENT_TOOL_REFUSED: memory admission could not be measured; run homelab converge.\n')
|
|
113
|
+
sys.exit(75)
|
|
@@ -274,7 +274,13 @@
|
|
|
274
274
|
"diskGcScript": "/usr/local/lib/personal-fleet-disk-gc.py",
|
|
275
275
|
"diskGcMemoryMaxMiB": 2048,
|
|
276
276
|
"diskGcGitTempHours": 1,
|
|
277
|
-
"diskGcFetchMaxMiB": 256
|
|
277
|
+
"diskGcFetchMaxMiB": 256,
|
|
278
|
+
"agentTool": {
|
|
279
|
+
"memoryMiB": 4096,
|
|
280
|
+
"reserveMiB": 2048,
|
|
281
|
+
"swapMiB": 512,
|
|
282
|
+
"providerReserveMiB": 1024
|
|
283
|
+
}
|
|
278
284
|
},
|
|
279
285
|
"clock": {
|
|
280
286
|
"warnOffsetSeconds": 2,
|
|
@@ -44,7 +44,10 @@ def io_delta(previous, current):
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def workloads(args):
|
|
47
|
-
|
|
47
|
+
# Never kill a shared Codex provider to shed one shell tool.
|
|
48
|
+
yield from (group for group in args.agent_tree.rglob('t3code-*.scope')
|
|
49
|
+
if not group.name.startswith('t3code-codex-'))
|
|
50
|
+
yield from args.agent_tree.glob('homelab-tool-*.scope')
|
|
48
51
|
# The drop-ins place new transient units in the shared slice. Jobs that
|
|
49
52
|
# predate the policy can still be direct children of app.slice.
|
|
50
53
|
for tree in (args.agent_tree, args.app_tree):
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
mode: '0644'
|
|
167
167
|
content: |
|
|
168
168
|
# Managed by personal converge. Applies to every t3code-*.scope T3 starts for an agent.
|
|
169
|
-
# OOMPolicy=continue
|
|
169
|
+
# OOMPolicy=continue permits surviving processes to continue; it cannot protect the provider itself.
|
|
170
170
|
# IOAccounting=yes: the pressure guard needs each agent's io.stat to tell a writer from a reader it blocks.
|
|
171
171
|
[Scope]
|
|
172
172
|
MemoryMax={{ resourceSafety.agentMemoryMax }}
|
|
@@ -174,6 +174,48 @@
|
|
|
174
174
|
OOMPolicy=continue
|
|
175
175
|
IOAccounting=yes
|
|
176
176
|
register: agent_policy
|
|
177
|
+
# Codex app-server serves many threads. Its shell tools are separately admitted
|
|
178
|
+
# and capped; protecting the provider does not remove the aggregate hard cap.
|
|
179
|
+
- name: Create shared-provider and tool policy directories
|
|
180
|
+
ansible.builtin.file:
|
|
181
|
+
path: '{{ item }}'
|
|
182
|
+
state: directory
|
|
183
|
+
owner: root
|
|
184
|
+
group: root
|
|
185
|
+
mode: '0755'
|
|
186
|
+
loop:
|
|
187
|
+
- /etc/systemd/user/t3code-codex-.scope.d
|
|
188
|
+
- /usr/local/lib/personal-fleet-agent-tool
|
|
189
|
+
- name: Declare the shared Codex provider reserve
|
|
190
|
+
ansible.builtin.copy:
|
|
191
|
+
dest: /etc/systemd/user/t3code-codex-.scope.d/60-personal-fleet.conf
|
|
192
|
+
owner: root
|
|
193
|
+
group: root
|
|
194
|
+
mode: '0644'
|
|
195
|
+
content: |
|
|
196
|
+
# Managed by personal converge. A shared provider is not one shell tool.
|
|
197
|
+
[Scope]
|
|
198
|
+
MemoryMax=infinity
|
|
199
|
+
MemorySwapMax=infinity
|
|
200
|
+
MemoryMin={{ resourceSafety.agentTool.providerReserveMiB }}M
|
|
201
|
+
MemoryLow={{ resourceSafety.agentTool.providerReserveMiB }}M
|
|
202
|
+
OOMPolicy=continue
|
|
203
|
+
register: shared_provider_policy
|
|
204
|
+
- name: Install bounded shell tool admission
|
|
205
|
+
ansible.builtin.copy:
|
|
206
|
+
src: '{{ playbook_dir }}/{{ item }}'
|
|
207
|
+
dest: '/usr/local/lib/personal-fleet-agent-tool/{{ item }}'
|
|
208
|
+
owner: root
|
|
209
|
+
group: root
|
|
210
|
+
mode: '0644'
|
|
211
|
+
loop: [agent-tool.py, agent-tool.bash]
|
|
212
|
+
- name: Declare shell tool admission budgets
|
|
213
|
+
ansible.builtin.copy:
|
|
214
|
+
dest: /usr/local/lib/personal-fleet-agent-tool/agent-tool-policy.json
|
|
215
|
+
owner: root
|
|
216
|
+
group: root
|
|
217
|
+
mode: '0644'
|
|
218
|
+
content: '{{ resourceSafety.agentTool | to_nice_json }}'
|
|
177
219
|
- name: Charge automatically named systemd-run jobs to the shared agent budget
|
|
178
220
|
ansible.builtin.copy:
|
|
179
221
|
dest: '/etc/systemd/user/run-.{{ item | lower }}.d/60-personal-fleet.conf'
|
|
@@ -241,7 +283,7 @@
|
|
|
241
283
|
path: '{{ item.path }}'
|
|
242
284
|
state: absent
|
|
243
285
|
loop: '{{ agent_override_files.files }}'
|
|
244
|
-
when: item.path is match('^.*/app-t3code-agents(?:-[^/]*)
|
|
286
|
+
when: item.path is match('^.*/(?:app-t3code-agents(?:-[^/]*)?\\.slice|t3code-codex-[^/]+\\.scope)\\.d/50-[^/]+\\.conf$')
|
|
245
287
|
register: agent_overrides
|
|
246
288
|
- name: Restore declared pressure policy over worker user-service overrides
|
|
247
289
|
ansible.builtin.file:
|
|
@@ -261,7 +303,7 @@
|
|
|
261
303
|
ansible.builtin.systemd_service:
|
|
262
304
|
scope: user
|
|
263
305
|
daemon_reload: true
|
|
264
|
-
when: agent_policy.changed or transient_limits.changed or agent_slices.changed or agent_overrides.changed
|
|
306
|
+
when: agent_policy.changed or shared_provider_policy.changed or transient_limits.changed or agent_slices.changed or agent_overrides.changed
|
|
265
307
|
failed_when: false
|
|
266
308
|
- name: Run systemd-oomd
|
|
267
309
|
ansible.builtin.systemd_service:
|
package/ansible/uv.lock
CHANGED
|
@@ -20,7 +20,7 @@ wheels = [
|
|
|
20
20
|
|
|
21
21
|
[[package]]
|
|
22
22
|
name = "ansible-core"
|
|
23
|
-
version = "2.22.
|
|
23
|
+
version = "2.22.1"
|
|
24
24
|
source = { registry = "https://pypi.org/simple" }
|
|
25
25
|
dependencies = [
|
|
26
26
|
{ name = "cryptography" },
|
|
@@ -29,9 +29,9 @@ dependencies = [
|
|
|
29
29
|
{ name = "pyyaml" },
|
|
30
30
|
{ name = "resolvelib" },
|
|
31
31
|
]
|
|
32
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
32
|
+
sdist = { url = "https://files.pythonhosted.org/packages/a0/ab/738458619153c2bd32a8d1c6da68530c1092151a3016f0879ea34998644a/ansible_core-2.22.1.tar.gz", hash = "sha256:6e6d1a811f23e811b3279ffc18d856a885647402f60d342276885ba9d5e70475", size = 3484760, upload-time = "2026-11-30T18:59:32.856Z" }
|
|
33
33
|
wheels = [
|
|
34
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
34
|
+
{ url = "https://files.pythonhosted.org/packages/75/51/ec2ef298431b275eb26f206f71a2b8cb1bb43e83649cdbc1f6ef7ad3f459/ansible_core-2.22.1-py3-none-any.whl", hash = "sha256:12faa3d9d61e4334bc8b38be6bb896196feafd240778c119f31e901329a79b59", size = 2478965, upload-time = "2026-11-30T18:59:31.362Z" },
|
|
35
35
|
]
|
|
36
36
|
|
|
37
37
|
[[package]]
|
|
@@ -222,7 +222,7 @@ lint = [
|
|
|
222
222
|
]
|
|
223
223
|
|
|
224
224
|
[package.metadata]
|
|
225
|
-
requires-dist = [{ name = "ansible-core", specifier = "==2.22.
|
|
225
|
+
requires-dist = [{ name = "ansible-core", specifier = "==2.22.1" }]
|
|
226
226
|
|
|
227
227
|
[package.metadata.requires-dev]
|
|
228
228
|
lint = [{ name = "ansible-lint", specifier = "==26.11.1" }]
|
package/docs/convergence.md
CHANGED
|
@@ -94,6 +94,6 @@ and published themes. Workers install changed files and remove retired files
|
|
|
94
94
|
with `ansible/t3/customizations.yml`. The manager uses the same playbook when
|
|
95
95
|
recovering these files from fleet state.
|
|
96
96
|
|
|
97
|
-
The manager switches a running desktop to its verified release with `ansible/macos/t3-activate.yml` only when that desktop's release differs from the pin. The same release stays running, including a copy that is not the managed path. A converge started inside the desktop
|
|
97
|
+
The manager switches a running desktop to its verified release with `ansible/macos/t3-activate.yml` only when that desktop's release differs from the pin. The same release stays running, including a copy that is not the managed path. A converge started inside the desktop schedules activation in a detached Ansible job (`T3_DESKTOP_ACTIVATION_SCHEDULED`). The job waits for converge to exit, then restarts T3 even during active turns and verifies the running release.
|
|
98
98
|
|
|
99
99
|
`ansible/macos/legacy-monitoring.yml` applies only the guarded legacy monitoring retirement through `converge --only legacy-monitoring`; `--dry-run` uses Ansible check mode. It verifies the replacement process before and after retiring the exact predecessor, without restarting it.
|
package/docs/runbooks.md
CHANGED
|
@@ -354,7 +354,7 @@ runaway, write `1` to that agent scope’s `cgroup.kill`.
|
|
|
354
354
|
- `T3_PRIVATE_ROUTE_UNVERIFIED`: t3 private route unverified.
|
|
355
355
|
- `T3_CLIENT_SETTINGS_UNVERIFIED`: check the manager’s T3 client-settings.json, fleet state availability and the worker desktop service, then rerun converge. A pending desktop restart is retried.
|
|
356
356
|
- `T3_DESKTOP_ACTIVATION_FAILED`: open the verified manager bundle named in the remedy and rerun converge.
|
|
357
|
-
- `
|
|
357
|
+
- `T3_DESKTOP_ACTIVATION_SCHEDULED`: the detached Ansible job waits for converge to exit, then restarts T3 and verifies the pinned release. The remedy names its result file. If the job failed, check the result and rerun converge.
|
|
358
358
|
- `T3_CUSTOMIZATIONS_CONFLICT`: inspect the ownership marker in the manager’s T3 userdata directory. Move an unrelated marker aside before recovering the saved snapshot.
|
|
359
359
|
- `T3_CUSTOMIZATIONS_INVALID`: check that keybindings are a JSON array, theme files are regular files listed by the pinned T3 CLI, and the encoded customization snapshot fits the 1 MiB fleet state document limit.
|
|
360
360
|
- `T3_CLIENT_SETTINGS_INVALID`: repair the manager’s client-settings.json so its settings are a JSON object.
|
|
@@ -381,7 +381,7 @@ runaway, write `1` to that agent scope’s `cgroup.kill`.
|
|
|
381
381
|
- `T3_SERVER_STOPPED`: t3 server stopped: the lingering `t3code-headless.service` of a headless worker is not running.
|
|
382
382
|
- `T3_SETTINGS_BUSY`: t3 settings busy.
|
|
383
383
|
- `T3_VERSION_UNKNOWN`: a warning of `t3:version`: T3 on the machine the check names has not recorded the version it runs, so it cannot be compared with the pin. Start T3 there once, then run `homelab converge`.
|
|
384
|
-
- `T3_VERSION_SKEW`: a warning of `t3:version`: T3 on the machine the check names runs another release than the fleet pins; the remedy names both. `homelab converge` installs the pinned release on a worker and restarts T3. On the manager, converge switches a running desktop to the verified bundle when the running release differs from the pin
|
|
384
|
+
- `T3_VERSION_SKEW`: a warning of `t3:version`: T3 on the machine the check names runs another release than the fleet pins; the remedy names both. `homelab converge` installs the pinned release on a worker and restarts T3. On the manager, converge switches a running desktop to the verified bundle when the running release differs from the pin. The same release is left running. See `T3_DESKTOP_ACTIVATION_SCHEDULED`.
|
|
385
385
|
- `T3_UPDATES_UNMANAGED`: a warning of `t3:updates`: the administrator policy of T3 on the manager does not turn its own updater off, so T3 may update itself away from the pinned release. Stage the fleet's policy once, as an administrator, with the command the remedy prints. **Needs a person.**
|
|
386
386
|
- `T3_RUNNING_VERSION_UNKNOWN`: `t3:running-version` could not read the version of the running server from its local API, or the release installed on the worker. Read `worker:t3-health`, then run `homelab converge`, which reinstalls the pinned T3.
|
|
387
387
|
- `T3_RUNNING_VERSION_MISMATCH`: logged by `personal-worker-recovery` on the worker: T3 was restarted once for the installed release and still reports another version. It is not restarted again for that release and the run fails (`WORKER_RECOVERY_LAST_RUN_FAILED`). Run `homelab converge`, which reinstalls the pinned T3.
|
package/docs/ubuntu-sync.md
CHANGED
|
@@ -616,3 +616,48 @@ item in the volatile session keyring at startup. Its encrypted login keyring
|
|
|
616
616
|
can stay locked. The desktop service shares the existing primary display.
|
|
617
617
|
The manager checks pre-authentication negotiation and the certificate.
|
|
618
618
|
A client login is needed to confirm authenticated control.
|
|
619
|
+
|
|
620
|
+
### Shared Codex providers and shell tool memory
|
|
621
|
+
|
|
622
|
+
A Codex app-server can serve many T3 threads. Its scope therefore has no
|
|
623
|
+
single-tool hard cap; the combined agent slice still has its hard memory and
|
|
624
|
+
swap limits. A 1 GiB provider reserve protects its working memory. The pressure
|
|
625
|
+
guard never kills that shared scope to relieve CPU or I/O pressure.
|
|
626
|
+
|
|
627
|
+
On Ubuntu, managed Codex launchers set `shell_environment_policy.set.BASH_ENV`
|
|
628
|
+
to the fleet's tracked Bash startup hook. Each noninteractive Bash tool command
|
|
629
|
+
is re-executed in a `homelab-tool-*.scope` under the combined agent slice, with
|
|
630
|
+
its own memory cap of up to 4 GiB, 512 MiB swap cap and `OOMPolicy=stop`. Nested shells
|
|
631
|
+
stay in that tool's cap. An oversized tool fails without killing the provider.
|
|
632
|
+
The hook preserves shell arguments, stdin/stdout and exit status. Cancellation
|
|
633
|
+
stops its tool scope. The managed Python helper and budget are installed by
|
|
634
|
+
Ansible, not generated by a launcher.
|
|
635
|
+
|
|
636
|
+
Before creating a tool scope, a worker-wide lock serializes admission. The
|
|
637
|
+
helper checks host available memory and every ancestor cgroup's remaining
|
|
638
|
+
hard-limit headroom, subtracts unused reservations for already admitted tools,
|
|
639
|
+
and requires a further reserve of up to 2 GiB. On small workers, the
|
|
640
|
+
reserve and provider allowance each use at most a quarter of the agent slice,
|
|
641
|
+
and the tool cap shrinks to fit the remaining half. It refuses excess demand with
|
|
642
|
+
`AGENT_TOOL_REFUSED` and exit 75; finish jobs or move work to another worker
|
|
643
|
+
before retrying. It fails closed when it cannot measure admission. This is a
|
|
644
|
+
bounded supported workload envelope, not a guarantee for unlimited work.
|
|
645
|
+
|
|
646
|
+
`homelab converge --no-restart-busy` defers a T3 restart until idle, subject
|
|
647
|
+
to the existing 24 hour recovery deadline. Use it when running a rollout from
|
|
648
|
+
a T3 session. The flag survives worker-to-manager hand-off.
|
|
649
|
+
|
|
650
|
+
Convergence removes stale Codex scope property overrides and reloads the user
|
|
651
|
+
manager without restarting providers. Existing provider processes load the new
|
|
652
|
+
shell policy on their next launch; drain their turns before recycling a shared
|
|
653
|
+
provider. Do not restart T3 while relying on an agent inside it. Confirm a new
|
|
654
|
+
shell command's `/proc/self/cgroup` names a `homelab-tool-*.scope` before resuming
|
|
655
|
+
heavy work. The isolation covers Bash shell tools; explicit alternative shells,
|
|
656
|
+
non-shell native operations and manually detached named services are outside
|
|
657
|
+
that hook. Keep those separately bounded. `worker:pressure-events` reports
|
|
658
|
+
kernel shared-provider OOM kills as well as pressure guard and oomd activity.
|
|
659
|
+
|
|
660
|
+
Run `HOMELAB_TEST_SYSTEMD=1 python3 -B -m unittest discover -s
|
|
661
|
+
ansible/ubuntu/tests -p test_agent_tool.py` on a Linux development worker for a
|
|
662
|
+
small disposable-scope check of arguments, exit status, runaway containment and
|
|
663
|
+
provider survival. No production unit is stopped by that check.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crvouga/homelab",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.10",
|
|
4
4
|
"description": "Keeps a set of development machines in sync: one manager and many workers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "github:crvouga/homelab",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=22"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "d4be50a9b98a213dcbd5d228d92440fa885b0a54"
|
|
78
78
|
}
|
package/src/agents/launch.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
2
3
|
import { mkdirSync } from 'node:fs';
|
|
3
4
|
import { AgentConfigurationError } from './errors';
|
|
4
5
|
import { registry, type Selection } from './registry';
|
|
@@ -74,6 +75,7 @@ async function spawnAgent(
|
|
|
74
75
|
: selection.tool;
|
|
75
76
|
const command = [
|
|
76
77
|
executable,
|
|
78
|
+
...codexToolIsolation(selection.tool),
|
|
77
79
|
...pinned,
|
|
78
80
|
...launchArgs(selection, directory, args, env),
|
|
79
81
|
];
|
|
@@ -344,3 +346,16 @@ function configureGatewayEnvironment(
|
|
|
344
346
|
env[`ANTHROPIC_DEFAULT_${family}_MODEL`] = selection.model;
|
|
345
347
|
}
|
|
346
348
|
}
|
|
349
|
+
|
|
350
|
+
/** Bash commands from a Linux Codex provider enter worker-wide admitted scopes.
|
|
351
|
+
* Install policy before enabling it; other platforms retain their native shell. */
|
|
352
|
+
export function codexToolIsolation(
|
|
353
|
+
tool: string,
|
|
354
|
+
platform: string = process.platform,
|
|
355
|
+
installed: (path: string) => boolean = existsSync
|
|
356
|
+
): string[] {
|
|
357
|
+
const hook = '/usr/local/lib/personal-fleet-agent-tool/agent-tool.bash';
|
|
358
|
+
return tool === 'codex' && platform === 'linux' && installed(hook)
|
|
359
|
+
? ['-c', `shell_environment_policy.set.BASH_ENV=${JSON.stringify(hook)}`]
|
|
360
|
+
: [];
|
|
361
|
+
}
|
|
@@ -368,7 +368,9 @@ export function forwardedFlags(
|
|
|
368
368
|
for (const [option, flag] of Object.entries(HAND_OFF)) {
|
|
369
369
|
if (typeof flag !== 'string') continue;
|
|
370
370
|
const value: unknown = options[option as keyof FleetSyncOptions];
|
|
371
|
-
if (value ===
|
|
371
|
+
if (option === 'restartBusy' && value === false)
|
|
372
|
+
flags.push('--no-restart-busy');
|
|
373
|
+
else if (value === true) flags.push(flag);
|
|
372
374
|
else if (typeof value === 'string' && value) flags.push(flag, value);
|
|
373
375
|
else if (Array.isArray(value))
|
|
374
376
|
for (const entry of value) flags.push(flag, String(entry));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { record } from '../config';
|
|
2
|
+
import policy from '../../ansible/ubuntu/policy.json';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import type { Standing } from '../state/sync';
|
|
4
5
|
import type { Runner } from '../types';
|
|
@@ -95,14 +96,24 @@ export function toolChanges(
|
|
|
95
96
|
}));
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
export function restarts(
|
|
99
|
+
export function restarts(
|
|
100
|
+
tools: ToolChange[],
|
|
101
|
+
files: string[],
|
|
102
|
+
restartBusy = true
|
|
103
|
+
): Restart[] {
|
|
99
104
|
const found: Restart[] = [];
|
|
100
|
-
const when =
|
|
105
|
+
const when = restartBusy
|
|
106
|
+
? 'at once, ending running agent turns.'
|
|
107
|
+
: `when idle, or after the ${policy.t3RestartMaxDeferralHours} hour recovery deadline.`;
|
|
108
|
+
const deferred = restartBusy
|
|
109
|
+
? {}
|
|
110
|
+
: { deadlineHours: policy.t3RestartMaxDeferralHours };
|
|
101
111
|
if (tools.some((change) => change.tool === 't3'))
|
|
102
112
|
found.push({
|
|
103
113
|
service: 't3',
|
|
104
114
|
reason: `T3 is upgraded on every worker and restarted ${when}`,
|
|
105
|
-
endsRunningTurns:
|
|
115
|
+
endsRunningTurns: restartBusy,
|
|
116
|
+
...deferred,
|
|
106
117
|
});
|
|
107
118
|
else if (
|
|
108
119
|
files.some((file) =>
|
|
@@ -112,7 +123,8 @@ export function restarts(tools: ToolChange[], files: string[]): Restart[] {
|
|
|
112
123
|
found.push({
|
|
113
124
|
service: 't3',
|
|
114
125
|
reason: `The managed T3 policy may change: a T3 that has not loaded it is restarted ${when}`,
|
|
115
|
-
endsRunningTurns:
|
|
126
|
+
endsRunningTurns: restartBusy,
|
|
127
|
+
...deferred,
|
|
116
128
|
});
|
|
117
129
|
const agents = tools.filter((change) => AGENT_TOOLS.includes(change.tool));
|
|
118
130
|
if (agents.length)
|
|
@@ -145,6 +157,7 @@ export async function syncPlan(
|
|
|
145
157
|
nodes: string[];
|
|
146
158
|
sources: string[];
|
|
147
159
|
desktopPreferences?: boolean;
|
|
160
|
+
restartBusy?: boolean;
|
|
148
161
|
/** The fleet configuration last applied (from the fleet state), when
|
|
149
162
|
* there is one, and the one this sync applies. */
|
|
150
163
|
definitions?: { applied: unknown; selected: unknown };
|
|
@@ -175,7 +188,9 @@ export async function syncPlan(
|
|
|
175
188
|
revision: { from: input.from, to: input.to },
|
|
176
189
|
known: changes !== null,
|
|
177
190
|
tools: changes?.tools ?? [],
|
|
178
|
-
restarts: changes
|
|
191
|
+
restarts: changes
|
|
192
|
+
? restarts(changes.tools, changes.files, input.restartBusy)
|
|
193
|
+
: [],
|
|
179
194
|
nodes: input.nodes.map((node) => ({
|
|
180
195
|
node,
|
|
181
196
|
from: input.from,
|
|
@@ -260,7 +260,9 @@ function requested(
|
|
|
260
260
|
options: FleetSyncOptions
|
|
261
261
|
): Pick<BootstrapPayload, 'restartBusy' | 'allowMiseDowngrade'> {
|
|
262
262
|
return {
|
|
263
|
-
...(options.restartBusy
|
|
263
|
+
...(options.restartBusy === undefined
|
|
264
|
+
? {}
|
|
265
|
+
: { restartBusy: options.restartBusy }),
|
|
264
266
|
...(allowsMiseDowngrade(options, options.revision)
|
|
265
267
|
? { allowMiseDowngrade: true }
|
|
266
268
|
: {}),
|
package/src/cli/fleet-sync.ts
CHANGED
|
@@ -649,6 +649,9 @@ async function preview(
|
|
|
649
649
|
.map((node) => node.node)
|
|
650
650
|
.filter((node): node is string => typeof node === 'string'),
|
|
651
651
|
sources: planSources(settings.workspace, context.root),
|
|
652
|
+
...(options.restartBusy === undefined
|
|
653
|
+
? {}
|
|
654
|
+
: { restartBusy: options.restartBusy }),
|
|
652
655
|
desktopPreferences: (canonicalDefinition.ides ?? ['t3']).includes('t3'),
|
|
653
656
|
definitions: {
|
|
654
657
|
applied: appliedDefinition(),
|
|
@@ -237,6 +237,10 @@ function registerSync({ program, defaults, complete }: Registration) {
|
|
|
237
237
|
'--restart-busy',
|
|
238
238
|
'Restart a worker T3 for a new release or policy even while agent turns run, which ends them (the default)'
|
|
239
239
|
)
|
|
240
|
+
.option(
|
|
241
|
+
'--no-restart-busy',
|
|
242
|
+
'Defer a worker T3 restart until idle, subject to the existing recovery deadline'
|
|
243
|
+
)
|
|
240
244
|
.option(
|
|
241
245
|
'--allow-unmerged',
|
|
242
246
|
'Converge to a revision that is not on the default branch of the source repository; without it such a revision is refused before anything changes'
|
|
@@ -128,13 +128,44 @@ const memoryReserved: Probe = async (run) => {
|
|
|
128
128
|
: ['AGENT_PRESSURE_KILL_ENABLED', PRESSURE_POLICY_REMEDY];
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
const agentsBounded: Probe = async (run) =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
const agentsBounded: Probe = async (run) => {
|
|
132
|
+
for (const path of [
|
|
133
|
+
AGENT_DROP_IN,
|
|
134
|
+
'/etc/systemd/user/t3code-codex-.scope.d/60-personal-fleet.conf',
|
|
135
|
+
'/usr/local/lib/personal-fleet-agent-tool/agent-tool.bash',
|
|
136
|
+
'/usr/local/lib/personal-fleet-agent-tool/agent-tool.py',
|
|
137
|
+
'/usr/local/lib/personal-fleet-agent-tool/agent-tool-policy.json',
|
|
138
|
+
]) {
|
|
139
|
+
if (!(await run(['test', '-f', path])).ok)
|
|
140
|
+
return [
|
|
135
141
|
'AGENT_MEMORY_LIMIT_MISSING',
|
|
136
|
-
'
|
|
142
|
+
'Run homelab converge to install shared-provider protection and shell tool memory admission.',
|
|
137
143
|
];
|
|
144
|
+
}
|
|
145
|
+
const scopes = await run([
|
|
146
|
+
'systemctl',
|
|
147
|
+
'--user',
|
|
148
|
+
'show',
|
|
149
|
+
't3code-codex-*.scope',
|
|
150
|
+
'--property=MemoryMax,MemoryMin',
|
|
151
|
+
]);
|
|
152
|
+
const fields = scopes.stdout.trim().split('\n').filter(Boolean);
|
|
153
|
+
if (
|
|
154
|
+
!scopes.ok ||
|
|
155
|
+
fields.some(
|
|
156
|
+
(line) =>
|
|
157
|
+
(line.startsWith('MemoryMax=') && line !== 'MemoryMax=infinity') ||
|
|
158
|
+
(line.startsWith('MemoryMin=') &&
|
|
159
|
+
Number(line.slice('MemoryMin='.length)) <
|
|
160
|
+
policy.resourceSafety.agentTool.providerReserveMiB * MIB)
|
|
161
|
+
)
|
|
162
|
+
)
|
|
163
|
+
return [
|
|
164
|
+
'AGENT_LIMIT_OVERRIDDEN',
|
|
165
|
+
'Run homelab converge to migrate existing shared Codex scopes and remove stale property overrides. Verify a fresh Bash command enters a homelab-tool scope before heavy work.',
|
|
166
|
+
];
|
|
167
|
+
return undefined;
|
|
168
|
+
};
|
|
138
169
|
|
|
139
170
|
const agentSliceBounded: Probe = async (run) => {
|
|
140
171
|
const [slice, memory] = await Promise.all([
|
|
@@ -485,6 +516,28 @@ async function oomdAgentKills(run: Runner): Promise<number | undefined> {
|
|
|
485
516
|
return oomdReadable ? oomdKills : undefined;
|
|
486
517
|
}
|
|
487
518
|
|
|
519
|
+
async function kernelProviderKills(run: Runner): Promise<number | undefined> {
|
|
520
|
+
const kernel = await run([
|
|
521
|
+
'sudo',
|
|
522
|
+
'-n',
|
|
523
|
+
'journalctl',
|
|
524
|
+
'--quiet',
|
|
525
|
+
'--dmesg',
|
|
526
|
+
'--since=24 hours ago',
|
|
527
|
+
'--output=cat',
|
|
528
|
+
'--grep=oom-kill:',
|
|
529
|
+
]);
|
|
530
|
+
const kernelReadable =
|
|
531
|
+
kernel.ok || (kernel.reason === 'exit' && !kernel.stderr.trim());
|
|
532
|
+
return kernelReadable
|
|
533
|
+
? kernel.stdout
|
|
534
|
+
.split('\n')
|
|
535
|
+
.filter(
|
|
536
|
+
(line) => /task=codex,/.test(line) && /app-t3code-agents/.test(line)
|
|
537
|
+
).length
|
|
538
|
+
: undefined;
|
|
539
|
+
}
|
|
540
|
+
|
|
488
541
|
export async function pressureEvents(run: Runner): Promise<Check> {
|
|
489
542
|
const id = 'worker:pressure-events';
|
|
490
543
|
const events = await run([
|
|
@@ -505,6 +558,7 @@ export async function pressureEvents(run: Runner): Promise<Check> {
|
|
|
505
558
|
status: 'warn',
|
|
506
559
|
summary: 'Recent pressure guard activity could not be read.',
|
|
507
560
|
};
|
|
561
|
+
const providerKills = await kernelProviderKills(run);
|
|
508
562
|
const oomdKills = await oomdAgentKills(run);
|
|
509
563
|
const { stops, dryRuns, unclassified } = pressureCounts(events.stdout);
|
|
510
564
|
const count = stops.cpu + stops.io + stops.memory + stops.unknown;
|
|
@@ -513,16 +567,16 @@ export async function pressureEvents(run: Runner): Promise<Check> {
|
|
|
513
567
|
'-e',
|
|
514
568
|
'/run/personal-fleet-pressure-guard/active',
|
|
515
569
|
]);
|
|
516
|
-
const warn =
|
|
517
|
-
count
|
|
518
|
-
|
|
570
|
+
const warn =
|
|
571
|
+
[count, unclassified, active.ok, oomdKills, providerKills].some(Boolean) ||
|
|
572
|
+
[oomdKills, providerKills].includes(undefined);
|
|
519
573
|
const pressure = active.ok
|
|
520
574
|
? 'The guard currently reports sustained pressure.'
|
|
521
575
|
: 'The sustained-pressure marker is absent.';
|
|
522
576
|
return {
|
|
523
577
|
id,
|
|
524
578
|
status: warn ? 'warn' : 'pass',
|
|
525
|
-
summary: `In the last 24 hours the pressure guard stopped ${count} workloads (CPU: ${stops.cpu}, I/O: ${stops.io}, memory: ${stops.memory}, unknown cause: ${stops.unknown}). Dry runs: ${dryRuns}. Unclassified historical records: ${unclassified}. ${pressure} systemd-oomd agent kills: ${oomdKills ?? 'unavailable'}.`,
|
|
579
|
+
summary: `In the last 24 hours the pressure guard stopped ${count} workloads (CPU: ${stops.cpu}, I/O: ${stops.io}, memory: ${stops.memory}, unknown cause: ${stops.unknown}). Dry runs: ${dryRuns}. Unclassified historical records: ${unclassified}. ${pressure} systemd-oomd agent kills: ${oomdKills ?? 'unavailable'}. Kernel shared-provider OOM kills: ${providerKills ?? 'unavailable'}.`,
|
|
526
580
|
...(warn
|
|
527
581
|
? {
|
|
528
582
|
remedy: {
|
|
@@ -98,8 +98,7 @@ async function runningDesktop(
|
|
|
98
98
|
// (Dock copy, a previous digest directory) without there being an update.
|
|
99
99
|
// Quitting that process kills a converge started in its terminal.
|
|
100
100
|
const update = observed !== null && observed[2] !== version;
|
|
101
|
-
if (context.apply && installed && update)
|
|
102
|
-
return switchDesktop(context, pin, observed[2]!);
|
|
101
|
+
if (context.apply && installed && update) return switchDesktop(context, pin);
|
|
103
102
|
const action = installed
|
|
104
103
|
? `When manager sessions have finished, quit T3 Code, then run open ${shellQuote(app)}. Pin that copy in the Dock.`
|
|
105
104
|
: 'Stage the verified desktop with converge before opening it.';
|
|
@@ -123,31 +122,28 @@ async function runningDesktop(
|
|
|
123
122
|
return running;
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
/** Quit the running release and open the verified bundle. A converge that is
|
|
127
|
-
* itself a child of that desktop only warns: quitting it would end the run. */
|
|
128
125
|
async function switchDesktop(
|
|
129
126
|
context: MachineContext,
|
|
130
|
-
pin: { app: string; version: string; installed: boolean }
|
|
131
|
-
runningVersion: string
|
|
127
|
+
pin: { app: string; version: string; installed: boolean }
|
|
132
128
|
): Promise<Check> {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
status: 'warn',
|
|
137
|
-
summary: 'T3_DESKTOP_SWITCH_DEFERRED',
|
|
138
|
-
remedy: {
|
|
139
|
-
action: `The verified desktop for ${pin.version} is staged at ${pin.app}. This converge is running inside T3 ${runningVersion}, so the switch waits. Run homelab converge from Terminal or another session once this one has finished.`,
|
|
140
|
-
},
|
|
141
|
-
};
|
|
129
|
+
const waitFor = (await convergeRunsInsideDesktop(context.run))
|
|
130
|
+
? process.pid
|
|
131
|
+
: 0;
|
|
142
132
|
const switched = await runAnsible(
|
|
143
133
|
context.run,
|
|
144
134
|
join(context.workspace, 'ansible/macos/t3-activate.yml'),
|
|
145
135
|
{
|
|
146
|
-
input: JSON.stringify({
|
|
136
|
+
input: JSON.stringify({
|
|
137
|
+
bundle_id: BUNDLE_ID,
|
|
138
|
+
desktop_path: pin.app,
|
|
139
|
+
desktop_version: pin.version,
|
|
140
|
+
converge_pid: String(waitFor),
|
|
141
|
+
}),
|
|
147
142
|
timeoutMs: 90_000,
|
|
148
143
|
}
|
|
149
144
|
);
|
|
150
|
-
|
|
145
|
+
const job = /T3 activation job (j[0-9]+\.[0-9]+)/.exec(switched.stdout)?.[1];
|
|
146
|
+
if (!switched.ok || (waitFor && !job))
|
|
151
147
|
return {
|
|
152
148
|
id: 't3:version',
|
|
153
149
|
status: 'fail',
|
|
@@ -156,6 +152,16 @@ async function switchDesktop(
|
|
|
156
152
|
action: `Open the verified desktop with open ${shellQuote(pin.app)} and rerun converge.`,
|
|
157
153
|
},
|
|
158
154
|
};
|
|
155
|
+
if (waitFor)
|
|
156
|
+
return {
|
|
157
|
+
id: 't3:version',
|
|
158
|
+
status: 'warn',
|
|
159
|
+
summary: 'T3_DESKTOP_ACTIVATION_SCHEDULED',
|
|
160
|
+
remedy: {
|
|
161
|
+
action:
|
|
162
|
+
'T3 will restart after this converge exits. Check the manager desktop version after it relaunches.',
|
|
163
|
+
},
|
|
164
|
+
};
|
|
159
165
|
return runningDesktop({ ...context, apply: false }, pin);
|
|
160
166
|
}
|
|
161
167
|
|