mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 14:35:17 +01:00
fix(chat): keep a turn's progress messages apart in the conversation view (#20818)
# Branch Nevysha:fix/task-chat-progress-message-breaks → paperclipai:master # Body ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The task chat shows an agent's live run, including the short progress messages that the agent writes between tool calls > - The paperclip runner streams a whole provider turn under one assistant item, so all progress messages in a turn have the same `itemId` > - For a run that started before the page opened, the task page loads the conversation event view (#17593). This view returns only the text deltas, without the tool calls that normally separate the messages > - The transcript adapter joins consecutive deltas with the same `itemId`, so the whole turn becomes one block with no space between sentences > - This pull request starts a new paragraph when a delta comes from a different provider message than the delta just before it > - The benefit is that the live task chat stays readable for runs that started before the page opened ## Linked Issues or Issue Description Fixes #20812 Refs #17593 ## What Changed - `nativeRunEventsToTranscript()` reads the provider message id of each assistant delta (`providerItemId`, at the top level or in `update`). - When a delta continues the same item directly after the previous assistant delta, but comes from a different provider message, the delta text starts with a paragraph break (`\n\n`). - The change does not apply when another entry (for example a tool call) is between the two deltas. The adapter already shows those messages as separate rows. - The change does not apply when the delta has no provider message id. Those deltas join as before. - Added three tests to `native-run-events.test.ts`: the conversation-only case, the case with a tool call between the messages, and deltas without a provider message id. ## Verification - `cd ui && npx vitest run src/components/transcript/native-run-events.test.ts`: 86 tests pass. The new conversation-only test fails without the fix. - `cd ui && npx vitest run src/components/transcript/ src/components/task-chat/ src/lib/issue-chat-messages.test.ts src/components/TaskChatThread`: 76 files, 1618 tests pass, 1 skipped. - `cd ui && pnpm typecheck` passes. - I ran the projection on the events of a real run (paperclip_runner with Claude Code, about 35 progress messages in one turn): - Conversation view: before the fix, 1 message with no breaks. After the fix, 1 message with the progress messages as separate paragraphs. - Full event list: 36 message rows before and after the fix. No row starts with a line break. - I did not run the full `pnpm -r typecheck`, `pnpm test:run` and `pnpm build`. The CI gates run them. ## Risks - Low risk. The change applies only to assistant deltas that continue the same item and come from a different provider message. - The first delta of each new message now starts with `\n\n`. Markdown shows this as a new paragraph. `flattenSelfTalk()` changes it to one space. - Runners and adapters that do not send a provider message id keep the current behavior. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`, Anthropic), in Claude Code with tool use (shell commands, file reads and edits). It found the cause, wrote the change and the tests, and ran the checks. A human reviewed the change. ## 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 - [x] I have updated relevant documentation to reflect my changes (no documentation change is necessary) - [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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65614fa87e
commit
1cd359408d
2 files changed
+82
-1
No files matched your search
@@ -1523,6 +1523,63 @@ describe("edit diffs", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("assistant progress messages that share one streamed item", () => {
|
||||
const ITEM = "acpx-assistant-turn-1";
|
||||
const delta = (seq: number, messageId: string, text: string) =>
|
||||
itemEvent(seq, "item.delta", ITEM, {
|
||||
kind: "agentMessage",
|
||||
channel: "unknown",
|
||||
text,
|
||||
update: { kind: "agentMessage", channel: "progress", providerItemId: messageId, text, delta: text },
|
||||
});
|
||||
const toolStarted = (seq: number) =>
|
||||
event(seq, "tool.execution.started", {
|
||||
schema: "paperclip.tool.execution.v1",
|
||||
executionId: `exec-${seq}`,
|
||||
transport: "process",
|
||||
operation: "execute",
|
||||
name: "rg wars",
|
||||
status: "running",
|
||||
output: null,
|
||||
outputBytes: 0,
|
||||
outputTruncated: false,
|
||||
outputDigest: null,
|
||||
});
|
||||
const messages = (events: HeartbeatRunEvent[]) =>
|
||||
transcriptToTaskChatItems(nativeRunEventsToTranscript(events), {
|
||||
runId: RUN_ID,
|
||||
agentName: "Engineer",
|
||||
running: true,
|
||||
}).flatMap((item) => (item.kind === "message" ? [item.text] : []));
|
||||
|
||||
it("starts each provider message on a new paragraph in the conversation-only view", () => {
|
||||
expect(messages([
|
||||
delta(1, "msg_a", "Reading the cor"),
|
||||
delta(2, "msg_a", "p lists."),
|
||||
delta(3, "msg_b", "Still reading:"),
|
||||
delta(4, "msg_b", " next is the registry."),
|
||||
delta(5, "msg_c", "\nContext gathered."),
|
||||
])).toEqual([
|
||||
"Reading the corp lists.\n\nStill reading: next is the registry.\nContext gathered.",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps messages that a tool call separates as their own rows without extra breaks", () => {
|
||||
expect(messages([
|
||||
delta(1, "msg_a", "Reading the corp lists."),
|
||||
toolStarted(2),
|
||||
delta(3, "msg_b", "Still reading."),
|
||||
])).toEqual(["Reading the corp lists.", "Still reading."]);
|
||||
});
|
||||
|
||||
it("joins deltas without a provider message id as before", () => {
|
||||
expect(messages([
|
||||
itemEvent(1, "item.delta", ITEM, { kind: "agentMessage", channel: "progress", text: "Reading" }),
|
||||
itemEvent(2, "item.delta", ITEM, { kind: "agentMessage", channel: "progress", text: " the code." }),
|
||||
])).toEqual(["Reading the code."]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("an OpenCode reply settled from an answer and a closing line", () => {
|
||||
it("shows the saved reply once, without the answer repeated as progress", () => {
|
||||
const answer = "Two inbox items need you: [COM-2](/COM/issues/COM-2) and [COM-1](/COM/issues/COM-1).";
|
||||
|
||||
@@ -49,6 +49,10 @@ function normalizedItemText(payload: Record<string, unknown>): string | null {
|
||||
return text(payload.text) ?? text(item.text);
|
||||
}
|
||||
|
||||
function providerMessageId(payload: Record<string, unknown>): string | null {
|
||||
return text(payload.providerItemId) ?? text(record(payload.update)?.providerItemId);
|
||||
}
|
||||
|
||||
function assistantChannel(
|
||||
payload: Record<string, unknown>,
|
||||
fallback: "progress" | "final" | "unknown" = "unknown",
|
||||
@@ -990,6 +994,9 @@ export function nativeRunEventsToTranscript(events: readonly HeartbeatRunEvent[]
|
||||
let usageSinceLastCompaction = false;
|
||||
const proposalMarkdownById = new Map<string, string>();
|
||||
const completedProposalIds = new Set<string>();
|
||||
let lastAssistantDeltaIndex = -1;
|
||||
let lastAssistantDeltaItemId: string | null = null;
|
||||
let lastAssistantDeltaMessageId: string | null = null;
|
||||
for (const event of orderedEvents) {
|
||||
const envelope = record(event.payload?.prpEvent);
|
||||
if (
|
||||
@@ -1060,7 +1067,24 @@ export function nativeRunEventsToTranscript(events: readonly HeartbeatRunEvent[]
|
||||
// Before that point the deltas still provide the live streaming view.
|
||||
if (completedAgentMessageIds.has(itemId)) continue;
|
||||
const channel = itemIdentity.assistantChannel;
|
||||
entries.push({ kind: "assistant", ts, text: value, delta: true, channel, itemId });
|
||||
const messageId = providerMessageId(payload);
|
||||
const startsNewMessage =
|
||||
lastAssistantDeltaIndex === entries.length - 1
|
||||
&& lastAssistantDeltaItemId === itemId
|
||||
&& messageId !== null
|
||||
&& lastAssistantDeltaMessageId !== null
|
||||
&& messageId !== lastAssistantDeltaMessageId;
|
||||
entries.push({
|
||||
kind: "assistant",
|
||||
ts,
|
||||
text: startsNewMessage && !value.startsWith("\n") ? `\n\n${value}` : value,
|
||||
delta: true,
|
||||
channel,
|
||||
itemId,
|
||||
});
|
||||
lastAssistantDeltaIndex = entries.length - 1;
|
||||
lastAssistantDeltaItemId = itemId;
|
||||
lastAssistantDeltaMessageId = messageId;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user