Skip to content

plan-06: turn 生命周期收敛 — 取消传播 + 后台任务收割 + 出站配额 - #503

Merged
Milhouszhang merged 8 commits into
berabuddies:masterfrom
Milhouszhang:analysis/turn-lifecycle-plan-review
Jul 8, 2026
Merged

plan-06: turn 生命周期收敛 — 取消传播 + 后台任务收割 + 出站配额#503
Milhouszhang merged 8 commits into
berabuddies:masterfrom
Milhouszhang:analysis/turn-lifecycle-plan-review

Conversation

@Milhouszhang

Copy link
Copy Markdown
Collaborator

Closes agentenv/monorepo#768.

背景

turn 的中断/出错不向其派生的等待点和后台任务传播——turn 已死但"遗产"继续存活(#671 阻塞会话、#522 无限等待、#593 Gmail 无法停止、#621 无主发送循环 + TaskStop 报 unknown)。根因统一:turn 缺少"终止时收割全部子资源"的生命周期契约。

改动(8 commits)

  1. CurrentTurnContextAppState:每个 turn 可归属自己的后台任务/出站动作。
  2. TurnScope:收敛 pending permission/question map,bounded 交互等待,finish 立即解阻塞并标 late-resolve 为 expired/finished。
  3. owner-aware BackgroundTaskManager:owner turn/session + durability + cancel token;request_stop/stop_scoped_by_turn(stop→drain→abandon)真实停止(cancel token + 杀进程),terminal 单调。
  4. 后台 agent/shell 携 owner + cancel token 注册,可被收割。
  5. finish_turn:唯一移除 live turn 的路径,收割 scoped 子任务 + 清 turn 出站配额 + 解 pending 交互;替换 10+ 处散落 remove。
  6. per-turn 出站配额(draft / ungated-external)+ turn_id origin 标记。
  7. desktop:移除双层 resolver no-op 与前端静默 fallback;resolver 报错而非静默成功。
  8. review 清理:移除 finish_turn 冗余 cancel + 死方法 BackgroundTaskManager::stop。

验证(81 checks green / 0 failed)

单元 44 · 集成 11(daemon_turn_smoke,真实 daemon + mock provider)· 活 daemon RPC 3(真实 WS socket)· E2E 23(interrupt-clears-question / outbound-gate / tasks)。#768 测试矩阵 6 行全覆盖并通过。

🤖 Generated with Claude Code

Milhouszhang and others added 8 commits July 8, 2026 15:22
Interaction-timeout smoke coverage shipped as the late-resolve-rejection
variant (daemon_rejects_resolve_after_turn_finished) plus the Task 2 TurnScope
unit tests, per the plan's fallback; the mock SSE stream was not extended to
emit AskUserQuestion tool_use.
… fallback

Rust corbina suite green (112 passed incl. REGISTERED_TAURI_COMMANDS meta-test).
Playwright E2E not run here (needs a built frontend + browsers); the change is
behavior-preserving for the fake-daemon tests, which already exercised the
error-propagation path since canInvokeTauri() is false in the browser context.
…er::stop

finish_turn shared the turn's CancelToken with its TurnScope, and
TurnScope::finish already flips the token for every non-Complete reason,
so the explicit handle.cancel.cancel() in finish_turn was dead
duplication — removed, with cancellation ownership documented on scope.

BackgroundTaskManager::stop had no production callers: real stops route
through request_stop / stop_scoped_by_turn -> stop_one (which cancels the
token and kills the process). The bare stop only flipped status, orphaning
the worker/process — a footgun the owner-aware system replaced. Removed it
and reworked the two unit tests that relied on it to exercise the real
convergence paths (request_stop + complete -> Stopped; complete frees a slot).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Milhouszhang
Milhouszhang merged commit 28d1285 into berabuddies:master Jul 8, 2026
6 checks passed
@Milhouszhang
Milhouszhang deleted the analysis/turn-lifecycle-plan-review branch July 9, 2026 05:51
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.

1 participant