Repository navigation
Description
Context
Found while fixing #748 (PR #750). In a Copilot Workspace chat, when the agent calls a frontend tool such as get_page_info, the first run's messages are stored twice in the conversation's history. #748's notes guessed the duplicate came from the attachment thread id mismatch. With that fixed, the duplicate is still there, so it has a different cause. When a chat is reopened it can show the turn twice, and the model reads the repeated turn on later runs.
Seen on the v18 demo site with #750 applied. Rows read from umbracoAIConversationsMessage for one chat (a user message with a PDF, then get_page_info, then a final reply, then a second plain turn):
| seq | stored message |
|---|---|
| 0 | user message (with the file) |
| 1 | assistant get_page_info call, informationalOnly: true, no arguments |
| 2 | tool result "Success: Function completed." |
| 3 | user message again, new message id |
| 4 | assistant get_page_info call again, informationalOnly: false, arguments: {} |
| 5 | the real tool result (url and pathname) |
| 6 | final assistant reply |
| 7-8 | second turn, not duplicated |
So run 1 stores the turn with a placeholder tool result. Run 2 (the frontend tool's resume) then stores it again with the real result, under new message ids. DropAlreadyPersistedLeadingMessagesAsync doesn't drop the resent copy.
What we want
- A frontend tool round trip in a Workspace chat stores the user message, tool call and tool result once.
- The stored tool result is the real one from the browser, not the
"Success: Function completed."placeholder.
Acceptance criteria
- After a turn that calls a frontend tool, the conversation's messages hold the user message, one tool call and one tool result, with no repeats.
- Reopening the chat shows the turn once.
- A test covers a frontend-tool resume and asserts no duplicate is stored.
Notes
- Not checked yet: whether older versions and
v17/devbehave the same, and whether approval resumes (HITL) duplicate the same way. - Related: Copilot workspace: a message with a file attachment fails with "The request was rejected by the AI service" (Anthropic redacted_thinking signature) #748 / fix(copilot-workspace): Keep attachments on later turns by using the conversation id as thread id #750 (different cause), Copilot workspace conversations regularly dying mid stream #375 (the leading-message drop added for dropped connections).
Activity
mattbrailsford commentedon Nov 16, 2026
Notes for the investigation
Resumeentries (AGUIStreamingService.cs, thepersistenceSync?.DropAlreadyPersistedLeadingMessagesbranch).ConversationChatHistoryProvidermatches by message id when both sides have one."Success: Function completed."is not in this repo's source, so where it's written is not checked.v17/devand approval (HITL) resumes are not checked.Umbraco.AI.Agent.Copilot.Workspace/src/Umbraco.AI.Agent.Conversations.Core/Conversations/ConversationChatHistoryProvider.cs:DropAlreadyPersistedLeadingMessagesAsync(~212),IsSameMessage, and the write-sideDropAlreadyPersistedTailAsync(~419) withIsSameContent.Umbraco.AI.Agent/src/Umbraco.AI.Agent.Core/AGUI/AGUIStreamingService.cs: the resume branch versus the plain-turn branch.server-persisted-conversation.strategy.ts, whereoutboundsends everything after#persisted.Resumeentry or plain messages, and which message ids?mattbrailsford commentedon Nov 16, 2026
Notes for the fix
Follows the investigation notes.
Repro: v18 demo site, Anthropic profile, an agent on the
copilot-workspacesurface. New chat: "Check what page I'm on, then …" so the agent callsget_page_info. ReadumbracoAIConversationsMessagefor the conversation: rows 0-2 and 3-5 are the same turn twice.Cause: the server and the browser disagree about what run 1 stored, and the duplicate check matches on message ids that differ between the two copies.
"Success: Function completed.".tool_callinterrupt (run.controller.ts,#handleRunFinished, from Copilot: a restored thread can hold a tool_use without its tool_result; every later turn then fails with an Anthropic 400 #381). So the resume (run 2) resends the whole turn as plain messages: the user message, its own copy of the tool call, and the real result. There is noResumeentry, so it goes through the leading-message drop.ConversationChatHistoryProvider.IsSameMessage(andIsSameContenton the write side) compares byMessageIdwhen both sides have one. The ids differ, so neither drop matches, and all three are stored again.Proof: stored rows for conversation
d419d8be…(v18 demo site, with fix(copilot-workspace): Keep attachments on later turns by using the conversation id as thread id #750 applied):463494df…(client id)toolu_01EBu65…)msg_011Ch6Jn…(provider id)10129ec1…(server id)463494df…(same client id)c7c1435e…(client id)679f1aba…(client id)The user message matches by id, but the drop needs the whole leading run to match the stored tail. The assistant and tool messages have different ids on each side, so the overlap check fails at every length.
Same cause elsewhere:
Resumebranch, and the browser advances its boundary on those, so they're not affected (code read, not run).v17/devandv19/devhave the same client and server code.tool_useid, but Anthropic didn't reject the run.Suggested fix: on the resume after a frontend tool, recognise the resent turn by the tool call id, not the message id:
Size: the full pipeline. It changes both the read-side and write-side drops, needs a way to replace a stored row, and has a design choice (fix on the server, or stop storing the placeholder in run 1).
mattbrailsford commentedon Nov 16, 2026
Notes on the work
docs/plans/workspace-frontend-tool-duplicate-turn/. The branchv18/topic/workspace-frontend-tool-duplicate-turngets cut when the build starts.v17/devandv19/devfollow.