Skip to content

feat(web): support Pi-native turn interrupt and cancellation #342

Closed

Description

@sowen1023

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

Activity

  1. testikun commented on Sep 4, 2026

    @testikun
    Collaborator

    我来认领 #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)。
    • 本地按开发运行时要求确认 checkout revision,并由 pi list 验证唯一 OpenPI 来源为当前 /tmp/openpi-issue-342。
    • 使用正式 openpi web CLI、真实 PiWebRuntime / WebHost 和实际 outbound provider 请求验证:turn_started 后 UI 显示 Stop;点击后 Pi 返回 stopReason: aborted,Host 投影 canonical turn_settled(outcome=cancelled) 和 accepted receipt,UI 恢复 Send 并显示“当前回合已停止”。
    • 全量校验:bun run check 通过;bun run test 1246 pass / 0 fail / 1 skip,Vitest 30 pass。

    真实本地运行截图(请求运行中,Stop 控件可见;非 mock):

    OpenPI Web real turn cancellation test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions