DeepSeek-Reasonix icon indicating copy to clipboard operation
DeepSeek-Reasonix copied to clipboard

[Bug] Plan mode vs Ask/Auto/YOLO approval mode are conflated — plan approval bypasses all mode settings

Open Lumoa-dev opened this issue 5 months ago • 1 comments

描述 (Description)

Plan 模式和 Ask/Auto/YOLO 权限模式是两个正交维度,但当前代码将 Plan 审批硬塞进了工具审批管道,导致 Plan 审批无视用户的 Ask/Auto/YOLO 设置。

Plan mode and Ask/Auto/YOLO tool approval mode are two orthogonal dimensions, but the code conflates them: plan approval is hardcoded into the same requestApproval pipeline as tool approval, causing it to ignore the user's Ask/Auto/YOLO setting.


正确设计 (Expected Design)

两个正交维度应自由组合:

Plan 开关 (bool)
    ├── on  → AI researches → writes plan → wait for approval → execute
    └── off → AI executes directly

Ask/Auto/YOLO (approval mode)
    ├── Ask  → every tool call requires approval
    ├── Auto → tool calls matching allow rules are auto-approved
    └── YOLO → all tool calls are auto-approved

Expected combinations:
    Plan + Ask   = plan needs approval + tools need approval
    Plan + Auto  = plan needs approval + tools auto
    Plan + YOLO  = plan needs approval + tools YOLO
    Non-Plan + Ask  = no plan, tools need approval
    Non-Plan + Auto = no plan, tools auto
    Non-Plan + YOLO = no plan, tools YOLO

当前实现的问题 (Current Implementation Issues)

1. Plan 审批走工具审批管道

internal/control/controller.go:540-610 — runTurnWithRawDisplay:

// Line 582 — 无条件调用工具审批管道
allow, _, err := c.requestApproval(ctx, planApprovalTool, "", nil)

2. 工具审批管道硬编码排除了 Plan

internal/control/controller.go:3207-3213:

func requiresFreshApprovalTool(tool string) bool {
    switch tool {
    case planApprovalTool, memoryRememberTool, memoryForgetTool:
        return true   // ← Plan 审批永远不能绕过
    }
    return false
}

3. 测试断言了这个错误行为是"预期的"

测试 文件 断言
TestAutoApproveToolsStillAutoPlansAndRequiresPlanApproval internal/control/yolo_test.go:21 YOLO 不跳过 Plan 审批 ✅
TestPlanApprovalIgnoresAutoApproveTools internal/control/yolo_test.go:324 Auto 不跳过 Plan 审批 ✅
TestSetAutoApproveToolsDoesNotDrainPendingPlanApproval internal/control/yolo_test.go:417 切换 YOLO 时不 Drain 待审批 Plan ✅

这三个测试直接违背了用户直觉:选了 Auto/YOLO 就是不想被打断,但 Plan 审批还是弹窗。


具体冲突场景 (User-Visible Scenarios)

场景 1:Auto + Plan

  • 用户设置:toolApprovalMode=auto, planMode=true
  • 期望:Plan 需要审批 ✅,工具调用自动放行 ✅
  • 实际:Plan 需要审批 ✅(正确),工具调用自动放行 ✅(正确)
  • ✅ 这个场景看起来好像没问题

场景 2:Auto + 非 Plan(这是你报告的原始问题)

  • 用户设置:toolApprovalMode=auto, planMode=false
  • 期望:AI 直接执行,不弹窗
  • 实际:AI 的"自动规划"(maybeAutoPlan)判断当前任务需要规划 → 将 planMode 设为 true → 然后 Plan 审批弹窗
  • ❌ 用户选了 auto 模式,却还是被弹窗打断

场景 3:YOLO + Plan

  • 用户设置:toolApprovalMode=yolo, planMode=true
  • 期望:工具全放,Plan 需审批
  • 实际:Plan 需审批 ✅(正确),工具全放 ✅(正确)
  • ✅ 这个场景看起来 OK

场景 4:YOLO + 非 Plan(最严重)

  • 用户设置:toolApprovalMode=yolo, planMode=false
  • 期望:YOLO 全自动,什么都不问
  • 实际:maybeAutoPlan 判定需要规划 → 将 planMode 设为 true → Plan 审批弹窗
  • ❌ YOLO 模式下还被弹窗打断,那 YOLO 还有什么意义?

根因 (Root Cause)

planApprovalTool("exit_plan_mode")被当作一个"特殊的工具调用"挂在了工具审批管道上,而不是作为独立的行为模式审批通道。导致:

  1. approvalBypassAllowsLocked 无法忽略 Plan 审批(因为硬编码排除)
  2. drainApprovalsLocked 也无法 Drain Plan 审批(因为 requiresFreshApprovalTool 返回 true)
  3. Plan 审批和工具审批的逻辑耦合在一起,无法独立控制

建议修复 (Proposed Fix)

