141 lines
8.1 KiB
Nix
141 lines
8.1 KiB
Nix
# cc-ci.nix — the cc-ci operator session and weekly-upgrade/hourly-supervisor timers.
|
||
# The Builder/Adversary build is archived; its old unit name only records reboots.
|
||
#
|
||
# Exported from this repo's flake as `nixosModules.cc-ci-orchestrator` (and, for the host that
|
||
# used to import it under the old name, `nixosModules.cc-ci`). Split out of the shared agent
|
||
# host config on 2026-08-20; since 2026-09 it runs on the same Hetzner host as the CI server
|
||
# itself (`#cc-ci` in flake.nix), next to recipe-maintainers/cc-ci's `nixosModules.cc-ci-server`.
|
||
#
|
||
# All of it assumes the cc-ci workspaces exist on the host:
|
||
# /srv/cc-ci the loops workspace (+ .cc-ci-logs, upgrader.env) — a symlink to
|
||
# /srv/cc-ci-orch this repo (the orchestrator's own working dir), with cc-ci/ checked out
|
||
# and that a `loops` user, tmux, python3 and the standalone claude/opencode CLIs are present —
|
||
# those are host concerns, provided by nix/modules/orchestrator-host.nix, not by this module.
|
||
{ config, pkgs, lib, ... }:
|
||
{
|
||
# Keep the historical unit name for its boot-id-gated reboot record.
|
||
# The Builder/Adversary phase loops are complete and never launched.
|
||
systemd.services.cc-ci-loops = {
|
||
description = "cc-ci reboot record (legacy unit name)";
|
||
wantedBy = [ "multi-user.target" ];
|
||
after = [ "network-online.target" ];
|
||
wants = [ "network-online.target" ];
|
||
serviceConfig = {
|
||
Type = "oneshot"; RemainAfterExit = true;
|
||
User = "loops"; Group = "users";
|
||
WorkingDirectory = "/srv/cc-ci-orch";
|
||
ExecStart = "${pkgs.bash}/bin/bash /srv/cc-ci/scripts/cc-ci/reboot-log.sh";
|
||
};
|
||
};
|
||
|
||
# cc-ci-orchestrator supervisor — the operator's steering session. Same shape as
|
||
# lichen-orchestrator / project-orchestrator above: this unit only LAUNCHES the orchestrator's
|
||
# tmux session via the agent-orchestrator harness (scripts/cc-ci/agents.py); it does not own the
|
||
# session or the tmux server. This is the current operator steering agent,
|
||
# separate from the retired Builder/Adversary loops. Its backend/model are
|
||
# declared in scripts/cc-ci/agents.toml; it attaches to the shared
|
||
# opencode web server — opencode-web.service in orchestrator-host.nix — and steered from its
|
||
# web UI; no Claude on this host, operator 2026-09-07). The harness watchdog (started by
|
||
# `agents.py up`) keeps it alive: heal-only (no stall reboots — a persistent supervisor must not
|
||
# be killed just for idling). Added 2026-08-03 for reboot-resilience.
|
||
systemd.services.cc-ci-orchestrator = {
|
||
description = "cc-ci orchestrator (operator steering session) — agents.py up orchestrator";
|
||
wantedBy = [ "multi-user.target" ];
|
||
after = [ "network-online.target" "opencode-web.service" ];
|
||
wants = [ "network-online.target" ];
|
||
serviceConfig = {
|
||
# KillMode=process: see the note on cc-ci-loops — a rebuild that merely touches this unit
|
||
# must not tear down the (shared) tmux server and every agent session with it.
|
||
KillMode = "process";
|
||
Type = "oneshot"; RemainAfterExit = true;
|
||
User = "loops"; Group = "users";
|
||
WorkingDirectory = "/srv/cc-ci-orch";
|
||
};
|
||
environment = { HOME = "/home/loops"; };
|
||
path = [ pkgs.bash pkgs.tmux pkgs.git pkgs.python3 pkgs.openssh pkgs.nettools ];
|
||
script = ''
|
||
export PATH="/home/loops/.local/bin:$PATH"
|
||
proj="/srv/cc-ci-orch"
|
||
echo "$(cat /proc/sys/kernel/random/boot_id) boot $(date -u +%FT%TZ) — cc-ci-orchestrator up" \
|
||
>> "$proj/scripts/cc-ci/.ao-boot.log" 2>/dev/null || true
|
||
cd "$proj" && python3 scripts/cc-ci/agents.py up orchestrator || echo "cc-ci orchestrator agents.py up failed"
|
||
'';
|
||
};
|
||
|
||
# Weekly recipe upgrade — runs /upgrade-all over every enrolled recipe (opens recipe PRs
|
||
# verified by !testme, never merges). Replaces the boot-fragile busybox-crond-in-tmux from
|
||
# phase 5 §4 with a reboot-safe systemd timer. The service is timer-triggered only (NOT
|
||
# wantedBy multi-user.target) so it never runs on boot/activation — only on the schedule.
|
||
systemd.services.cc-ci-upgrade-all = {
|
||
description = "cc-ci weekly /upgrade-all run (recipe upgrade survey + PRs, never merges)";
|
||
after = [ "network-online.target" "opencode-install.service" ];
|
||
wants = [ "network-online.target" ];
|
||
serviceConfig = {
|
||
Type = "oneshot"; # launch-upgrader.py spawns the cc-ci-upgrader tmux session and returns
|
||
User = "loops"; Group = "users";
|
||
WorkingDirectory = "/srv/cc-ci";
|
||
# Optional per-run overrides for backend/model (LOOP_BACKEND, LOOP_MODEL, OPENCODE_SHARE,
|
||
# UPGRADER_ARGS, …). The leading "-" makes it optional: absent file → the in-code defaults,
|
||
# which are opencode + LOOP_TIER=go (the only tier with a key on this host; ZEN models are
|
||
# dead here — the in-code default is 'go' for exactly that reason, see launch-upgrader.py).
|
||
# Current config: LOOP_TIER=go with LOOP_MODEL / REPORT_MODEL / SUPERVISOR_MODEL all
|
||
# opencode-go/deepseek-v4.1-flash (upgrader, report, supervisor). Subagents use the same
|
||
# deepseek via the cc-ci repo's opencode config. No rebuild needed to switch — the env file is read at each
|
||
# timer fire. Holds no secrets (the API key lives in the opencode config / auth.json).
|
||
EnvironmentFile = "-/srv/cc-ci/upgrader.env";
|
||
};
|
||
environment = { HOME = "/home/loops"; };
|
||
path = [ pkgs.bash pkgs.tmux pkgs.git pkgs.python3 pkgs.openssh pkgs.nettools ];
|
||
script = ''
|
||
export PATH="/home/loops/.local/bin:$PATH"
|
||
python3 /srv/cc-ci/scripts/cc-ci/launch-upgrader.py start >> /srv/cc-ci/.cc-ci-logs/upgrader-cron.log 2>&1
|
||
'';
|
||
};
|
||
|
||
systemd.timers.cc-ci-upgrade-all = {
|
||
description = "Weekly trigger for cc-ci-upgrade-all (Saturdays 22:00 America/New_York — Boston 10pm)";
|
||
wantedBy = [ "timers.target" ];
|
||
timerConfig = {
|
||
# 10pm Saturday Boston time, i.e. the weekly run (and the Recipe Report it launches) happens
|
||
# on the weekend, avoiding DeepSeek's weekday peak-pricing windows (01:00–04:00 & 06:00–10:00
|
||
# UTC). DST-aware (EDT→02:00 UTC Sunday, EST→03:00 UTC Sunday) via the tz in OnCalendar.
|
||
OnCalendar = "Sat *-*-* 22:00:00 America/New_York";
|
||
Persistent = true; # if the box was down at the scheduled time, run once on next boot
|
||
};
|
||
};
|
||
|
||
# Hourly SUPERVISOR — a deepseek-v4.1-flash orchestrator wake-up that keeps the weekly run on track.
|
||
# The log-idle/429 watchdog only handles opencode-go usage-limit stalls; it does NOT cover a host
|
||
# disk-full crash (which killed the 2026-07-03 run) or any other environmental wedge. This is a
|
||
# CHEAP deterministic gate: if the weekly run is complete or actively progressing it does NOTHING
|
||
# (zero model tokens). Only when a run has stalled/died before completing does it launch a
|
||
# short-lived deepseek-v4.1-flash agent that diagnoses the blockage and drives the run to a clean DONE.
|
||
systemd.services.cc-ci-upgrade-supervisor = {
|
||
description = "cc-ci hourly weekly-run supervisor (deepseek-v4.1-flash — drives a stalled /upgrade-all to completion)";
|
||
after = [ "network-online.target" ];
|
||
wants = [ "network-online.target" ];
|
||
serviceConfig = {
|
||
Type = "oneshot"; # launch-supervisor.py check: gate now, spawn the agent into tmux, return
|
||
User = "loops"; Group = "users";
|
||
WorkingDirectory = "/srv/cc-ci";
|
||
# Shares the weekly run's optional override file (e.g. SUPERVISOR_MODEL=…); "-" = optional.
|
||
EnvironmentFile = "-/srv/cc-ci/upgrader.env";
|
||
};
|
||
environment = { HOME = "/home/loops"; };
|
||
path = [ pkgs.bash pkgs.tmux pkgs.git pkgs.python3 pkgs.openssh pkgs.nettools ];
|
||
script = ''
|
||
export PATH="/home/loops/.local/bin:$PATH"
|
||
python3 /srv/cc-ci/scripts/cc-ci/launch-supervisor.py check >> /srv/cc-ci/.cc-ci-logs/supervisor-cron.log 2>&1
|
||
'';
|
||
};
|
||
|
||
systemd.timers.cc-ci-upgrade-supervisor = {
|
||
description = "Hourly trigger for cc-ci-upgrade-supervisor (weekly-run health check + drive)";
|
||
wantedBy = [ "timers.target" ];
|
||
timerConfig = {
|
||
OnCalendar = "*-*-* *:07:00"; # every hour at :07 (offset from the weekly :00 fire)
|
||
Persistent = false; # a missed hourly check is moot — the next hour re-checks
|
||
};
|
||
};
|
||
}
|