Skip to content
Merged
4 changes: 2 additions & 2 deletions doc/fleet-schedule-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ The OS-timer half of surface 2. Cadence is the unit's own `OnCalendar`/`OnUnitAc
| `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 |
| `queue-coverage-reconcile.timer` (repo-shipped, not yet installed) | `OnCalendar=*-*-* *:41:00` | `queue-coverage-reconcile.service` | laptop (user systemd; code#7016) | not recorded | not recorded | 2026-11-08 | 2026-11-08 |
| `scheduled-history.timer` | `OnCalendar=*-*-* *:0/5:00` | `scheduled-history.service` | laptop (user systemd; code#2174) | not recorded | not recorded | 2026-11-11 | 2026-11-14 |
| `supabase-backup.timer` | `OnCalendar=*-*-* 04:42:00,OnCalendar=*-*-* 16:42:00` | `supabase-backup.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `supabase-turso-coord-mirror.timer` | `OnCalendar=*-*-* 04:24:00` | `supabase-turso-coord-mirror.service` | laptop (user systemd) | not recorded | not recorded | 2026-11-11 | 2026-11-11 |
| `supabase-backup.timer` | retired in config 2026-11-18 (activation pending) | `supabase-backup.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | <!-- Retired in configuration 2026-11-18: muse-dev2 deleted; existing dumps, mirror records and checkpoint retained. Live timer retirement requires activation. -->
| `supabase-turso-coord-mirror.timer` | retired in config 2026-11-18 (activation pending) | `supabase-turso-coord-mirror.service` | laptop (user systemd) | not recorded | not recorded | 2026-11-11 | 2026-11-11 | <!-- Retired in configuration 2026-11-18: muse-dev2 deleted; existing dumps, mirror records and checkpoint retained. Live timer retirement requires activation. -->
| `sync-models.timer` | `OnCalendar=*-*-* 00:00:00` | `sync-models.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `systemd-tmpfiles-clean.timer` | `OnUnitActiveUSec=1d,OnStartupUSec=5min` | `systemd-tmpfiles-clean.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
| `tldr-update.timer` | `OnCalendar=Mon *-*-* 00:00:00` | `tldr-update.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 |
Expand Down
3 changes: 2 additions & 1 deletion nixos/home/laptop-backups.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
let
cfg = config.services.laptop-backups;
home = config.home.homeDirectory;
pmAggregator = pkgs.callPackage ../../pkgs/pm-aggregator/package.nix { };
dashboardPkg = pkgs.writeShellScriptBin "pm-dashboard-backup" (
builtins.readFile ./pm-dashboard-backup.sh
);
Expand Down Expand Up @@ -309,7 +310,7 @@ in
Service = {
Type = "oneshot";
ExecStart = "${dashboardPkg}/bin/pm-dashboard-backup";
Environment = "PATH=${servicePath}:${home}/tools/bin:/run/current-system/sw/bin";
Environment = [ "PATH=${servicePath}:${home}/tools/bin:/run/current-system/sw/bin" "PM_AGG_STORE_BACKEND=turso" "PM_AGG_TURSO_EXPORT_BIN=${pmAggregator}/bin/pm-aggregator-export-turso-stores" ];
};
};
})
Expand Down
41 changes: 38 additions & 3 deletions nixos/home/pm-dashboard-backup-manifest.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ fi
if manifest_json missing-optional | python3 -c '
import json, sys
m = json.load(sys.stdin)
sys.exit(0 if len(m.get("expected", [])) == 36 else 1)
sys.exit(0 if len(m.get("expected", [])) == 46 else 1)
'; then
ok "missing-optional: manifest lists all 36 expected members"
ok "missing-optional: manifest lists all 46 expected members"
else
fail "missing-optional: manifest expected list is not the full 36-member set"
fail "missing-optional: manifest expected list is not the full 46-member set"
fi

