Skip to content

The open-source app everyone uses to manage agents at work

[codex] Clear stale queued comment targets (#4234)

Dotta014aa0eb2d14
diff --git a/ui/src/lib/optimistic-issue-comments.test.ts b/ui/src/lib/optimistic-issue-comments.test.ts
index d9a0a3376a..1c53fb7fe9 100644
--- a/ui/src/lib/optimistic-issue-comments.test.ts
+++ b/ui/src/lib/optimistic-issue-comments.test.ts
@@ -720,7 +720,7 @@ describe("optimistic issue comments", () => {
const result = applyLocalQueuedIssueCommentState(comment, {
queuedTargetRunId: "run-1",
- hasLiveRuns: true,
+ targetRunIsLive: true,
runningRunId: "run-1",
});
@@ -746,10 +746,31 @@ describe("optimistic issue comments", () => {
const result = applyLocalQueuedIssueCommentState(comment, {
queuedTargetRunId: "run-1",
- hasLiveRuns: false,
+ targetRunIsLive: false,
runningRunId: null,
});
expect(result).toBe(comment);
});
+
+ it("does not keep local queued state when a different run is live", () => {
+ const comment = {
+ id: "comment-1",
+ companyId: "company-1",
+ issueId: "issue-1",
+ authorAgentId: null,
+ authorUserId: "board-1",
+ body: "Follow up after the active run",
+ createdAt: new Date("2026-03-28T16:20:05.000Z"),
+ updatedAt: new Date("2026-03-28T16:20:05.000Z"),
+ };
+
+ const result = applyLocalQueuedIssueCommentState(comment, {
+ queuedTargetRunId: "run-1",
+ targetRunIsLive: true,
+ runningRunId: "run-2",
+ });
+
+ expect(result).toBe(comment);
+ });
});
diff --git a/ui/src/lib/optimistic-issue-comments.ts b/ui/src/lib/optimistic-issue-comments.ts
index 30cf5cbaf3..f35a484c3b 100644
--- a/ui/src/lib/optimistic-issue-comments.ts
+++ b/ui/src/lib/optimistic-issue-comments.ts
@@ -91,12 +91,12 @@ export function applyLocalQueuedIssueCommentState<T extends IssueComment>(
comment: T,
params: {
queuedTargetRunId?: string | null;
- hasLiveRuns: boolean;
+ targetRunIsLive: boolean;
runningRunId?: string | null;
},
): T | LocallyQueuedIssueComment<T> {
const queuedTargetRunId = params.queuedTargetRunId ?? null;
- if (!queuedTargetRunId || !params.hasLiveRuns) return comment;
+ if (!queuedTargetRunId || !params.targetRunIsLive) return comment;
if (params.runningRunId && params.runningRunId !== queuedTargetRunId) return comment;
return {
diff --git a/ui/src/pages/IssueDetail.tsx b/ui/src/pages/IssueDetail.tsx
index 1718362218..f627624887 100644
--- a/ui/src/pages/IssueDetail.tsx
+++ b/ui/src/pages/IssueDetail.tsx
@@ -613,19 +613,22 @@ const IssueDetailChatTab = memo(function IssueDetailChatTab({
() => resolveRunningIssueRun(resolvedActiveRun, resolvedLiveRuns),
[resolvedActiveRun, resolvedLiveRuns],
);
+ const liveRunIds = useMemo(() => {
+ const ids = new Set<string>();
+ for (const run of resolvedLiveRuns) ids.add(run.id);
+ if (resolvedActiveRun) ids.add(resolvedActiveRun.id);
+ return ids;
+ }, [resolvedActiveRun, resolvedLiveRuns]);
const timelineRuns = useMemo(() => {
- const liveIds = new Set<string>();
- for (const run of resolvedLiveRuns) liveIds.add(run.id);
- if (activeRun) liveIds.add(activeRun.id);
- const historicalRuns = liveIds.size === 0
+ const historicalRuns = liveRunIds.size === 0
? resolvedLinkedRuns
- : resolvedLinkedRuns.filter((run) => !liveIds.has(run.runId));
+ : resolvedLinkedRuns.filter((run) => !liveRunIds.has(run.runId));
return historicalRuns.map((run) => ({
...run,
adapterType: run.adapterType,
hasStoredOutput: (run.logBytes ?? 0) > 0,
}));
- }, [activeRun, resolvedLinkedRuns, resolvedLiveRuns]);
+ }, [liveRunIds, resolvedLinkedRuns]);
const commentsWithRunMeta = useMemo<IssueDetailComment[]>(() => {
const activeRunStartedAt = runningIssueRun?.startedAt ?? runningIssueRun?.createdAt ?? null;
const runMetaByCommentId = new Map<string, { runId: string; runAgentId: string | null; interruptedRunId: string | null }>();
@@ -651,9 +654,10 @@ const IssueDetailChatTab = memo(function IssueDetailChatTab({
return comments.map((comment) => {
const meta = runMetaByCommentId.get(comment.id);
const nextComment: IssueDetailComment = meta ? { ...comment, ...meta } : { ...comment };
+ const queuedTargetRunId = locallyQueuedCommentRunIds.get(comment.id) ?? null;
const locallyQueuedComment = applyLocalQueuedIssueCommentState(nextComment, {
- queuedTargetRunId: locallyQueuedCommentRunIds.get(comment.id) ?? null,
- hasLiveRuns,
+ queuedTargetRunId,
+ targetRunIsLive: queuedTargetRunId ? liveRunIds.has(queuedTargetRunId) : false,
runningRunId: runningIssueRun?.id ?? null,
});
if (locallyQueuedComment !== nextComment) {
@@ -676,7 +680,7 @@ const IssueDetailChatTab = memo(function IssueDetailChatTab({
}
return nextComment;
});
- }, [comments, hasLiveRuns, locallyQueuedCommentRunIds, resolvedActivity, resolvedLinkedRuns, runningIssueRun]);
+ }, [comments, liveRunIds, locallyQueuedCommentRunIds, resolvedActivity, resolvedLinkedRuns, runningIssueRun]);
const timelineEvents = useMemo(
() => extractIssueTimelineEvents(resolvedActivity),
[resolvedActivity],
@@ -1625,6 +1629,7 @@ export function IssueDetail() {
const previousLiveRuns = queryClient.getQueryData<LiveRunForIssue[]>(queryKeys.issues.liveRuns(issueId!));
const previousActiveRun = queryClient.getQueryData<ActiveRunForIssue | null>(queryKeys.issues.activeRun(issueId!));
const previousIssue = queryClient.getQueryData<Issue>(queryKeys.issues.detail(issueId!));
+ const previousLocalQueuedCommentRunIds = locallyQueuedCommentRunIds;
const liveRunList = previousLiveRuns ?? [];
const cachedActiveRun = previousActiveRun ?? null;
const runningIssueRun = resolveRunningIssueRun(cachedActiveRun, liveRunList);
@@ -1653,12 +1658,17 @@ export function IssueDetail() {
queryKeys.issues.detail(issueId!),
(current: Issue | undefined) => clearIssueExecutionRun(current, runId),
);
+ setLocallyQueuedCommentRunIds((current) => {
+ const next = new Map([...current].filter(([, targetRunId]) => targetRunId !== runId));
+ return next.size === current.size ? current : next;
+ });
return {
previousRuns,
previousLiveRuns,
previousActiveRun,
previousIssue,
+ previousLocalQueuedCommentRunIds,
};
},
onSuccess: () => {
@@ -1675,6 +1685,9 @@ export function IssueDetail() {
queryClient.setQueryData(queryKeys.issues.liveRuns(issueId!), context?.previousLiveRuns);
queryClient.setQueryData(queryKeys.issues.activeRun(issueId!), context?.previousActiveRun);
queryClient.setQueryData(queryKeys.issues.detail(issueId!), context?.previousIssue);
+ if (context?.previousLocalQueuedCommentRunIds) {
+ setLocallyQueuedCommentRunIds(context.previousLocalQueuedCommentRunIds);
+ }
pushToast({
title: "Interrupt failed",
body: err instanceof Error ? err.message : "Unable to interrupt the active run",