Listen to Claude Code's StopFailure hook to detect API-failed turns immediately

已关闭
#865 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

Start by reading the Claude profile's hook registration in bmad-loop init, then trace how the relay journals Stop and how the engine handles transport or environment faults. The issue does not name specific files or tests, so first locate those entry points and existing recovery paths. Done means StopFailure is registered and journaled, transient errors recover without charging a dev attempt, and account or quota errors pause with an escalation.

由索引模型根据 Issue 内容生成。

描述

Describe your idea
Register Claude Code's StopFailure hook event in the relay, so a turn that ends on an API error is seen at once instead of through the stall budget.

Why is this needed?
On bmad-loop 0.13.0 (Claude Code adapter, herdr backend, Linux), a dev session finished its work, then its turn ended on an API error ("Connection lost mid-response"). The relay recorded no Stop for that session. The pane sat idle for about 34 minutes until I unblocked it by hand with a message. Policy at the time: session_timeout_min = 90, dev_stall_grace_s = 600, dev_stall_nudges = 2. From the hook events alone I cannot tell whether the stall nudges fired.

bmad-loop init registers SessionStart, Stop, SessionEnd, PreCompact and Notification. Claude Code also emits StopFailure when a turn ends because of an API error. Its input carries error (rate_limit, overloaded, server_error, unknown, authentication_failed, billing_error, ...), error_details and last_assistant_message (type StopFailureHookInput in Claude Code's hook type definitions). Today this signal is lost, and the loop can only learn about the failure from silence. I found no mention of StopFailure in the 0.13.1 release notes or in existing issues.

How should it work?

  • init registers StopFailure for the claude profile, next to the existing events, and the relay journals it like Stop.
  • On StopFailure, the engine classifies the turn as a transport or environment fault without charging a dev attempt, then recovers through the existing path (nudge or relaunch) instead of waiting for the grace to expire.
  • error drives the choice: transient values (overloaded, server_error, unknown) retry; account or quota values (rate_limit, billing_error, authentication_failed) pause the run with a clear escalation, since a retry cannot succeed.

Additional context
Related: #194 (API failure charged as a timeout), #470 (stall detection arming), #764 (late transient 5xx classified as an environment fault), #610 (usage-limit pattern).

主要语言
Python
星标
178
派生
73
平均合并
17 小时 56 分钟
30 天内合并 PR
95

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bmad-code-org/bmad-loop 的其他 Issue

查看 bmad-code-org/bmad-loop 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。