Skip to content

feat(plan): 计划完成门 — 拦截未完成 plan 的提前 end_turn - #19

Merged
1-ztc merged 6 commits into
mainfrom
feature/plan-completion-gate-main
Jul 25, 2026
Merged

feat(plan): 计划完成门 — 拦截未完成 plan 的提前 end_turn#19
1-ztc merged 6 commits into
mainfrom
feature/plan-completion-gate-main

Conversation

@1-ztc

@1-ztc 1-ztc commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

做了什么

给 moss 主循环加计划完成门:模型 end_turn 时若该 session 有 approved/executing 状态的 plan 且 steps 未全做完(completed+skipped)→ 否决完成、注入 correction 逼模型继续,逃生口是 plan_step skip 带理由。堵长任务最典型失败——"有 plan 没做完就声称 done"。

main 干净开,只含完成门 + 前提重构 + 测试,不夹带 observability 分支上的其他工作(skill-eval/discovery 等)。

改动(5 commit)

  1. per-session store (8006fe6) — 把 plan-tools.ts 进程级单例换成按 sessionKey 路由的 store(plan-controller-store.ts)。多 session 嵌入式 host 不再串读对方 active plan。完成门前提。PlanExecuteController 业务逻辑不动。
  2. 完成门本体 (f59f62b) — evaluatePlanCompletionGate(request, deps),接进 CLI createCliCompletionGate 链(排 evaluatePlanEvalCompletionGate 后)+ MossAgent completionGate 包装(无 structured-pending 分支)。fail-open 5 路径;类型干净(required→optional 子类型,无适配)。
  3. MOSS_PLAN_GATE flag (f758f0c) — default on。=off 可关做 A/B baseline。端到端验证:ON 拦+注入 correction,OFF 彻底 no-op。
  4. 集成测试 (2bacf21) — 真起 MossAgent loop:create→approve+start→提前 end_turn→被否决→skip 两步→放行。
  5. off vs on mock 对比 (6b2fcea) — 同一偷懒 mock:off 放行无 correction、on 拦住注入 correction。证明机制方向(非真实收益)。

测试

6 个相关 spec 全过(plan-controller-store / plan-completion-gate 9 case / -integ / -ab / plan-tools-nudge / interaction-mode-exit)。build + typecheck 干净。完成门不依赖 observability 任何东西,从 main 独立成立。

已知限制(诚实)

  1. 完成门真实收益未经验证 — 机制 + 集成测试证明方向对,但真实任务增益(真模型 + N≥3)未测;真 provider 试过 N=1 全噪声且烧 quota。MOSS_PLAN_GATE flag 留作后续真 A/B。
  2. retry 超限崩 run — 模型死活不完成也不 skip,retry 用尽会 throw Completion rejected 崩 run(平台既有 exhaustion 行为,非 force-complete)。
  3. shared/no-session plan 不受 gate 覆盖ctx.sessionKey 空时走 shared 兜底,gate 查不到 → fail-open 放行。CLI 总有 sessionKey,影响主要在无 sessionKey 嵌入 host。
  4. tech-debt(文档级):CLI 路径 gate 在 chain 和 wrapper 各跑一次(幂等纯函数,仅冗余)。

🤖 Generated with Claude Code

1-ztc and others added 6 commits July 25, 2026 20:56
Replace the process-wide singleton in plan-tools.ts with a sessionKey-routed
store. Multi-session embedded hosts no longer cross-read each other's active
plan. store maintains sessionKey->activePlanId; controller business logic
unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
…d steps

evaluatePlanCompletionGate checks plan step completeness (not just whether
plan tools were called this turn like evaluatePlanEvalCompletionGate). Wired
into the CLI completion-gate chain and the MossAgent completionGate wrapper.
Escape hatch via plan_step skip with reason; fail-open on any fault.

Co-Authored-By: Claude <noreply@anthropic.com>
Add MOSS_PLAN_GATE (default on) so the plan completion gate can be disabled
(MOSS_PLAN_GATE=off) to take an A/B baseline against the same task set. Mirrors
criticEnabled() in plan-critic.ts but defaults the opposite way (critic is
experimental off, gate is shipped on). Verified end-to-end: default ON rejects
premature end_turn with correction; OFF is a true no-op (no correction). 9 unit
cases + integration test pass; typecheck clean.

Co-Authored-By: Claude <noreply@anthropic.com>
Drives a real MossAgent loop end-to-end with a mock LLM provider:
turn1 create -> turn2 approve+start -> turn3 plain end_turn (premature,
0/2 steps) -> gate rejects + injects correction -> turn4 skip step1 ->
turn5 skip step2 -> turn6 end_turn passes. Closes the final-review M4 gap
(spec-promised integration test was missing). Verified the gate only fires
on end_turn with no pending tool_use, and that skipStep is sequential.

Co-Authored-By: Claude <noreply@anthropic.com>
Same slack-off mock (5-step plan, completes 1, then premature end_turn):
MOSS_PLAN_GATE=off -> premature end_turn passes, no correction. Default on
-> rejected + correction injected. Verifies mechanism direction with a mock
provider — NOT real-world gain (a mock is not a model that decides whether to
slack off). Real gain needs a real model + controlled task set + N>=3.

Co-Authored-By: Claude <noreply@anthropic.com>
…imits)

Co-Authored-By: Claude <noreply@anthropic.com>
@1-ztc
1-ztc merged commit f70f06f into main Jul 25, 2026
3 checks passed
@1-ztc
1-ztc deleted the feature/plan-completion-gate-main branch July 27, 2026 04:02
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