Skip to content

feat(web): expose Pi-native turn cancellation - #358

Closed
seekskyworld wants to merge 2 commits into
openpi-dev:mainfrom
seekskyworld:fix/issue-342-turn-cancellation
Closed

feat(web): expose Pi-native turn cancellation#358
seekskyworld wants to merge 2 commits into
openpi-dev:mainfrom
seekskyworld:fix/issue-342-turn-cancellation

Conversation

@seekskyworld

Copy link
Copy Markdown
Contributor

Problem

Implements the first runtime slice of #342. The Web host had no per-turn cancellation endpoint and could only abort sessions during host disposal.

Value

A browser client can request cancellation without tearing down unrelated Web runtime state, while stale Session requests are rejected.

Approach

Add an optional interruptTurn controller seam backed by Pi AgentSession.abort(). Bind the request to the active Session id, return cancelled or already_settled, emit a cancellation event, and expose POST /api/prompt/cancel. Existing test doubles remain compatible through the optional interface member.

Validation

  • npx tsc --noEmit
  • node --test --experimental-strip-types tests/web/pi-runtime.test.ts tests/web/web-host.test.ts (39 passed)
  • git diff --check

Impact

  • User-visible behavior: adds a server cancellation seam; UI control wiring remains a follow-up.
  • Model-visible context/tools: none.
  • Runtime/lifecycle: per-turn abort is distinct from host disposal and uses Pi lifecycle.
  • Persisted config/data: none.
  • Compatibility/risk: old controllers without the optional seam receive a bounded 501 response.

Signed-off-by: seekskyworld <djh1813553759@gmail.com>
Signed-off-by: seekskyworld <djh1813553759@gmail.com>

@tt-a1i tt-a1i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

需要改:用 abort() 返回值当取消完成

interruptTurnawait abort() 之后立刻发 prompt_cancelled 并返回 cancelled,没有等 Pi 的 stopReason: "aborted"。这是从调用结果推断完成,违反「不要从标签/调用返回值推断完成」。

另外没有 commandId / epoch:同一 session 上,过期客户端可以取消更新的 turn。preparing/queued 走 already_settled no-op。

同 issue 的 #385 才是 turn 范围的回执(sessionId+commandId+epoch,等 turn_settled)。请关掉本 PR,或 rebase 成那份合同。不要再叠 #357 的 capability-intent 改动。

tt-a1i added a commit that referenced this pull request Sep 7, 2026
…utions (#439)

Restore the clipboard fallback from #352 in React with honest failure feedback, focus and selection restoration, and cleanup. Keep current exact-turn cancellation and request deadlines, and add timeout regression coverage inspired by #377. Credit the original #352, #377, and #358 contributions in README.

Closes #438

Co-authored-by: QuinnWan <144975606+somewan820@users.noreply.github.com>
Co-authored-by: seekskyworld <djh1813553759@gmail.com>
@tt-a1i

tt-a1i commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Pi-native cancellation is implemented on main with exact session, command, and epoch targeting. #439 records this proposal and credits seekskyworld in README and as a recognized co-author of main commit 41c59d4. The unrelated capability-intent change remains tracked separately in #357. Closing the overlapping session-only cancellation implementation.

@tt-a1i tt-a1i closed this Sep 7, 2026
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