方案 A(推荐,重构 Plan 审批通道):

将 Plan 审批从 requestApproval 管道中分离出来,在 Controller 中增加独立的 planApprovalCh 通道和 PlanMode 相关的审批方法:

// Controller 新增字段
pendingPlanApproval bool
planApprovalCh      chan planApprovalReply

type planApprovalReply struct {
    allow bool
}

runTurnWithRawDisplay 中 Plan 审批走独立的 Plan 通道,不再经过 requestApproval。

方案 B(最小修复,适用于当前的紧耦合架构):

在 runTurnWithRawDisplay 第 582 行之前,加模式判断:

// Plan 审批也遵守 toolApprovalMode 设置
c.mu.Lock()
mode := c.toolApprovalMode
c.mu.Unlock()

if mode == ToolApprovalAuto || mode == ToolApprovalYolo {
    allow = true // Plan 自动批准
} else {
    allow, _, err = c.requestApproval(ctx, planApprovalTool, "", nil)
}

需要在测试文件中修改三个相关测试用例的断言。


涉及文件

文件 说明
internal/control/controller.go runTurnWithRawDisplay(第 540-610 行)、requiresFreshApprovalTool(第 3207 行)、approvalBypassAllowsLocked(第 3178 行)
internal/control/yolo_test.go TestAutoApproveToolsStillAutoPlansAndRequiresPlanApproval(第 21 行)、TestPlanApprovalIgnoresAutoApproveTools(第 324 行)、TestSetAutoApproveToolsDoesNotDrainPendingPlanApproval(第 417 行)
desktop/app.go SetPlanMode、SetToolApprovalMode 绑定方法

Lumoa-dev avatar Jun 14 '26 14:06 Lumoa-dev

关联说明:在排查 #5385 并合入 #5391 时,我们重新核对了 Plan approval 与 Ask/Auto/YOLO 的边界;#5391 没有采用本 issue 里“Auto/YOLO 自动批准 plan”的语义变更。

当前仓库的文档、UI copy 和控制层测试都把 Auto/YOLO 定义为“跳过普通工具审批”:

  • deny 规则仍会拦截;
  • ask 问题仍等待用户回答;
  • exit_plan_mode / 计划批准仍等待用户确认。

#5391 修的是另一个问题:用户已经明确批准计划后,桌面端不应因为 stale plan restore intent 在 turn_done / tab meta 刷新后又自动回到 Plan mode,从而 block 后续执行。它保持现有产品契约,只修复批准后的状态恢复 bug。

如果产品方向要改成 Auto/YOLO 下自动批准计划,建议作为单独设计 PR 处理,并同时更新 controller 语义、测试、桌面/CLI 文案和相关文档。

SivanCola avatar Jun 26 '26 17:06 SivanCola

我这边也遇到了这个问题。我的输入是:

@docs/overall-analysis.md 以下是新的补充建议:

[Pasted text #4 · 163 lines]

把这个建议补充到指定的文档中,不要直接照搬,而是整合进文档现有结构里。

结果 reasonix 自动注入了 Goal mode 相关内容:

...我的原始消息...

Goal mode: pursue this goal autonomously. Treat the user's goal as a task contract:

  • Honor Context, Request, Output format, Constraints...
  • Complete only when the concrete request is done... End every goal-mode assistant reply with [goal:continue], [goal:complete], or [goal:blocked]

AutoResearch protocol: this goal looks like long-horizon research... Treat AutoResearch as a durable strategy for this Goal...

task_id: 20260718-150944-docs-overall-analysis-md-pasted-text-4-163-lines-begin-p status: running iteration: 0 ...

Start pursuing the active goal now.

然后我的 cli 模式就只能在 goal+yolo 和 goal+auto 之间切换。我从头到尾没有用过 /goal 。个人感觉这个应该做成一个选项,可以在自动进入goal 模式和手动指定之间选择。希望这个 bug 能尽早修一下~

Asianfleet avatar Jul 18 '26 15:07 Asianfleet

Resolved by #6734 (merge commit 77fd1a47) for the unexpected interruptions described in scenarios 2 and 4.

Non-Plan Auto/YOLO turns no longer run maybeAutoPlan, so they cannot be switched into Plan Mode automatically. Explicit Plan Mode remains orthogonal to tool approval: choosing Plan still requires plan confirmation, while Auto/YOLO continues to control tool approvals. We intentionally did not make Auto/YOLO auto-approve an explicitly selected plan.

The later Goal Mode report in this thread is a separate path and is not covered by this fix; please track any remaining Goal Mode reproduction separately.

Verified:

  • go test ./internal/control -run 'TestAutoApproveToolsStillRequiresExplicitPlanApproval|TestPlanApprovalIgnoresAutoApproveTools' passed.
  • All 17 required checks on #6734 passed.

Availability: merged into main-v2; this is not included in v1.17.16 and will ship in the next release.

SivanCola avatar Jul 20 '26 13:07 SivanCola