Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@ A folder whose `agent.yaml` names a `plugins` list now fails to load with `plugi

## Bug Fixes

### A tool call's approval is no longer changed while its reply is being written to Chat

Answering a held tool call's approval changed it in place on the reply, which the router could at the same moment be writing to the Chat channel or sending to the conversation's socket. The queued write and the update now each keep their own copy of the approval, so neither is encoded while it changes (AI-3198).
### JavaScript: an approval shown from a conversation's history can be answered

`session.decide` answered only a call its own socket was asked, and did nothing for one an approval card showed from the channel, after `sessions.resume` or a restart, so the card waited forever. `AgentChat.decide(toolCallId, { allowed, summary })` answers such a call from what the reply shows: its `ai_tool_call` step, and the request and turn in `support_runtime`. Allowed, a call of one of the session's tools runs on this device, once however often it is answered; declined, the model is told so. A call whose arguments were too long for the reply to keep is failed rather than left waiting, and `AgentChat.decide` rejects when no loaded message shows the call waiting, so the card can offer to try again. `session.decide` takes the same as an optional `call`, and without it still leaves a call it wasn't asked alone.
Expand Down
24 changes: 24 additions & 0 deletions acceleration/internal/conversation/approvals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,27 @@ func (s *DisplaySuite) TestAHeldCallThatWasNotSentIsNotFinishedInTools() {
s.Equal(status, tool.Summary)
}
}

// A write waiting in the queue, and an update already handed to the conversation's listener,
// keep the approval they were made with while the reply being written has its approval
// answered, so neither is encoded while it changes.
func (s *DisplaySuite) TestQueuedAndPublishedCopiesKeepTheirOwnApproval() {
c := s.open("on_call")
var published []Updated
c.Attach(func(update Updated) { published = append(published, update) })
c.mu.Lock()
defer c.mu.Unlock()
reply := Message{ID: "reply", Role: "assistant", Parts: []Part{{
Type: partToolCall, ID: "call", Status: "awaiting_approval", Approval: &Approval{Title: "Send it?"},
}}}
c.enqueue(reply, false)
c.publish(reply)
queued := c.data.Pending[len(c.data.Pending)-1]

s.True(decided(&reply, "call", true, "", time.Now()))

s.Equal("allowed", reply.Parts[0].Approval.Decision)
s.Empty(queued.Message.Parts[0].Approval.Decision, "the queued write")
s.Require().Len(published, 1)
s.Empty(published[0].Message.Parts[0].Approval.Decision, "the published update")
}
4 changes: 2 additions & 2 deletions acceleration/internal/conversation/conversation.go
Comment thread
getstream-jeffery[bot] marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ func (c *Conversation) finish(state string) {
func (c *Conversation) publish(m Message) {
if c.emit != nil {
m.Tools = append([]Tool{}, m.Tools...)
m.Parts = append([]Part{}, m.Parts...)
m.Parts = clonedParts(m.Parts)
m.Sources = append([]Source{}, m.Sources...)
m.Artifacts = append([]ArtifactAttachment{}, m.Artifacts...)
m.Files = append([]sandbox.Attachment{}, m.Files...)
Expand All @@ -2040,7 +2040,7 @@ func (c *Conversation) StreamApp() int64 {
}
func (c *Conversation) enqueue(m Message, create bool) {
m.Tools = append([]Tool{}, m.Tools...)
m.Parts = append([]Part{}, m.Parts...)
m.Parts = clonedParts(m.Parts)
m.Sources = append([]Source{}, m.Sources...)
m.Artifacts = append([]ArtifactAttachment{}, m.Artifacts...)
m.Files = append([]sandbox.Attachment{}, m.Files...)
Expand Down
14 changes: 14 additions & 0 deletions acceleration/internal/conversation/parts.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ func reasonOf(arguments, name string) string {
return capRunes(strings.Join(strings.Fields(text), " "), maxApprovalReason)
}

// clonedParts copies parts with approvals of their own. DecideApproval answers an approval in
// place on the reply being written, while a queued write or a published update of that reply
// may still be encoding the copy elsewhere.
func clonedParts(parts []Part) []Part {
cloned := append([]Part{}, parts...)
for i := range cloned {
if approval := cloned[i].Approval; approval != nil {
copied := *approval
cloned[i].Approval = &copied
}
}
return cloned
}

// decided records a person's answer to a call awaiting their approval. Allowed, the call
// goes on as it would have; declined, it is cancelled with their summary. It reports
// whether the call was waiting for an answer.
Expand Down
Loading