Skip to content

fix(sdk-js): answer a tool's question from a reopened app - #2120

Open
isekovanic wants to merge 2 commits into
mainfrom
fix/js-v10-tool-step-fields
Open

isekovanic wants to merge 2 commits into
mainfrom
fix/js-v10-tool-step-fields

Conversation

@isekovanic

@isekovanic isekovanic commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Linear: AI-3392

Why

After the app was closed while a tool call waited for the person's approval, the reopened app couldn't run the call:

  • On stream-chat 10, callShown read the step's type, id, name, status and arguments at the attachment's top level, where stream-chat 10 keeps them under custom. AgentChat.decide found no call to answer.
  • With the step found, a server tool's step keeps no arguments, so decideShown failed the call with "The call's arguments were too long for the conversation to keep".

The router now sends a call still waiting for its answer to a session that attaches later (#2119), but AgentChat.decide usually runs before that frame arrives.

Changes

  • callShown reads the step with messageField, as the message's own fields are read.
  • decideShown remembers an allowed call it has no arguments for, and runs it when the router sends it, without asking again. A declined one is answered as before.
  • A changelog entry under Unreleased bug fixes.

Validation

  • npm test in sdks/js: 725/725 on stream-chat 9 and on 10 (npm install --no-save stream-chat@^10.0.2, as the CI job does).
  • Tests:
    • the stream-chat 10 test now builds the step under custom, and fails without the change;
    • "allowed without its arguments, runs it once the router sends the call" replaces the test for the old failure.
  • On the iOS simulator, in the crew React Native app with these changes applied to its installed SDK and a router built from fix(router): keep a tool's question when the app that was asked is closed #2119: killed the app while the card was up, reopened, tapped Send for review. The call ran on the phone and the reply finished. Before, the step showed "Didn't complete".

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The JavaScript SDK now reads stream-chat 10 tool-call fields from the attachment’s custom field. When an approved historical call has no arguments, the session records its approval and waits for the router to deliver the call before running it. Updated tests cover field extraction and deferred execution.

Merge Risk: Minimal · up to 5e7e2

Reopened apps can now answer a tool call that was awaiting approval, and the call runs once the router sends it. No actionable merge-blocking risk remains after review.

- [ ] 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 863be34 and 5e7e29b.

Files selected for processing: 1

  • sdks/js/tests/session.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Finishing Touches
Fix failing CI checks

  • Commit to this branch
  • Create a new PR

@isekovanic
isekovanic force-pushed the fix/js-v10-tool-step-fields branch from ce5ecd4 to d5748c7 Compare November 19, 2026 14:27

@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 ce5ecd4 and d5748c7.

Files selected for processing: 4

  • CHANGELOG.md
  • sdks/js/src/agent-chat.ts
  • sdks/js/tests/agent-chat.test.ts
  • sdks/js/tests/session.test.ts
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; 4 remain after this review.

Comment thread sdks/js/tests/session.test.ts Resolved
isekovanic added a commit that referenced this pull request Nov 19, 2026
…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.
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.
AgentChat.decide reads the call's step under custom in stream-chat 10. A call allowed
from the conversation before it reached the session runs once the router sends it,
rather than failing for the arguments the conversation does not keep.

AI-3392
@isekovanic
isekovanic force-pushed the fix/js-v10-tool-step-fields branch from d5748c7 to 863be34 Compare November 19, 2026 17:51

This branch has not been deployed

No deployments
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