throughline 0.4.9 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,20 @@ shipped to npm but were not individually tagged on GitHub.
10
10
 
11
11
  ## [Unreleased]
12
12
 
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
+
13
27
  ## [0.4.9] — 2026-05-09
14
28
 
15
29
  ### Changed
package/README.md CHANGED
@@ -252,8 +252,11 @@ Haiku path. This is an explicit compatibility mode, not silent auto-detection.
252
252
  looked like a rolled-back user prompt could reappear after VS Code restart /
253
253
  reconnect, but controlled model-visible rollback smokes did not reproduce that
254
254
  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
257
260
  token-monitor feature: the Codex `UserPromptSubmit` hook reads the current
258
261
  rollout `token_count` and, at the verified 75% threshold, injects a same-session
259
262
  instruction to run the installed `$throughline` workflow before answering. The
@@ -695,7 +698,7 @@ entry to the `tasks` array yourself:
695
698
  | `throughline codex-sidecar-diagnostics` | Check `codex-sidecar` diagnostics status for this project |
696
699
  | `throughline codex-sidecar-dry-run` | Print a normalized read-only sidecar request without running the app server |
697
700
  | `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 |
699
702
  | `throughline trim --execute --host codex` | Scripted Codex current-thread rollback + Throughline DB memory inject; this is what bare `$throughline` runs in Codex |
700
703
  | `throughline status` | Print DB statistics (sessions, skeletons, bodies, details) |
701
704
  | `throughline --version` | Print the installed version |
@@ -33,7 +33,7 @@ Claude Code transcript と handoff behavior は守りつつ、Codex primary brid
33
33
  ## 優先順位
34
34
 
35
35
  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` 補正に使う。
37
37
  3. そのあと Claude 側の `/rewind` UX / 自動化 surface を詰める。
38
38
 
39
39
  Claude transcript handling の置き換えから始めないでください。Codex 対応は adapter / bridge / Codex primary entrypoint として追加します。
@@ -26,7 +26,7 @@
26
26
  - 現行 Claude path は、Claude hooks、slash command、handoff baton、DB、resume context、L1 / L2 / L3 persistence で成立している。
27
27
  - 外部モデル的に呼ぶ主要箇所は L2 -> L1 要約。
28
28
  - Claude-primary の現行 L2 -> L1 要約は `codex-sidecar` が configured の場合に sidecar を優先し、使えない場合は Claude Haiku 経路に戻る。Codex-primary は Codex CLI backend 失敗を明示 error にし、Claude Haiku / raw L2 へ fallback しない。
29
- - Codex guarded trim は、Codex app-server の `thread/read` / `thread/resume` / `thread/rollback` / `thread/inject_items` を使う。明示 thread identityrollout/app-server turn count guard、injectable memory がない場合は mutation 前に拒否する。
29
+ - Codex guarded trim は、Codex app-server の `thread/read` / `thread/resume` / `thread/rollback` / `thread/inject_items` を使う。明示 thread identity と injectable memory がない場合は mutation 前に拒否する。rollout/app-server turn count mismatch は診断に残し、`thread/read` / `thread/resume` が同じ count を返す場合は app-server 側の差分で rollback `numTurns` を補正する。
30
30
  - Claude `/rewind` 自動化はまだ有効化しない。
31
31
  - Codex automatic refresh mutation は再有効化済み。`75%` の verified usage threshold で rollback / Throughline DB memory inject を試行し、estimate usage では実行しない。Codex native auto-compact より先に Throughline refresh を走らせつつ、70% warning よりは mutation を遅らせる。
32
32
 
@@ -40,8 +40,8 @@ Codex 側で実装済み / 診断可能なもの:
40
40
  - `codex-summarize`: Codex CLI backend で L2 -> L1 を書ける。Claude Haiku / raw L2 へ fallback しない。
41
41
  - `codex-resume`: L1 summary と active L2 context を Codex active-work context / fresh-thread handoff / developer message item として描画できる。
42
42
  - `trim --dry-run --host codex` / `doctor --trim --host codex`: rollback / inject plan、memory contract、context reduction estimate、diagnostics を表示する。fresh-thread handoff は代替継続 surface として残すが、current thread trim の代替ではない。
43
- - `trim --preflight --host codex`: rollout / app-server turn count guard を確認する。restore-safety diagnostics と planned rollback risk は報告するが、拒否条件ではない。
44
- - `trim --execute --host codex`: live app-server へ guarded rollback + Throughline DB memory inject を送る。env gate や host primitive audit gate は不要。DB memory が無い場合、または rollout/app-server turn count がずれる場合は mutation 前に拒否する。
43
+ - `trim --preflight --host codex`: rollout / app-server turn count を診断し、必要なら app-server count 由来の rollback 数補正 preview を表示する。restore-safety diagnostics と planned rollback risk は報告するが、拒否条件ではない。
44
+ - `trim --execute --host codex`: live app-server へ guarded rollback + Throughline DB memory inject を送る。env gate や host primitive audit gate は不要。DB memory が無い場合は mutation 前に拒否する。rollout/app-server turn count がずれる場合は、`thread/read` / `thread/resume` が一致していれば app-server count を正として rollback `numTurns` を補正する。
45
45
  - `codex-visibility-smoke`: injected active-work memory が次 model turn で model-visible になることを確認済み。
46
46
  - `codex-rollback-model-visible-smoke`: controlled two-phase smoke。`--prepare` は unique marker を含む user turn を開始して 1 turn rollback し、`--verify` は full marker を含まない prefix-only prompt で rollback 済み marker が model-visible かを測る。これは実 current thread を mutate するため明示 env 必須。live run では `--marker-file` を使い、full marker を同一 thread の chat/tool output に出さない。
47
47
  - `codex-restore-smoke`: fresh app-server process を複数回起動し、`thread/read` / `thread/resume` / paginated `thread/turns/list` turn count が rollout active turn count と一致し続けるかを read-only で確認できる。ただし proof scope は `app_server_process_restart_only` で、VS Code restart-safe 証明ではない。
@@ -318,7 +318,7 @@ TODO:
318
318
  - post-inject visibility check
319
319
  - [x] execute env gate を外せる条件を再検討した。
320
320
  - 2026-05-07 correction: live app-server smoke / post-inject visibility / worktree 非破壊性だけでは不十分だったため、一時的に `THROUGHLINE_EXPERIMENTAL_CODEX_TRIM_EXECUTE=1` gate を戻した。
