Skip to content

[#774] fix-codex-reconnect#775

Merged
nrslib merged 1 commit into
mainfrom
takt/774/fix-codex-reconnect
May 29, 2026
Merged

[#774] fix-codex-reconnect#775
nrslib merged 1 commit into
mainfrom
takt/774/fix-codex-reconnect

Conversation

@nrslib
Copy link
Copy Markdown
Owner

@nrslib nrslib commented May 29, 2026

Summary

背景

Codex プロバイダで長尺レスポンス(例: スライド60枚を1コールでレビュー)を実行すると、サーバ側がレスポンス完了前に websocket を切断することがある(websocket closed by server before response.completed)。

この切断時、codex バイナリ自身は最大5回の再接続(Reconnecting... N/5)を持っているが、TAKT 側がそれを活かせていない。実ログ(debug)で次が確認できた。

  • 終端は毎回 type:"error"("Reconnecting..." 通知)で、SDK 本来の終端シグナル turn.failed は1度も発生していない(error 9回 / turn.failed 0回)
  • 再接続カウンタは毎回 2/5 止まりで 3/5 以降に進まない
  • TAKT は error を終端扱いしてストリームを打ち切り、独自にスレッドを丸ごと再実行する retry(PR [#758] fix-codex-reconnect-retry #767)を最大8回・上限なしの指数バックオフ(合計約255秒)で繰り返した末に失敗する

調査の結果(Codex CLI にもセカンドオピニオンを取得)、TAKT が type:"error"(再接続中の通知)を「回復不能エラー」と誤認してストリームを break し、その結果 SDK の generator が閉じて codex の子プロセスが kill され、バイナリ自身の再接続が毎回途中で潰されていることが「再接続できない」真因と判断した。SDK 公式コンシューマ(Thread.run())は error を無視して読み続け、終端は turn.failed のみで扱っている点も裏付けになる。

(留保: SDK 型定義のコメントは ThreadErrorEvent を "unrecoverable" と記載しており、設計意図としては終端の可能性も残る。状態に基づく判定で安全に吸収する想定。)

やりたいこと

  • ストリーム中の error イベントだけでストリームを打ち切らず、codex バイナリ/SDK 自身の再接続を完遂させる
  • 終端の確定は turn.failed / 例外 / 外部 abort / idle-timeout に限定し、ストリームが正常終了したのに完了も有効な出力も無い場合のみ、記録しておいた最後のエラーで失敗とする
  • PR [#758] fix-codex-reconnect-retry #767 で入った「error 起点でスレッド丸ごと再実行する retry」は見直す(turn.failed・例外・idle-timeout 起点の retry は限定的に残す)
  • 併せて、再試行の指数バックオフに上限キャップを入れる(現状は上限なしで長尺タスク時に数分間フリーズして見える)

補足

  • 関連: PR [#758] fix-codex-reconnect-retry #767(Codex reconnect を retry 可能にした変更。層を取り違えており本件で置き換え検討)
  • 再現: 長尺レスポンスを出すエージェント(gpt-5.5 等)で、サーバ側 websocket 切断が起きるケース

Execution Report

Workflow takt-default completed successfully.

Closes #774

Summary by CodeRabbit

  • Bug Fixes

    • ストリーム通信中のエラーハンドリング処理とリトライ挙動を調整し、より安定した接続管理を実現しました。
  • Tests

    • リトライメカニズムの検証テストを拡充し、複数のエラーシナリオをカバーするようにしました。
    • 依存パッケージのセキュリティバージョン固定の検証テストを新たに追加しました。
  • Chores

    • 複数の依存パッケージをアップデートしました。

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ad4e8362-c54e-4275-9218-548c23cef4d6

📥 Commits

Reviewing files that changed from the base of the PR and between e0fee24 and 445528c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json, !package-lock.json
📒 Files selected for processing (4)
  • package.json
  • src/__tests__/codex-client-retry.test.ts
  • src/__tests__/dependency-versions.test.ts
  • src/infra/codex/client.ts

📝 Walkthrough
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR タイトル「[#774] fix-codex-reconnect」は、リンク issue #774 で説明されている Codex 再接続問題の修正を明確に示しており、変更内容の主要な焦点と一致している。
Linked Issues check ✅ Passed PR の変更内容は、issue #774 で述べられた全ての主要な目標(error イベントでストリーム切断しない、turn.failed のみを終端にする、スレッド再実行 retry を見直す、指数バックオフに上限を設定)に対応している。
Out of Scope Changes check ✅ Passed すべての変更は issue #774 の目標に関連している。package.json の依存関係更新と dependency-versions.test.ts のセキュリティ検証は、Codex SDK バージョン管理と関連する必要な技術的変更であり、scope 内と判定される。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch takt/774/fix-codex-reconnect

Comment @coderabbitai help to get the list of available commands and usage tips.

@nrslib nrslib merged commit 7cd9018 into main May 29, 2026
4 checks passed
@nrslib nrslib deleted the takt/774/fix-codex-reconnect branch May 29, 2026 22:40
@coderabbitai coderabbitai Bot mentioned this pull request May 31, 2026
@nrslib nrslib mentioned this pull request Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex プロバイダ: ストリーム切断時にバイナリ自身の再接続を中断してしまい、長尺レスポンスが回復できない

1 participant