Skip to content

fix(router): keep a tool's question when the app that was asked is closed - #2119

Merged
isekovanic merged 2 commits into
mainfrom
fix/router-store-waiting-approval
Nov 19, 2026
Merged

isekovanic merged 2 commits into
mainfrom
fix/router-store-waiting-approval

Conversation

@isekovanic

@isekovanic isekovanic commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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 fix(sdk-js): answer a tool's question from a reopened app #2120 and fix(examples): crew approvals come back in a reopened app #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.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 66d91ea and b7c830d.

Files selected for processing: 5

  • CHANGELOG.md
  • acceleration/internal/conversation/conversation.go
  • acceleration/internal/session/command_test.go
  • acceleration/internal/session/session.go
  • acceleration/internal/session/tools.go
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0bacd97 and 66d91ea.

Files selected for processing: 5

  • CHANGELOG.md
  • acceleration/internal/conversation/approvals_test.go
  • acceleration/internal/conversation/conversation.go
  • acceleration/internal/session/command_test.go
  • acceleration/internal/session/session.go

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
@isekovanic
isekovanic force-pushed the fix/router-store-waiting-approval branch from 66d91ea to b7c830d Compare November 19, 2026 14:51
@isekovanic
isekovanic requested a review from kanat November 19, 2026 15:47
@isekovanic
isekovanic merged commit c67ef60 into main Nov 19, 2026
24 checks passed
@isekovanic
isekovanic deleted the fix/router-store-waiting-approval branch November 19, 2026 17:11
isekovanic added a commit that referenced this pull request Nov 19, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants