-- Durable registry of the live container backing each agent (terminal / agent / -- browser), so ANY server replica can find + reuse it instead of the former -- in-process map (which made a 2nd replica spawn duplicate containers). node_id -- records placement for the multi-node node-pool (Phase 2); it is 'local' today. CREATE TABLE agent_containers ( agent_id UUID NOT NULL REFERENCES agents (id) ON DELETE CASCADE, kind TEXT NOT NULL, -- 'terminal' | 'agent' | 'browser' node_id TEXT NOT NULL DEFAULT 'local', container_id TEXT NOT NULL, name TEXT NOT NULL, workspace_id UUID NOT NULL REFERENCES workspaces (id) ON DELETE CASCADE, session_count INTEGER NOT NULL DEFAULT 0, -- live attached sessions (terminals) created_at TIMESTAMPTZ NOT NULL DEFAULT now(), last_seen TIMESTAMPTZ NOT NULL DEFAULT now(), PRIMARY KEY (agent_id, kind) ); CREATE INDEX agent_containers_idle_idx ON agent_containers (kind, last_seen);