321
- - 2026-05-08 unblock: controlled rollback model-visible smoke が app-server restart 境界と VS Code reload/reconnect 境界の両方で `not-reproduced` だったため、env gate / host primitive audit gate / restore-safety-only blocker を解除した。現行 blocker は thread identity、Throughline DB injectable memory、rollout/app-server turn-count mismatch
321
+ - 2026-05-08 unblock: controlled rollback model-visible smoke が app-server restart 境界と VS Code reload/reconnect 境界の両方で `not-reproduced` だったため、env gate / host primitive audit gate / restore-safety-only blocker を解除した。2026-05-09 update: rollout/app-server turn-count mismatch も blocker から外し、app-server `thread/read` / `thread/resume` が一致する場合は差分補正で rollback `numTurns` を決める。
322
322
  - [x] partial rollback の multi-turn harness を作る。
323
323
  - [x] rollback marker / injected memory が live `thread/resume` 後も効くか確認する。
324
324
  - [x] ローカルファイル変更が戻らないことを、実ファイル付き smoke で確認する。
@@ -328,7 +328,7 @@ TODO:
328
328
  - `throughline codex-restore-smoke --codex-thread-id <id>` は fresh app-server process を複数回起動し、rollout active turn count と `thread/read` / `thread/resume` / paginated `thread/turns/list` の一致を確認する。
329
329
  - proof scope は `app_server_process_restart_only`。VS Code restart / reconnect 越しの rollback / inject durability はまだ証明しない。
330
330
  - [x] failure mode を固定する。
331
- - turn count mismatch
331
+ - turn count mismatch diagnostic / app-server-count rollback adjustment
332
332
  - inject visibility timeout
333
333
  - app-server unavailable
334
334
  - thread not found
@@ -344,10 +344,10 @@ TODO:
344
344
  Phase 4 implementation status (2026-05-07):
345
345
 
346
346
  - [x] `throughline trim --preflight --host codex --codex-thread-id <id>` は `thread/read` / `thread/resume` まで実行し、rollback / inject は送らない。
347
- - [x] historical: `throughline trim --execute --host codex --codex-thread-id <id>` は guarded execute を行う実装だった。2026-05-07 correction では env gate と host primitive audit gate を戻して一時 blocked にした。2026-05-08 unblock では controlled rollback model-visible smoke が再現しなかったため、env gate / host primitive audit gate / restore-safety-only blocker を外し、DB memory と rollout/app-server turn-count guard を残した。
348
- - [x] rollout source を使う場合、rollback 前に rollout active turn count と app-server `thread/read` / `thread/resume` turn count を照合する。不一致なら rollback / inject を送らず refuse する。
347
+ - [x] historical: `throughline trim --execute --host codex --codex-thread-id <id>` は guarded execute を行う実装だった。2026-05-07 correction では env gate と host primitive audit gate を戻して一時 blocked にした。2026-05-08 unblock では controlled rollback model-visible smoke が再現しなかったため、env gate / host primitive audit gate / restore-safety-only blocker を外し、DB memory と rollout/app-server turn-count diagnostics を残した。
348
+ - [x] rollout source を使う場合、rollback 前に rollout active turn count と app-server `thread/read` / `thread/resume` turn count を照合する。不一致でも refuse せず診断に残す。`readTurns === resumedTurns` なら planned rollback turns `readTurns - expectedTurns` を足して `thread/rollback.numTurns` を送る。
349
349
  - [x] guarded execute は `thread/rollback` -> `thread/inject_items` -> post-inject `thread/read` polling の順に進む。`turn/start` は呼ばない。
350
- - [x] fake app-server harness で partial rollback、delayed inject visibility、mismatch refusal、mutation not sent preflight を固定した。
350
+ - [x] fake app-server harness で partial rollback、delayed inject visibility、mismatch adjustment、mutation not sent preflight を固定した。
351
351
  - [x] `thread/resume` 後に injected memory が維持されることを、実 Codex host smoke として確認済み。
352
352
  - [x] 実 Codex host での next model turn visibility smoke は Phase 3 の `codex-visibility-smoke` で確認済み。active-work developer message が次の model turn の agent delta に反映された。
353
353
  - [x] 実 Codex host で `trim --preflight --host codex --codex-thread-id 019dfa40-1cc8-7d13-a110-16b09364fa6a --json` を実行し、guard が mutation 前に read / resume count を照合することを確認した。
@@ -419,7 +419,7 @@ TODO:
419
419
  - [x] Codex trim / setup まで含む command surface を決める。
420
420
  - `throughline trim --host codex`
421
421
  - `throughline trim --preflight --host codex --codex-thread-id <id>`
422
- - `throughline trim --execute --host codex --codex-thread-id <id>` (DB memory rollout/app-server turn-count guard がそろう場合に current-thread rollback / inject を実行)
422
+ - `throughline trim --execute --host codex --codex-thread-id <id>` (DB memory がある場合に current-thread rollback / inject を実行し、rollout/app-server turn-count mismatch は診断と `numTurns` 補正に使う)
423
423
  - `doctor --codex` / `codex-capture` / `codex-summarize` / `codex-resume --memo-stdin` / `codex-visibility-smoke`
424
424
  - [x] Codex primary の doctor を追加または拡張する。
425
425
  - [x] Codex primary の setup / install 手順を追加する。
@@ -461,7 +461,7 @@ Phase 5 implementation status (2026-05-06):
461
461
  - 最終確認: hook shape 変更後に新しく開始した VSCode-origin Codex session で 1 turn 完了後、`throughline doctor --codex` を実行した。`current Codex thread` は `019dfd62-9a9d-7211-bf91-89d8e3fc908e`、`latest DB session` は `codex:019dfd62-9a9d-7211-bf91-89d8e3fc908e` で一致し、`Codex hooks feature: enabled`、`Codex Stop hook: registered`、command は `/usr/bin/node /home/kite/projects/Throughline/bin/throughline.mjs codex-hook stop`、`async: false`、`timeoutSec: 300` だった。VSCode-origin の自然 Stop hook による DB capture も解決済みとして扱う。
462
462
  - historical 2026-05-07 correction: 以下の Codex trim smoke は live app-server primitive の履歴として残す。ただし 2026-05-06 incident 後、restart / reconnect 越しの durable context trim 成功とは一時的に扱わず、`$throughline` / Codex Stop hook の automatic mutation を止めていた。
