Skip to content

feat(web): add turn-scoped cancellation - #385

Merged
tt-a1i merged 8 commits into
openpi-dev:mainfrom
testikun:codex/issue-342-web-interrupt
Sep 5, 2026
Merged

feat(web): add turn-scoped cancellation#385
tt-a1i merged 8 commits into
openpi-dev:mainfrom
testikun:codex/issue-342-web-interrupt

Conversation

@testikun

@testikun testikun commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Adds a Stop control for the current Pi agent execution without stopping the Web Host. Requests bind to the Session, command, and execution epoch, so stale tabs cannot cancel a later execution.

Closes #342.

The runtime invokes native AgentSession.abort() and waits for agent_settled. Individual assistant messages, including toolUse, do not establish execution completion. Cancellation needs an aborted assistant result; missing terminal evidence remains uncertain. The browser restores the control from snapshots and SSE and does not optimistically claim completion. Queued follow-ups remain under Pi ownership and may continue within the same execution; this does not introduce per-input cancellation or a second queue.

Validation: bun run check passed; final integrated focused Web tests passed 75/75. The repair's standalone Node 22 full suite passed 1405 tests with one skip, plus Vitest 30/30. CI is running against the updated head. Earlier live-provider evidence in the issue predates this repair and is not a new runtime acceptance result.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 4, 2026
@testikun

testikun commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

CI status note: Node 22/24 completed this PR's repository checks and failed only at the final fresh-install Smoke-test packed standalone Web CLI step, where the child exits before the test can read its URL. The same failure now occurs on unrelated PRs #385, #386, and #387.

I reproduced the packed install independently: npm now admits Pi 0.85.0 through OpenPI's published peerDependencies: "*"; the CLI then exits with Cannot find module '@earendil-works/pi-server'. The checkout/lock-based bun run check and full test suite remain green. I recorded the shared packaging regression and suggested peer-range follow-up in #328: #328 (comment)

No dependency workaround is mixed into this feature PR.

@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.

方向对,有一处应修;请用这份替换 #358

turn 范围(sessionId+commandId+epoch)、等 turn_settled(outcome=cancelled)、不乐观结算,这些都符合合同。#358abort() 返回值推断取消,请关掉那份。

应修:cancelActiveTurnPromise.race([settlement, abortFailure])。如果 abort() resolve 了,但又没有 assistant message_end,HTTP 会一直挂着(没有超时)。请给 settlement 加界,或把「abort 成功但未结算」变成明确的非终态/错误,而不是挂起。

CI 红是共享的打包 openpi web 冒烟,不是这份 diff 独有的。

@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() 成功但没有 message_end 时 HTTP 会一直挂

上一评写成 COMMENT 偏软。cancelActiveTurn 里:

const abortFailure = new Promise<never>((_, reject) => {
  void abortOperation.catch(reject);
});
const terminal = await Promise.race([settlement, abortFailure]);

abort() resolve、又没有 assistant message_end 时,settlement 永不 settle,abortFailure 也不 reject,HTTP 无限等。这是取消合同上的无界挂起,合入前要加超时或明确的非终态/错误。

方向仍对:sessionId+commandId+epoch、等 turn_settled、替换 #358。CI 红仍是共享打包冒烟。

@testikun

testikun commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

已按 review 修复并推送到 c4305ad:取消请求现在同时等待 settlement、abort 失败和 10 秒有界超时;abort 成功但没有 message_end/turn_settled 时会返回明确的 failed 错误,不会让 HTTP 请求无限挂起。原有 Pi runtime 测试 22/22 通过,diff 检查通过。

@tt-a1i
tt-a1i merged commit a726c46 into openpi-dev:main Sep 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants