refactor: enhance delete run logic with locking mechanism and update sidebar button visibility

This commit is contained in:
tusharmagar 2026-02-16 15:45:58 +05:30
parent 5f3b0a3174
commit 6b0f31c369
2 changed files with 25 additions and 14 deletions

View file

@ -1056,21 +1056,23 @@ function TasksSection({
) : null}
<span className="min-w-0 flex-1 truncate text-sm">{run.title || '(Untitled chat)'}</span>
{run.createdAt ? (
<span className="shrink-0 text-[10px] text-muted-foreground group-hover/chat-item:hidden">
<span className={`shrink-0 text-[10px] text-muted-foreground${processingRunIds?.has(run.id) ? '' : ' group-hover/chat-item:hidden'}`}>
{formatRunTime(run.createdAt)}
</span>
) : null}
<button
type="button"
className="shrink-0 hidden group-hover/chat-item:flex items-center justify-center text-muted-foreground hover:text-destructive transition-colors"
onClick={(e) => {
e.stopPropagation()
actions?.onDeleteRun(run.id)
}}
aria-label="Delete chat"
>
<Trash2 className="size-3.5" />
</button>
{!processingRunIds?.has(run.id) && (
<button
type="button"
className="shrink-0 hidden group-hover/chat-item:flex items-center justify-center text-muted-foreground hover:text-destructive transition-colors"
onClick={(e) => {
e.stopPropagation()
actions?.onDeleteRun(run.id)
}}
aria-label="Delete chat"
>
<Trash2 className="size-3.5" />
</button>
)}
</div>
</SidebarMenuButton>
</SidebarMenuItem>

View file

@ -6,6 +6,7 @@ import { IRunsRepo } from "./repo.js";
import { IAgentRuntime } from "../agents/runtime.js";
import { IBus } from "../application/lib/bus.js";
import { IAbortRegistry } from "./abort-registry.js";
import { IRunsLock } from "./lock.js";
import { forceCloseAllMcpClients } from "../mcp/mcp.js";
export async function createRun(opts: z.infer<typeof CreateRunOptions>): Promise<z.infer<typeof Run>> {
@ -66,8 +67,16 @@ export async function stop(runId: string, force: boolean = false): Promise<void>
}
export async function deleteRun(runId: string): Promise<void> {
const repo = container.resolve<IRunsRepo>('runsRepo');
await repo.delete(runId);
const runsLock = container.resolve<IRunsLock>('runsLock');
if (!await runsLock.lock(runId)) {
throw new Error(`Cannot delete run ${runId}: run is currently active`);
}
try {
const repo = container.resolve<IRunsRepo>('runsRepo');
await repo.delete(runId);
} finally {
await runsLock.release(runId);
}
}
export async function fetchRun(runId: string): Promise<z.infer<typeof Run>> {