Repository navigation
Closed
Description
Parent
Problem
The current Web workbench can submit prompts and queue follow-up input, but it cannot stop an active model turn. The browser exposes only a Send action; WebRuntimeController has no interrupt/cancel operation, and the runtime only aborts sessions while disposing the whole Web host.
A long, stuck, or accidentally submitted turn therefore cannot be stopped without closing the workbench. Closing the host is not an acceptable per-turn control because it also tears down unrelated Web runtime state.
Value
- Let users recover immediately from a runaway or unwanted turn.
- Preserve the same cancellation lifecycle and terminal evidence as Pi instead of inventing a browser-only status.
- Establish the command/receipt boundary needed by future capability controls.
Approach constraints
- Reuse Pi AgentSession cancellation and lifecycle events as the source of truth.
- Bind every cancel request to the expected Web Session and current command/turn epoch.
- Define an exact receipt that distinguishes accepted, already settled, stale session, and failed cancellation.
- Do not infer cancellation from button state or optimistic UI.
- Keep queued follow-up prompt behavior explicit: cancellation must define whether queued input is retained or discarded.
- Preserve controller serialization, SSE resync, shutdown, and multi-client lease boundaries.
Acceptance criteria
- While a real provider turn is active, the composer exposes a Stop action.
- A valid Stop request cancels that turn through Pi native session lifecycle.
- A stale request cannot cancel a newer turn or a different Session.
- The UI reaches a canonical cancelled terminal state from runtime evidence.
- Repeated Stop requests are idempotent and return an explicit receipt.
- Behaviour for queued follow-up prompts is specified and covered by tests.
- Refresh/reconnect converges to the same state through snapshot + events.
- Host disposal remains separate from per-turn cancellation.
- Focused Web runtime/host/UI tests, bun run check, and bun run test pass.
Out of scope
- A global pause across every OpenPI capability; that broader problem is tracked in control: 研究 Pi-native 的全局安全暂停,让所有 Agent 在下一执行边界停住 #161.
- Controller handoff between TUI and Web.
- Adding a second cancellation state machine in the browser.
Metadata
Metadata
Assignees
Labels
No labels
Activity
testikun commentedon Sep 4, 2026
我来认领 #342。
技术方案:复用 Pi AgentSession 的原生 abort/turn lifecycle,在现有 WebRuntimeController 串行命令边界增加绑定 expected Session 与当前 command/turn epoch 的 cancel 请求;receipt 明确区分 accepted、already-settled、stale-session、stale-turn 和 failed,不从按钮状态推断取消完成。浏览器仅在 canonical snapshot/event 表明当前 turn 活跃时显示 Stop;重复请求幂等,refresh/reconnect 继续由 snapshot + SSE 收敛。已被 admission 接受的 queued follow-up 保留并在当前 turn 终态后按现有队列继续,Stop 只取消它绑定的 active turn。
我会分开补 runtime、host/protocol、UI 状态测试,并验证 shutdown 与 stale request 不回归。该项有 UI 修改:完成后会本地真实启动 OpenPI Web、执行真实交互测试并截图,把真实测试图编辑回本条首评论;不会使用 mock 图。最后运行 bun run check 与 bun run test,按模板提交 PR。
完成与真实 UI 验证
bd85475(分支testikun:codex/issue-342-web-interrupt)。pi list验证唯一 OpenPI 来源为当前/tmp/openpi-issue-342。openpi webCLI、真实PiWebRuntime/WebHost和实际 outbound provider 请求验证:turn_started后 UI 显示 Stop;点击后 Pi 返回stopReason: aborted,Host 投影 canonicalturn_settled(outcome=cancelled)和acceptedreceipt,UI 恢复 Send 并显示“当前回合已停止”。bun run check通过;bun run test1246 pass / 0 fail / 1 skip,Vitest 30 pass。真实本地运行截图(请求运行中,Stop 控件可见;非 mock):