Skip to content

Answer a Bot that stops its own run to ask before it uses a tool - #2618

Open
mme wants to merge 6 commits into
mainfrom
mme/bot-approval-card
Open

mme wants to merge 6 commits into
mainfrom
mme/bot-approval-card

Conversation

@mme

@mme mme commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Split out of #2326 so it can merge on its own. Two commits:

  1. A Bot that stops its own run to ask can be answered. A Bot connected by its address can pause a run on an AG-UI interrupt of its own, as a harness does before it runs one of its own tools. The server already passes that interrupt and its answer through (endpointResume); the app showed nothing, and the agent then refused every later run. The conversation now shows a card with the tool and its arguments and Allow / Don't allow. An interrupt that is not a yes or no gets "Carry on without it", which cancels it.

     <ChannelChat>
       <ConversationAllowances />
    +  <BotApprovalNotice />        # only interrupts the server does not own
    +    botRaisedInterrupts()      # app/src/lib/copilot/bot-raised-interrupts.ts
    +    copilotkit.runAgent({ agent, resume })
       <HandoffResumeNotice />
  2. A single-user OpenBot in a container answers the page's deployment question. Asked without cookies it said 403 on every page, so the release check and attachment limits were missing. The page asks once more with its cookies. The first, refused request still shows in the console.

Where it runs

  • New state that outlives a request? None. The card reads the interrupts the AG-UI agent in the page already holds.
  • What happens on the second replica? Nothing new on the server. The answer travels as the next run's resume, on the path a run already takes.
  • Anything serialised? No.
  • Anything fanned out to a browser? No new path. The interrupt arrives with the run's events as before.
  • New listener, port, or schedule? No.

Boundary and audit

  • Every acting call still goes through the gateway: resolve, decide, audit, then act.
  • New refusals and new failures each write a row.
  • Nothing new is trusted from the client that the server can resolve itself.

The two unticked boxes need a reviewer's call. The approval the card answers is about the Bot's own tool, run inside the Bot's process. It never went through the gateway, and Allow or Don't allow writes no audit row. This PR does not change that; it makes the question answerable.

API and database

  • Nothing under api/, no database change and no release-policy.json. One app request changes, within the rules in docs/api-and-migrations.md: when the web app's anonymous read of the deployment is answered 403, it now sends a second GET to the same endpoint with the browser's cookies. Same endpoint, same response contract; nothing is removed, renamed or tightened.

Changelog

Bots.

  • A Bot that stops to ask before it uses a tool can be answered. A Bot connected by its address can pause its own run to ask, as a harness does before it runs one of its own tools. The conversation now shows what the Bot wants to use and with what, with Allow and Don't allow; a wait that is not a yes or no, or whose time is over, can be let go. Before, nothing showed and the conversation was stuck: every later message was refused until the wait was answered.

One container.

  • A single-user OpenBot in a container tells its browser about the deployment. It refused the page's first question about the deployment on every page, so the release check and attachment limits were missing. The page now asks once more as the browser that was let in.

Proof

On this branch:

  • bun run typecheck in app: clean. biome lint on the touched files: clean.
  • bun test tests/bot-raised-interrupts.test.ts tests/second-organization.test.tsx tests/failure-said.test.ts: 17 pass.

Earlier, on an older base, in a single-container OpenBot with this app build and an AWS Strands harness Bot connected by address, driven through the browser:

  • The card appears when the harness asks before shell; Allow runs the tool, Don't allow tells the Bot it was refused, and a follow-up message is answered either way.
  • A reload with an approval waiting shows the card again.
  • OpenBot's own approval and the Bot's approval both work in one conversation.

Not done:

  • No screenshot or recording is attached.
  • On AWS Strands harness as a Bot #2326 the WebKit test shows "Thinking" within 200 ms ... from home failed once. I could not run it locally (it needs the CI's bun), so this PR's run is the check of whether the card is the cause.

@contextablemark contextablemark 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.

