Skip to content

Ask people the questions of app APIs on the calling app's open pages - #534

Merged
tnkuehne merged 3 commits into
mainfrom
app-questions-in-runtime
Dec 1, 2026
Merged

tnkuehne merged 3 commits into
mainfrom
app-questions-in-runtime

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

When an app calls another app's API as the signed-in person and that API asks a question, such as a template asking before it deletes, the person now answers it in a dialog on the calling app's open page. The calling app's code awaits the method and receives its result. It no longer receives input_required, needs no question UI of its own and cannot answer in the person's place.

How it works

  • Pages: the runtime adds <script src="/.widefleet/questions.js" defer> to every HTML document with a <head> (fragments without one are left alone, so pages that insert fetched HTML do not load it twice). The 850-byte script keeps a WebSocket to the runtime and loads the dialog module (/.widefleet/questions-dialog.js) only when a question arrives. The dialog renders in a shadow root with the shared form fields of the MCP input form, and follows the device's light or dark setting.
  • Questions: AppQuestions is a Durable Object per app and person. Pages connect with hibernatable WebSockets after the runtime checks the upgrade and the page's origin. A binding call whose provider returns input_required connects as a second kind of hibernatable socket and sends the question; the object stores it, shows it on every open page and sleeps until someone answers. The first answer continues the call, which the gateway runs again with ctx.props.input as before.
  • Unanswered questions: without an open page, after the last page closes, after five minutes or once the caller's delegation expires, the provider is called again with every question cancelled and returns its own result. A provider that asks again after a cancellation fails the call.
  • Bindings: withInput is removed from app bindings, from the generated binding types and from the reserved method names. Generated Result<R> types no longer include questions.
  • Configuration: the runtime binds WIDEFLEET_APP_QUESTIONS (wrangler migration v6, and the self-hosted runtime configuration). The auth proxy rebuilds WebSocket handshakes with its usual cookie handling, so renewed sign-in cookies reach the browser.

Direct MCP calls keep their native dialogs and MCP Apps forms.

Screenshots

There was no dialog before: the calling app received input_required and had to show the question itself.

A template approval, 1280 px light and dark:

A question with a form field, 390 px light and dark:

Remaining variants

Not checked: Safari and Firefox rendering, apps that set their own restrictive CSP in HTML.

Tests

  • app-services-runtime.test.ts on workerd and celld: a question reaches an open page and the answer continues the call; questions are cancelled without a page and when the last page closes; a question near the 16 KiB limit with a character outside Latin-1; pages of other origins are refused; the dialog in Chromium from click to result.
  • Page HTML and ETag expectations in the Cloudflare runtime and dynamic celld suites; binding type expectations.
  • pnpm check, cargo test -p platform-agent runtime.

The lint error in templates/hubspot/tests/provider.ts comes from main.

Documentation

The guides "Ask the user before continuing" and "Approve changes" are updated in the draft docs PR #535.

When an app calls another app's API as the signed-in person and that API asks a
question, the runtime shows the question in a dialog on the person's open pages
of the calling app and continues the call with their answer. The calling app
receives the method's result; it never handles input_required or answers in the
person's place, and withInput is removed from bindings.

Pages load a small script that keeps a hibernatable WebSocket to a Durable Object
per person and app. Waiting calls connect to the same object, which sleeps until
the person answers. Without an open page, after the last page closes or when
nobody answers in time, the API is called again with its questions cancelled.
… handshakes

A page connected longer than a caller proof lasts reconnects through sign-in
before it is shown a question, so a tab left open after signing out stops
receiving the person's questions. The auth proxy rebuilds WebSocket handshakes
with the same cookie handling as other responses, keeping renewed sign-in
cookies. Closing a page cancels its questions even when the runtime refuses to
echo the close code, a dismissed dialog counts as a cancellation, and a page
drops dialogs that were settled while it was disconnected and retries a dialog
that failed to load.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs ab3a07b Dec 01 2026, 11:30 AM

