Skip to content

The requires_user_input regex heuristic is the only semantic guess in the pipeline #1

Open

Description

@longzhi

Problem

requires_user_input() in tools/codex-hook.py uses a set of Chinese and English regexes to decide whether the assistant's last paragraph is asking the user a question, and derives response_kind: input_required from that.

This is the only place in the whole pipeline that guesses at semantics. The project's core stance (see key decision #7 in docs/architecture.md) is "don't scrape the Codex UI and don't parse the unstable transcript; use only the structured events from the official Hooks." We are forced to make an exception here because Codex Hooks don't provide a structured field saying whether a reply requires an answer from the user.

Asymmetric impact

Case Consequence
False positive (an ordinary ending is taken for a question) The buddy gets stuck on "needs input" and swallows the completion announcement it should have made
False negative (a real question is taken for completion) It announces "task complete", the user thinks everything is fine, but Codex is actually waiting for an answer

Both directly break the product's core promise: "telling you when it's time to come back."

Known weak spots in the current rules

  • QUESTION_AT_END only looks for a question mark at the end of the last paragraph. Rhetorical questions trigger false positives.
  • DIRECT_REPLY_REQUEST matches phrases like "请确认" ("please confirm"), but it also fires when the assistant is paraphrasing the user's own words or quoting documentation.
  • CHOICE_LIST only treats a list as options if the second-to-last paragraph ends with a question mark. The rule is on the strict side and prone to false negatives.
  • Mixed-language phrasing (anything other than pure Chinese or pure English) and question marks inside code blocks are not excluded.

Possible directions (undecided)

  1. Wait for the official Codex Hooks to provide a structured field. Cleanest, but out of our control.
  2. Keep the regexes but add a batch of regression tests built from real-world samples to quantify the false-positive and false-negative rates. tools/test_codex_hook.py already provides a foundation.
  3. Make it correctable on the device side: Stage 5's K2 acknowledge lets the user manually clear a false-positive "needs input", downgrading the accuracy problem to a UX problem.
  4. Judge it with a small on-device model on the Mac. This introduces a new dependency and latency, which conflicts with the adapter's "minimal, low-latency" positioning.

References

  • tools/codex-hook.py:23-50
  • docs/codex-adapter.md
  • Item 3 in LESSONS.md (Stop does not mean the task succeeded)

This issue is for the record only; no action for now.

Update (2026-09-14)

Update from hands-on testing (2026-09-14): Claude Code's Stop and SubagentStop also provide last_assistant_message, so the Claude Adapter will reuse the text rules here rather than bypass them by relying on an explicit signal (see ADR-0002, which supersedes ADR-0001, the approach originally meant to bypass them).

As a result, this rule has gone from a local problem in a single Adapter to a shared dependency of both pipelines; a misjudgment will affect both Codex and Claude Code at once. Its priority goes up accordingly.

A new mitigation direction: Claude Code's PermissionRequest is an explicit event, so permission-type waits no longer go through text classification, and the regexes really only need to cover purely conversational questions. This narrows their area of responsibility but doesn't eliminate it.


Original (Chinese)

Original title: codex-hook 的 requires_user_input 正则启发式是链路中唯一的语义猜测

问题

tools/codex-hook.py 的 requires_user_input() 用一组中英文正则判断助手的最后一段是否在向用户提问,从而派生 response_kind: input_required。

这是整条链路里唯一一处"猜语义"的地方。项目的核心立场(见 docs/architecture.md 关键决定第 7 条)是"不抓取 Codex UI,也不解析不稳定的 transcript,只用官方 Hook 的结构化事件"。这里被迫破例,因为 Codex Hook 没有提供"这条回复是否要求用户回答"的结构化字段。

影响不对称

情况 后果
误报(普通结尾被当成提问) 宠物停在"需要确认",并吞掉本该播报的完成通知
漏报(真提问被当成完成) 播报"任务完成",用户以为没事了,实际 Codex 在等回答

两种都直接破坏产品的核心承诺——"告诉你什么时候该回来"。

当前规则的已知薄弱点

  • QUESTION_AT_END 只看最后一段结尾的问号。反问句、修辞性问句会误报。
  • DIRECT_REPLY_REQUEST 匹配"请确认"等词,但助手转述用户原话或引用文档时也会命中。
  • CHOICE_LIST 要求倒数第二段以问号结尾才认列表为选项,规则偏严,容易漏报。
  • 纯中文/纯英文以外的混合表达、代码块内的问号都没有排除。

可能的方向(未决)

  1. 等 Codex 官方 Hook 提供结构化字段——最干净,但不可控。
  2. 保持正则但补一批真实语料的回归测试,量化误报/漏报率。tools/test_codex_hook.py 已有基础。
  3. 让设备侧可纠正:Stage 5 的 K2 acknowledge 能让用户手动消除误报的"需要确认",把准确率问题降级为体验问题。
  4. 本机小模型判定——引入新依赖和延迟,与"最小化、低延迟"的适配器定位冲突。

参考

  • tools/codex-hook.py:23-50
  • docs/codex-adapter.md
  • LESSONS.md 第三条(Stop 不等于任务成功)

本 issue 只做记录,暂不处理。

Comment (2026-09-14):

实测更新(2026-09-14):Claude Code 的 Stop 与 SubagentStop 同样提供 last_assistant_message,因此 Claude Adapter 将复用这里的文本规则,而不是依赖显式信号绕开它(见 ADR-0002,它取代了原本打算绕开的 ADR-0001)。

这条规则因此从单一 Adapter 的局部问题变成两条链路的共同依赖,误判会同时影响 Codex 和 Claude Code。优先级相应上升。

一个新的缓解方向:Claude Code 的 PermissionRequest 是显式事件,权限类等待不再经过文本判断,正则实际只需要覆盖纯对话式提问。这缩小了它的责任面,但没有消除它。

Activity

  1. longzhi commented on Sep 14, 2026

    @longzhi
    CollaboratorAuthor

    实测更新(2026-09-14):Claude Code 的 Stop 与 SubagentStop 同样提供 last_assistant_message,因此 Claude Adapter 将复用这里的文本规则,而不是依赖显式信号绕开它(见 ADR-0002,它取代了原本打算绕开的 ADR-0001)。

    这条规则因此从单一 Adapter 的局部问题变成两条链路的共同依赖,误判会同时影响 Codex 和 Claude Code。优先级相应上升。

    一个新的缓解方向:Claude Code 的 PermissionRequest 是显式事件,权限类等待不再经过文本判断,正则实际只需要覆盖纯对话式提问。这缩小了它的责任面,但没有消除它。

  2. changed the title [-]codex-hook 的 requires_user_input 正则启发式是链路中唯一的语义猜测[/-] [+]The requires_user_input regex heuristic is the only semantic guess in the pipeline[/+] on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions