Skip to content

Commit de13df9

Browse files
committed
Fix Codex trim turn-count adjustment
1 parent 28496f7 commit de13df9

14 files changed

Lines changed: 189 additions & 76 deletions

AGENTS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ VS Code restart / reconnect 後に rollback 済み user prompt が復活した i
5858
Codex 側をやり直さず、現行状態から継続する。2026-05-08 時点では Codex
5959
current-thread trim は `trim --execute --host codex --all` で guarded rollback +
6060
Throughline DB developer-memory inject を送れる。必須条件は Codex thread identity、
61-
Throughline DB injectable memory、rollout/app-server turn-count guard であり、
61+
Throughline DB injectable memory であり、rollout/app-server turn-count mismatch は
62+
diagnostic と app-server count 由来の rollback `numTurns` 補正に使う。
6263
`restoreSafety.status = risk`、planned restore-safety risk、host primitive audit は
6364
diagnostic-only として扱う。developer memory inject は item-level で、現行 Codex
6465
host では即時 `thread/read` の turn count を増やさない場合がある。durable success は

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ shipped to npm but were not individually tagged on GitHub.
1010

1111
## [Unreleased]
1212

13+
## [0.4.10] — 2026-05-09
14+
15+
### Fixed
16+
17+
- Codex current-thread trim no longer refuses execution solely because the
18+
rollout active turn count differs from the Codex app-server count. When
19+
`thread/read` and `thread/resume` agree, Throughline now treats the mismatch
20+
as diagnostics and adjusts `thread/rollback.numTurns` by the app-server delta.
21+
For example, `expectedTurns = 6` and `readTurns = resumedTurns = 7` under
22+
`--all` now sends `numTurns: 7`.
23+
- `trim --preflight --host codex` now reports the same rollback adjustment
24+
preview instead of returning `preflight-refused` for this recoverable
25+
mismatch.
26+
1327
## [0.4.9] — 2026-05-09
1428

1529
### Changed

