Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(issues): preserve active run order before later comments (MUL-7632) (#8748)

Jiayuan Zhang3ec96f6860e3
diff --git a/packages/views/issues/components/comment-runs.test.ts b/packages/views/issues/components/comment-runs.test.ts
index 47a7e4b65a..2806a43671 100644
--- a/packages/views/issues/components/comment-runs.test.ts
+++ b/packages/views/issues/components/comment-runs.test.ts
@@ -356,12 +356,14 @@ describe("orderTimelineWithRuns", () => {
.toEqual(["first", "second", "run"]);
});
- it("parks a working run at the live end and keeps live runs in enqueue order", () => {
- const earlier = task("earlier", { status: "running", created_at: "2026-09-07T10:00:00Z" });
+ it.each(["queued", "dispatched", "waiting_local_directory", "running"] as const)("keeps a %s run before later comments in enqueue order", (status) => {
+ const earlier = task("earlier", { status, created_at: "2026-09-07T10:00:00Z" });
const later = task("later", { status: "queued", created_at: "2026-09-07T10:30:00Z" });
+ const before = comment("before", { created_at: "2026-09-07T09:45:00Z" });
+ const between = comment("between", { created_at: "2026-09-07T10:15:00Z" });
const posted = comment("posted", { created_at: "2026-09-07T10:45:00Z" });
- expect(order([posted], [{ task: earlier, hasReply: false }, { task: later, hasReply: false }]))
- .toEqual(["posted", "earlier", "later"]);
+ expect(order([before, between, posted], [{ task: later, hasReply: false }, { task: earlier, hasReply: false }]))
+ .toEqual(["before", "earlier", "between", "later", "posted"]);
});
it("settles a run that ended without a reply at the time it ended", () => {
diff --git a/packages/views/issues/components/comment-runs.ts b/packages/views/issues/components/comment-runs.ts
index 840dfe599c..8dc0d7e0a8 100644
--- a/packages/views/issues/components/comment-runs.ts
+++ b/packages/views/issues/components/comment-runs.ts
@@ -196,19 +196,13 @@ export function buildCommentRunView(
/**
* Where a standalone run block sits in the timeline.
*
- * A block's slot must agree with the timestamp it renders, or the timeline
- * stops reading chronologically (MUL-7211): a run enqueued at 10:00 that
- * replies at 10:40 used to sit in the 10:00 slot while its card showed 10:40,
- * pushing it above every comment written in between. The sort key is the run's
- * `created_at` — the moment it was ENQUEUED, not started — and runs serialize
- * per (issue, agent), so even a five-minute run can carry a slot from far
- * earlier and bracket several later comments.
+ * Once a run publishes a reply, the reply's own time owns the slot (MUL-7211).
+ * This keeps the card's timestamp in chronological order even after a long
+ * queue wait or execution. A run that ended without a reply sorts when it ended.
*
- * So: once a run has published its reply, the reply's own time owns the slot.
- * A run still working has no timestamp to show (its card counts elapsed time),
- * so it parks at the live end and settles in place when the reply lands —
- * no jump. A run that ended without a reply is history, not live: it sorts at
- * the moment it ended.
+ * Until then, an active run keeps its enqueue-time slot (MUL-7632). Parking it
+ * at the live end would insert every later comment above an already visible
+ * assignment block, including a mention that starts another agent's run.
*/
function publishedReply(run: CommentRun, entryById: ReadonlyMap<string, TimelineEntry>): TimelineEntry | undefined {
return run.hasReply && run.commentId ? entryById.get(run.commentId) : undefined;
@@ -217,7 +211,7 @@ function publishedReply(run: CommentRun, entryById: ReadonlyMap<string, Timeline
function standaloneRunSortTime(run: CommentRun, entryById: ReadonlyMap<string, TimelineEntry>): number {
const reply = publishedReply(run, entryById);
if (reply) return Date.parse(reply.created_at);
- if (isActiveCommentRun(run.task)) return Number.POSITIVE_INFINITY;
+ if (isActiveCommentRun(run.task)) return Date.parse(run.task.created_at);
return Date.parse(run.task.completed_at ?? run.task.created_at);
}
@@ -243,9 +237,6 @@ export function orderTimelineWithRuns(
// invariant sortTimelineEntriesAsc holds for the flat cache.
const slotRow = (item: TimelineEntry | CommentRun): { created_at: string; id: string } =>
"task" in item ? publishedReply(item, entryById) ?? item.task : item;
- // Compare with `<` rather than subtraction: two live runs both sort at
- // Infinity, and Infinity - Infinity is NaN, which would leave the
- // comparator inconsistent.
return [...topLevel.filter((entry) => !slotted.has(entry.id)), ...standaloneRuns].sort((a, b) => {
const left = sortTime(a), right = sortTime(b);
if (left !== right) return left < right ? -1 : 1;
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsx
index 127960d09c..160c7509a3 100644
--- a/packages/views/issues/components/issue-detail.test.tsx
+++ b/packages/views/issues/components/issue-detail.test.tsx
@@ -455,7 +455,11 @@ const scrollToIndexSpy = vi.hoisted(() => vi.fn());
vi.mock("react-virtuoso", () => ({
Virtuoso: forwardRef(function MockVirtuoso(
- { data, itemContent }: { data: unknown[]; itemContent: (i: number, item: unknown) => unknown },
+ { data, itemContent, computeItemKey }: {
+ data: unknown[];
+ itemContent: (i: number, item: unknown) => unknown;
+ computeItemKey: (i: number, item: unknown) => React.Key;
+ },
ref: any,
) {
useImperativeHandle(ref, () => ({
@@ -468,7 +472,7 @@ vi.mock("react-virtuoso", () => ({
return (
<div data-testid="virtuoso-mock">
{data.map((item, i) => (
- <div key={i}>{itemContent(i, item) as React.ReactElement}</div>
+ <div key={computeItemKey(i, item)}>{itemContent(i, item) as React.ReactElement}</div>
))}
</div>
);
@@ -2975,6 +2979,47 @@ describe("IssueDetail (shared)", () => {
});
});
+ it("keeps the initial assignment block before a later mention and its run (MUL-7632)", async () => {
+ const assignment: AgentTask = {
+ id: "initial-assignment", agent_id: "agent-1", runtime_id: "rt-1", issue_id: "issue-1",
+ kind: "direct", status: "running", priority: 0,
+ created_at: "2026-01-16T00:00:00Z", started_at: "2026-01-16T00:00:00Z",
+ dispatched_at: null, completed_at: null, result: null, error: null, delivered_comment_ids: [],
+ };
+ mockApiObj.listTimeline.mockResolvedValue([]);
+ mockApiObj.listTasksByIssue.mockResolvedValue([assignment]);
+ const client = createTestQueryClient();
+ const { container } = render(
+ <I18nProvider locale="en" resources={TEST_RESOURCES}>
+ <QueryClientProvider client={client}>
+ <IssueDetail issueId="issue-1" defaultSidebarOpen={false} />
+ </QueryClientProvider>
+ </I18nProvider>,
+ );
+ await waitFor(() => expect(container.querySelector('[data-run-slot-id="initial-assignment"]')).not.toBeNull());
+ const initialSlot = container.querySelector('[data-run-slot-id="initial-assignment"]')!;
+ const mention: TimelineEntry = {
+ type: "comment", id: "later-mention", actor_type: "member", actor_id: "user-1",
+ content: "Please handle the other task", parent_id: null, created_at: "2026-01-16T00:01:00Z",
+ };
+ const mentionedRun: AgentTask = {
+ ...assignment, id: "mentioned-run", agent_id: "agent-2", trigger_comment_id: mention.id,
+ created_at: "2026-01-16T00:01:01Z", delivered_comment_ids: [mention.id],
+ };
+ mockApiObj.listTimeline.mockResolvedValue([mention]);
+ mockApiObj.listTasksByIssue.mockResolvedValue([assignment, mentionedRun]);
+ act(() => {
+ client.setQueryData(issueKeys.timeline("issue-1"), [mention]);
+ client.setQueryData(issueKeys.tasks("issue-1"), [assignment, mentionedRun]);
+ });
+ await screen.findByText(mention.content!);
+ await waitFor(() => expect(container.querySelector('[data-run-id="mentioned-run"]')).not.toBeNull());
+ expect(container.querySelector('[data-run-slot-id="initial-assignment"]')).toBe(initialSlot);
+ const mentionBlock = container.querySelector("#comment-later-mention")!;
+ expect(initialSlot.compareDocumentPosition(mentionBlock) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ expect(mentionBlock.querySelector('[data-run-id="mentioned-run"]')).not.toBeNull();
+ });
+
// MUL-7211 regression: a standalone run's published reply belongs at the
// reply's own time. It used to render in the run's ENQUEUE slot while the
// card showed the reply time, pushing it above every comment written while
diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsx
index fb10f05a47..527cced445 100644
--- a/packages/views/issues/components/issue-detail.tsx
+++ b/packages/views/issues/components/issue-detail.tsx
@@ -1621,8 +1621,8 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
"duplicate_added",
"duplicate_removed",
]);
- // Unanchored runs join the timeline at the time their card shows: a
- // published reply's own time, the live end while still working.
+ // Unanchored runs keep their enqueue-time slot while working, then use
+ // the published reply's time or the run's end time.
const entryById = new Map(displayTimeline.map((entry) => [entry.id, entry]));
const chronological = orderTimelineWithRuns(topLevel, standaloneRuns, entryById);
const coalesced: (TimelineEntry | CommentRun)[] = [];