Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions doc/fleet-schedule-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ The OS-timer half of surface 2. Cadence is the unit's own `OnCalendar`/`OnUnitAc
| `cold-store-drill.timer` | `OnCalendar=*-*-01 05:12:00` | `cold-store-drill.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `cold-store-nightly.timer` | `OnCalendar=*-*-* 03:12:00` | `cold-store-nightly.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `dashboard-backup.timer` | `OnCalendar=*-*-* 04:30:00` | `dashboard-backup.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `fleet-feed-collector.timer` | `OnUnitActiveUSec=5min,OnBootUSec=2min` | `fleet-feed-collector.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `fleet-feed-collector.timer` (retirement pending deployment) | `OnUnitActiveUSec=5min,OnBootUSec=2min` | `fleet-feed-collector.service` | laptop (user systemd; source retired by #8570, live disable not verified) | not recorded | not recorded | not recorded | 2026-11-24 |
| `git-maintenance@daily.timer` | `OnCalendar=Tue..Sun *-*-* 00:56:00` | `git-maintenance@daily.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `git-maintenance@hourly.timer` | `OnCalendar=*-*-* 01..23:56:00` | `git-maintenance@hourly.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `git-maintenance@weekly.timer` | `OnCalendar=Mon *-*-* 00:56:00` | `git-maintenance@weekly.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
Expand Down Expand Up @@ -417,7 +417,7 @@ The OS-timer half of surface 2. Cadence is the unit's own `OnCalendar`/`OnUnitAc
| `pm-kaneo-sync-guard.timer` | `OnCalendar=*-*-* *:00:00` | `pm-kaneo-sync-guard.service` | laptop (user systemd) | not recorded | not recorded | 2026-11-14 | 2026-11-15 |
| `pm-projector-reconcile.timer` | `OnCalendar=*-*-* *:00/15:00` | `pm-projector-reconcile.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `pm-tunnel-watchdog.timer` (Nix-configured; not yet loaded) | `OnUnitActiveSec=2min,OnBootSec=2min` (not live-verified) | `pm-tunnel-watchdog.service` | laptop (user systemd) | not recorded | not recorded | 2026-11-11 | 2026-11-11 |
| `quota-gatherer.timer` | `OnCalendar=*-*-* *:00/15:00` | `quota-gatherer.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-22 |
| `quota-gatherer.timer` (retirement pending deployment) | `OnCalendar=*-*-* *:00/15:00` | `quota-gatherer.service` | laptop (user systemd; source retired by #8570, live disable not verified) | not recorded | not recorded | not recorded | 2026-11-24 |
| `quota-weekly-review.timer` | `OnCalendar=Mon *-*-* 07:20:00` | `quota-weekly-review.service` | laptop (user systemd; code#12701; NixOS module `services.pm-stack`, package `pkgs/pm-aggregator` — Stage-3 S7 weekly forecast-accuracy review: posts the report to epic #12694, S6 proposal PRs only, never edits config; Nix-configured pending deployment) | not recorded | not recorded | 2026-11-23 | 2026-11-23 |
| `repo-archive-backup.timer` | `OnCalendar=*-*-* 05:15:00` | `repo-archive-backup.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `repo-universe-issue-check.timer` | `OnCalendar=*-*-* 00:00:00` | `repo-universe-issue-check.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
Expand Down Expand Up @@ -445,6 +445,14 @@ it targeted the retired sandbox collector. The drill script is laptop-only
sandbox's installed-unit state still requires the operator audit linked from
issue #1319.

2026-11-24 #8570 timer cutover is prepared in source: pm-core retains the
quota (15m) and fleet-feed (5m) cadences in-process; the quota and collector
systemd timer declarations/installer activation are removed. The two rows
above remain until deployment verifies the laptop units are inactive and
disabled; this PR does not claim a live systemd cutover. The kill-collector
drill now pauses the in-process feed job through its state-file gate and
refuses to run while the legacy collector timer remains active.

### 2c. Sandbox systemd system timers (1 listed)

The sandbox's system-scope timers (the sandbox has no user bus). A listed
Expand Down
56 changes: 34 additions & 22 deletions nixos/services/pm-stack/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,16 @@ in
# signal delivered to this service is attributed in
# ${aggState}/sigterm-witness.log before it is
# forwarded to the app.
# Refresh the collector's local OpenCode password when possible;
# a missing/failing helper must not take the board offline.
ExecStartPre = "-${home}/.local/bin/fleet-feed-oc-password.sh";
ExecStart = "${sigtermWitness}/bin/sigterm-witness --log ${aggState}/sigterm-witness.log ${pmAggregator}/bin/pm-aggregator";
EnvironmentFile = "${aggState}/.env";
# The in-process quota job also needs the optional Antigravity
# credential file previously loaded by quota-gatherer.service.
EnvironmentFile = [
"${aggState}/.env"
"-%h/.local/state/opencode/mistral-api-key.env"
];
# The projector is a deployed service of this stack — never
# render it off (see the header note). The coverage snapshot
# is runtime state: keep it in the state dir, not the
Expand Down Expand Up @@ -323,6 +331,30 @@ in
# switching this back to "file" is the rollback.
"PM_AGG_STORE_BACKEND=turso"
"PM_AGG_STORE_WRITER=pm-aggregator.service"
# #8570: preserve the old quota-gatherer service's state paths
# when its main() runs inside pm-aggregator.
"QUOTA_CURRENT_PATH=${aggState}/quota-current.json"
"QUOTA_HEARTBEAT_PATH=${aggState}/quota-gatherer-heartbeat.json"
"QUOTA_GATHERER_STATE_PATH=${aggState}/quota-gatherer-state.json"
"QUOTA_SNAPSHOTS_DIR=${aggState}/snapshots"
"POOL_STATE_PATH=${home}/.local/state/opencode-claimant/pool-state.json"
# #8570: preserve the collector's source paths and runtime
# credentials when it runs inside pm-aggregator rather than its
# former oneshot unit.
"QUOTA_VIEW_PATH=${home}/hatch-personal/workspace/goals/stewardship-commission-recurring-review-and-dispatch/hidden_files/visibility/quota-view.md"
"QUOTA_REGISTRY_PATH=${home}/hatch-personal/workspace/goals/keep-the-four-repos-healthy/hidden_files/provider-quota-registry.md"
"ORCHESTRATION_PATH=${home}/hatch-personal/workspace/goals/keep-the-four-repos-healthy/hidden_files/orchestration.json"
"DNS_REGISTER_PATH=${home}/hatch-personal/workspace/goals/stand-up-lab-cluster-talm-talos-cozystack-postgres-rustfs/files/dns-domain-register.md"
"AA_OPENCODE_CONFIG_PATH=${home}/git/code/.opencode/opencode.jsonc"
"CHARGE_CANDIDATES_PATH=${home}/hatch-personal/workspace/goals/keep-the-four-repos-healthy/hidden_files/charges-candidates.json"
"CHARGES_SURFACED_STATE_PATH=${home}/hatch-personal/workspace/goals/keep-the-four-repos-healthy/hidden_files/charges-surfaced-state.json"
"CLAUDE_LAUNCH_RECORDS_PATH=${home}/hatch-personal/workspace/goals/keep-the-four-repos-healthy/hidden_files/claude-launch-records.jsonl"
"USAGE_SNAPSHOT_OUTBOX_PATH=${aggState}/usage-snapshot-outbox.jsonl"
"SANDBOX_OPENCODE_URL=http://127.0.0.1:13420"
"OPENCODE_SERVER_URL=http://127.0.0.1:13420"
"OPENCODE_SESSION_SOURCE=opencode-laptop"
"OPENCODE_SERVER_PASSWORD_FILE=${aggState}/opencode-server-password"
"PM_AGG_FRESHNESS_URL=http://127.0.0.1:4871/publish"
"BWS_BIN=/run/current-system/sw/bin/bws"
"BWS_ACCESS_TOKEN_FILE=${home}/.config/bws/access-token"
# The digest archive (#1278) is runtime state too: one
Expand Down Expand Up @@ -534,6 +566,7 @@ in
"PM_AGG_STORE_BACKEND=turso"
"PM_AGG_STORE_WRITER=fleet-feed-collector"
"FLEET_FEED_OUT=${aggState}/fleet-feed.json"
"PM_CORE_FEED_CREDENTIAL_REFRESH=${home}/.local/bin/fleet-feed-oc-password.sh"
"PM_AGG_FRESHNESS_URL=http://127.0.0.1:4871/publish"
"QUOTA_VIEW_PATH=${home}/hatch-personal/workspace/goals/stewardship-commission-recurring-review-and-dispatch/hidden_files/visibility/quota-view.md"
"QUOTA_REGISTRY_PATH=${home}/hatch-personal/workspace/goals/keep-the-four-repos-healthy/hidden_files/provider-quota-registry.md"
Expand Down Expand Up @@ -661,17 +694,6 @@ in
Install.WantedBy = [ "timers.target" ];
};

quota-gatherer = {
Unit.Description = "Run the quota gatherer every 15 minutes (pm-stack, #1151)";
Timer = {
OnCalendar = "*:0/15";
RandomizedDelaySec = 20;
Persistent = true;
Unit = "quota-gatherer.service";
};
Install.WantedBy = [ "timers.target" ];
};

pm-digest-daily = {
Unit.Description = "Run the PM daily digest every morning at 07:00 local (pm-stack, #1278)";
Timer = {
Expand Down Expand Up @@ -705,16 +727,6 @@ in
Install.WantedBy = [ "timers.target" ];
};

fleet-feed-collector = {
Unit.Description = "Collect the fleet feed for the laptop aggregator every ~5 minutes";
Timer = {
OnBootSec = "2min";
OnUnitActiveSec = "5min";
Unit = "fleet-feed-collector.service";
};
Install.WantedBy = [ "timers.target" ];
};

pm-kaneo = {
Unit.Description = "Retry pm-kaneo until the Kaneo stack is up (docker-ordering self-heal)";
Timer = {
Expand Down
31 changes: 16 additions & 15 deletions pm-stack/aggregator/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ if [ "$CHANGED" -eq 1 ]; then
echo "$SRC_INPUTS" >"$STATE_DIR/.deploy-inputs-hash"
fi

# #8570: pm-core owns quota (15m) and fleet-feed (5m) schedules in-process.
# Retire any previously enabled user timers before the aggregator (re)starts,
# so the legacy collector cannot overlap the in-process one.
for RETIRED_TIMER in quota-gatherer.timer fleet-feed-collector.timer; do
if systemctl --user is-active --quiet "$RETIRED_TIMER"; then
systemctl --user stop "$RETIRED_TIMER"
fi
if systemctl --user is-enabled --quiet "$RETIRED_TIMER"; then
systemctl --user disable "$RETIRED_TIMER"
fi
done

systemctl --user daemon-reload
systemctl --user enable pm-aggregator.service
if [ "$CHANGED" -eq 1 ]; then
Expand Down Expand Up @@ -255,33 +267,22 @@ curl -s "http://${TAILNET_IP}:4870/api/health"
echo
systemctl --user is-active pm-aggregator.service

# Quota gatherer (#1151): a user timer on the same 15-minute cadence
# as the Meta file exporter (#1301), running scripts/gather-quota.ts
# from this checkout. Units ship with this package (systemd/). Guarded:
# a checkout without the units skips this block instead of failing the install.
# Keep the quota oneshot service available for explicit operator runs, but
# do not install or enable its retired timer.
GATHERER_SVC_SRC="$SRC/systemd/quota-gatherer.service"
GATHERER_TMR_SRC="$SRC/systemd/quota-gatherer.timer"
if [ -f "$GATHERER_SVC_SRC" ] && [ -f "$GATHERER_TMR_SRC" ]; then
if [ -f "$GATHERER_SVC_SRC" ]; then
# Home-manager hosts manage these units as symlinks into /nix/store
# (#9586): a plain cp over the symlink aborts the install on the
# read-only store. Mirror the pm-aggregator unit guard above: skip
# the copy for symlink-managed destinations and leave those units
# to the NixOS/home-manager switch.
GATHERER_SVC_DST="$HOME/.config/systemd/user/quota-gatherer.service"
GATHERER_TMR_DST="$HOME/.config/systemd/user/quota-gatherer.timer"
if [ -L "$GATHERER_SVC_DST" ]; then
echo "quota-gatherer.service is symlink-managed at $GATHERER_SVC_DST; skipping unit copy"
else
cp "$GATHERER_SVC_SRC" "$GATHERER_SVC_DST"
fi
if [ -L "$GATHERER_TMR_DST" ]; then
echo "quota-gatherer.timer is symlink-managed at $GATHERER_TMR_DST; skipping unit copy"
else
cp "$GATHERER_TMR_SRC" "$GATHERER_TMR_DST"
fi
systemctl --user daemon-reload
systemctl --user enable --now quota-gatherer.timer
echo "quota-gatherer.timer: $(systemctl --user is-active quota-gatherer.timer)"
else
echo "quota-gatherer units not found — gatherer timer not installed"
echo "quota-gatherer service not found — explicit gatherer runs unavailable"
fi
35 changes: 19 additions & 16 deletions pm-stack/aggregator/scripts/age-feed-drill.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@
# Deliberately age the fleet feed while the collector keeps running, and
# verify the PM stack notices a feed that is alive but OLD — the failure
# mode the kill-collector drill (first slice, #1823) cannot reach: there
# the collector is dead, here it runs on schedule and the data it
# the collector is paused, here it stays scheduled and the data it
# presents is stale, so "everything is fine" is a lie the process tree
# does not contradict.
#
# What it does, in order:
# 1. Interlocks (any failure = refuse to start, nothing is touched):
# - flock on the drill lock (a second drill, manual or scheduled,
# cannot overlap this one);
# - shared flock on the drill lock (the age-feed and kill-collector
# drills, manual or scheduled, cannot overlap one another);
# - the incident flag file ($PM_DRILL_INCIDENT_FLAG) must not exist —
# during a real incident the stack is not a drill canvas;
# - the collector timer must be active (this drill's premise is a
# running collector) and the feed must currently be FRESH. An
# - the legacy collector timer must be inactive (pm-core owns
# collection) and the feed must currently be FRESH. An
# already-stale feed is a real incident, not a drill.
# 2. Saves the feed's exact bytes, then arms restore (trap on
# EXIT/INT/TERM) immediately BEFORE the first write, so every
# refusal path above leaves the feed untouched.
# 3. Ages the feed by rewriting its top-level generatedAt into the past
# (PM_DRILL_AGE_MS, default 20 min > the 15-min FEED_STALE_MS in
# src/health.ts + src/sources/live.ts) while leaving every other
# field intact. The collector keeps running on its ~5-min timer; if
# field intact. The in-process pm-core collector keeps its 5-min cadence; if
# it rewrites the feed with a fresh stamp mid-drill, the drill
# re-ages it, which is exactly the "collector runs, data is old"
# scenario.
# scenario. The in-process pm-core collector runs on its ~5-minute
# cadence throughout the drill.
# 4. Polls /api/health until feed.ageMs crosses FEED_STALE_MS and the
# payload reports degraded, saving that payload as the fired-signal
# evidence; it also records (best effort) whether the #1148
Expand All @@ -35,7 +36,7 @@
# carries the stale-feed warning (#1116 item 5).
# 5. Restores ALWAYS once the aging has happened: the saved bytes are
# written back atomically and the drill waits (up to
# PM_DRILL_RESTORE_WAIT_MIN) for the collector's next scheduled run
# PM_DRILL_RESTORE_WAIT_MIN) for the in-process collector's next 5-min tick
# to make the feed fresh again, confirming via /api/health. The
# restore is gated on the aging: a drill that refuses to start
# touches nothing.
Expand All @@ -47,8 +48,9 @@
#
# Where it runs: on the host that owns the feed and the aggregator —
# the laptop, where the collector moved on 2026-10-31 (code#3362/#3363).
# The collector/aggregator are NixOS user units, so the timer check uses
# `systemctl --user`; nothing here needs root.
# The aggregator is a NixOS user unit. The old collector timer is checked
# inactive to prevent a second collector from invalidating the drill;
# nothing here needs root.
#
# Scheduling: systemd/age-feed-drill.{service,timer} in this repo's
# pm-stack/aggregator/systemd/ directory (weekly, in a quiet window that
Expand Down Expand Up @@ -111,7 +113,7 @@ die() {
}

# --- interlock: one drill at a time ---------------------------------------
exec 9>"$STATE_DIR/age-feed.lock"
exec 9>"$STATE_DIR/pm-drills.lock"
if ! flock -n 9; then
die "another age-feed drill holds the lock; not starting"
fi
Expand Down Expand Up @@ -209,18 +211,19 @@ restore() {
trap restore EXIT INT TERM

# --- preconditions ----------------------------------------------------------
systemctl --user is-active --quiet "$COLLECTOR_TIMER" ||
die "$COLLECTOR_TIMER is not active; this drill's premise is a running collector, and a stopped collector outside a drill is itself a finding"
if systemctl --user is-active --quiet "$COLLECTOR_TIMER"; then
die "$COLLECTOR_TIMER is still active; pm-core owns collection and the legacy timer must be retired"
fi
[ -r "$FEED_FILE" ] || die "cannot read the feed file $FEED_FILE"
[ -n "$(feed_stamp)" ] || die "feed file $FEED_FILE has no readable generatedAt; refusing to drill blind"
BASELINE="$(health_json | feed_facts)" || die "cannot read aggregator /api/health; refusing to drill blind"
BASE_AGE="${BASELINE%% *}"
[ "$BASE_AGE" -ge 0 ] 2>/dev/null || die "cannot read aggregator /api/health; refusing to drill blind"
[ "$BASE_AGE" -le "$STALE_MS" ] || die "feed is already stale at drill start (age ${BASE_AGE}ms > ${STALE_MS}ms): that is a real incident, not a drill"
cp -p "$FEED_FILE" "$BACKUP_FILE" || die "cannot save the feed's original bytes to $BACKUP_FILE"
log "preconditions ok: collector active, feed fresh (age ${BASE_AGE}ms), feed saved, no incident flag, lock held"
log "preconditions ok: legacy timer inactive, in-process collector scheduled, feed fresh (age ${BASE_AGE}ms), feed saved, no incident flag, lock held"

# --- age the feed, collector still running ------------------------------------
# --- age the feed, in-process collector still scheduled -----------------------
# Pin the stamp once so every re-age during the drill presents the same
# "alive but old" feed; the collector's own rewrites are re-aged below.
PIN_STAMP="$(python3 -c '
Expand Down Expand Up @@ -345,7 +348,7 @@ if [ "${PM_DRILL_NO_POST:-0}" != "1" ] && command -v gh >/dev/null 2>&1; then
if [ "$OUTCOME" = "passed" ]; then
gh issue comment "$ISSUE" --repo "$ISSUE_REPO" --body "✅ **Chaos drill passed — age the feed** (queue task 7919, second slice of this issue, epic #$EPIC)

- Aged \`fleet-feed.json\`'s \`generatedAt\` by ${AGE_MS}ms at $STARTED_AT **while \`$COLLECTOR_TIMER\` stayed active** — the stale-but-alive feed the kill-collector drill cannot produce. Health payload at the signal moment: degraded=$DEGRADED, watchdog \`watchdog:feed\` item seen=$WATCHDOG.
- Aged \`fleet-feed.json\`'s \`generatedAt\` by ${AGE_MS}ms at $STARTED_AT **while pm-core's in-process collector remained scheduled** — the stale-but-alive feed the kill-collector drill cannot produce. Health payload at the signal moment: degraded=$DEGRADED, watchdog \`watchdog:feed\` item seen=$WATCHDOG.
- The aggregator's feed-age signal crossed the 15-minute \`FEED_STALE_MS\` (#1148) threshold instead of presenting old data as fine.
- Restoration confirmed via \`/api/health\`: the original bytes were written back and the collector's next run made the feed fresh again.
- Script: \`pm-stack/aggregator/scripts/age-feed-drill.sh\` (interlocked: flock, incident-flag refusal, refuses to start on an already-stale feed or an inactive collector; always restores via trap). Result JSON is written to \`~/.local/state/pm-drills/age-feed-result.json\` per run." >/dev/null 2>&1 &&
Expand Down
Loading