CLAUDE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
| [docs/THROUGHLINE_CLEAR_AUTO_HANDOFF_PLAN.md](docs/THROUGHLINE_CLEAR_AUTO_HANDOFF_PLAN.md) | **v0.4.0 の現行設計仕様** + 実装 TODO。auto path (`source='clear'`) + baton path (`/tl`) の 2 経路、env `THROUGHLINE_DISABLE_AUTO_HANDOFF` |
3333
| [docs/PUBLIC_RELEASE_PLAN.md](docs/PUBLIC_RELEASE_PLAN.md) | 公開配布化プラン(§0 フォールバック禁止ルール、CLI 設計、バージョン別実装ステータス、E2E 検証手順、未完タスク) |
3434
| [docs/THROUGHLINE_CODEX_FIRST_ROADMAP.md](docs/THROUGHLINE_CODEX_FIRST_ROADMAP.md) | **次フェーズの実装順 / TODO**。Codex primary 実用化、Codex Rewind 互換、Claude 側 finalization の順で進める |
35-
| [docs/THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md](docs/THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md) | Codex rollback / inject incident の調査・修正履歴。controlled user marker の rollback 後 model-visible reproduction は、fresh app-server verify と VS Code reload/reconnect 後 verify の両方で未再現。これを受けて `trim --execute --host codex`、preflight、Codex Stop hook auto-refresh の overbroad blocker は解除済み。`compacted.replacement_history` retentionhost primitive audit は診断として残すが、mutation 前拒否には使わない。実 execute は rollout/app-server turn-count guard、Throughline DB injectable memory、post-inject visibility、durable rollout evidence に基づき `execute-sent-live-only` / `execute-unverified` / `execute-durable-verified` を返す |
35+
| [docs/THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md](docs/THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md) | Codex rollback / inject incident の調査・修正履歴。controlled user marker の rollback 後 model-visible reproduction は、fresh app-server verify と VS Code reload/reconnect 後 verify の両方で未再現。これを受けて `trim --execute --host codex`、preflight、Codex Stop hook auto-refresh の overbroad blocker は解除済み。`compacted.replacement_history` retentionhost primitive audit、rollout/app-server turn-count mismatch は診断として残すが、mutation 前拒否には使わない。実 execute は Throughline DB injectable memory、app-server turn-count による rollback 数補正、post-inject visibility、durable rollout evidence に基づき `execute-sent-live-only` / `execute-unverified` / `execute-durable-verified` を返す |
3636
| [docs/THROUGHLINE_CODEX_TRIM_IMPLEMENTATION_PLAN.md](docs/THROUGHLINE_CODEX_TRIM_IMPLEMENTATION_PLAN.md) | Codex 両対応 + rollback trim の旧統合実装計画と実装履歴。完了済み成果と根拠として参照する |
3737
| [docs/THROUGHLINE_CODEX_DUAL_SUPPORT.md](docs/THROUGHLINE_CODEX_DUAL_SUPPORT.md) | Claude / Codex 両対応の architecture brief。Claude path を置き換えず、Codex support を adapter / projection として追加する方針 |
3838
| [docs/throughline-rollback-context-trim-insight.md](docs/throughline-rollback-context-trim-insight.md) | rollback を model-visible context の delete primitive と見る設計メモ。次フェーズでは Codex Rewind 互換の根拠として扱う |
@@ -53,7 +53,7 @@
5353
| [src/transcript-reader.mjs](src/transcript-reader.mjs) | transcript JSONL パーサー |
5454
| [src/transcript-usage.mjs](src/transcript-usage.mjs) | 最新 assistant の `message.usage` から実測トークン数を抽出、1M context 検出 |
5555
| [src/codex-capture.mjs](src/codex-capture.mjs) | Codex rollout JSONL の active turns を Throughline DB の `bodies` に保存する capture adapter。`thread_rolled_back` 適用後の active thread だけを `codex:<thread_id>` session として再構成する |
56-
| [src/codex-rollout-memory.mjs](src/codex-rollout-memory.mjs) | Codex rollout JSONL から active turns / restore-safety diagnostics / trim source を構築する。trim source では現在進行中の in-flight turn と latest rollback 後の未完了 assistant continuation を rollback 候補から除外し、app-server `thread/read` / `thread/resume` の完了済み turn count と合わせる |
56+
| [src/codex-rollout-memory.mjs](src/codex-rollout-memory.mjs) | Codex rollout JSONL から active turns / restore-safety diagnostics / trim source を構築する。trim source では現在進行中の in-flight turn と latest rollback 後の未完了 assistant continuation を rollback 候補から除外する。実 rollback 直前に app-server `thread/read` / `thread/resume` が同じ turn count を返し、rollout count と差がある場合は app-server 側の差分で rollback 数を補正する |
5757
| [src/codex-usage.mjs](src/codex-usage.mjs) | Codex rollout の `event_msg` / `token_count` verified shape から monitor 用 usage sample を抽出する。open turn 中は `input_tokens + output_tokens` を live footprint として返し、`task_complete` 後は verified `input_tokens` のみに戻す。`token_count` が無い rollout では active rollout text の `chars / 4` estimate を `estimated: true` として返す |
5858
| [src/codex-auto-refresh.mjs](src/codex-auto-refresh.mjs) | Codex automatic refresh 判定。verified usage が 75% 以上なら rollout source と Throughline DB memory を確認し、guarded rollback + Throughline DB memory inject を送る。estimate usage / estimated context window では実行しない。Codex `UserPromptSubmit` / `PostToolUse` hooks は同じ usage 判定で current-session `$throughline` 指示を注入し、token-monitor には依存しない |
5959
| [src/codex-handoff.mjs](src/codex-handoff.mjs) | `HandoffRecord` から Codex-facing `throughline_handoff` v1 JSON block と Codex developer-message 用 active-work context を生成。`source='throughline'` / `trust='local'` / `kind='throughline_handoff'` を固定 |
@@ -109,7 +109,7 @@
109109
| [src/cli/codex-vscode-rollback-smoke.mjs](src/cli/codex-vscode-rollback-smoke.mjs) | `codex-vscode-rollback-smoke` — rollout を read-only で読み、rollback event、rollback 済み user text、rollback 後 user turn、`restoreSafety.status = ok``--after-vscode-restart` がそろう場合だけ rollback 非復活 proof として `restartSafe: true` を返す。incident-shaped live run は `restore_safety_risk` として扱う。text output は retained / resurrected counts と risk type summary を出す |
110110
| [src/cli/codex-sidecar-diagnostics.mjs](src/cli/codex-sidecar-diagnostics.mjs) | `codex-sidecar-diagnostics``codex-sidecar diagnostics --project <repo> --preset <preset>` を実行し、JSON status を返す。failure は explicit `unavailable` |
111111
| [src/cli/codex-sidecar-dry-run.mjs](src/cli/codex-sidecar-dry-run.mjs) | `codex-sidecar-dry-run``review` / `risk-check` などの sidecar request を Codex App Server へ送らず正規化 JSON として確認する |
112-
| [src/cli/trim.mjs](src/cli/trim.mjs) | `trim --dry-run` / `--preflight` / guarded `--execute`。Codex `--execute` は明示コマンドとして rollback + Throughline DB memory inject を送る。restore-safety diagnosticshost primitive audit は診断であり、実行前 blocker ではない。結果 status は `execute-sent-live-only` / `execute-unverified` / `execute-durable-verified` に分かれ、durable verified には rollout 上の新 rollback marker と active-work memory injection が必要。developer memory inject は item-level で、`thread/inject_items` が turn list を返さない場合は post-inject turn 増加を期待しない |
112+
| [src/cli/trim.mjs](src/cli/trim.mjs) | `trim --dry-run` / `--preflight` / guarded `--execute`。Codex `--execute` は明示コマンドとして rollback + Throughline DB memory inject を送る。restore-safety diagnosticshost primitive audit、rollout/app-server turn-count mismatch は診断であり、実行前 blocker ではない。結果 status は `execute-sent-live-only` / `execute-unverified` / `execute-durable-verified` に分かれ、durable verified には rollout 上の新 rollback marker と active-work memory injection が必要。developer memory inject は item-level で、`thread/inject_items` が turn list を返さない場合は post-inject turn 増加を期待しない |
113113
| [src/token-monitor.mjs](src/token-monitor.mjs) | `monitor` — マルチセッション対応トークンモニター。Claude transcript / Codex rollout の mtime と live usage を state snapshot より優先するため、Stop hook 完了待ちではなく監視中に更新できる。Codex は `~/.codex/sessions/**/rollout-*.jsonl` も直接 discovery するため、Throughline state 未生成の現在 thread も表示できる。Claude / Codex の host を compact 表示し、Codex usage が estimate の場合は `est` / `win?`、Codex open turn では `input_tokens + output_tokens` を token count に overlay する。Codex 表示 ID は `codex:` prefix を外した raw thread id 先頭 8 桁。`--diag` で TTY/columns/env を出力(描画不具合の切り分け用) |
114114
| [src/sc-detail.mjs](src/sc-detail.mjs) | `/sc-detail <時刻>` スラッシュコマンド([.claude/commands/sc-detail.md](.claude/commands/sc-detail.md) 経由) |
115115