463
463
  - 2026-05-09 UX 修正: bare `$throughline` は `doctor --codex` / `trim --dry-run --all` / `trim --preflight --all` を AI に順番実行させる説明 surface ではなく、`throughline trim --execute --host codex --all --json` を直接実行する scripted current-thread refresh に戻す。注入 memory は L2 最新 20 full bodies + L1 older summaries + L3 references only。diagnostics / dry-run / preflight / fresh-thread handoff は明示要求時だけ使う。
464
- - memory contract 修正: Codex guarded trim でも注入 memory は元の `/tl` 思想を正とする。古い turn は L1 summaries、直近 20 turn は L2 full bodies、L3 は reference only で、L3 bodies / tool payloads は注入しない。rollout source は rollback candidate / app-server turn count guard の根拠であり、Throughline DB memory がある場合に rollout active work preview を注入 memory として使わない。DB memory が無い execute は rollout preview を注入せず、mutation 前に拒否する。
464
+ - memory contract 修正: Codex guarded trim でも注入 memory は元の `/tl` 思想を正とする。古い turn は L1 summaries、直近 20 turn は L2 full bodies、L3 は reference only で、L3 bodies / tool payloads は注入しない。rollout source は rollback candidate app-server turn-count 補正の根拠であり、Throughline DB memory がある場合に rollout active work preview を注入 memory として使わない。DB memory が無い execute は rollout preview を注入せず、mutation 前に拒否する。
465
465
  - doctor visibility 修正: `doctor --codex` は旧 context refresh readiness として rollback source、inject memory source、memory contract、L1 summaries / recent L2 bodies / L3 references-only count、heuristic reduction estimate を表示していた。実 thread `019dfd62-9a9d-7211-bf91-89d8e3fc908e` では live readiness として `context refresh: ready`、`rollback source: codex-rollout`、`inject memory source: throughline-db`、`memory contract: older L1 + latest 20 L2 full bodies + L3 references only` を確認した。ただし incident 後は restart-safe readiness ではない。
466
466
  - 削減量の記録: `trim --dry-run --host codex` は rollout text がある場合に `contextReductionEstimate` を返す。2026-05-06 の現在 thread `019dfd62-9a9d-7211-bf91-89d8e3fc908e` では通常 keep-recent preview だと `capturedTurns = 14` / `keepRecent = 20` のため `rollbackTurns = 0`、推定削減量も 0 だった。旧 bare `$throughline` context refresh は `--all` を使っていたため、この keep-recent preview の 0 は「Codex で削減できない」という意味ではない。
467
467
  - historical live-only `$throughline` context refresh smoke: 同じ VSCode-origin thread `019dfd62-9a9d-7211-bf91-89d8e3fc908e` で `trim --dry-run --host codex --all --json` -> `trim --preflight --host codex --all --json` -> `trim --execute --host codex --all` を実行した。preflight は rollout/app-server turn count `20 / 20` match、execute は `rollbackSent = true`、`injectSent = true`、`injectedItems = 1`、`rollback candidate turns = 20`。直前見積もりは `rollbackEstimatedTokens = 179780`、`injectedMemoryEstimatedTokens = 2009`、`netEstimatedTokens = 177771`、`reductionPct = 99` (`chars / 4` heuristic)。これは live app-server smoke であり、restart-safe durability の証明ではない。
@@ -515,7 +515,7 @@ TODO:
515
515
 
516
516
  ## 次の作業
517
517
 
518
- Codex primary の capture / summarize / resume は完了扱い。Codex trim execute / auto-refresh も 2026-05-08 の controlled rollback model-visible smoke 後に再有効化済み。[THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md](THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md) の Phase 0-4、read-only app-server process restart smoke、local restore source audit、host primitive audit、manual VS Code restore smoke protocol、実 VS Code reload / reconnect marker proof、rollback 非復活 verifier、controlled rollback model-visible smoke surface は実装済み。incident-shaped live rollback run は `restoreSafety.status = risk` で、`compacted.replacement_history` retention と rollback 済み text match を診断上は観測した。後続の app-server response 分類では retained text が `aggregatedOutput` の引用に限定され、direct user message / model-visible reproduction とは分けて扱う。host primitive audit でも current-thread rollback non-resurrection primitive は見つかっていないが、これは diagnostic-only で、DB memory rollout/app-server turn-count guard がそろう `trim --execute` を塞がない。
518
+ Codex primary の capture / summarize / resume は完了扱い。Codex trim execute / auto-refresh も 2026-05-08 の controlled rollback model-visible smoke 後に再有効化済み。[THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md](THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md) の Phase 0-4、read-only app-server process restart smoke、local restore source audit、host primitive audit、manual VS Code restore smoke protocol、実 VS Code reload / reconnect marker proof、rollback 非復活 verifier、controlled rollback model-visible smoke surface は実装済み。incident-shaped live rollback run は `restoreSafety.status = risk` で、`compacted.replacement_history` retention と rollback 済み text match を診断上は観測した。後続の app-server response 分類では retained text が `aggregatedOutput` の引用に限定され、direct user message / model-visible reproduction とは分けて扱う。host primitive audit でも current-thread rollback non-resurrection primitive は見つかっていないが、これは diagnostic-only で、DB memory がある `trim --execute` を塞がない。rollout/app-server turn-count mismatch は診断と app-server-count `numTurns` 補正に使う。
519
519
 
520
520
  再開時は次を実施する:
521
521
 
@@ -45,7 +45,7 @@ rollback trim は最終的な理想に近いが、host primitive の実測が必
45
45
  - Claude hooks、slash command、transcript parsing、handoff baton、SessionStart resume behavior を Codex 用に置き換えない。
46
46
  - Claude-facing field / command / DB semantics を rename しない。
47
47
  - Codex 対応は adapter / projection として足す。