I’d hold this for the resume fixes. I could answer a single active approval, but mixed waits and expired approvals still left the conversation stuck. A failed resume also gave me no feedback. I reproduced those cases in ChannelChat with the pinned SDK and a mocked runtime.

pending: readonly HeldInterrupt[],
approved: boolean,
): InterruptAnswer[] {
return botRaisedInterrupts(pending).map((interrupt) =>

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.

P1. Mixed waits block the Bot’s answer. If the SDK holds one Bot interrupt and one OpenBot-owned interrupt, this drops the OpenBot ID from resume. AG-UI validates coverage against every pending ID before the run starts. I replayed both kinds together and clicked Allow. No request left the browser, and the card returned with no error. Please reconcile the OpenBot-owned wait before resuming the Bot’s wait, while keeping the OpenBot decision on its existing server path. The helper test covers the filtered payload, so please add a ChannelChat test that verifies the answer actually goes out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a97deb7. The answer now lets go of OpenBot's own wait on the agent before it is sent, the same way a new message does (releaseServerOwnedInterrupts), and resume carries only the Bot's wait, so OpenBot's decision stays on its server path. tests/bot-approval-resume.test.tsx mounts ChannelChat with both waits replayed, clicks Allow and checks the run request that goes out.

): InterruptAnswer[] {
return botRaisedInterrupts(pending).map((interrupt) =>
asksForApproval(interrupt)
? { interruptId: interrupt.id, status: "resolved", payload: { approved } }

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.

P2. An expired approval can leave the conversation stuck. For a wait with an elapsed expiresAt, the pinned SDK rejects resolved before sending the request. I clicked both Allow and Don’t allow after replaying an expired approval. Neither sent a request, and there was no way to cancel the wait. Please check expiry when the person clicks and give them a way to continue with status: "cancelled".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a97deb7. A wait whose expiresAt has passed is sent as cancelled. The card says the Bot no longer takes the answer and offers only "Carry on without it"; expiry is checked again at the click, so an Allow on a wait that expired while the card was open is not sent as a cancel without saying so. Covered in the same ChannelChat test and in the helper test.

setRunsInFlight((count) => count + 1);
try {
await whileObserved(agent, () =>
copilotkit.runAgent({ agent, resume }),

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.

P2. The resume skips the conversation’s run handling. With a mocked HTTP 503, the SDK reported an error but resolved the promise. The card’s catch never ran, and the conversation showed no failure. A successful resume showed the Bot’s reply in the transcript but sent no activity update for the conversation list. Please route this through the existing run tracking or cover both outcomes explicitly, including a visible error when the answer fails to send.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a97deb7. The answer now runs as a turn like any other (answerBotWait): it is counted and watched by the same subscription as a message, so the Bot's reply reaches the conversation list and a failed run is said under the transcript by the existing fail. A run that never leaves the browser is said on the card. Two tests: a successful resume sends the activity update and the busy signal goes up and down once; a mocked 503 shows an alert and leaves the card to try again. say's turn counting moved into a small duringTurn wrapper so both share it, with no change to say itself.

});
} catch (error) {
if (!(error instanceof ClientError) || error.status !== 403) throw error;
return getDeployment(DEPLOYMENT_ORGANIZATION, options);

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.

Please update the PR’s API checklist to call out this browser request change. A 403 from the anonymous deployment read now triggers a second GET with the browser’s cookies, using the existing endpoint and response contract.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: the API checklist in the description now calls out the second GET, same endpoint and response contract.

…nce its time is over, and tracked as a turn

- A wait OpenBot holds beside the Bot's is released on the agent before the
  answer is sent, as before any message: with both replayed, Allow sent nothing.
- A wait whose time is over can only be let go. The card says so and offers
  that, and a click checks again.
- The answer runs as a turn like any other, so what the Bot goes on to say
  reaches the roster and a failed run is said under the transcript; one that
  never left the browser is said on the card.
@mme
mme requested a review from contextablemark December 4, 2026 10:34

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.

2 participants