You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(router): keep a tool's question when the app that was asked is closed - #2119
When an app was killed while a tool call waited for the person's approval and then reopened, the question was gone: the conversation showed "Thinking…" until the tool's timeout failed the call. This affects every client SDK.
Two things lost it:
The step's question reached the channel only through live (ephemeral) updates, and Stream stored it once the reply settled. Connector calls held for approval are stored at once (AwaitApproval), and tool calls weren't.
The call itself went only to the socket of the app that asked. A reopened app had nothing to run when the person allowed it: a server tool's step keeps no arguments, and Swift, Kotlin and Dart answer only calls in their live approvals.
Changes
Conversation.Observe stores the reply when a tool call's step starts waiting for the person (awaiting_approval) and when they answer, as AwaitApproval does for connector calls.
Session.watch sends a call still waiting for the person's approval to a watcher that attaches later, with its command, as askTool sends it, so the result is taken. A call the person already answered isn't sent again, so nothing runs twice. This is the replay a resumed watcher with a cursor and a voice tool host already get, for a client that comes back without a cursor, such as a relaunched app. The calls are read before s.mu, since the conversation broadcasts to the session under its own lock.
DecideCommandTool records the answer on the waiting call (bridge.decide) before the conversation hears it, and watch re-checks under s.mu that the call still waits for an answer (bridge.asking). A call answered or finished between that read and the send isn't sent.
Watch's comment says what is replayed now.
A changelog entry under Unreleased bug fixes.
With this, each SDK's existing decide answers the re-sent call. The JavaScript SDK also needs #2120 for an Allow tapped before the call arrives, and the crew sample uses it in #2121.
Validation
New tests:
TestAToolsQuestionAndAnswerAreWrittenToChat: the question and the answer are in Chat.
TestACallWaitingForThePersonIsSentAgainToALaterWatcher: a later watcher gets the call with its arguments and command; one answered in the window before the send, or answered for good, doesn't.
Each fails without its change, the race case without the re-check.
go test of internal/conversation, internal/session and internal/api passes, and so does go test -tags integration of the same three packages (local Postgres and Redis).
asked for a repair ticket, killed the app while the card was up, reopened the conversation: the card is back, Send for review runs the tool on the phone (POST /crew/tickets), the router logs outcome=ok, and the reply finishes with the ticket;
the same flow without a kill still shows one card and runs once.
Swift, Kotlin and Dart get the re-sent call through the same path but weren't run on a device.
No actionable comments were generated in the recent review.
Walkthrough
Approval questions and decisions are saved when observed. When a watcher attaches, the session selects pending approval calls and re-sends those not already sent through resumable replay. The tool bridge tracks whether a person has answered each call. Tests cover saved approval state and watcher replay before and after approval.
Merge Risk: Minimal · up to b7c83
Pending tool-approval questions are now stored in chat and re-sent to a later-attaching watcher. A call answered or finished before the re-send is no longer replayed. A very narrow timing window remains, but no harmful effect was shown for it. No merge-blocking risk was found.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Files skipped from review as they are similar to previous changes: 1
CHANGELOG.md
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
…osed
A call waiting for the person to allow it reached the channel only in live updates,
and the call itself only the socket of the app that asked, so an app reopened while
it waited had no question to show and nothing to run. The question and the answer
are now stored on the step at once, as a connector call's are, and a call still
waiting for its answer is sent again, with its command, to a watcher that attaches
later.
AI-3392
The waiting calls are read before s.mu, so an answer could land between the read and
the send. DecideCommandTool now records the answer on the call before the conversation
hears it, and the replay re-checks under s.mu that the call still waits for one. Watch's
comment says what it replays.
AI-3392
Linear: AI-3392
## Why
The crew app declared the tools that ask first (`request_shift_swap`,
`create_support_ticket`, `book_check_in`) with the client executor. The
router asks a client tool's question on its step only when it can
address the phone, which the SDK can't name yet. So the question lived
only on the session, shown by `AgentNotices` above the composer, and was
lost when the app was closed while it waited. The SDK docs say to
declare a tool that asks first with the server executor until then.
## Changes
- `deviceTools.ts`: those three tools are declared with the server
executor, so the question is on the reply's step and comes back in a
reopened app. The phone still runs them.
- `crewTools.ts`: each names the argument its card shows
(`reasonArgument`: the ticket's summary, the swap's note, the check-in's
topic), since the step keeps no other arguments.
- `AgentNotices.tsx`: the approval cards above the composer are gone,
since the step shows the question. It keeps the failure notice.
## Validation
- `tsc --noEmit` and `jest` (13/13) in the app.
- On the iOS simulator against a router built from #2119, with #2120
applied to the installed SDK:
- one card shows, with the ticket's summary, and Send for review drafts
the ticket;
- killed the app while the card was up, reopened the conversation: the
card is back, and Send for review drafts the ticket and the reply
finishes.
## Before merging
A reopened app needs #2119 deployed and a `@stream-io/stream-agents`
release with #2120. Until then, this change only moves the card onto the
step. Bump the app's `@stream-io/stream-agents` once that release is
out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: AI-3392
Why
When an app was killed while a tool call waited for the person's approval and then reopened, the question was gone: the conversation showed "Thinking…" until the tool's timeout failed the call. This affects every client SDK.
Two things lost it:
AwaitApproval), and tool calls weren't.approvals.Changes
Conversation.Observestores the reply when a tool call's step starts waiting for the person (awaiting_approval) and when they answer, asAwaitApprovaldoes for connector calls.Session.watchsends a call still waiting for the person's approval to a watcher that attaches later, with its command, asaskToolsends it, so the result is taken. A call the person already answered isn't sent again, so nothing runs twice. This is the replay a resumed watcher with a cursor and a voice tool host already get, for a client that comes back without a cursor, such as a relaunched app. The calls are read befores.mu, since the conversation broadcasts to the session under its own lock.DecideCommandToolrecords the answer on the waiting call (bridge.decide) before the conversation hears it, andwatchre-checks unders.muthat the call still waits for an answer (bridge.asking). A call answered or finished between that read and the send isn't sent.Watch's comment says what is replayed now.With this, each SDK's existing
decideanswers the re-sent call. The JavaScript SDK also needs #2120 for an Allow tapped before the call arrives, and the crew sample uses it in #2121.Validation
TestAToolsQuestionAndAnswerAreWrittenToChat: the question and the answer are in Chat.TestACallWaitingForThePersonIsSentAgainToALaterWatcher: a later watcher gets the call with its arguments and command; one answered in the window before the send, or answered for good, doesn't.go testofinternal/conversation,internal/sessionandinternal/apipasses, and so doesgo test -tags integrationof the same three packages (local Postgres and Redis).POST /crew/tickets), the router logsoutcome=ok, and the reply finishes with the ticket;