From 5ae709fdda9963c681c3ea8b997fe6d48a31372f Mon Sep 17 00:00:00 2001 From: govind arora Date: Sun, 17 May 2026 15:23:36 +0530 Subject: [PATCH] fix(agents): clear stuck Claude session on model swap + UX confirm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PATCH `/api/admin/agents/:id` now invalidates the per-task Claude session when the model changes, so the next wake actually starts a fresh CLI run on the new model instead of silently resuming the previous session (which would keep using the old model regardless of what the agent row says). Backend (`admin-routes.ts`): - When `body.model` changes, scan tasks assigned to this agent in active states whose latest `agent_runs.status` is **not** `running`, and `UPDATE tasks SET session_id = NULL`. In-flight runs are left alone — those finish on the old model, then the next wake takes the new model. Status enums imported from `@boringos/shared` instead of hardcoded strings. - The PATCH response now carries a `sessionInvalidation: { tasksCleared, tasksDeferred }` block so the UI can render an accurate post-swap toast. - The shell-agent guard is relaxed from "block all writes" to "allow model / runtimeId / fallbackRuntimeId / status / permissions / budgetMonthlyCents only", with everything else still blocked at 403. Without this, the model dropdown returned 403 on framework-source agents (copilot, replier, triage) which is exactly where the bug matters most. Frontend (`AgentsPanel.tsx` + new `ConfirmModelChangeDialog.tsx`): - The model `