-- Bind durable task runs to the Agent instance that owns their local session. BEGIN; ALTER TABLE workbench.operational_task_runs ADD COLUMN IF NOT EXISTS agent_instance_id text; CREATE INDEX IF NOT EXISTS operational_task_runs_agent_owner_idx ON workbench.operational_task_runs(project_id,agent_instance_id,status,created_at,run_id) WHERE agent_instance_id IS NOT NULL AND status IN ('claimed','running'); COMMIT;