48
- - `thread/rollback` / `thread/inject_items` は live host primitive として実測済み。2026-05-06 incident 後に Codex guarded execute / auto-refresh は一時停止したが、2026-05-08 の controlled rollback model-visible smoke が再現しなかったため、過剰 blocker は解除済み。現在は [THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md](THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md) を優先し、DB memory rollout/app-server turn-count guard を必須にする。Claude `/rewind` 自動化はまだ有効化しない。
48
+ - `thread/rollback` / `thread/inject_items` は live host primitive として実測済み。2026-05-06 incident 後に Codex guarded execute / auto-refresh は一時停止したが、2026-05-08 の controlled rollback model-visible smoke が再現しなかったため、過剰 blocker は解除済み。現在は [THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md](THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md) を優先し、DB memory を必須にする。rollout/app-server turn-count mismatch は診断と app-server count 由来の rollback `numTurns` 補正に使う。Claude `/rewind` 自動化はまだ有効化しない。
49
49
  - fallback や silent recovery で失敗を隠さない。互換モードは条件と理由を明示する。
50
50
 
51
51
  ## 運用ルール
@@ -372,7 +372,7 @@ Phase 6 result (2026-05-06):
372
372
  - `thread/inject_items` に raw Responses API item `{ type: "message", role: "developer", content: [{ type: "input_text", text: "..." }] }` を渡し、次の `turn/start` で injected memory が model-visible になることを確認した。marker `TL_PHASE6_INJECT_OK` を正しく返した。
373
373
  - その後の Codex primary 実装で、`codex-resume` が描画する active-work developer message も実 Codex host で model-visible になることを確認した。marker `TL_CODEX_VISIBLE_REAL_20260506_C` が `item/agentMessage/delta` に出た。詳細な実測値は [THROUGHLINE_CODEX_FIRST_ROADMAP.md](THROUGHLINE_CODEX_FIRST_ROADMAP.md) の Phase 3 result を正とする。
374
374
  - さらに `thread/inject_items` 後にもう一度 `thread/resume` してから `turn/start` を呼ぶ smoke も追加し、実 Codex host で marker `TL_CODEX_RESUME_AFTER_INJECT_REAL_20260506` が `item/agentMessage/delta` に出ることを確認した。
375
- - Codex host primitive は live app-server 上では実測済み。ただし restart-safe durability は未証明。現在は明示 `--codex-thread-id` または env thread identity と rollout/app-server turn count guard live mutation の最低条件であり、durable success は別分類で扱う。2026-05-06 incident 後はいったん Codex Stop hook 後の automatic refresh mutation を blocked としたが、2026-05-08 unblock 後は guarded rollback / inject を試行する。2026-05-09 以降は Codex native auto-compact より先に Throughline refresh を走らせるため、verified usage 75% 以上を既定閾値にする。
375
+ - Codex host primitive は live app-server 上では実測済み。ただし restart-safe durability は未証明。現在は明示 `--codex-thread-id` または env thread identity と Throughline DB memory が live mutation の最低条件であり、rollout/app-server turn-count mismatch は診断と rollback `numTurns` 補正に使う。durable success は別分類で扱う。2026-05-06 incident 後はいったん Codex Stop hook 後の automatic refresh mutation を blocked としたが、2026-05-08 unblock 後は guarded rollback / inject を試行する。2026-05-09 以降は Codex native auto-compact より先に Throughline refresh を走らせるため、verified usage 75% 以上を既定閾値にする。
376
376
  - Claude `/rewind conversation only` は手動 UX として扱う。外部ツールからの自動化 surface は未確認。Claude host の automatic rollback / inject は `manual-only`。
377
377
  - Phase 8 では dry-run / preflight を本線にしつつ、Codex だけ guarded execute を追加した。Claude は manual-only のまま扱う。
378
378
 
@@ -386,7 +386,7 @@ Phase 6 result (2026-05-06):
386
386
 
387
387
  TODO:
388
388
 
389
- - [x] host identity model を整理する。Claude `session_id`、Codex `thread_id`、`project_path`、origin session / thread references の対応表を作る。Codex は `thread_id` と rollout JSONL を app-server で扱い、明示 identity と turn count guard がある場合だけ guarded execute へ進む。
389
+ - [x] host identity model を整理する。Claude `session_id`、Codex `thread_id`、`project_path`、origin session / thread references の対応表を作る。Codex は `thread_id` と rollout JSONL を app-server で扱い、明示 identity と Throughline DB memory がある場合に guarded execute へ進む。turn count mismatch は診断と app-server count 由来の rollback `numTurns` 補正に使う。
390
390
  - [x] current session / thread の captured turn count を記録または導出する方法を決める。
391
391
  - [x] rollback 可能な最大 turn 数を計算する。
392
392
  - [x] keep-recent の既定値を決める。
@@ -428,7 +428,7 @@ TODO:
428
428
  - [x] 実行前に captured turns / keep turns / injected memory summary を表示する。
429
429
  - [x] Codex dry-run では `--codex-thread-id` を受け取り、Claude / Throughline の `session_id` と Codex `thread_id` を混同しない形で plan に残す。
430
430
  - [x] Codex non-dry-run の最初の統合として `--preflight` を追加する。これは app-server の initialize / read / resume だけを実行し、rollback / inject は送らない。
431
- - [x] Codex の guarded execution として `--execute` を追加する。ただし `--host codex`、明示または env の Codex thread identity、rollout/app-server turn count guard を必須にし、実行後に model turn は開始しない。
431
+ - [x] Codex の guarded execution として `--execute` を追加する。ただし `--host codex`、明示または env の Codex thread identity、Throughline DB memory を必須にし、実行後に model turn は開始しない。rollout/app-server turn-count mismatch は診断と rollback `numTurns` 補正に使う。
432
432
  - [ ] 自動 rollback 対応 host では、実行後に resume / injected memory が restart / reconnect 後も有効か検証する。Codex は Phase 6 spike、2026-05-06 guarded execute smoke、post-inject resume visibility smoke で live app-server 上の rollback/inject と injected memory visibility だけを確認した。2026-05-06 incident 後、これは restart-safe durability の完了条件を満たさない。
433
433
  - [x] `doctor` に trim 関連診断を追加する。
434
434
 
@@ -436,11 +436,11 @@ Phase 8 partial implementation result (2026-05-06):
436
436
 
437
437
  - `throughline trim --dry-run [--host claude|codex|unknown] [--keep-recent N] [--all] [--session <id>] [--codex-thread-id <id>] [--json]` を追加。
438
438
  - `throughline trim --dry-run --memo-stdin` を追加。`/tl` が解決した「L1/L2 はあるが今やっている作業として認識されない」問題を `/tl-trim` でも再発させないため、current-work memo を curated memory preview の先頭に入れる。
