feat(swarm): persist DeckyConfig snapshot per shard + enrich list API

Dispatch now writes the full serialised DeckyConfig into
DeckyShard.decky_config (plus decky_ip as a cheap extract), so the
master can render the same rich per-decky card the local-fleet view
uses — hostname, distro, archetype, service_config, mutate_interval,
last_mutated — without round-tripping to the worker on every page
render. DeckyShardView gains the corresponding fields; the repository
flattens the snapshot at read time. Pre-migration rows keep working
(fields fall through as None/defaults).

Columns are additive + nullable so SQLModel.metadata.create_all handles
the change on both SQLite and MySQL. Backfill happens organically on
the next dispatch or (in a follow-up) agent heartbeat.
This commit is contained in:
2026-04-19 21:29:45 -04:00
parent f576564f02
commit 3ebd206bca
5 changed files with 64 additions and 5 deletions

View File

@@ -22,9 +22,8 @@ async def list_deckies(
shards = await repo.list_decky_shards(host_uuid)
hosts = {h["uuid"]: h for h in await repo.list_swarm_hosts()}
# IPs live on the stored DecnetConfig, not on the shard row. Resolve by
# decky_name — if the master rebooted without a config, the column falls
# back to "—" rather than blocking the list.
# Pre-heartbeat fallback — older rows without decky_config can still
# surface their IP from the master's deploy state snapshot.
deploy_state = await repo.get_state("deployment") or {}
cfg_deckies = (deploy_state.get("config") or {}).get("deckies") or []
ip_by_name: dict[str, str] = {
@@ -38,7 +37,7 @@ async def list_deckies(
host = hosts.get(s["host_uuid"], {})
out.append(DeckyShardView(
decky_name=s["decky_name"],
decky_ip=ip_by_name.get(s["decky_name"]),
decky_ip=s.get("decky_ip") or ip_by_name.get(s["decky_name"]),
host_uuid=s["host_uuid"],
host_name=host.get("name") or "<unknown>",
host_address=host.get("address") or "",
@@ -48,5 +47,12 @@ async def list_deckies(
last_error=s.get("last_error"),
compose_hash=s.get("compose_hash"),
updated_at=s["updated_at"],
hostname=s.get("hostname"),
distro=s.get("distro"),
archetype=s.get("archetype"),
service_config=s.get("service_config") or {},
mutate_interval=s.get("mutate_interval"),
last_mutated=s.get("last_mutated") or 0.0,
last_seen=s.get("last_seen"),
))
return out