Skip to content

Publish prompts for Workflow event waits - #200

Closed
tnkuehne wants to merge 3 commits into
mainfrom
feat/workflow-event-prompts
Closed

tnkuehne wants to merge 3 commits into
mainfrom
feat/workflow-event-prompts

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

A Workflow that waits for an event can now say what it is waiting for. Clients can read the question from the instance status and answer it with an ordinary event.

const approval = await step.waitForEvent<{ accepted: boolean }>("approval", {
  type: "approval",
  timeout: "1 day",
  prompt: {
    message: `Send "${message}"?`,
    requestedSchema: {
      type: "object",
      properties: { accepted: { type: "boolean", title: "Send" } },
      required: ["accepted"],
    },
  },
});

status then reports:

{ "status": "waiting", "prompts": [{ "id": "0b9d3c4e-…", "name": "approval", "type": "approval", "message": "Send \"Example\"?", "requestedSchema": { "...": "..." } }] }

Behavior

  • prompt is validated in the trusted host: a message of up to 4,096 characters and a flat form of up to 32 string/number/integer/boolean fields (the primitive subset of MCP form elicitation), at most 16 KiB. An invalid prompt rejects the waitForEvent call. The native engine receives only type and timeout.
  • Both hosts register the native wait first and then publish the prompt to the app's WorkflowCatalog. Selective restart depends on native registration order. The hosts are CloudflareWorkflowSteps on Cloudflare and AppWorkflow on celld. It is keyed by the step identity (name, type, occurrence), so parallel waits each publish their own prompt.
  • status lists open prompts while the instance is running or waiting. The local Cloudflare engine reports an open event wait as running before hibernating, and celld reports it as waiting.
  • A prompt is settled when an event of its type is sent, or when the native wait returns or fails. Settled waits are remembered, so a replay of a completed wait never publishes its prompt again. Restart and terminate clear prompts and settled marks; restarted waits publish again when they are reached.
  • Each published prompt has an id. Replays of an open wait keep it, and a restart publishes a new one.
  • The CLI, HTTP API, app detail page and app Workflow bindings already pass the status JSON through, so all of them show prompts without further changes. Answers use the existing sendEvent. The payload is not validated against requestedSchema.
  • A management sendEvent may name the prompt ("prompt": id, CLI --prompt). The catalog then delivers the event only while that prompt is open, checking atomically with the send. Without this, an answer to a question that a restart has replaced would reach the new run. Bindings keep Cloudflare's sendEvent signature.

Tests

  • packages/contracts: the prompt schema's accept and reject cases, including a prompt of exactly 16 KiB that is also published with its step name and event type (unit).
  • celld (RUN_DYNAMIC_TESTS=1, celld 0.6.3): a prompt is published while waiting, survives an abrupt runtime restart with the same id, is answered by its id, is gone right after sendEvent, is absent once complete, is published again with a new id after restart, refuses an answer naming the old id, and is removed by terminate. Restarting a parallel step that runs after an answered prompted wait keeps the wait's event. An invalid prompt errors the instance before any step runs. The full workflows.test.ts and workflow-adapter.test.ts suites pass (55 tests).
  • Local Cloudflare engine (RUN_CLOUDFLARE_TESTS=1): a prompt appears while the wait is open, is gone after sendEvent, and is published again after a selective restart. Prompt text never reaches observations.
  • pnpm check passes.

Known limits

  • Settled marks grow with the number of prompted waits an instance has run. A Workflow that loops over thousands of prompted waits would grow its catalog record accordingly.
  • A selective restart clears every settled mark. Waits before the restart point can publish their prompt again for the moment it takes their cached replay to return.
  • prompt is not part of Cloudflare's WorkflowStep type. The guide shows the declaration that adds it in TypeScript.

RetriggerView in GreptileConfidence Score: 4/5

Update PR #202's prompt fixtures before merging the combined stack.

Findings

  1. P1 Stacked prompt tests break ▶

Summary

Workflow event waits can publish questions in instance status. This update gives each published question an ID and lets management clients reject answers to questions replaced by a restart.

  • Workflow waits now publish their questions in instance status.
  • Callers can target an open prompt when they send its event.