439
- - non-dry-run `throughline trim` は Claude / unknown host では automatic rollback / inject 未対応として exit 1 で明示拒否する。Codex host には `--execute` 経路が実装済み。2026-05-06 incident 後はいったん拒否したが、2026-05-08 unblock 後は明示 `--execute`、Codex thread identity、Throughline DB memoryrollout/app-server turn-count guard がそろえば mutation へ進む。
439
+ - non-dry-run `throughline trim` は Claude / unknown host では automatic rollback / inject 未対応として exit 1 で明示拒否する。Codex host には `--execute` 経路が実装済み。2026-05-06 incident 後はいったん拒否したが、2026-05-08 unblock 後は明示 `--execute`、Codex thread identity、Throughline DB memory がそろえば mutation へ進む。2026-05-09 以降は rollout/app-server turn-count mismatch refuse せず、app-server count 由来で rollback `numTurns` を補正する。
440
440
  - `src/codex-app-server.mjs` を追加し、newline JSON framing、initialize / read / resume / rollback / inject / turn-start request builder、server line parser をテストで固定した。Codex guarded execute はこの helper を通り、model turn は開始しない。
441
441
  - `--codex-thread-id` の明示入力を最優先で信頼する。明示入力が無い場合のみ、`THROUGHLINE_CODEX_THREAD_ID` / `CODEX_THREAD_ID` を current-thread identity signal として使う。最新 rollout 推測による automatic trim は行わない。
442
442
  - `throughline trim --preflight --host codex --codex-thread-id <id> [--json]` を追加した。これは `thread/read` と `thread/resume` が対象 thread に届くことを確認し、`rollbackRequestPreview` を返すが、`thread/rollback` / `thread/inject_items` は送らない。
443
- - `codex-rollout` source の場合、preflight は rollout 側 active turn count と app-server `thread/read` / `thread/resume` の turn count を突き合わせる。不一致または app-server count 不明なら `preflight-refused` として止まり、rollback / inject は送らない。
443
+ - `codex-rollout` source の場合、preflight は rollout 側 active turn count と app-server `thread/read` / `thread/resume` の turn count を突き合わせる。不一致でも `preflight-refused` にはせず、`readTurns === resumedTurns` なら app-server count 由来の rollback `numTurns` 補正 preview を返す。preflight なので rollback / inject は送らない。
444
444
  - 同日、検証 thread `019dfaba-f87e-7f41-a144-d5ca7c6dd7f9` に実 app-server preflight を当て、`readTurns: 1` / `resumedTurns: 1` / `rollbackSent: false` / `injectSent: false` を確認した。
445
445
  - `throughline trim --execute --host codex --codex-thread-id <id> [--json]` を追加した。2026-05-06 incident 後は既定で拒否し、2026-05-07 追加修正では host primitive audit gate も置いた。2026-05-08 unblock 後はこの env gate / host primitive audit gate を外し、app-server の `thread/read`、`thread/resume`、`thread/rollback`、`thread/inject_items`、確認用 `thread/read` へ進む。host primitive audit と restore-safety は diagnostic-only。
446
446
  - 実 app-server smoke では `thread/inject_items` の直後に返る turn 配列が、注入 item の可視化より早い場合があると分かった。その後の current-thread live run で、現行 Codex host の developer memory injection は item-level で、即時 `thread/read` の turn count を増やさない場合があることも確認した。そのため `--execute` は `thread/inject_items` の応答に turn list があればその turn count を期待値とし、応答に turn list がなければ rollback 後 turn count を期待値として post-inject `thread/read` を短く poll する。`postInjectVisibilityCheck` は `match` / `timeout` / `unchecked` を記録する。CLI 外側の status は `executed` ではなく、live mutation だけなら `execute-sent-live-only`、timeout や durable evidence 不足なら `execute-unverified`、rollout に新 rollback marker と active-work memory injection が観測された場合は `execute-durable-verified` とする。restore-safety は durable mutation evidence とは別の diagnostic として表示する。exit 0 は `execute-durable-verified` に限る。
@@ -18,7 +18,9 @@ quoted/tool-output field に残り得ることは確認済みですが、それ
18
18
  model-visible input に入ることは controlled smoke で再現していません。incident-shaped
19
19
  run の retained text は risk evidence として残す一方、単独では mutation 前 blocker にしません。
20
20
  Codex current-thread trim は、明示 `--execute`、Throughline DB injectable memory、
21
- Codex thread identityrollout/app-server turn-count guard を条件に実行します。Codex Stop hook
21
+ Codex thread identity を条件に実行します。rollout/app-server turn-count mismatch は診断に残し、
22
+ app-server `thread/read` / `thread/resume` が同じ count を返す場合は、その差分で rollback `numTurns`
23
+ を補正します。Codex Stop hook
22
24
  auto-refresh は verified usage 75% 以上で同じ guarded path を試行し、estimate usage では実行しません。
23
25
 
24
26
  最初のインシデント仮説に対する重要な訂正:
@@ -293,7 +295,8 @@ TODO:
293
295
  repair contract が blocked の場合は拒否していた。
294
296
  - 2026-05-08 unblock: host primitive audit は diagnostic-only に変更した。
295
297
  現行 Codex CLI に same-thread repair primitive が無い事実は表示するが、
296
- DB memory rollout/app-server turn-count guard がそろう execute を塞がない。
298
+ DB memory がある execute を塞がない。rollout/app-server turn-count mismatch
299
+ 診断と app-server count 由来の rollback `numTurns` 補正に使う。
297
300
  - `~/.codex/state_5.sqlite` の `threads` table は rollout path / metadata を持つが、
298
301
  turn bodies は持たない。turn body の主根拠は rollout JSONL 側である可能性が
299
302
  高いが、VS Code extension restore source は別途未確定。
@@ -624,8 +627,9 @@ TODO:
624
627
  mutation 前 blocker にはしない。
625
628
  - [x] 明示 `trim --execute --host codex` の製品判断を固定する。
626
629
  - 判断: 明示 `--execute` で実行する。env opt-in と host primitive audit gate は外す。
