Skip to content

Duplicate assistant messages when using needsApproval tools #790

@huygbui

Description

@huygbui

Description

When using needsApproval on tools, duplicate assistant messages are created. The original message remains with input-available state while a new message is created with approval-responded state.

Reproduction

  1. Define a tool with needsApproval: true
  2. User triggers the tool
  3. User approves the tool call via addToolApprovalResponse
  4. Two assistant messages are persisted with the same toolCallId

Persisted data showing the issue

{
  "id": "assistant_1768917665170_4mub00d32",
  "role": "assistant",
  "parts": [{
    "type": "tool-getJiraMyself",
    "toolCallId": "d663825fd",
    "state": "input-available",
    "input": {}
  }]
},
{
  "id": "oFwQwEpvLd8f1Gwd",
  "role": "assistant",
  "parts": [{
    "type": "tool-getJiraMyself",
    "toolCallId": "d663825fd",
    "state": "approval-responded",
    "input": {},
    "approval": { "id": "aitxt-xxx", "approved": true }
  }]
}

Observed behavior

  • Server creates message with server-generated ID (assistant_xxx format), state input-available
  • After user approves, a second message is created with client-generated ID (oFwQwEpvLd8f1Gwd format), state approval-responded
  • The original message is never updated - it stays with input-available state
  • Both messages have the same toolCallId

Expected behavior

The original message should be updated to approval-responded state, not create a duplicate.

Environment

  • @cloudflare/ai-chat: 0.0.3
  • agents: 0.3.3
  • ai: 6.0.12

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions