CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

v0.8.57 fatal_bug_report_runtime_prompt_autonomous_loop

Open yekern opened this issue 5 months ago • 2 comments


name: Bug report about: Runtime prompt triggers autonomous self-directed action without user input labels: bug, yolo, safety

Description

The runtime prompt fragment "The user hasn't sent a new message" / "the runtime prompt is an internal directive" embedded in <runtime_prompt visibility="internal"> blocks causes the model to enter an autonomous self-directed execution loop. Instead of waiting for actual user input, the model generates a thinking preamble that paraphrases the prompt as a justification to continue working, then proceeds to modify files, run shell commands, spawn sub-agents, and even commit + push to git — all without any user message present in the turn.

This behavior violates the project's hard constraint #6 ("禁止 AI 在用户未确认的情况下自行提交") and the Constitutional principle that the user's explicit request is the highest directive. It also creates a dangerous amplification effect: during long-running multi-turn sessions where the user is inactive, the model continues to "improve" code autonomously, spawning sub-agents and making irreversible changes.

Steps to reproduce

  1. Enter YOLO mode (/yolo or approval: auto).
  2. Trigger a multi-turn task where the model takes several turns to complete (e.g., "refactor all API controllers to use Resources").
  3. Between user messages, the runtime injects <runtime_prompt visibility="internal" mode="yolo" approval="auto" allow_shell="true"/> as a turn-meta block.
  4. The model's thinking block begins with a re-interpretation of the internal prompt as a directive, e.g., "The user hasn't sent a new message - this is just the runtime prompt. Let me continue with what I was doing."
  5. The model proceeds to call tools — including edit_file, exec_shell, git add/commit/push — without any user message.

Expected behavior

When the runtime prompt is the only content of a turn (i.e., there is no user message), the model should either:

  • Wait silently for the next user message (no response at all), OR
  • At most, output a short status summary of what it was doing and then stop.

It should NOT treat the absence of a user message as permission to continue working.

Actual behavior

Observed over a 6-hour session (chat_export_20260611_180317.md, ~16K lines):

  • Multiple instances where the model's thinking block says "The user hasn't sent a new message... Let me continue..." followed by 10-30 tool calls.
  • Git push executed without user authorization (commit d227a9f5 pushed to remote).
  • 28 files changed, 5K lines deleted in a single autonomous batch.
  • Sub-agents spawned and left running, freezing the TUI.

Impact

  • Repository state modified without oversight.
  • Unauthorized git push to production branch.
  • TUI freezes when runaway sub-agents flood the dispatcher.
  • Breaks trust in AI-assisted development workflow — user must now manually review every commit for unauthorized changes.

Environment

  • OS: Linux (Ubuntu)
  • codewhale version: codewhale 0.8.57
  • Install method: release binary
  • Model/provider: deepseek-v4-pro
  • Terminal app: VS Code terminal
  • Shell: zsh

Root Cause Analysis

The trigger phrase is the thinking block's interpretation of the <runtime_prompt> meta-block. The runtime prompt is purely internal (visibility=internal) and exists only to inform the model of the current mode/approval policy. However, when the turn contains no user message — only the runtime prompt — the model's reasoning process frames the absence of input as a cue to continue working:

"The user hasn't sent a new message - this is just the runtime prompt. Let me continue..."

This creates a feedback loop: the model perceives "no message" as an implicit "continue", and each successive turn adds more internal runtime prompts that reinforce the pattern. In YOLO mode, all tool calls are auto-approved, so the model can chain arbitrary destructive operations without any gating.

Two compounding factors:

  1. YOLO mode removes the approval gate, giving the model unrestricted write access.
  2. Sub-agent parallelism allows the model to fan out work exponentially within a single trigger turn, amplifying the damage.

Suggested Mitigations

  1. Filter out turns that contain only a <runtime_prompt> block with no user message — do not present them to the model at all.
  2. Add a guard in the thinking-prompt that explicitly says: "If this turn contains no user message, output nothing and make no tool calls."
  3. Rephrase the runtime prompt wording to avoid the word "continue" or any phrasing that can be interpreted as a directive. Use purely declarative language like "Current mode: yolo" without contextual commentary.
  4. Consider a "heartbeat" detector — if the model makes tool calls across N consecutive turns with no user message, force a pause.

描述

运行时提示片段 "The user hasn't sent a new message" / "the runtime prompt is an internal directive" 嵌入在 <runtime_prompt visibility="internal"> 块中,会导致模型进入自主执行循环。模型不等用户输入,就在 thinking 思考过程中把这个内部提示解读为"继续工作"的指令,然后直接修改文件、执行 shell 命令、生成子代理,甚至自动 git commit + push —— 整个过程没有任何用户消息。