627
- DB memory が無い場合、または rollout/app-server turn count guard が合わない場合は
628
- mutation 前に拒否する。実行後は `execute-sent-live-only` /
630
+ DB memory が無い場合は mutation 前に拒否する。rollout/app-server turn count がずれる場合は
631
+ refusal ではなく診断に残し、app-server count を正として rollback `numTurns` を補正する。
632
+ 実行後は `execute-sent-live-only` /
629
633
  `execute-unverified` / `execute-durable-verified` で結果を分ける。
630
634
 
631
635
  受け入れ条件:
@@ -673,5 +677,9 @@ TODO:
673
677
  作業量や複雑さを理由に目標を下げない。2026-05-08 時点の製品仕様は、
674
678
  同一 Codex thread で guarded rollback + Throughline DB memory inject を実行し、
675
679
  rollout 上の新 rollback event と injected active-work memory で durable evidence を確認すること。
676
- restore-safety / host primitive audit は diagnostics として残すが、単独では execute / auto-refresh の blocker にしない。
677
- mutation 前 refusal は thread identityThroughline DB injectable memory、rollout/app-server turn-count mismatch に限定する。
680
+ restore-safety / host primitive audit / rollout-app-server turn-count mismatch は diagnostics として残すが、単独では execute / auto-refresh の blocker にしない。
681
+ mutation 前 refusal は thread identityThroughline DB injectable memory に限定する。
682
+ 2026-05-09 update: rollout/app-server turn-count mismatch は mutation 前 refusal から外した。
683
+ app-server `thread/read` / `thread/resume` が同じ count を返す場合、planned rollback turns に
684
+ `readTurns - expectedTurns` を足して `thread/rollback.numTurns` を送る。例:
685
+ `expectedTurns = 6` / `readTurns = resumedTurns = 7` / `--all` なら `numTurns = 7`。
@@ -15,11 +15,13 @@
15
15
 
16
16
  この文書は「rollback は欠けていた delete primitive かもしれない」という洞察を残すもの。実装時は、未検証の host primitive を本線仕様にせず、次フェーズ計画 [THROUGHLINE_CODEX_FIRST_ROADMAP.md](THROUGHLINE_CODEX_FIRST_ROADMAP.md) の Codex Rewind 互換 Phase で実測してから本線 UX に進む。
17
17
 
18
- 2026-05-06 update: Codex app-server の `thread/rollback` / `thread/inject_items` は live host primitive として実測済み。Throughline CLI には明示 `--codex-thread-id` または `THROUGHLINE_CODEX_THREAD_ID` / `CODEX_THREAD_ID` による current-thread identity、rollout/app-server turn count guard、guarded execute が入った。
18
+ 2026-05-06 update: Codex app-server の `thread/rollback` / `thread/inject_items` は live host primitive として実測済み。Throughline CLI には明示 `--codex-thread-id` または `THROUGHLINE_CODEX_THREAD_ID` / `CODEX_THREAD_ID` による current-thread identity、rollout/app-server turn count diagnostics、guarded execute が入った。
19
19
 
20
20
  2026-05-07 correction: VS Code restart / reconnect 後に rollback 済み user prompt が復活したように見える incident が起きたため、Codex rollback / inject は restart-safe な context trim primitive としていったん未証明へ戻した。特に `compacted.replacement_history` など、live app-server read/resume 以外の restore source を検証するまで、`$throughline` と Codex Stop hook auto-refresh は mutation を自動実行しない方針にした。Claude `/rewind` 自動化はまだ有効化しない。
21
21
 
22
- 2026-05-08 unblock: その後の切り分けで、incident thread の retained text は app-server response 上では `aggregatedOutput` など quoted/tool-output field に分類され、controlled rollback model-visible smoke は app-server restart 境界と VS Code reload/reconnect 境界の両方で `not-reproduced` だった。これを受け、Codex `trim --execute --host codex` と Stop hook auto-refresh の過剰 blocker は解除する。`compacted.replacement_history` retention、restore-safety risk、host primitive audit は引き続き diagnostics だが、単独では mutation 前 refusal にしない。DB memory 不在と rollout/app-server turn-count 不一致は引き続き mutation 前 blocker。
22
+ 2026-05-08 unblock: その後の切り分けで、incident thread の retained text は app-server response 上では `aggregatedOutput` など quoted/tool-output field に分類され、controlled rollback model-visible smoke は app-server restart 境界と VS Code reload/reconnect 境界の両方で `not-reproduced` だった。これを受け、Codex `trim --execute --host codex` と Stop hook auto-refresh の過剰 blocker は解除する。`compacted.replacement_history` retention、restore-safety risk、host primitive audit は引き続き diagnostics だが、単独では mutation 前 refusal にしない。DB memory 不在は引き続き mutation 前 blocker。
23
+
24
+ 2026-05-09 update: rollout/app-server turn-count 不一致も mutation 前 blocker から外した。app-server `thread/read` / `thread/resume` が同じ count を返す場合、planned rollback turns に `readTurns - expectedTurns` を足して `thread/rollback.numTurns` を送る。`expectedTurns = 6` / `readTurns = resumedTurns = 7` / `--all` なら `numTurns = 7`。
23
25
 
24
26
  2026-05-09 skill UX: bare `$throughline` は diagnostics / dry-run / preflight を AI に順番実行させる surface ではなく、`throughline trim --execute --host codex --all --json` を直接走らせる scripted current-thread refresh とする。目的は rollback と、Throughline DB の L2 最新 20 full bodies + older L1 summaries + L3 references-only memory injection のみ。doctor / dry-run / preflight / fresh-thread handoff / restore-safety / host primitive audit は明示診断用であり、通常 `$throughline` の前段にはしない。
25
27
 
@@ -265,8 +267,8 @@ Codex で考えられる流れ:
265
267
 
266
268
  現行実装では、Codex Stop hook 後の 75% automatic refresh は guarded rollback / inject
267
269
  mutation を試行する。明示 CLI の `throughline trim --execute --host codex --codex-thread-id <id>`
268
- も env gate なしで実行する。明示 Codex thread identityinjectable Throughline DB memory
269
- rollout/app-server turn count guard live mutation の最低条件であり、durable success は
270
+ も env gate なしで実行する。明示 Codex thread identityinjectable Throughline DB memory
271
+ は live mutation の最低条件であり、rollout/app-server turn-count mismatch は診断と app-server count 由来の rollback `numTurns` 補正に使う。durable success は
270
272
  post-execute rollout evidence で `execute-durable-verified` として別判定する。
271
273
 
