Repository navigation
fix(examples): crew approvals come back in a reopened app - #2121
Conversation
The tools that ask first are declared with the server executor, as the SDK docs say, so their question is on the reply's step, with a line from the call, and the card above the composer that repeated it is gone. AI-3392
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…osed (#2119) 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: - 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). - On the iOS simulator, in the crew React Native app against a router built from this branch, with #2120 and #2121: - 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.
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 byAgentNoticesabove 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 --noEmitandjest(13/13) in the app.Before merging
A reopened app needs #2119 deployed and a
@stream-io/stream-agentsrelease with #2120. Until then, this change only moves the card onto the step. Bump the app's@stream-io/stream-agentsonce that release is out.