Repository navigation
fix(worker): resume the impl session when it exits without a pull request - #128
Merged
Merged
Conversation
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…uest 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…late 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
impl フェーズが exit 0 で終了したのに Pull Request が作られておらず、
ai/impl/failedに落ちてしまう問題を修正します。GitHub Issue は起票していません(運用中のワーカーのログと失敗コメントから直接特定した不具合です)。原因は
claude -pの終了タイミングです。非対話モードの CLI はモデルが最終メッセージを返した時点で終了するため、モデルがバックグラウンドのテストや CI の完了を待つつもりでターンを終えると、そこでプロセスが正常終了して PR 作成まで到達しません。:failedは trigger ラベルを剥がすため自動リトライされず、worktree も破棄されるので、それまでの実装がまるごと失われて人手でのやり直しが必要になっていました。既存の対策はどちらも効いていませんでした。impl テンプレートの「実行環境」節は対象リポジトリの CLAUDE.md にある「長時間ジョブはバックグラウンドで起動して完了通知を待つ」という指示と競合して負けます。
CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MSは CLI 側の実装上、実行中のバックグラウンドタスクが 1 件以上ある分岐でしか参照されず、モデルが「待ちます」と述べただけのケースには到達しません。Changes
ワーカー
exit code だけでは完了を判定できないので、PR の紐づけという確定的なシグナルを見て、足りていなければ Claude 自身にセッションを終わらせてもらう方針にしました。
claude -p --continueでセッションを 1 回だけ再開し、PR を再照会するようにしましたexecution.timeout_minutesの残予算内で行います。この値は初回実行と再開を合わせた壁時計予算として扱い、初回実行の直前に deadline を確定させますCLI_TIMEOUT、それ以外の例外はCLI_EXECUTION_ERRORとして、実際の原因と異なるカテゴリで報告されないようにしています「変更不要」と判断されたケースの切り分け
Claude が「Issue は既に解消済み」と結論して意図的に PR を作らないケースも、これまで同じ
No Linked Pull Requestに落ちていました。再開機構を入れると毎回無駄な再開を 1 回消費してしまうので、停止シグナルを用意しています。IMPL_NO_CHANGE_REQUIREDとして診断を分けます:failed(人間が確認するゲート)のまま変えていませんプロンプトテンプレート
これは多層防御の 1 枚で、修正の本体ではありません。
~/.sabori-flow/prompts/にコピー済みのユーザーには届かないため、再発率を下げるだけの位置づけです。Checklist
npm run buildが通ることnpm testが全件通ること(830 → 863 件)claude -p --continueの挙動を実機で確認(会話の永続化、stdin からのプロンプト読み取り、cwd スコープでの解決、会話が無い場合は exit 0 で新規開始)その他
再開しても直らないケースは残ります。モデルが同じ理由で再びターンを終える場合や、本当に行き詰まっている場合は結局
:failedになります。この変更は発生頻度を下げるもので、ゼロにするものではありません。また、初回セッションの終了時点でバックグラウンドの検証結果は失われているため、検証コストの高いリポジトリでは再開に必要な時間が初回とほぼ同等になりえます。その場合は残予算に収まらず
CLI_TIMEOUTに落ちるので、運用としてはtimeout_minutesを上げて対応します。🤖 Generated with Claude Code