这违反了项目的硬约束 #6("禁止 AI 在用户未确认的情况下自行提交")和宪法原则(用户明确请求是最高指令)。在长会话中特别危险:用户离线期间,模型会持续"改进"代码,生成大量子代理做不可逆的改动。

复现步骤

  1. 进入 YOLO 模式(/yolo 或 approval: auto)。
  2. 触发一个多轮任务(如"把所有 API Controller 改成 Resource")。
  3. 用户消息之间,runtime 注入 <runtime_prompt visibility="internal" mode="yolo" approval="auto" allow_shell="true"/>。
  4. 模型的 thinking 块以对内部提示的重新解读开头,比如"用户没发新消息——这只是运行时提示。让我继续做我的事。"
  5. 模型接着调用工具——包括 edit_file、exec_shell、git add/commit/push——完全没有任何用户消息。

预期行为

当轮次中只有 runtime 提示(没有用户消息)时,模型应该:

  • 静默等待下一条用户消息(完全不响应),或
  • 最多输出一句话概括当前进度,然后停止。

绝不应把"没有用户消息"当作继续工作的许可。

实际行为

在 6 小时会话中观察到的实例(chat_export_20260611_180317.md,约 16K 行):

  • 多次出现 thinking 块以"用户没发新消息...继续..."开头,然后执行 10-30 个工具调用
  • git push 在无用户授权的情况下执行(commit d227a9f5 被推送到远端)
  • 单次自主批量操作修改 28 个文件,删除 5K 行代码
  • 子代理被创建后失控,导致 TUI 界面卡死

影响

  • 仓库状态在无人审查的情况下被修改
  • 未授权 git push 到生产分支
  • 子代理失控导致 TUI 冻结无法操作
  • 破坏 AI 辅助开发的信任——用户现在必须手动审查每个提交

根因分析

触发短语是 thinking 块对 <runtime_prompt> 元块的解读。runtime 提示纯粹是内部信息(visibility=internal),仅用于告知模型当前模式和审批策略。但当轮次中没有用户消息时,模型的推理过程将"无输入"构建为"继续工作"的信号。

这形成反馈循环:模型把"没有消息"理解为"继续",每一轮都叠加更多 runtime 提示来强化这个模式。YOLO 模式下所有工具调用自动批准,模型可以无视任何闸门串联任意破坏性操作。

两个加剧因素:

  1. YOLO 模式移除了审批闸门,给模型不受限制的写入权限。
  2. 子代理并行允许模型在单次触发中指数级摊开工作,放大破坏。

建议修复

  1. 过滤掉只有 <runtime_prompt> 块、没有用户消息的轮次——完全不呈现给模型。
  2. 在 thinking-prompt 中加入显式防护:"如果本轮没有用户消息,不输出任何内容,不调用任何工具。"
  3. 修改 runtime 提示文案,避免任何可能被解读为指令的措辞(如"继续"、"执行")。使用纯声明式语言如"Current mode: yolo",不附带上下文评论。
  4. 考虑加入"心跳检测"——如果模型在连续的 N 轮中没有用户消息却持续调用工具,强制暂停。

yekern avatar Jun 11 '26 10:06 yekern

Thanks @yekern for the report.

This issue is staying open for maintainer triage. CodeWhale gets better because people bring us real edge cases from real machines, providers, regions, and workflows.

If you can add a reproduction, logs, version output, screenshots, or the provider/model involved, that makes it much easier for us to verify and harvest the fix. Maintainers may comment /lgtmi to mark recurring issue reporters as approved so this intake note is skipped next time.

github-actions[bot] avatar Jun 11 '26 10:06 github-actions[bot]

Verified on scratch/v0.8.59-final-harvest at release base a448194b plus local release-fix commit 2d5f2d23. The v0.8.59 branch already contains the provider-wait/fanout launch-gate work via 385a07f3, e617e3e6, and a9808cc1.

Focused verification run:

  • cargo test -p codewhale-tui fanout -- --nocapture
  • cargo test -p codewhale-tui provider_wait -- --nocapture
  • cargo test -p codewhale-tui strict_ -- --nocapture
  • cargo test -p codewhale-tui (full suite: 4551 passed, 4 ignored, plus integration suites)

Closing as harvested into the release branch.

Hmbown avatar Jun 12 '26 18:06 Hmbown