Skip to content

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

Go

fix(issues): keep a run's comments in the order they were posted (MUL-7548) (#8626)

Bohan Jiang2eef9760f4c7
diff --git a/packages/views/issues/components/comment-card.tsx b/packages/views/issues/components/comment-card.tsx
index 2533577f57..32b48cb4a9 100644
--- a/packages/views/issues/components/comment-card.tsx
+++ b/packages/views/issues/components/comment-card.tsx
@@ -1073,8 +1073,15 @@ function CommentCardImpl({
// over. Every tombstone has at least one live descendant (the server prunes
// one that loses its last reply), so no content hides behind this.
const visibleReplies = allNestedReplies.filter((reply) => !isDeletedComment(reply));
- const slottedReplyIds = new Set(runs.filter((run) => run.hasReply && run.anchorCommentId && run.commentId !== entry.id)
- .map((run) => run.commentId));
+ // A run anchored here renders in one slot after its input, ending with its
+ // reply (the run's latest comment). The rest of what the run posted in this
+ // thread joins that slot in posting order; left in the chronological list,
+ // it would render after the reply it preceded (MUL-7548).
+ const slottedRuns = runs.filter((run) => run.hasReply && run.anchorCommentId && run.commentId !== entry.id);
+ const runOutputs = new Map(slottedRuns.map((run) => [run.task.id,
+ allNestedReplies.filter((reply) => reply.actor_type === "agent" && reply.source_task_id === run.task.id)]));
+ const slottedReplyIds = new Set(slottedRuns.flatMap((run) =>
+ [run.commentId, ...(runOutputs.get(run.task.id) ?? []).map((reply) => reply.id)]));
const renderRuns = (commentId: string, presentation: "inline" | "header" = "inline") => runs.filter((run) => run.commentId === commentId && run.hasReply
&& showCommentRunInHeader(run) === (presentation === "header")
&& (!run.anchorCommentId || run.anchorCommentId === commentId || replyFolded))
@@ -1084,13 +1091,52 @@ function CommentCardImpl({
&& !(replyFolded && run.hasReply))
.map((run) => {
const reply = run.hasReply ? allNestedReplies.find((entry) => entry.id === run.commentId) : undefined;
- return <Fragment key={run.task.id}><AgentRunComment run={run} entering={enteringRunIds?.has(run.task.id)} commentProps={reply ? {
- issueId, entry: reply, replies: [], currentUserId, canModerate, onReply, onEdit, onDelete,
- onToggleReaction, onCreateSubIssue, onResolveToggle, onCopyLink, highlightedCommentId, enteringRunIds,
- onLocateComment,
- } : undefined} />{reply && reply.id !== commentId && renderAnchoredRuns(reply.id)}</Fragment>;
+ return <Fragment key={run.task.id}>
+ {runOutputs.get(run.task.id)?.filter((output) => output.id !== run.commentId).map(renderReply)}
+ <AgentRunComment run={run} entering={enteringRunIds?.has(run.task.id)} commentProps={reply ? {
+ issueId, entry: reply, replies: [], currentUserId, canModerate, onReply, onEdit, onDelete,
+ onToggleReaction, onCreateSubIssue, onResolveToggle, onCopyLink, highlightedCommentId, enteringRunIds,
+ onLocateComment,
+ } : undefined} />{reply && reply.id !== commentId && renderAnchoredRuns(reply.id)}</Fragment>;
});
+ const renderReply = (reply: TimelineEntry) => (
+ <Fragment key={reply.id}>
+ {/* A tombstone keeps its place in the walk — runs anchored to
+ it still render — but contributes no row of its own. */}
+ {!isDeletedComment(reply) && (
+ <div
+ id={`comment-${reply.id}`}
+ className={cn(
+ "border-t border-border/50 transition-colors duration-700",
+ highlightedCommentId === reply.id && highlightedCommentBackgroundClass,
+ )}
+ >
+ <CommentRow
+ issueId={issueId}
+ entry={reply}
+ runHeader={renderRuns(reply.id, "header")}
+ runMetadata={renderRuns(reply.id)}
+ currentUserId={currentUserId}
+ canModerate={canModerate}
+ isResolution={reply.id === replyResolutionId}
+ isHighlighted={highlightedCommentId === reply.id}
+ hasReplies={repliedToIds.has(reply.id)}
+ onEdit={onEdit}
+ onDelete={onDelete}
+ onToggleReaction={onToggleReaction}
+ onCreateSubIssue={onCreateSubIssue}
+ onResolveToggle={onResolveToggle}
+ onCopyLink={onCopyLink}
+ deliveryRepliesByTask={deliveryRepliesByTask}
+ onLocateComment={onLocateComment}
+ />
+ </div>
+ )}
+ {renderAnchoredRuns(reply.id)}
+ </Fragment>
+ );
+
const replyCount = visibleReplies.length;
const repliedToIds = new Set(allNestedReplies.map((reply) => reply.parent_id));
const deleted = isDeletedComment(entry);
@@ -1495,42 +1541,7 @@ function CommentCardImpl({
</button>
)}
{/* Replies — chronological; the resolution keeps its place with a badge */}
- {allNestedReplies.filter((reply) => !slottedReplyIds.has(reply.id)).map((reply) => (
- <Fragment key={reply.id}>
- {/* A tombstone keeps its place in the walk — runs anchored to
- it still render — but contributes no row of its own. */}
- {!isDeletedComment(reply) && (
- <div
- id={`comment-${reply.id}`}
- className={cn(
- "border-t border-border/50 transition-colors duration-700",
- highlightedCommentId === reply.id && highlightedCommentBackgroundClass,
- )}
- >
- <CommentRow
- issueId={issueId}
- entry={reply}
- runHeader={renderRuns(reply.id, "header")}
- runMetadata={renderRuns(reply.id)}
- currentUserId={currentUserId}
- canModerate={canModerate}
- isResolution={reply.id === replyResolutionId}
- isHighlighted={highlightedCommentId === reply.id}
- hasReplies={repliedToIds.has(reply.id)}
- onEdit={onEdit}
- onDelete={onDelete}
- onToggleReaction={onToggleReaction}
- onCreateSubIssue={onCreateSubIssue}
- onResolveToggle={onResolveToggle}
- onCopyLink={onCopyLink}
- deliveryRepliesByTask={deliveryRepliesByTask}
- onLocateComment={onLocateComment}
- />
- </div>
- )}
- {renderAnchoredRuns(reply.id)}
- </Fragment>
- ))}
+ {allNestedReplies.filter((reply) => !slottedReplyIds.has(reply.id)).map(renderReply)}
{/* Reply input */}
<div className="border-t border-border/50 px-4 max-md:px-3 py-2.5">
diff --git a/packages/views/issues/components/comment-runs.test.ts b/packages/views/issues/components/comment-runs.test.ts
index f14dcf0b65..813b430919 100644
--- a/packages/views/issues/components/comment-runs.test.ts
+++ b/packages/views/issues/components/comment-runs.test.ts
@@ -159,6 +159,23 @@ describe("groupCommentRuns", () => {
expect(timeline.find((entry) => entry.id === "assigned-answer")?.parent_id).toBe("root");
});
+ it("moves a run's earlier top-level comments into the thread with its reply", () => {
+ // MUL-7548: only the latest comment used to move under the trigger, so it
+ // rendered above the run's earlier top-level comments.
+ const run = task("run", { trigger_comment_id: "confirm", delivered_comment_ids: ["confirm"] });
+ const timeline = [comment("confirm"),
+ comment("other-thread"),
+ comment("step2", { actor_type: "agent", source_task_id: run.id, created_at: "2026-09-07T00:01:00Z" }),
+ comment("fan-out", { parent_id: "other-thread", actor_type: "agent", source_task_id: run.id, created_at: "2026-09-07T00:02:00Z" }),
+ comment("step3", { actor_type: "agent", source_task_id: run.id, created_at: "2026-09-07T00:03:00Z" })];
+ const view = buildCommentRunView([run], timeline);
+ const parentOf = (id: string) => view.timeline.find((entry) => entry.id === id)?.parent_id;
+ expect(parentOf("step2")).toBe("confirm");
+ expect(parentOf("step3")).toBe("confirm");
+ expect(parentOf("fan-out")).toBe("other-thread");
+ expect(view.runs.get("confirm")).toEqual([{ task: run, commentId: "step3", anchorCommentId: "confirm", hasReply: true }]);
+ });
+
it("does not project reply relationships that would create a comment cycle", () => {
const first = task("first", { trigger_comment_id: "b" });
const second = task("second", { trigger_comment_id: "a" });
diff --git a/packages/views/issues/components/comment-runs.ts b/packages/views/issues/components/comment-runs.ts
index a093db9d7f..f9d5f02653 100644
--- a/packages/views/issues/components/comment-runs.ts
+++ b/packages/views/issues/components/comment-runs.ts
@@ -95,6 +95,13 @@ export function buildCommentRunView(
return entry?.id;
};
const replies = agentReplyByTask(timeline);
+ const topLevelOutputs = new Map<string, TimelineEntry[]>();
+ for (const entry of comments.values()) {
+ if (!entry.source_task_id || entry.actor_type !== "agent" || entry.parent_id) continue;
+ const outputs = topLevelOutputs.get(entry.source_task_id) ?? [];
+ outputs.push(entry);
+ topLevelOutputs.set(entry.source_task_id, outputs);
+ }
const byTask = new Map(inlineTasks.map((task) => [task.id, task]));
const priorAnchors = new Map([...previous.values()].flatMap((runs) => runs.map((run) => [run.task.id, run.anchorCommentId] as const)));
const placements: CommentRun[] = [];
@@ -150,9 +157,13 @@ export function buildCommentRunView(
// Project every task-owned answer first, then use that same tree for run
// grouping, replies, resolution, and navigation. Assignment answers become
// roots even if the agent originally posted them inside an existing thread.
+ // The run's other top-level comments follow its reply: moving only the
+ // latest one would render it above the progress posted before it (MUL-7548).
+ // Comments the agent placed in a thread stay where it put them.
const parents = new Map<string, string | undefined>();
for (const run of placements) {
if (run.hasReply && run.commentId && run.commentId !== run.anchorCommentId) {
+ for (const output of topLevelOutputs.get(run.task.id) ?? []) parents.set(output.id, run.anchorCommentId);
parents.set(run.commentId, run.anchorCommentId);
}
}
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsx
index 6ecd0bf16d..4d8f907ef9 100644
--- a/packages/views/issues/components/issue-detail.test.tsx
+++ b/packages/views/issues/components/issue-detail.test.tsx
@@ -3103,6 +3103,43 @@ describe("IssueDetail (shared)", () => {
expect(rendered.indexOf("comment-midway")).toBeLessThan(rendered.indexOf("comment-run-reply"));
});
+ // MUL-7548 regression: a comment-triggered run that posts several comments
+ // used to render its latest one first — the run slot after the trigger held
+ // only the latest, and the earlier ones followed it (or stayed top-level).
+ it.each([
+ { placement: "top-level", parentId: null },
+ { placement: "in the trigger's thread", parentId: "confirm" },
+ ])("renders every comment of a run in posting order when posted $placement", async ({ parentId }) => {
+ const agentComment = (id: string, content: string, created_at: string): TimelineEntry => ({
+ type: "comment", id, actor_type: "agent", actor_id: "agent-1", content, parent_id: parentId,
+ source_task_id: "task-steps", created_at, updated_at: created_at, comment_type: "comment",
+ });
+ mockApiObj.listTimeline.mockResolvedValue([
+ {
+ type: "comment", id: "confirm", actor_type: "member", actor_id: "user-1",
+ content: "Confirmed", parent_id: null,
+ created_at: "2026-01-17T00:00:00Z", updated_at: "2026-01-17T00:00:00Z", comment_type: "comment",
+ },
+ agentComment("step2", "Step 2 done", "2026-01-17T00:10:00Z"),
+ agentComment("step3", "Step 3 done", "2026-01-17T00:20:00Z"),
+ ]);
+ mockApiObj.listTasksByIssue.mockResolvedValue([{
+ id: "task-steps", agent_id: "agent-1", runtime_id: "rt-1", issue_id: "issue-1",
+ kind: "issue", status: "running", priority: 0,
+ dispatched_at: "2026-01-17T00:00:01Z", started_at: "2026-01-17T00:00:01Z",
+ completed_at: null, result: null, error: null,
+ created_at: "2026-01-17T00:00:01Z", trigger_comment_id: "confirm", delivered_comment_ids: ["confirm"],
+ }]);
+
+ const { container } = renderIssueDetail();
+ await screen.findByText("Step 2 done");
+ await screen.findByText("Step 3 done");
+
+ const rendered = Array.from(container.querySelectorAll("[id^='comment-']")).map((el) => el.id)
+ .filter((id) => ["comment-confirm", "comment-step2", "comment-step3"].includes(id));
+ expect(rendered).toEqual(["comment-confirm", "comment-step2", "comment-step3"]);
+ });
+
});
describe("groupSubIssuesByStage", () => {