feat(web): add turn-scoped cancellation - #385
Conversation
|
CI status note: Node 22/24 completed this PR's repository checks and failed only at the final fresh-install I reproduced the packed install independently: npm now admits Pi 0.85.0 through OpenPI's published No dependency workaround is mixed into this feature PR. |
tt-a1i
left a comment
There was a problem hiding this comment.
方向对,有一处应修;请用这份替换 #358
turn 范围(sessionId+commandId+epoch)、等 turn_settled(outcome=cancelled)、不乐观结算,这些都符合合同。#358 从 abort() 返回值推断取消,请关掉那份。
应修:cancelActiveTurn 里 Promise.race([settlement, abortFailure])。如果 abort() resolve 了,但又没有 assistant message_end,HTTP 会一直挂着(没有超时)。请给 settlement 加界,或把「abort 成功但未结算」变成明确的非终态/错误,而不是挂起。
CI 红是共享的打包 openpi web 冒烟,不是这份 diff 独有的。
tt-a1i
left a comment
There was a problem hiding this comment.
需要改: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 红仍是共享打包冒烟。
Problem
OpenPI Web has no way to stop the currently running provider turn without stopping the Host. A browser also needs an exact, reconnect-safe identity for the turn it intends to cancel so that a stale tab cannot abort a newer turn.
Closes #342.
Value
Users can stop a long or unwanted Web response while preserving the Host, Session, and already-admitted follow-ups. The result is derived from Pi's canonical lifecycle rather than optimistic browser state, so refreshes, reconnects, retries, and multiple clients converge on the same outcome.
Approach
{ sessionId, commandId, epoch }in snapshots andturn_startedevents.POST /api/turns/cancelendpoint whose receipt distinguishesaccepted,already-settled,stale-session,stale-turn, andfailed.AgentSession.abort(), and wait for the canonical assistant terminal message before reporting success.turn_settled(outcome=cancelled). Refresh and SSE reconnect recover the control from the snapshot.docs/development/OPENPI_WEB_DEVELOPMENT.mdand link it back to feat(web): support Pi-native turn interrupt and cancellation #342.Validation
bun run check— passed.bun run test— Node tests: 1246 passed, 0 failed, 1 skipped; Vitest: 30 passed.openpi webCLI and realPiWebRuntime/WebHost: an actual outbound provider request producedturn_started; Stop invoked native abort; Pi emittedstopReason: aborted; the Host emitted canonicalturn_settled(outcome=cancelled)and anacceptedreceipt; Send was restored. The first claim comment contains the real screenshot and full evidence.Impact