# --- decisions ledger is required (#10293) -----------------------------------
Expand Down Expand Up @@ -479,6 +479,41 @@ else
fail "supabase-export: log lacks the per-table counts: $(cat "$TMP_ROOT/supabase-export.log")"
fi

# --- Turso exporter stages every required table, no credentials in fixtures ---
setup_home turso-export
EXPORTER="$TMP_ROOT/turso-fixture-exporter"
cat >"$EXPORTER" <<'STUBEOF'
#!/usr/bin/env bash
set -eu
[[ "$1" == --output-dir && $# == 2 ]]
mkdir -p "$2"
for table in agg_actions agg_activity_ingestion agg_activity_gaps agg_usage_snapshots agg_store_documents alerts_incidents alerts_incident_events alerts_push_subscriptions alerts_notification_sends orch_runs; do
printf '[]' >"$2/$table.json"
done
STUBEOF
chmod +x "$EXPORTER"
PATH="$BIN:$PATH" HOME="$RUN_HOME" BWS_ACCESS_TOKEN=fake-token \
RCLONE_STUB_DIR="$TMP_ROOT/turso-export/rclone-store" \
RCLONE_CALLS_LOG="$TMP_ROOT/turso-export/rclone-calls.log" \
PM_DB_DUMP_SCRIPT="$DUMP_SCRIPT_ARG" PM_AGG_STORE_BACKEND=turso \
PM_AGG_TURSO_EXPORT_BIN="$EXPORTER" \
bash "$SCRIPT" 2026-10-28 >"$TMP_ROOT/turso-export.log" 2>&1
RC=$?
if [[ $RC -eq 0 ]]; then ok "turso-export: completed"; else fail "turso-export: rc=$RC $(cat "$TMP_ROOT/turso-export.log")"; fi
assert_member turso-export turso/agg_actions.json required present
assert_member turso-export turso/alerts_push_subscriptions.json required present
assert_member turso-export turso/orch_runs.json required present

setup_home turso-missing
PATH="$BIN:$PATH" HOME="$RUN_HOME" BWS_ACCESS_TOKEN=fake-token \
RCLONE_STUB_DIR="$TMP_ROOT/turso-missing/rclone-store" \
RCLONE_CALLS_LOG="$TMP_ROOT/turso-missing/rclone-calls.log" \
PM_DB_DUMP_SCRIPT="$DUMP_SCRIPT_ARG" PM_AGG_STORE_BACKEND=turso \
PM_AGG_TURSO_EXPORT_BIN=/nonexistent/turso-exporter \
bash "$SCRIPT" 2026-10-28 >"$TMP_ROOT/turso-missing.log" 2>&1
RC=$?
if [[ $RC -ne 0 ]] && no_upload turso-missing; then ok "turso-missing: fails without uploading"; else fail "turso-missing: did not fail closed"; fi

if ((failures > 0)); then
echo "pm-dashboard-backup manifest tests: $failures failure(s)" >&2
exit 1
Expand Down
34 changes: 31 additions & 3 deletions nixos/home/pm-dashboard-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,16 @@ conditional file supabase/agg_activity_ingestion.json
conditional file supabase/agg_activity_gaps.json
conditional file supabase/agg_usage_snapshots.json
conditional file supabase/agg_store_documents.json
conditional file turso/agg_actions.json
conditional file turso/agg_activity_ingestion.json
conditional file turso/agg_activity_gaps.json
conditional file turso/agg_usage_snapshots.json
conditional file turso/agg_store_documents.json
conditional file turso/alerts_incidents.json
conditional file turso/alerts_incident_events.json
conditional file turso/alerts_push_subscriptions.json
conditional file turso/alerts_notification_sends.json
conditional file turso/orch_runs.json
conditional tree db-dumps
conditional file projector/pmp_links.sql
optional tree aggregator/snapshots
Expand Down Expand Up @@ -610,13 +620,14 @@ fi
# relocated project; the password and project ref come from Bitwarden by
# key name only and are never logged.
SUPA_RAN=0
TURSO_RAN=0
SUPA_MODE="${PM_AGG_SUPABASE_EXPORT:-auto}"
case "$SUPA_MODE" in
auto | off) ;;
*) fail "PM_AGG_SUPABASE_EXPORT must be auto or off, got '$SUPA_MODE'" ;;
esac
SUPA_BACKEND=""
if [ -f "$AGG/.env" ]; then
SUPA_BACKEND="${PM_AGG_STORE_BACKEND:-}"
if [ -z "$SUPA_BACKEND" ] && [ -f "$AGG/.env" ]; then
SUPA_BACKEND="$(grep -E '^[[:space:]]*(export[[:space:]]+)?PM_AGG_STORE_BACKEND[[:space:]]*=' "$AGG/.env" 2>/dev/null |
tail -n 1 | sed -E 's/^[[:space:]]*(export[[:space:]]+)?PM_AGG_STORE_BACKEND[[:space:]]*=[[:space:]]*//')"
SUPA_BACKEND="$(pmp_trim_value "$SUPA_BACKEND")"
Expand Down Expand Up @@ -666,6 +677,21 @@ PYEOF
)" || fail "Supabase export produced unreadable JSON"
SUPA_RAN=1
log "canonical aggregator stores exported from Supabase: $SUPA_COUNTS"
elif [ "$SUPA_MODE" = "auto" ] && [ "$SUPA_BACKEND" = "turso" ]; then
TURSO_EXPORT_BIN="${PM_AGG_TURSO_EXPORT_BIN:-pm-aggregator-export-turso-stores}"
command -v "$TURSO_EXPORT_BIN" >/dev/null 2>&1 || fail "Turso exporter not found"
"$TURSO_EXPORT_BIN" --output-dir "$STAGE/turso" || fail "Turso canonical store export failed"
python3 - "$STAGE/turso" <<'PYEOF'
import json, pathlib, sys
root = pathlib.Path(sys.argv[1])
for name in ('agg_actions','agg_activity_ingestion','agg_activity_gaps','agg_usage_snapshots','agg_store_documents','alerts_incidents','alerts_incident_events','alerts_push_subscriptions','alerts_notification_sends','orch_runs'):
rows = json.loads((root / (name + '.json')).read_text())
if not isinstance(rows, list): raise SystemExit(name + ': not a JSON array')
print(name + '=' + str(len(rows)))
PYEOF
[ $? -eq 0 ] || fail "Turso export produced unreadable or missing JSON"
TURSO_RAN=1
log "canonical aggregator stores exported from Turso"
else
log "aggregator store backend is '${SUPA_BACKEND:-file}' — Supabase store export not applicable"
fi
Expand All @@ -687,7 +713,7 @@ done
# --- manifest (files as staged + the expected set's per-member status) ---
AGG_DIR="$AGG" AGG_DERIVED="$AGG_DERIVED" \
EXPECTED_SET="$EXPECTED_SET" DUMP_RAN="$DUMP_RAN" PMP_RAN="$PMP_RAN" \
SUPA_RAN="$SUPA_RAN" \
SUPA_RAN="$SUPA_RAN" TURSO_RAN="$TURSO_RAN" \
python3 - "$STAGE" "$DATE" "$CREATED_AT" <<'PYEOF'
import hashlib, json, os, sys
stage, date, created = sys.argv[1], sys.argv[2], sys.argv[3]
Expand Down Expand Up @@ -716,6 +742,8 @@ for line in os.environ.get("EXPECTED_SET", "").splitlines():
if cls == "conditional":
if rel.startswith("supabase/"):
ran = os.environ.get("SUPA_RAN")
elif rel.startswith("turso/"):
ran = os.environ.get("TURSO_RAN")
elif rel.startswith("projector/"):
ran = os.environ.get("PMP_RAN")
else:
Expand Down
4 changes: 3 additions & 1 deletion nixos/hosts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ in
home-manager.users.user = {
imports = [ ../home/laptop-backups.nix ];
services.laptop-backups.enable = true;
# muse-dev2 deleted; preserve existing dumps, retire failed source backup.
services.laptop-backups.supabase.enable = false;
};
}
{
Expand Down Expand Up @@ -234,7 +236,7 @@ in
# the store units below.
home-manager.users.user = {
imports = [ ../home/supabase-turso-coord-mirror.nix ];
services.supabase-turso-coord-mirror.enable = true;
services.supabase-turso-coord-mirror.enable = false; # source retired 2026-11-18
};
}
{
Expand Down
10 changes: 5 additions & 5 deletions nixos/services/pm-stack/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ in
"PM_AGG_ACTIVITY_FILE=${aggState}/activity-ingestion.json"
# #6815: the four aggregator stores that used to live only
# in this state dir (actions, activity-ingestion, usage
# snapshots, aa-last-good) are canonical in Supabase
# muse-dev2. The local files stay as a rebuildable cache
# snapshots, aa-last-good) are canonical in Turso
# fleet-platform. The local files stay as a rebuildable cache
# (see pm-stack/aggregator/README.md, "Store backend");
# switching this back to "file" is the rollback.
"PM_AGG_STORE_BACKEND=supabase"
"PM_AGG_STORE_BACKEND=turso"
"PM_AGG_STORE_WRITER=pm-aggregator.service"
"BWS_BIN=/run/current-system/sw/bin/bws"
"BWS_ACCESS_TOKEN_FILE=${home}/.config/bws/access-token"
Expand Down Expand Up @@ -472,10 +472,10 @@ in
"BWS_BIN=/run/current-system/sw/bin/bws"
"BWS_ACCESS_TOKEN_FILE=${home}/.config/bws/access-token"
# #6815: the collector writes the aa-last-good canonical
# document to Supabase muse-dev2 (the local file stays a
# document to Turso fleet-platform (the local file stays a
# rebuildable cache). Same writer identity as the
# aggregator unit env; see "Store backend" in the README.
"PM_AGG_STORE_BACKEND=supabase"
"PM_AGG_STORE_BACKEND=turso"
"PM_AGG_STORE_WRITER=fleet-feed-collector"
"FLEET_FEED_OUT=${aggState}/fleet-feed.json"
"PM_AGG_FRESHNESS_URL=http://127.0.0.1:4871/publish"
Expand Down
19 changes: 19 additions & 0 deletions pkgs/fleet-state-writers/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Preserve the relative helper imports when deploying either operator writer.
{ stdenvNoCC, python3, makeWrapper }:
stdenvNoCC.mkDerivation {
pname = "fleet-state-writers";
version = "2026-11-18";
dontUnpack = true;
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
root=$out/libexec/fleet-state-writers
mkdir -p $root/scripts $root/pm-stack/shared-schema $out/bin
cp ${../../scripts/fleet_turso.py} $root/scripts/fleet_turso.py
cp ${../../scripts/ainventory-interpretation.py} $root/scripts/ainventory-interpretation.py
cp ${../../pm-stack/shared-schema/orchestration-writer.py} $root/pm-stack/shared-schema/orchestration-writer.py
makeWrapper ${python3}/bin/python3 $out/bin/orchestration-writer \
--add-flags "$root/pm-stack/shared-schema/orchestration-writer.py"
makeWrapper ${python3}/bin/python3 $out/bin/ainventory-interpretation \
--add-flags "$root/scripts/ainventory-interpretation.py"
'';
}
2 changes: 2 additions & 0 deletions pkgs/pm-aggregator/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ stdenvNoCC.mkDerivation {
--add-flags "run $out/libexec/pm-aggregator/scripts/gather-quota.ts"
makeWrapper ${lib.getExe bun} $out/bin/pm-aggregator-generate-digest \
--add-flags "run $out/libexec/pm-aggregator/scripts/generate-digest.ts"
makeWrapper ${lib.getExe bun} $out/bin/pm-aggregator-export-turso-stores \
--add-flags "run $out/libexec/pm-aggregator/scripts/export-turso-stores.ts"
runHook postInstall
'';

Expand Down
23 changes: 23 additions & 0 deletions pm-stack/shared-schema/ainventory-turso-guards.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Apply after recovery creates the ainventory_* tables. Never weakens access
-- controls or rewrites recovered records. SQLite counterpart of PG event guards.
CREATE TRIGGER IF NOT EXISTS ainventory_findings_no_update BEFORE UPDATE ON ainventory_findings BEGIN SELECT RAISE(ABORT,'findings is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_findings_no_delete BEFORE DELETE ON ainventory_findings BEGIN SELECT RAISE(ABORT,'findings is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_interpretation_runs_no_update BEFORE UPDATE ON ainventory_interpretation_runs BEGIN SELECT RAISE(ABORT,'interpretation_runs is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_interpretation_runs_no_delete BEFORE DELETE ON ainventory_interpretation_runs BEGIN SELECT RAISE(ABORT,'interpretation_runs is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_notes_no_update BEFORE UPDATE ON ainventory_notes BEGIN SELECT RAISE(ABORT,'notes is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_notes_no_delete BEFORE DELETE ON ainventory_notes BEGIN SELECT RAISE(ABORT,'notes is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_measurement_events_no_update BEFORE UPDATE ON ainventory_measurement_events BEGIN SELECT RAISE(ABORT,'measurement_events is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_measurement_events_no_delete BEFORE DELETE ON ainventory_measurement_events BEGIN SELECT RAISE(ABORT,'measurement_events is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_price_events_no_update BEFORE UPDATE ON ainventory_price_events BEGIN SELECT RAISE(ABORT,'price_events is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_price_events_no_delete BEFORE DELETE ON ainventory_price_events BEGIN SELECT RAISE(ABORT,'price_events is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_provider_policies_no_update BEFORE UPDATE ON ainventory_provider_policies BEGIN SELECT RAISE(ABORT,'provider_policies is append-only'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_provider_policies_no_delete BEFORE DELETE ON ainventory_provider_policies BEGIN SELECT RAISE(ABORT,'provider_policies is append-only'); END;

-- Explicit identity collision guards also reject INSERT OR REPLACE when
-- recursive_triggers is off. These source tables have no other UNIQUE keys.
CREATE TRIGGER IF NOT EXISTS ainventory_findings_no_replace BEFORE INSERT ON ainventory_findings WHEN EXISTS (SELECT 1 FROM ainventory_findings WHERE id=NEW.id) BEGIN SELECT RAISE(ABORT,'findings identity already exists'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_interpretation_runs_no_replace BEFORE INSERT ON ainventory_interpretation_runs WHEN EXISTS (SELECT 1 FROM ainventory_interpretation_runs WHERE id=NEW.id) BEGIN SELECT RAISE(ABORT,'interpretation_runs identity already exists'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_notes_no_replace BEFORE INSERT ON ainventory_notes WHEN EXISTS (SELECT 1 FROM ainventory_notes WHERE id=NEW.id) BEGIN SELECT RAISE(ABORT,'notes identity already exists'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_measurement_events_no_replace BEFORE INSERT ON ainventory_measurement_events WHEN EXISTS (SELECT 1 FROM ainventory_measurement_events WHERE id=NEW.id) BEGIN SELECT RAISE(ABORT,'measurement_events identity already exists'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_price_events_no_replace BEFORE INSERT ON ainventory_price_events WHEN EXISTS (SELECT 1 FROM ainventory_price_events WHERE id=NEW.id) BEGIN SELECT RAISE(ABORT,'price_events identity already exists'); END;
CREATE TRIGGER IF NOT EXISTS ainventory_provider_policies_no_replace BEFORE INSERT ON ainventory_provider_policies WHEN EXISTS (SELECT 1 FROM ainventory_provider_policies WHERE id=NEW.id) BEGIN SELECT RAISE(ABORT,'provider_policies identity already exists'); END;
Loading