feat(nodes): remote sleep/wake — idle detection + wake-page ingress

Agents report per-container net IO at heartbeat; the sleeper measures
idleness from those counters for remote services, removes replicas via
the agent queue, and repoints the domain route at the backend's new
/internal/wake-page endpoint (replacePath + priority-100 route in the
file provider). First hit serves a reloading page and retriggers the
wake reconcile, which recreates replicas and restores real upstreams.

Manual POST /services/:id/sleep also routes remote; local sleep/wake
flow is unchanged.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Tomas DvorakandDevin committed 2026-10-09 18:43:33 +02:00
1 parent 4028639239
commit 59dfd35583
12 files changed
+264 -37

No files matched your search

+5 -3
View File
@@ -180,7 +180,7 @@ LIMIT 1;
UPDATE node_agents SET tags = $2::jsonb, updated_at = NOW() WHERE id = $1;
-- name: ListServiceContainers :many
SELECT id, name, node_agent_id, status, ports FROM container_instances
SELECT id, name, node_agent_id, status, ports, resources FROM container_instances
WHERE service_id = $1;
-- name: SetAgentSchedulable :exec
@@ -204,10 +204,12 @@ ON CONFLICT (id) DO UPDATE SET
DELETE FROM container_instances WHERE node_agent_id = $1 AND service_id = $2;
-- name: UpdateContainerStateByName :exec
-- Agent heartbeat reports real docker state; reconcile inventory for rows
-- this node owns. Tombstones win — never resurrect a removed replica.
-- Agent heartbeat reports real docker state + net counters; reconcile
-- inventory for rows this node owns. Tombstones win — never resurrect a
-- removed replica. $4 is the cumulative rx+tx byte counter.
UPDATE container_instances SET
status = jsonb_set(status, '{state}', $3::jsonb),
resources = jsonb_set(COALESCE(resources, '{}'::jsonb), '{net_bytes}', $4::jsonb),
updated_at = NOW()
WHERE name = $1 AND node_agent_id = $2
AND status->>'state' IS DISTINCT FROM 'removed';