Files
PaperClipAI/ui
DottaandPaperclip 8abbf84fc7 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>
2026-12-04 18:24:02 -06:00
..
…

@paperclipai/ui

Published static assets for the Paperclip board UI.

What gets published

The npm package contains the production build under dist/. It does not ship the UI source tree or workspace-only dependencies.

Storybook

Storybook config, stories, and fixtures live under ui/storybook/.

pnpm --filter @paperclipai/ui storybook
pnpm --filter @paperclipai/ui build-storybook

Typical use

Install the package, then serve or copy the built files from node_modules/@paperclipai/ui/dist.

Editor dependency identity

Keep the root and workspace overrides for @codemirror/state, @codemirror/view, and @lezer/common aligned. CodeMirror requires shared extension identity, while Lezer parsers and syntax highlighters require shared NodeProp IDs. Multiple Lezer copies can crash code-block highlighting with tags is not iterable. src/lib/codemirror-single-instance.test.ts checks the installed dependency graph and highlights sample code through the editor's real language dependencies. GitHub Actions owns regeneration of pnpm-lock.yaml.