@tnkuehne
tnkuehne merged commit e3efb84 into main Dec 1, 2026
16 of 22 checks passed
@tnkuehne
tnkuehne deleted the app-questions-in-runtime branch December 1, 2026 12:19
tnkuehne added a commit that referenced this pull request Dec 1, 2026
…536)

A question now reaches the person where they started the work. Since
#534, questions from app calls appear on the calling app's open pages.
That is right when a person clicks in the app, but an agent that calls
an app through Widefleet MCP had no page: the question was cancelled,
and the agent received the API's declined result. Now, when an agent
calls an app and that app calls an API that asks — for example a CRM
that sends mail through the Gmail template — the question appears in the
agent's client. The app waits, then continues with the answer without
running again, and its code still never handles questions.

## How it works

- **Runs:** every MCP `call` and `execute` runs apart from the request
that started it. `McpRunner` (a Durable Object per run) starts the run
through a `McpRun` entrypoint and keeps it going. `McpQuestions` (a
Durable Object per run) takes the run's questions and the answers. The
two are separate objects because a run that calls back into the object
that started it waits for itself on celld.
- **Questions:** a provider called directly by the run, and any API the
run reaches through app bindings, ask the run's questions object. The
caller proof carries the run through every hop, so the binding gateway
sends the question there instead of to app pages. Calls a person makes
from an app's page keep the page dialog from #534.
- **Answers:** the MCP response is the existing native `input_required`,
or the `ask`/`answer` form for clients without their own dialog. The
answer, from the client's retry or the form, settles the waiting
question, and the response carries the run's next question or its
result. Each question token is bound to the person and answers only on
its own channel: the client's retry, the agent's request to show the
form, or the form itself.
- **Programs:** `execute` suspends the program while any question of its
run waits, also one from an app the program called, using CodeMode's
snapshots and durable tool calls. The person's time does not count
toward the 30-second limit, and the program resumes with the answer. A
run that ends cancels its waiting questions.
- **Access:** an answered call checks the person's access to the app
again before it runs. Runs reuse the claims their request verified, so a
company token is exchanged once per request.
- **Limits:** a question waits up to five minutes and never past the
agent's credential; a run that is lost after 14 minutes reports that
instead of waiting.
- **Removed:** the sealed `requestState` handling (`sealInput`,
`openInput`, `rebindInput`) and its contracts. `ask` and `answer` take
only the question token.
- **Types:** a patch for `@cloudflare/workers-types` passes JSON-like
RPC results by value without recursing through the serializability check
and pipelining types, which never ends for recursive types such as a
JSON value (cloudflare/workerd#3063). Other results keep their types.
The run objects exchange typed events.
- **Configuration:** `WIDEFLEET_MCP_RUNNERS` and
`WIDEFLEET_MCP_QUESTIONS` (wrangler migration `v7`, and the self-hosted
runtime configuration).

## Tests

- `app-services-runtime.test.ts` on workerd and celld: native dialog
questions and form questions, including management; an answer from
another person, a second answer, a relayed token on the form and a
program token on a call are refused; an agent calls an app that calls a
provider that asks, through `call` and through `execute`, and the app's
effect before the question runs once; an app's question answered after
31 seconds still completes the program; a program that ends while a
question waits does not show it; an answer after the person lost access
is refused.
- New unit tests for validating answers against the question's form.
- Cloudflare runtime and dynamic celld suites, MCP management and MCP
login runtime suites, `cargo test -p platform-agent runtime`, `pnpm
check` (except the HubSpot lint error on `main`).

Not covered by tests: a run interrupted by a Durable Object restart, and
the real Cloudflare edge. A client that disconnects no longer stops a
running program on self-hosted celld; on Cloudflare it never did,
because the runtime's compatibility date predates `request.signal`. A
spike verified that a runner keeps an app waiting for 70 seconds after
the first request ended, on workerd and celld.
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