@@ -207,7 +207,7 @@ global install 時は Codex 側も [src/cli/install.mjs](src/cli/install.mjs)
207207
- Codex UserPromptSubmit / PostToolUse hooks は token-monitor に依存しない。hook 自身が当該 Codex session の rollout `token_count` を読み、verified 75% 以上なら同じ user turn または tool loop 継続前に `$throughline` workflow 実行指示を `additionalContext` で注入する。これは monitor を起動していないユーザーでも動く current-session trigger であり、モニターの表示値を自動発火の根拠にしない。
208208
- Codex Stop hook は DB capture / L1 summarize に加え、monitor 用 state も書く。`transcriptPath` は Claude transcript 用に残し、Codex rollout path は `rolloutPath` に保存する。monitor は state の `rolloutPath` と、state 未生成でも `~/.codex/sessions/**/rollout-*.jsonl` から直接 discovery した Codex rollout をライブに読み、`token_count` event がある場合は実測 usage として出し、無い場合だけ `estimated: true` の明示 estimate を出す。
209209
- Codex Stop hook 後の automatic refresh mutation は、verified usage が `75%` 以上なら rollback / inject を送る。estimate usage または estimated context window では実行しない。Codex native auto-compact より先に Throughline memory refresh を走らせつつ、70% warning よりは mutation を遅らせる。
210-
- Codex guarded trim の rollback source は rollout/app-server turn count guard に使うが、注入 memory は Throughline DB の `/tl` contract を正とする。`--session` 未指定時の Codex memory source は現在の `CODEX_THREAD_ID` / `THROUGHLINE_CODEX_THREAD_ID` に対応する `codex:<thread_id>` であり、同じ project の latest session へ fallback しない。古い turn は L1 summaries、直近 20 turn は L2 full bodies、L3 は reference only で、L3 bodies / tool payloads は注入しない。rollout preview を DB memory の代わりとして注入せず、DB memory が無い execute は mutation 前に拒否する。`codex-host-primitive-audit` と restore-safety diagnostics は表示するが、mutation 前 blocker にはしない。`doctor --codex``doctor --trim --host codex` はこの inject memory source / contract / L1-L2-L3 counts を表示する。
210+
- Codex guarded trim の rollback source は rollout を使って計画するが、実 rollback 直前に app-server `thread/read` / `thread/resume` が同じ turn count を返し、rollout count と差がある場合は app-server 側の差分で `numTurns` を補正する。turn-count mismatch は診断であり mutation 前 blocker ではない。注入 memory は Throughline DB の `/tl` contract を正とする。`--session` 未指定時の Codex memory source は現在の `CODEX_THREAD_ID` / `THROUGHLINE_CODEX_THREAD_ID` に対応する `codex:<thread_id>` であり、同じ project の latest session へ fallback しない。古い turn は L1 summaries、直近 20 turn は L2 full bodies、L3 は reference only で、L3 bodies / tool payloads は注入しない。rollout preview を DB memory の代わりとして注入せず、DB memory が無い execute は mutation 前に拒否する。`codex-host-primitive-audit` と restore-safety diagnostics は表示するが、mutation 前 blocker にはしない。`doctor --codex` と `doctor --trim --host codex` はこの inject memory source / contract / L1-L2-L3 counts を表示する。
211211
- Codex trim の削減量は host tokenizer の厳密実測ではなく、現時点では rollout text の `chars / 4` heuristic estimate として dry-run に表示する。rollback candidate turns が 0 の場合は、削減量も 0 と明示する。
212212
- L2 → L1 要約は現行実装で唯一の subagent 的 external model call。`codex-sidecar` が configured の環境では `summarize-l1` preset を使い、使えない場合は従来通り Claude Haiku 経路を使う。`/tl` の in-flight memo はメイン Claude が slash command 手順で書くため sidecar 移行対象ではない
213213
- Claude CLI を実際に呼ぶテスト / smoke は、明示的に必要な場合だけ実行し、モデルは Haiku を使う。他モデルを使う必要がある場合は根拠を残してから実行する

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,11 @@ Haiku path. This is an explicit compatibility mode, not silent auto-detection.
252252
looked like a rolled-back user prompt could reappear after VS Code restart /
253253
reconnect, but controlled model-visible rollback smokes did not reproduce that
254254
path. `throughline trim --execute --host codex` now sends the guarded
255-
rollback + Throughline DB memory injection when app-server turn-count guards and
256-
injectable DB memory are available. Codex current-session auto-refresh is not a
255+
rollback + Throughline DB memory injection when injectable DB memory is
256+
available. If the Codex rollout and app-server turn counts differ, Throughline
257+
keeps the mismatch as diagnostics and, when `thread/read` and `thread/resume`
258+
agree, adjusts `thread/rollback.numTurns` from the app-server count. Codex
259+
current-session auto-refresh is not a
257260
token-monitor feature: the Codex `UserPromptSubmit` hook reads the current
258261
rollout `token_count` and, at the verified 75% threshold, injects a same-session
259262
instruction to run the installed `$throughline` workflow before answering. The
@@ -695,7 +698,7 @@ entry to the `tasks` array yourself:
695698
| `throughline codex-sidecar-diagnostics` | Check `codex-sidecar` diagnostics status for this project |
696699
| `throughline codex-sidecar-dry-run` | Print a normalized read-only sidecar request without running the app server |
697700
| `throughline trim --dry-run --host codex` | Preview Codex same-thread context trim memory and host boundary; does not rollback automatically |
698-
| `throughline trim --preflight --host codex` | Read/resume the explicit Codex thread and verify turn-count guards without rollback/inject |
701+
| `throughline trim --preflight --host codex` | Read/resume the explicit Codex thread and preview any app-server-count rollback adjustment without rollback/inject |
699702
| `throughline trim --execute --host codex` | Scripted Codex current-thread rollback + Throughline DB memory inject; this is what bare `$throughline` runs in Codex |
700703
| `throughline status` | Print DB statistics (sessions, skeletons, bodies, details) |
701704
| `throughline --version` | Print the installed version |

docs/THROUGHLINE_CODEX_DUAL_SUPPORT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Claude Code transcript と handoff behavior は守りつつ、Codex primary brid
3333
## 優先順位
3434

3535
1. Throughline を Codex primary で使えるようにする。Codex primary の L2 -> L1 backend は Codex CLI を本線にする。
36-
2. Codex で Claude Rewind 相当の context trim を完成させる。2026-05-08 時点では Codex current-thread trim execute / auto-refresh は再有効化済みで、DB memory と turn-count guard を必須にする
36+
2. Codex で Claude Rewind 相当の context trim を完成させる。2026-05-09 時点では Codex current-thread trim execute / auto-refresh は再有効化済みで、DB memory を必須にし、turn-count mismatch は diagnostics と app-server count 由来の rollback `numTurns` 補正に使う
3737
3. そのあと Claude 側の `/rewind` UX / 自動化 surface を詰める。
3838

3939
Claude transcript handling の置き換えから始めないでください。Codex 対応は adapter / bridge / Codex primary entrypoint として追加します。

0 commit comments

Comments
 (0)