fix(ui): stop coalescing native runner turns across consecutive agent replies (#23799)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Agent chats and task threads assemble settled runs and reply bubbles
through `TaskChatThread` and
`ui/src/components/task-chat/transcript-adapter.ts`.
> - Native Paperclip Runner turns set `standaloneHeader: true` and
render an open chronological timeline (`beforeTurn`) above their reply
bubble, including provider progress commentary such as "I'll check...".
> - `coalesceSettledTurns` was designed for legacy collapsed "Worked"
footers and merged back-to-back same-agent turns across intermediate
agent bubbles, including native `standaloneHeader` turns and cross-task
`send_chat_message` updates.
> - When an agent completed several consecutive automated runs without
an intervening user message, every earlier run's progress commentary
moved off its original reply and piled up above the newest reply, making
the commentary list stick to the bottom of the chat.
> - `attachSettledTurns` also attached settled turns to any preceding
same-agent bubble without checking anchor ownership, allowing unanchored
native turns or turns with their own `finalResponse` to attach above an
earlier reply or cross-task message.
> - This pull request stops `coalesceSettledTurns` from merging
`standaloneHeader` turns (and stops legacy coalescing across
`fast_response` and `chatMessage` bubbles) and enforces explicit
`anchorCommentId` ownership checks in `attachSettledTurns`.
> - The benefit is that each native runner turn keeps its own commentary
and timeline on its own reply bubble, while legacy collapsed footer
coalescing keeps its existing behavior.

## Linked Issues or Issue Description

**What happened?**

In Agent Chat (and any task thread with consecutive native Paperclip
Runner runs from the same agent), when an agent runs several times in a
row without an intervening user message (for example, consecutive
automated follow-up wakes and cross-task `send_chat_message` updates),
every prior run's provider progress commentary (such as "I'll check the
latest result...") is removed from its original reply and stacked
together above the newest reply bubble. Whenever a new run finishes, the
accumulated commentary block moves down again to the newest reply,
making earlier "I'll check..." messages appear sticky at the bottom of
the chat.

**Expected behavior**

Each native Paperclip Runner turn keeps its own chronological timeline
and progress commentary attached only to its own reply bubble (or stays
standalone in chronological order when unanchored). Earlier runs'
commentary never accumulates or moves onto later replies.

**Steps to reproduce**

1. Open a persistent Agent Chat or task thread for an agent running on
the native Paperclip Runner with a provider that emits progress
commentary (`channel: "progress"`).
2. Let the agent complete two or more consecutive runs without an
intervening user message (for example, automated task-completion wakes
with optional cross-task `send_chat_message` updates in between), with
their settled transcripts loaded.
3. Observe that the earlier reply loses its own commentary and the
newest reply renders every prior run's commentary stacked above its
body.

**Paperclip version or commit**

Reproduced on `master` (commit `306437a2a5`).

**Deployment mode**

Self-hosted server

## What Changed

- Require `anchorCommentId: string | null` on `SettledTurnMergeMeta` in
`ui/src/components/task-chat/transcript-adapter.ts`, and populate it
from `TaskChatThread` (`ui/src/components/TaskChatThread.tsx`) and
`ui/src/components/design-sandbox/settled-preview-reply.ts`.
- Update `coalesceSettledTurns` in
`ui/src/components/task-chat/transcript-adapter.ts` so
`standaloneHeader` (native Paperclip Runner) turns never coalesce across
runs or replies, and so legacy turn coalescing stops at `origin:
"fast_response"` and cross-task `chatMessage` bubbles.
- Update `attachSettledTurns` in
`ui/src/components/task-chat/transcript-adapter.ts` so turns carrying
`finalResponse` never attach to a preceding bubble, cross-task
`chatMessage` bubbles never accept an attached turn, and
`standaloneHeader` turns attach only when `meta.anchorCommentId ===
prev.id`.
- Add red-then-green regression tests in
`ui/src/components/task-chat/transcript-adapter.test.ts` and
`ui/src/components/TaskChatThread.test.tsx` covering consecutive native
runner turns, interleaved cross-task `chatMessage` bubbles,
`fast_response` boundaries, unanchored/mismatched `standaloneHeader`
turns, and `finalResponse` turns.

## Verification

- Confirmed red before the fix and green after the fix:
- `pnpm vitest run
ui/src/components/task-chat/transcript-adapter.test.ts
ui/src/components/TaskChatThread.test.tsx` (failed 3 unit tests + 1
component test before the fix; passed after the fix).
- `pnpm vitest run ui/src/components/task-chat/
ui/src/components/TaskChatThread.test.tsx
ui/src/pages/IssueDetail.agentChatPanel.test.tsx` (30 test files passed,
962 passed, 1 skipped on latest head `13e71a2e58`).
- `pnpm --filter @paperclipai/ui typecheck` (passed with 0 errors on
latest head `13e71a2e58`).

## Risks

Low risk. Legacy collapsed-footer turns (`standaloneHeader` falsy) keep
their existing back-to-back coalescing behavior across consecutive
replies from the same agent. Native `standaloneHeader` turns now remain
scoped to their own reply bubble or chronological slot instead of
merging across turns.

## Model Used

- Google Gemini (Antigravity, high reasoning effort, with code
inspection, file editing, test execution, and API diagnostics).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-12-04 18:24:02 -06:00
1 parent f23af2e079
commit 8abbf84fc7
5 files changed
+289 -13

No files matched your search

+108
View File
@@ -6418,3 +6418,111 @@ it("explains a missing provider runtime with an installation repair", () => {
expect(container.textContent).toContain("Reinstall or rebuild Paperclip");
expect(container.textContent).toContain("test the agent's runtime");
});
it("keeps each consecutive native runner turn's progress commentary on its own reply instead of stacking onto the latest message", () => {
nativeTranscriptState.transcriptByRun.set("codie-run-1", [
assistantEntry("2026-12-04T17:18:17.000Z", "I'll check the setup task's final notes.", "progress"),
assistantEntry("2026-12-04T17:18:39.000Z", "PAP-7268 is complete (first update).", "final"),
]);
nativeTranscriptState.transcriptByRun.set("codie-run-2", [
assistantEntry("2026-12-04T17:52:43.000Z", "I'll check the latest saved result for PAP-7268.", "progress"),
assistantEntry("2026-12-04T17:53:12.000Z", "PAP-7268 is Done (second update).", "final"),
]);
const codie = { id: "agent-codie", name: "Codie", urlKey: "codie", icon: null } as unknown as Agent;
renderThread({
issueId: "chat-codie",
conversationMode: true,
agentMap: new Map([[codie.id, codie]]),
comments: [
{
id: "reply-1",
companyId: "company-1",
issueId: "chat-codie",
authorType: "agent",
authorAgentId: codie.id,
authorUserId: null,
body: "PAP-7268 is complete (first update).",
presentation: null,
metadata: null,
runId: "codie-run-1",
createdByRunId: "codie-run-1",
createdAt: new Date("2026-12-04T17:18:41.000Z"),
updatedAt: new Date("2026-12-04T17:18:41.000Z"),
},
{
id: "cross-task-msg",
companyId: "company-1",
issueId: "chat-codie",
authorType: "agent",
authorAgentId: codie.id,
authorUserId: null,
body: "- Native recovery PR #23696 merged.",
presentation: null,
metadata: {
version: 1,
sections: [],
chatMessage: {
sourceTaskId: "task-7354",
sourceTaskIdentifier: "PAP-7354",
sourceRunId: "other-task-run",
contentHash: "hash-1",
},
},
runId: "other-task-run",
createdByRunId: "other-task-run",
createdAt: new Date("2026-12-04T17:35:00.000Z"),
updatedAt: new Date("2026-12-04T17:35:00.000Z"),
},
{
id: "reply-2",
companyId: "company-1",
issueId: "chat-codie",
authorType: "agent",
authorAgentId: codie.id,
authorUserId: null,
body: "PAP-7268 is Done (second update).",
presentation: null,
metadata: null,
runId: "codie-run-2",
createdByRunId: "codie-run-2",
createdAt: new Date("2026-12-04T17:53:15.000Z"),
updatedAt: new Date("2026-12-04T17:53:15.000Z"),
},
],
onAdd: async () => {},
linkedRuns: [
{
runId: "codie-run-1",
runtimeMode: "native",
status: "succeeded",
agentId: codie.id,
agentName: "Codie",
adapterType: "paperclip_runner",
createdAt: "2026-12-04T17:17:24.000Z",
startedAt: "2026-12-04T17:17:24.000Z",
finishedAt: "2026-12-04T17:18:39.000Z",
execution: { phase: "completed", label: "Completed", canStop: false, cause: null, lastConfirmedActivityAt: null, retryAt: null, attempt: 1, maxAttempts: 3, recoveryOwner: null, nextAction: null, permittedActions: [], predecessorRunId: null, successorRunId: null },
},
{
runId: "codie-run-2",
runtimeMode: "native",
status: "succeeded",
agentId: codie.id,
agentName: "Codie",
adapterType: "paperclip_runner",
createdAt: "2026-12-04T17:52:00.000Z",
startedAt: "2026-12-04T17:52:00.000Z",
finishedAt: "2026-12-04T17:53:12.000Z",
execution: { phase: "completed", label: "Completed", canStop: false, cause: null, lastConfirmedActivityAt: null, retryAt: null, attempt: 1, maxAttempts: 3, recoveryOwner: null, nextAction: null, permittedActions: [], predecessorRunId: null, successorRunId: null },
},
],
});
const firstCommentEl = container.querySelector("#comment-reply-1");
const secondCommentEl = container.querySelector("#comment-reply-2");
expect(firstCommentEl?.textContent).toContain("I'll check the setup task's final notes.");
expect(firstCommentEl?.textContent).not.toContain("I'll check the latest saved result for PAP-7268.");
expect(secondCommentEl?.textContent).toContain("I'll check the latest saved result for PAP-7268.");
expect(secondCommentEl?.textContent).not.toContain("I'll check the setup task's final notes.");
});
+11 -7
View File
@@ -2038,6 +2038,7 @@ export function TaskChatThread(props: TaskChatThreadProps) {
turnMergeMetaById.set(turnId, {
agentKey: meta?.agentId ?? "",
agentName: meta?.agentName,
anchorCommentId: null,
parts: [{ entries, durationMs, failed }],
});
settledTurns.push({
@@ -2251,9 +2252,17 @@ export function TaskChatThread(props: TaskChatThreadProps) {
Number.isFinite(segment.startMs) && Number.isFinite(segmentFinishedMs)
? Math.max(0, segmentFinishedMs - segment.startMs)
: durationMs;
const anchorCommentId = segmented
? null
: sourceIsPaperclipRunner
? sourceHasPresentationComment
? sourcePresentationCommentId
: null
: (lastCommentIdByRun.get(source.id) ?? null);
turnMergeMetaById.set(turnId, {
agentKey: meta?.agentId ?? "",
agentName: meta?.agentName,
anchorCommentId,
parts: [
{ entries: segment.entries, durationMs: segmentDurationMs, failed },
],
@@ -2283,13 +2292,7 @@ export function TaskChatThread(props: TaskChatThreadProps) {
failed,
}),
},
anchorCommentId: segmented
? null
: sourceIsPaperclipRunner
? sourceHasPresentationComment
? sourcePresentationCommentId
: null
: (lastCommentIdByRun.get(source.id) ?? null),
anchorCommentId,
// A post-steering segment ties the acknowledgement-backed human
// bubble and is therefore inserted immediately after it. The first
// segment retains the normal run-start slot.
@@ -2346,6 +2349,7 @@ export function TaskChatThread(props: TaskChatThreadProps) {
turnMergeMetaById.set(turnId, {
agentKey: liveRun.agentId ?? "",
agentName: liveRun.agentName,
anchorCommentId: null,
parts: [
{
entries: segment.entries,
@@ -9,5 +9,5 @@ export function settledPreviewReply(response: TaskChatMessageItem, entries: Para
id: `${runId}:turn`, kind: "turn", settled: true, historical: true,
items: settledRunChildren(parsed), summary: buildTurnSummary(entries, { durationMs, failed }),
};
return attachSettledTurns([response, turn], new Map([[turn.id, { agentKey: "synthetic-agent", agentName: response.authorName, parts: [{ entries, durationMs, failed }] }]]));
return attachSettledTurns([response, turn], new Map([[turn.id, { agentKey: "synthetic-agent", agentName: response.authorName, anchorCommentId: null, parts: [{ entries, durationMs, failed }] }]]));
}
@@ -2558,6 +2558,7 @@ describe("coalesceSettledTurns (PAP-362)", () => {
{
agentKey: "agent-1",
agentName: "CEO",
anchorCommentId: null,
parts: [{ entries: runA, durationMs: 30_000 }],
},
],
@@ -2566,6 +2567,7 @@ describe("coalesceSettledTurns (PAP-362)", () => {
{
agentKey: "agent-1",
agentName: "CEO",
anchorCommentId: null,
parts: [{ entries: runB, durationMs: 15_000 }],
},
],
@@ -2628,6 +2630,7 @@ describe("coalesceSettledTurns (PAP-362)", () => {
otherAgent.set("run-b:turn", {
agentKey: "agent-2",
agentName: "QA",
anchorCommentId: null,
parts: [{ entries: runB }],
});
const sameShape: TaskChatItem[] = [
@@ -2643,8 +2646,8 @@ describe("coalesceSettledTurns (PAP-362)", () => {
it("lets another agent's chat message end the merge when runs carry no display name", () => {
const unnamed = new Map<string, SettledTurnMergeMeta>([
["run-a:turn", { agentKey: "agent-1", parts: [{ entries: runA, durationMs: 30_000 }] }],
["run-b:turn", { agentKey: "agent-1", parts: [{ entries: runB, durationMs: 15_000 }] }],
["run-a:turn", { agentKey: "agent-1", anchorCommentId: null, parts: [{ entries: runA, durationMs: 30_000 }] }],
["run-b:turn", { agentKey: "agent-1", anchorCommentId: null, parts: [{ entries: runB, durationMs: 15_000 }] }],
]);
const fromAgent = (id: string, agentId: string, authorName: string): TaskChatItem => ({
id, kind: "message", author: "agent", authorName, agent: { id: agentId }, text: "Note.",
@@ -2693,6 +2696,89 @@ describe("coalesceSettledTurns (PAP-362)", () => {
(merged[0] as Extract<TaskChatItem, { kind: "turn" }>).animateFold,
).toBe(true);
});
it("never coalesces standaloneHeader (native runner) turns across consecutive replies", () => {
const nativeTurn = (id: string, commentary: string): TaskChatItem => ({
id,
kind: "turn",
settled: true,
historical: true,
standaloneHeader: true,
items: [
{
id: `${id}:phase:0`,
kind: "activity_phase",
active: false,
summary: "",
interstitial: {
id: `${id}:interstitial:0`,
kind: "message",
author: "agent",
channel: "progress",
interstitial: true,
text: commentary,
},
items: [],
},
],
summary: buildTurnSummary([], { durationMs: 10_000 }),
});
const nativeMeta = new Map<string, SettledTurnMergeMeta>([
["run-1:turn", { agentKey: "codie", agentName: "Codie", anchorCommentId: "msg-1", parts: [{ entries: [], durationMs: 10_000 }] }],
["run-2:turn", { agentKey: "codie", agentName: "Codie", anchorCommentId: "msg-2", parts: [{ entries: [], durationMs: 12_000 }] }],
]);
const items: TaskChatItem[] = [
{ id: "msg-1", kind: "message", author: "agent", authorName: "Codie", agent: { id: "codie" }, text: "First update.", sourceRunId: "run-1" },
nativeTurn("run-1:turn", "I'll check the setup task's final notes."),
{ id: "msg-2", kind: "message", author: "agent", authorName: "Codie", agent: { id: "codie" }, text: "Second update.", sourceRunId: "run-2" },
nativeTurn("run-2:turn", "I'll check the latest saved result for PAP-7268."),
];
const out = coalesceSettledTurns(items, nativeMeta);
expect(out.map((i) => i.id)).toEqual(["msg-1", "run-1:turn", "msg-2", "run-2:turn"]);
const firstTurn = out[1] as Extract<TaskChatItem, { kind: "turn" }>;
const secondTurn = out[3] as Extract<TaskChatItem, { kind: "turn" }>;
expect(firstTurn.items).toHaveLength(1);
expect(secondTurn.items).toHaveLength(1);
});
it("does not coalesce legacy turns across fast_response or cross-task chatMessage bubbles", () => {
const withFastResponse: TaskChatItem[] = [
agentBubble("msg-a"),
turn("run-a:turn", runA, 30_000),
{ id: "msg-fr", kind: "message", author: "agent", authorName: "CEO", origin: "fast_response", text: "On it." },
agentBubble("msg-b"),
turn("run-b:turn", runB, 15_000),
];
expect(coalesceSettledTurns(withFastResponse, metaById).map((i) => i.id)).toEqual([
"msg-a",
"run-a:turn",
"msg-fr",
"msg-b",
"run-b:turn",
]);
const withChatMessage: TaskChatItem[] = [
agentBubble("msg-a"),
turn("run-a:turn", runA, 30_000),
{
id: "msg-cross",
kind: "message",
author: "agent",
authorName: "CEO",
text: "Merged PR #123.",
chatMessage: { sourceTaskId: "task-1", sourceTaskIdentifier: "PAP-7354", sourceRunId: "other-run", contentHash: "abc" },
},
agentBubble("msg-b"),
turn("run-b:turn", runB, 15_000),
];
expect(coalesceSettledTurns(withChatMessage, metaById).map((i) => i.id)).toEqual([
"msg-a",
"run-a:turn",
"msg-cross",
"msg-b",
"run-b:turn",
]);
});
});
describe("attachSettledTurns (round 9)", () => {
@@ -2725,6 +2811,7 @@ describe("attachSettledTurns (round 9)", () => {
{
agentKey: "agent-1",
agentName: "CEO",
anchorCommentId: null,
parts: [{ entries: runA, durationMs: 30_000 }],
},
],
@@ -2771,7 +2858,7 @@ describe("attachSettledTurns (round 9)", () => {
it("matches the bubble's agent ID when the run carries no display name", () => {
const unnamed = new Map<string, SettledTurnMergeMeta>([
["run-a:turn", { agentKey: "agent-1", parts: [{ entries: runA, durationMs: 30_000 }] }],
["run-a:turn", { agentKey: "agent-1", anchorCommentId: null, parts: [{ entries: runA, durationMs: 30_000 }] }],
]);
const fromAgent = (agentId: string, authorName: string): TaskChatItem => ({
id: `msg-${agentId}`, kind: "message", author: "agent", authorName, agent: { id: agentId }, text: "Done.",
@@ -2808,6 +2895,59 @@ describe("attachSettledTurns (round 9)", () => {
(twice[0] as Extract<TaskChatItem, { kind: "message" }>).attachedTurn?.id,
).toBe("run-a:turn");
});
it("never attaches an unanchored or mismatched standaloneHeader turn, finalResponse turn, or cross-task chatMessage bubble", () => {
const standaloneTurn = (id: string, extra?: Partial<TaskChatTurnItem>): TaskChatTurnItem => ({
id,
kind: "turn",
settled: true,
standaloneHeader: true,
items: [],
summary: buildTurnSummary([], { durationMs: 10_000 }),
...extra,
});
const meta = new Map<string, SettledTurnMergeMeta>([
["run-unanchored:turn", { agentKey: "codie", agentName: "Codie", anchorCommentId: null, parts: [] }],
["run-anchored:turn", { agentKey: "codie", agentName: "Codie", anchorCommentId: "msg-1", parts: [] }],
["run-other:turn", { agentKey: "codie", agentName: "Codie", anchorCommentId: "msg-2", parts: [] }],
]);
const bubble1: TaskChatItem = {
id: "msg-1", kind: "message", author: "agent", authorName: "Codie", agent: { id: "codie" }, text: "First reply.", sourceRunId: "run-1",
};
// Unanchored native turn after an earlier reply stays standalone (must not invert above msg-1).
const unanchoredOut = attachSettledTurns([bubble1, standaloneTurn("run-unanchored:turn")], meta);
expect(unanchoredOut.map((i) => i.id)).toEqual(["msg-1", "run-unanchored:turn"]);
// Mismatched anchorCommentId native turn stays standalone.
const mismatchedOut = attachSettledTurns([bubble1, standaloneTurn("run-other:turn")], meta);
expect(mismatchedOut.map((i) => i.id)).toEqual(["msg-1", "run-other:turn"]);
// Turn carrying its own finalResponse never attaches to a preceding bubble.
const withFinal = standaloneTurn("run-anchored:turn", {
finalResponse: { id: "final-1", kind: "message", author: "agent", text: "Own final." },
});
const finalOut = attachSettledTurns([bubble1, withFinal], meta);
expect(finalOut.map((i) => i.id)).toEqual(["msg-1", "run-anchored:turn"]);
// Cross-task send_chat_message bubble never accepts an attached turn.
const crossTaskBubble: TaskChatItem = {
id: "msg-1",
kind: "message",
author: "agent",
authorName: "Codie",
agent: { id: "codie" },
text: "Merged PR #123.",
chatMessage: { sourceTaskId: "task-1", sourceTaskIdentifier: "PAP-7354", sourceRunId: "other-run", contentHash: "abc" },
};
const crossOut = attachSettledTurns([crossTaskBubble, standaloneTurn("run-anchored:turn")], meta);
expect(crossOut.map((i) => i.id)).toEqual(["msg-1", "run-anchored:turn"]);
// Matching anchored native turn attaches cleanly to its own reply bubble.
const matchedOut = attachSettledTurns([bubble1, standaloneTurn("run-anchored:turn")], meta);
expect(matchedOut).toHaveLength(1);
expect((matchedOut[0] as Extract<TaskChatItem, { kind: "message" }>).attachedTurn?.id).toBe("run-anchored:turn");
});
});
describe("assembleThreadItems (PAP-367)", () => {
@@ -2899,6 +3039,7 @@ describe("assembleThreadItems (PAP-367)", () => {
{
agentKey: "agent-1",
agentName: "CEO",
anchorCommentId: null,
parts: [{ entries: [toolCall("Read")], durationMs: 34_000 }],
},
],
@@ -2498,6 +2498,12 @@ export interface SettledTurnMergeMeta {
agentKey: string;
/** Display name, used to keep another agent's bubble from bridging a merge. */
agentName?: string;
/**
* Explicit reply comment id this turn anchored to (`null` = unanchored).
* Keeps unanchored or mismatched standaloneHeader turns from attaching above
* an earlier agent bubble and inverting chronology.
*/
anchorCommentId: string | null;
parts: TurnSummaryPart[];
}
@@ -2542,6 +2548,15 @@ export function coalesceSettledTurns(
let heldIdx = -1; // index in `out` of the last mergeable settled turn
for (const item of items) {
if (item.kind === "turn" && item.settled) {
// Paperclip Runner turns own an open chronological timeline rendered
// above their reply bubble (`beforeTurn`), including progress commentary.
// Never coalesce them across runs or replies: doing so steals earlier
// runs' timelines and stacks every prior commentary onto the newest reply.
if (item.standaloneHeader) {
out.push(item);
heldIdx = -1;
continue;
}
const meta = metaFor(item.id);
const held = heldIdx >= 0 ? (out[heldIdx] as TaskChatTurnItem) : null;
const heldMeta = held ? metaFor(held.id) : undefined;
@@ -2572,7 +2587,12 @@ export function coalesceSettledTurns(
continue;
}
out.push(item);
if (item.kind === "message" && item.author === "agent") {
if (
item.kind === "message" &&
item.author === "agent" &&
item.origin !== "fast_response" &&
!item.chatMessage
) {
// The same agent's reply bubble sits between its runs — keep merging
// across it. A different agent's bubble ends the run of turns.
const heldMeta =
@@ -2608,15 +2628,18 @@ export function attachSettledTurns(
if (
item.kind === "turn" &&
item.settled &&
!item.finalResponse &&
prev?.kind === "message" &&
prev.author === "agent" &&
prev.origin !== "fast_response" &&
!prev.chatMessage &&
!prev.interstitial &&
!prev.streaming &&
prev.attachedTurn == null
) {
const meta = metaById.get(item.id);
if (meta != null && sameTurnAgent(meta, prev)) {
const standaloneOwnershipMatches = !item.standaloneHeader || meta?.anchorCommentId === prev.id;
if (meta != null && sameTurnAgent(meta, prev) && standaloneOwnershipMatches) {
out[out.length - 1] = { ...prev, attachedTurn: item };
continue;
}