Reviews (5) · Last reviewed commit: "Identify published prompts so answers ca..." · Reviewed by Greptile

step.waitForEvent accepts an optional prompt with a message and a flat
form schema. The Cloudflare and celld hosts store it in the app's
Workflow catalog while the wait is open and pass only the native options
to the engine. Instance status lists open prompts for running and
waiting instances; sending an event of the prompt's type, the wait
returning, restart and termination close them. Settled waits are
remembered so replays of a completed wait never offer it again.
Comment thread packages/contracts/src/workflows.ts Resolved
Comment thread apps/docs/docs/guides/workflows.md Resolved
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 18, 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 c80b806 Nov 18 2026, 03:19 PM

Selective restart relies on native step registration order. Waiting for
the catalog before registering the native wait let a later parallel step
register first, so restarting that step discarded the wait's consumed
event. The host now registers the wait immediately and publishes the
prompt alongside it.

Apply the prompt size limit to the prompt content only, so a prompt at
the limit can still be published with its step name and event type, and
make the documented TypeScript declaration cover every supported field
option.
Each published prompt gets an ID that replays keep and restarts replace.
A management sendEvent may name that ID; the catalog then delivers the
event only while that prompt is open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread packages/contracts/src/workflows.ts Resolved
@tnkuehne

Copy link
Copy Markdown
Contributor Author

Superseded by #213, which lets service methods ask through MCP input requests and app bindings without Workflows.

@tnkuehne tnkuehne closed this Nov 18, 2026
tnkuehne added a commit that referenced this pull request Nov 19, 2026
A service method can now ask the person behind a call to confirm an
action or fill in a short form, and continue with the answer. The same
method works for MCP clients and for other apps; nothing needs to be
imported.

## Provider

```ts
async send(offerId: string) {
  const input = this.ctx.props.input;
  if (!input)
    return {
      resultType: "input_required",
      inputRequests: { confirm: { message: "Send this offer?", requestedSchema: { type: "object", properties: {} } } },
      requestState: { text },
    };
  if (input.inputResponses.confirm?.action !== "accept") return { sent: false };
  // input.requestState is the value returned above
}
```

The method is called again with the same arguments; `ctx.props.input`
holds `{ inputResponses, requestState }`.

## Callers

- **MCP `call`, client with input dialogs** (form elicitation declared
on the 2026-07-28 request): the gateway returns `input_required` with
one form elicitation per request. The client retries the same call with
`inputResponses` and `requestState`, and the gateway calls the method
again with the answers.
- **MCP `call`, other clients that render MCP Apps:** `call` tells the
agent to call `ask` with the same call and the sealed state. `ask`
renders `ui://widefleet/input-form.html`, a Svelte view built from the
shared UI fields on the official MCP Apps client
(`@modelcontextprotocol/ext-apps`, new dependency agreed with the
maintainer). The package build inlines its script and styles into that
one HTML resource (about 590 KB), because hosts load a view as a single
document. The form submits through `answer`, which is app-only
(`_meta.ui.visibility: ["app"]`), retries the method, shows follow-up
questions in place, and reports the outcome through
`ui/update-model-context` and `ui/message` where the host offers them.
2025-era clients take this path because the stateless gateway cannot see
their capabilities; some of them render MCP Apps without declaring the
extension.
- **MCP 2026-07-28 clients with neither:** `call` returns a tool error.
- **MCP `execute`:** the script receives the question as a value. It
cannot answer it.
- **App bindings:** the caller receives the question as the method's
result and retries with `env.OFFERS.withInput({ inputResponses,
requestState }).send(offerId)`. `withInput` is reserved as a service
method name.

Tested with real clients on a probe server: the native dialog in Claude
Code, claude.ai, ChatGPT (Codex-based workspace client) and Codex CLI
with its 2026 feature flag; the MCP Apps form plus app-only answer tool
in ChatGPT, claude.ai and Microsoft 365 Copilot Cowork (2025-11-25
only). No host offered the app-only tool to the model.

## Platform guarantees