272
274
  重要な考え:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "throughline",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "type": "module",
5
5
  "description": "Claude Code hooks plugin for structured context compression (/clear-safe persistent memory)",
6
6
  "keywords": [
package/src/cli/trim.mjs CHANGED
@@ -366,15 +366,6 @@ async function runPreflight(parsed, plan) {
366
366
  expectedTurns: expectedCodexAppServerTurns(plan),
367
367
  command,
368
368
  });
369
- const turnCountStatus = preflight.turnCountCheck?.status;
370
- if (turnCountStatus === 'mismatch' || turnCountStatus === 'unknown') {
371
- return {
372
- status: 'preflight-refused',
373
- reason: preflight.turnCountCheck.reason,
374
- plan,
375
- preflight,
376
- };
377
- }
378
369
 
379
370
  return {
380
371
  status: 'preflight-ready',
@@ -209,6 +209,48 @@ export function buildThreadRollbackRequest({ id, threadId, numTurns }) {
209
209
  };
210
210
  }
211
211
 
212
+ export function resolveRollbackTurnsForAppServer({
213
+ plannedRollbackTurns,
214
+ expectedTurns = null,
215
+ readTurns = null,
216
+ resumedTurns = null,
217
+ } = {}) {
218
+ if (!Number.isInteger(plannedRollbackTurns) || plannedRollbackTurns < 1) {
219
+ throw new Error('resolveRollbackTurnsForAppServer: plannedRollbackTurns must be an integer >= 1');
220
+ }
221
+ assertOptionalTurnCount(expectedTurns, 'resolveRollbackTurnsForAppServer: expectedTurns');
222
+
223
+ const result = {
224
+ plannedRollbackTurns,
225
+ requestedRollbackTurns: plannedRollbackTurns,
226
+ adjustment: 0,
227
+ basis: 'planned',
228
+ reason: 'using_planned_rollback_turns',
229
+ };
230
+
231
+ if (
232
+ Number.isInteger(expectedTurns) &&
233
+ Number.isInteger(readTurns) &&
234
+ Number.isInteger(resumedTurns) &&
235
+ readTurns === resumedTurns &&
236
+ readTurns !== expectedTurns
237
+ ) {
238
+ const adjustment = readTurns - expectedTurns;
239
+ const adjustedTurns = plannedRollbackTurns + adjustment;
240
+ if (adjustedTurns >= 1) {
241
+ return {
242
+ plannedRollbackTurns,
243
+ requestedRollbackTurns: Math.min(adjustedTurns, readTurns),
244
+ adjustment,
245
+ basis: 'app_server_turn_count',
246
+ reason: 'adjusted_by_app_server_turn_delta',
247
+ };
248
+ }
249
+ }
250
+
251
+ return result;
252
+ }
253
+
212
254
  export function buildThreadInjectItemsRequest({ id, threadId, items }) {
213
255
  assertRequestId(id, 'buildThreadInjectItemsRequest');
214
256
  assertNonEmptyString(threadId, 'buildThreadInjectItemsRequest: threadId');
@@ -313,6 +355,12 @@ export async function runCodexTrimPreflight({
313
355
  );
314
356
  const readTurns = countTurns(beforeRead);
315
357
  const resumedTurns = countTurns(resumed);
358
+ const rollbackResolution = resolveRollbackTurnsForAppServer({
359
+ plannedRollbackTurns: rollbackTurns,
360
+ expectedTurns,
361
+ readTurns,
362
+ resumedTurns,
363
+ });
316
364
 
317
365
  return {
318
366
  status: 'preflight-ready',
@@ -321,6 +369,8 @@ export async function runCodexTrimPreflight({
321
369
  injectSent: false,
322
370
  readTurns,
323
371
  resumedTurns,
372
+ rollbackRequestedTurns: rollbackResolution.requestedRollbackTurns,
373
+ rollbackResolution,
324
374
  turnCountCheck: compareTurnCounts({
325
375
  expectedTurns,
326
376
  readTurns,
@@ -329,7 +379,7 @@ export async function runCodexTrimPreflight({
329
379
  rollbackRequestPreview: buildThreadRollbackRequest({
330
380
  id: 'rollback-preview',
331
381
  threadId,
332
- numTurns: rollbackTurns,
382
+ numTurns: rollbackResolution.requestedRollbackTurns,
333
383
  }),
334
384
  notifications: [...new Set(client.notifications)],
335
385
  stderr: client.stderr,
@@ -964,27 +1014,17 @@ export async function runCodexTrimExecution({
964
1014
  readTurns,
965
1015
  resumedTurns,
966
1016
  });
967
- if (turnCountCheck.status === 'mismatch' || turnCountCheck.status === 'unknown') {
968
- return {
969
- status: 'refused',
970
- reason: 'codex_rollout_app_server_turn_mismatch',
971
- threadId,
972
- rollbackSent: false,
973
- injectSent: false,
974
- injectedItems: 0,
975
- readTurns,
976
- resumedTurns,
977
- rollbackRequestedTurns: rollbackTurns,
978
- turnCountCheck,
979
- notifications: [...new Set(client.notifications)],
980
- stderr: client.stderr,
981
- };
982
- }
1017
+ const rollbackResolution = resolveRollbackTurnsForAppServer({
1018
+ plannedRollbackTurns: rollbackTurns,
1019
+ expectedTurns,
1020
+ readTurns,
1021
+ resumedTurns,
1022
+ });
983
1023
  const rollback = await client.request(
984
1024
  buildThreadRollbackRequest({
985
1025
  id: randomUUID(),
986
1026
  threadId,
987
- numTurns: rollbackTurns,
1027
+ numTurns: rollbackResolution.requestedRollbackTurns,
988
1028
  }),
989
1029
  );
990
1030
  const inject = await client.request(
@@ -1016,7 +1056,8 @@ export async function runCodexTrimExecution({
1016
1056
  injectedItems: 1,
1017
1057
  readTurns,
1018
1058
  resumedTurns,
1019
- rollbackRequestedTurns: rollbackTurns,
1059
+ rollbackRequestedTurns: rollbackResolution.requestedRollbackTurns,
1060
+ rollbackResolution,
1020
1061
  rollbackResultTurns,
1021
1062
  injectResultTurns,
1022
1063
  afterTurns: postInjectRead.turns,
@@ -19,6 +19,7 @@ import {
19
19
  compareTurnCounts,
20
20
  encodeAppServerMessage,
21
21
  parseAppServerLine,
22
+ resolveRollbackTurnsForAppServer,
22
23
  runCodexModelVisibilitySmoke,
23
24
  runCodexRollbackModelVisiblePrepare,
24
25
  runCodexRollbackModelVisibleVerify,
@@ -203,6 +204,50 @@ test('compareTurnCounts: rejects invalid expected turn count', () => {
203
204
  );
204
205
  });
205
206
 
207
+ test('resolveRollbackTurnsForAppServer adjusts planned rollback by app-server turn delta', () => {
208
+ assert.deepEqual(
209
+ resolveRollbackTurnsForAppServer({
210
+ plannedRollbackTurns: 6,
211
+ expectedTurns: 6,
212
+ readTurns: 7,
213
+ resumedTurns: 7,
214
+ }),
215
+ {
216
+ plannedRollbackTurns: 6,
217
+ requestedRollbackTurns: 7,
218
+ adjustment: 1,
219
+ basis: 'app_server_turn_count',
220
+ reason: 'adjusted_by_app_server_turn_delta',
221
+ },
222
+ );
223
+
224
+ assert.deepEqual(
225
+ resolveRollbackTurnsForAppServer({
226
+ plannedRollbackTurns: 2,
227
+ expectedTurns: 22,
228
+ readTurns: 21,
229
+ resumedTurns: 21,
230
+ }),
231
+ {
232
+ plannedRollbackTurns: 2,
233
+ requestedRollbackTurns: 1,
234
+ adjustment: -1,
235
+ basis: 'app_server_turn_count',
236
+ reason: 'adjusted_by_app_server_turn_delta',
237
+ },
238
+ );
239
+
240
+ assert.equal(
241
+ resolveRollbackTurnsForAppServer({
242
+ plannedRollbackTurns: 6,
243
+ expectedTurns: 6,
244
+ readTurns: 7,
245
+ resumedTurns: 8,
246
+ }).requestedRollbackTurns,
247
+ 6,
248
+ );
249
+ });
250
+
206
251
  test('summarizeAppServerStderr: compacts repeated unknown-turn item warnings', () => {
207
252
  const stderr = [
208
253
  '2026-05-06T00:00:00Z WARN codex_app_server_protocol::protocol::thread_history: dropping turn-scoped item for unknown turn id `turn-a` item_id="call_1"',
@@ -137,6 +137,7 @@ rl.on('line', (line) => {
137
137
  send({ id: msg.id, error: { code: -32000, message: 'mutation must not be called' } });
138
138
  return;
139
139
  }
140
+ appendFileSync(log, 'ROLLBACK_TURNS:' + msg.params.numTurns + '\\n');
140
141
  turns = turns.slice(0, Math.max(0, turns.length - msg.params.numTurns));
141
142
  appendRollout({ type: 'event_msg', payload: { type: 'thread_rolled_back', num_turns: msg.params.numTurns } });
142
143
  send({ id: msg.id, result: { thread: { id: threadId, turns } } });
@@ -843,7 +844,7 @@ test('trim CLI preflight proceeds when compacted history already retains target
843
844
  }
844
845
  });
845
846
 
846
- test('trim CLI execute refuses before rollback when rollout and app-server turn counts differ', async () => {
847
+ test('trim CLI execute adjusts rollback turns from app-server count when counts differ', async () => {
847
848
  const home = makeTempHome();
848
849
  const codexHome = makeTempHome();
849
850
  const project = makeTempProject();
@@ -853,12 +854,12 @@ test('trim CLI execute refuses before rollback when rollout and app-server turn
853
854
  writeCodexRollout(codexHome, {
854
855
  project,
855
856
  threadId,
856
- turnCount: 22,
857
+ turnCount: 6,
857
858
  });
858
859
  const { script, log } = makeFakeCodexAppServer(project, {
859
860
  allowMutation: true,
860
861
  threadId,
861
- turnCount: 21,
862
+ turnCount: 7,
862
863
  });
863
864
  const result = runTrim(
864
865
  home,
@@ -868,8 +869,7 @@ test('trim CLI execute refuses before rollback when rollout and app-server turn
868
869
  'codex',
869
870
  '--codex-thread-id',
870
871
  threadId,
871
- '--keep-recent',
872
- '20',
872
+ '--all',
873
873
  '--execute',
874
874
  '--codex-app-server-bin',
875
875
  script,
@@ -881,17 +881,25 @@ test('trim CLI execute refuses before rollback when rollout and app-server turn
881
881
 
882
882
  assert.equal(result.status, 1);
883
883
  const payload = JSON.parse(result.stdout);
884
- assert.equal(payload.status, 'execute-refused');
885
- assert.equal(payload.reason, 'codex_rollout_app_server_turn_mismatch');
886
- assert.equal(payload.execution.rollbackSent, false);
887
- assert.equal(payload.execution.injectSent, false);
884
+ assert.notEqual(payload.status, 'execute-refused');
885
+ assert.equal(payload.execution.rollbackSent, true);
886
+ assert.equal(payload.execution.injectSent, true);
887
+ assert.equal(payload.execution.rollbackRequestedTurns, 7);
888
888
  assert.equal(payload.execution.turnCountCheck.status, 'mismatch');
889
+ assert.deepEqual(payload.execution.rollbackResolution, {
890
+ plannedRollbackTurns: 6,
891
+ requestedRollbackTurns: 7,
892
+ adjustment: 1,
893
+ basis: 'app_server_turn_count',
894
+ reason: 'adjusted_by_app_server_turn_delta',
895
+ });
889
896
 
890
897
  const calledMethods = readFileSync(log, 'utf8');
891
898
  assert.match(calledMethods, /thread\/read/);
892
899
  assert.match(calledMethods, /thread\/resume/);
893
- assert.doesNotMatch(calledMethods, /thread\/rollback/);
894
- assert.doesNotMatch(calledMethods, /thread\/inject_items/);
900
+ assert.match(calledMethods, /thread\/rollback/);
901
+ assert.match(calledMethods, /ROLLBACK_TURNS:7/);
902
+ assert.match(calledMethods, /thread\/inject_items/);
895
903
  } finally {
896
904
  rmSync(project, { recursive: true, force: true });
897
905
  rmSync(home, { recursive: true, force: true });