Files
loki/drizzle/0026_runner_presence.sql
Mao NakamotoandClaude Opus 4.8 37595ec6b0 feat(presence): connection-based runner presence, replacing the heartbeat
The web inferred 'Fleet Runner online' from the freshness of a 5-min
runtime-state heartbeat (offline if >8min stale), so a healthy runner looked
dead for minutes after any restart. Presence is now a property of the live
runner<->bridge SSE connection instead of a timer.

- bridge: runner connections tag themselves ?client=runner; on connect/disconnect
  the bridge upserts runner_presence and pg_notify's the web stream channel.
  Boot resets all counts so a crashed bridge can't leave stale 'connected'.
- web: /control/stream carries live runnerConnected; the badge flips in <1s.
  ADDITIVE: online = connected OR heartbeat-fresh, so the current (untagged)
  runner keeps working until the desktop rebuild ships. Cutover (drop heartbeat
  + long-poll) is staged separately.
- desktop runner tags its bridge connection ?client=runner.

Docs: docs/architecture/connection-presence.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 22:48:48 +02:00

17 lines
840 B
SQL

-- Connection-based runner presence (replaces the heartbeat-freshness guess).
-- Written by the bridge on runner SSE connect/disconnect.
-- Idempotent + additive: safe to apply to a live DB; nothing reads it until
-- the web cutover. See docs/architecture/connection-presence.md.
CREATE TABLE IF NOT EXISTS "runner_presence" (
"user_id" uuid PRIMARY KEY NOT NULL,
"connection_count" integer DEFAULT 0 NOT NULL,
"connected" boolean DEFAULT false NOT NULL,
"connected_at" timestamp with time zone,
"last_change_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "runner_presence" ADD CONSTRAINT "runner_presence_user_id_users_id_fk"
FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION WHEN duplicate_object THEN NULL; END $$;