fix: Codex セッションのモデルが一覧に出ない(問い合わせが早すぎて必ず空振りしていた) - #123
Merged
Conversation
`/agent` で Codex に切り替えて始めたセッションのモデル欄が空のままになる。 #121 で rollout の `turn_context` を読む仕組みを入れたが、実バイナリで計測すると **一度も答えを拾えていなかった**。 実測(codex-cli 0.147.0、`codex exec --json` を実際に走らせて計測): | 時刻(`thread.started` 基準) | 起きること | |---|---| | +0.0s | stdout に `thread.started` | | ~+0.2s | rollout ファイルが作られる | | **~+3.0s** | **`turn_context`(モデル slug)が書かれる** | | +7.2s | `turn.completed` | 対して問い合わせ側は 200ms × 6 回 = 最長 1.2 秒(しかもファイル探索の上限 `MAX_ROLLOUT_SEARCHES` で実質 0.6 秒)で諦めていた。空振りの記憶はしないが、 引き直す契機が次の `thread.started` しか無いため、**1 ターンで終わるセッション (一度指示して結果を待つ、いちばん普通の使い方)は永久に空のまま**だった。 - ターンが終わったあとに**引き直す**(本命)。そこでは `turn_context` は必ず 書かれているので当たる。猶予は短く(1.5 秒)— ここだけは await するので、 取れない環境でターンの合間を引き止めない。 - ターン中の問い合わせは猶予を 20 秒に伸ばし、バックオフで読み直す(誰も待たない ので長くても害が無い。長いターンでは走行中に一覧が埋まる)。 - ファイル探索の回数上限を外す(猶予そのものが上限)。ファイルが作られる前に 張った問い合わせを、出現を待てずに諦めさせないため。 - 空振りの予算は 4 回(1 ターンにつき最大 2 回消費)に。 検証: 実 `codex` を 1 ターン走らせて修正前後を比較(修正前は `model_resolved` が 一切来ない / 修正後は `model_resolved gpt-5.6-sol` が届く)。
takecchi
commented
Aug 12, 2026
takecchi
left a comment
Owner
Author
There was a problem hiding this comment.
レビュー完了です。追加の修正指摘はありません。
主に次の点を確認しました。
thread.started直後の問い合わせが、rolloutファイル自体とturn_contextの遅延生成を猶予内で待てること- ターン中の長い問い合わせをストリーム側でawaitせず、通常の応答を止めないこと
- ターン終了後に短い猶予で再問い合わせし、1ターンだけのセッションでも
model_resolvedを出せること - ターン中と終了後の問い合わせが並行しても、解決済みモデルの重複が状態を壊さないこと
/modelの明示指定が遅れて届いた既定モデルより優先され、既定へ戻したときは探索予算が復元されること- 中断・abort時は終了後問い合わせを行わず、遅い回答を別providerの状態へ流さないこと
- rolloutの探索が日付上限なしで、ファイル出現前からdeadlineまで継続すること
- 指数バックオフが指定された猶予を越えて待たないこと
確認結果:
- PR用worktreeで関連4ファイル: 108 tests passed
npm run typecheck: 成功- GitHub CI check: 成功
実測した書き込みタイミングに合わせて、ターン中の非同期探索と終了後の確実な再取得を分けた修正は妥当です。取れない環境では空振り予算と短いtail猶予で負荷・待ち時間も制限されています。
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.
概要
/agentで Codex に切り替えて始めたセッションのモデル欄が一覧で空のままになる問題を直します。#121 で「rollout の
turn_contextを読む」仕組みを入れましたが、実バイナリで計測すると一度も答えを拾えていませんでした(問い合わせが早すぎて必ず空振りする)。
原因(実測 codex-cli 0.147.0)
実際に
codex exec --jsonを走らせて計測した順序:thread.started基準)thread.startedsession_metaが先)turn_context(モデル slug)が書かれる(入力response_itemとworld_stateのあと)turn.completedつまり
turn_contextは「ターン開始時」ではなく約 3 秒遅れて書かれます。一方 codiva 側は
thread.startedを見た直後に問い合わせ、200ms × 6 回 = 最長 1.2 秒(さらにファイル探索の上限
MAX_ROLLOUT_SEARCHESで実質 0.6 秒)で諦めていました。空振りを記憶しない作りにはなっていましたが、引き直す契機が次の
thread.startedしか無いため、1 ターンで終わるセッション(一度指示して結果を待つ = いちばん普通の使い方)では
モデル欄が永久に空のままでした。
修正
turn_contextは必ず書かれているので当たります。猶予は短く(1.5 秒)— ここだけは
awaitするため、取れない環境でターンの合間を引き止めません。長いターンでは走行中にモデル欄が埋まります。
thread.startedのあとに作られるため、「数回探して無ければ諦める」だと出現を待てずに空振りしていました。
テスト
lint/typecheck/test/buildを通しています(CI でも確認)。codex-adapter.spec.ts「re-asks at the end of the turn when the in-turn lookup was too early」= 今回の本命(1 ターンで終わるセッションでもモデルが届く)
codex.spec.ts「keeps looking for the rollout file until the deadline」= 探索上限の撤去codex.spec.ts「gives up within the patience window it was given」= 猶予は必ず守る/tmpの使い捨てリポジトリで 1 ターン):session_started→assistant_text→turn_completed…model_resolvedが一切来ない3.45s model_resolved gpt-5.6-solが届く