- `requestState` is encrypted with AES-GCM under a key derived from the
control token, so callers relay it without reading it.
- The state is bound to the caller (organization, issuer and subject for
MCP; calling app and user for bindings), to the app, entrypoint and
method, to a typed fingerprint of the arguments, and to a 24-hour
lifetime.
- MCP state is also bound to its answering channel. State the agent sees
in a `call` result answers only through the client's dialog; `ask`
rebinds it for the form without extending its lifetime, and passes it to
the view in result `_meta` only. `answer` refuses state from a `call`
result.
- Accepted content is validated against the requested form, including
string formats. Answers that do not fit, or that answer keys the method
did not ask, are dropped.
- Limits: 8 requests per call, flat forms of up to 32 primitive fields,
16 KiB of requests and 8 KiB of `requestState`. Sealed state may take up
to 64 KiB, enough for both limits at once.
- A sealed state can be resubmitted until it expires. The docs ask
providers to make the confirmed action idempotent.
- Analytics drop error messages of `ask` and `answer` like those of
`call`.

## Tests

- `service-input.test.ts` (unit):
  - round trip with hidden state;
  - form validation, including email, URI, date and date-time formats;
  - declines and cancellations;
- rejection for another caller, other arguments, another method, another
key, a modified token and after expiry;
- arguments that JSON renders alike (`42n` and `{ $bigint: "42" }`,
typed arrays over the same bytes, `Map` and entry arrays, `NaN` and
`null`, `0` and `-0`) do not share state, and a 1 MiB byte argument is
matched;
- a question at the full request and state limits seals into a token
that callers can send back;
- rebinding to the form channel keeps the lifetime, and neither channel
accepts the other's state.
- `app-services-runtime.test.ts` on workerd and celld
(`RUN_SERVICE_TESTS=1`, 40 passed):
- MCP 2026-07-28 with input dialogs: `input_required` → retry with
answers → result with the caller's identity;
  - state minted for one user is refused for another;
- a 2025 client and a 2026 client with MCP Apps are sent to `ask`; a
2026 client with neither gets the tool error;
- `ask` and `answer` are listed with the UI resource and app-only
visibility, and the form resource is served as
`text/html;profile=mcp-app`;
- `ask` returns the form's question in `_meta`, `answer` completes the
call, and `answer` refuses the state from the `call` result;
- an app binding answers with `withInput` and never sees the provider's
state;
  - an answer redirected to other arguments is refused.
- `fields.test.ts`: form defaults and answers, including a date-time
default in the hour repeated when daylight saving ends.
- The built form was driven in Chromium against a test host:
initialization, theming, a date-time default in a non-UTC zone, submit,
follow-up question, decline, a failed answer and outcome messages.
- `pnpm check` passes.

Replaces #200 and #202, whose Workflow-based approach is no longer
needed for this.















<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a
href="https://app.greptile.com/api/retrigger?id=111555729&amp;sig=a82e5eb97c922074e64586a3b835f8679cee4010b229e83aaf408efd2b3a438d"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F213&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5</h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge based on
the code reviewed.

<details open><summary><h3>Summary</h3></summary>

Service methods can ask callers for confirmation or form answers, then
resume the same call with private saved state.

- Service methods can pause for input and resume with the same call.
- MCP calls can ask people for input in their own client dialog.
- MCP Apps clients can show service questions in an embedded form.

The earlier findings appear addressed. No new actionable issues were
established. Tests were not run; dependencies are not installed in this
checkout.
</details>

<details open><summary><h3>Diagram</h3></summary>

```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Provider[Service asks for input] --> State[Seal private state for this caller and call]
  State --> Dialog[MCP client dialog]
  State --> Ask[ask tool opens embedded form]
  State --> Binding[Calling app shows its own form]
  Dialog --> Retry[Retry call with answers]
  Ask --> Answer[App-only answer tool]
  Binding --> WithInput[withInput retry]
  Retry --> Check[Check caller, call, channel, expiry and answers]
  Answer --> Check
  WithInput --> Check
  Check --> Resume[Call service again with input]
```
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (6) · Last reviewed commit: ["Build the input form as a
Svelte view
on..."](aa7d514)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
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