Skip to content

feat(react): answer session interrupts from Chat with renderInterrupt - #1683

Open
blove wants to merge 38 commits into
mainfrom
blove/react-chat-render-interrupt
Open

blove wants to merge 38 commits into
mainfrom
blove/react-chat-render-interrupt

Conversation

@blove

@blove blove commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

React Chat can now answer the interrupts a session reports in snapshot.interrupts, through an opt-in renderInterrupt prop. The app draws the card; Chat wires the answer to session.resume.

<Chat
  session={session}
  renderInterrupt={(interrupt, respond) => (
    <ApprovalCard
      disabled={respond.sending || respond.answered}
      actions={[
        { id: 'approve', label: 'Approve', onSelect: () => respond.resolve({ approved: true }) },
      ]}
    >
      {interrupt.message ?? interrupt.reason}
    </ApprovalCard>
  )}
/>

Stacked on #1682, which is stacked on #1678 and #1681. Until they merge, this PR's diff also shows their changes. The commit that belongs to this PR is feat(react): answer session interrupts from Chat with renderInterrupt.

What changed

  • renderInterrupt(interrupt, respond), off unless set. Chat shows nothing for an interrupt by itself: which value answers an interrupt is the backend's contract, so there is no built-in card. This was a product decision.
  • respond.resolve(value) / respond.cancel() record an answer. Chat holds each one until every pending interrupt has an answer, then sends them together with one session.resume, because a paused run continues once. respond.answered and respond.sending let a card disable itself.
  • The cards take the place of the approval slot, so the composer placeholder and the return of focus work as they do for approval.
  • onInterruptError receives a rejected resume; the answers are dropped so the person can answer again. With no handler the failure is reported as an unhandled error rather than swallowed.
  • renderInterrupt is ignored while approval is set and on a session with no resume, so existing apps are unchanged.

Verification

  • nx run-many -t test,type-tests,lint -p react passes, with new Chat tests over the fake session: nothing shown without the prop, one interrupt, several held then sent together, a refused answer, and approval taking precedence.
  • Mutation check: sending on the first answer instead of waiting for all fails a test.
  • The website docs-content rules pass for the edited page. inventory.mjs --check --drift warn passes.
  • Not run: the full website suite, Playwright e2e, and a browser check against a real paused run.

🤖 Generated with Claude Code

blove and others added 30 commits November 17, 2026 20:12
AgentSession and AgentSnapshot take a second type parameter for application
state. The snapshot gains an optional, deeply readonly `state`, and `submit`
accepts `{ message, state }` with a partial state as well as plain text.

A session is told its state type by one declaration: `type<T>()` for the type
alone, or any Standard Schema value to also check each state as it arrives.
`readState` runs that check for session implementations. The fake session
holds, sets and validates state the same way.

No backend session supplies `state` yet; LangGraph and AG-UI follow.
createSession takes a stateType, either type<T>() or a Standard Schema.
createAgentSession publishes the state document as the typed state of the
core snapshot, checks it once per document when a schema is declared, and
reports a rejected document in stateIssues without failing the run. A
session created without a state reports none until one is supplied.
The session createSession returns now publishes the core snapshot itself:
messages, tool calls, error, usage and typed state beside the protocol
evidence. createAgentSession is removed. retry rejects when the failure
leaves the backend outcome open, as the core contract requires, and the
literal state document a request sends is no longer published.
…ntract

The snapshot gains optional interrupts and subagents, and the session an
optional resume(responses) that answers pending interrupts by id. The fake
session publishes both fields and records resume calls.
Every published interrupt has an id, and resume takes the core contract's
responses in place of a bare value. One pending interrupt receives its
response's value; several are answered as one map keyed by backend id.
Callers in the cockpit examples, the native conversation example and the
parity fixtures move to the new command.
…he client only

The raw session has loaded nothing at that point, so its resume rejects for
a missing pause, not for the unmatched id. The session's own specs cover
the rejection; the diagnostic keeps the provider routing evidence.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant