throughline 0.16.11 → 0.16.12

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,29 @@ shipped to npm but were not individually tagged on GitHub.
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.16.12] — 2026-10-10
14
+
15
+ ### 修正
16
+
17
+ - Codex Desktopの自動継続が、旧タスクの順番待ちに入力が残っていると`handoff_source_input_pending`で止まり、そのタスクでは何度入力しても同じ理由で止まり続けた。Windowsの実機で、2つのタスクに7回続き、どちらもそのまま使われなくなった。止めたタスクではCodexが順番待ちを動かさないので、順番待ちは空にならない。
18
+ - 引き継ぎを断らない。後継が作業を続けたのを確かめた後に、旧タスクの順番待ちの入力を、順番を保って後継の順番待ちへ運ぶ([ADR 0045](docs/adr/0045-codex-handoff-carries-pending-queue.md))。
19
+ - 二重に送らない。後継へ入れた結果が分からない入力は入れ直さず、旧タスクの順番待ちに残す。運べなくても引き継ぎは止めない。
20
+ - 0.16.11までで止まっていたタスクは、次の入力でやり直しが動き、引き継がれる。その時点で順番待ちに残っている入力は、全部後継へ運ばれる。
21
+
22
+ ### 変わらない事
23
+
24
+ - 実行中の子agent、設定の不一致、追跡されていない旧handoff記憶で止まる扱い。引き継ぎ済みの旧タスクへ後から届く入力の扱い。Claude Codeの自動継続。
25
+
26
+ ### 確認した範囲
27
+
28
+ - Linux(Codex Desktop同梱のCodex 0.162.0-alpha.2)の試験用フォルダで、本物のCodex Desktopに自動継続を2回続けて流した。最初のターンが動いている間に、順番待ちへ入力を1つ入れた。2回とも引き継ぎは`continued`になり、入力は後継から次の後継へ運ばれ、最後の後継で継続の指示のターンの後に1回だけ実行された。旧い2本のrolloutには出ていない。順番待ちは3本とも空になった。
29
+ - macOS(同梱のCodex 0.162.0-alpha.2)とWindowsの同梱のCodexで、試験タスク2本の間で順番待ちを運んだ。入力2つが、先に入っていた1つの後ろへ元の順番で並び、旧い方は空になった。もう一度呼んでも入れ直さなかった。この2つの端末では、引き継ぎの通しは流していない。
30
+
31
+ ### 確認していない範囲
32
+
33
+ - 0.16.11までで止まっていた実機のタスクが、次の入力で引き継がれる所(利用者の入力が要る)。
34
+ - 後継へ入れる応答が本当に切れた時の動き(試験では作り物の応答で確かめた)。
35
+
13
36
  ## [0.16.11] — 2026-10-09
14
37
 
15
38
  ### 修正
@@ -2124,7 +2147,8 @@ two attempts, instrument first instead of patching again.
2124
2147
 
2125
2148
  ---
2126
2149
 
2127
- [Unreleased]: https://github.com/kitepon/Throughline/compare/v0.16.11...HEAD
2150
+ [Unreleased]: https://github.com/kitepon/Throughline/compare/v0.16.12...HEAD
2151
+ [0.16.12]: https://github.com/kitepon/Throughline/compare/v0.16.11...v0.16.12
2128
2152
  [0.16.11]: https://github.com/kitepon/Throughline/compare/v0.16.10...v0.16.11
2129
2153
  [0.16.10]: https://github.com/kitepon/Throughline/compare/v0.16.9...v0.16.10
2130
2154
  [0.16.9]: https://github.com/kitepon/Throughline/compare/v0.16.8...v0.16.9
package/README.ja.md CHANGED
@@ -33,7 +33,7 @@ throughline auto-handoff disable
33
33
 
34
34
  記憶は引き継ぎ全体の直近20ターンをL2全文、それより古いターンをL1で渡します。元のユーザー依頼と中断地点を保持し、tool結果とThinkingは注入しません。本文内の`auto-handoff detail`コマンドで、凍結したL2/L3を引き継ぎID・origin・turnから取得できます。A→B→Cの連続引き継ぎでも祖先の詳細を取得できます。
35
35
 
36
- 設定不一致、未処理入力、実行中の子agentや既知のnativeコマンド、追跡されていない旧handoff記憶では固定理由を残して停止します。失敗時はローカルの説明ページを開きます。新タスクだけで容量が尽きる場合も、新タスクを増やし続けません。結果不明の指示は自動で再送しません。
36
+ 設定不一致、実行中の子agentや既知のnativeコマンド、追跡されていない旧handoff記憶では固定理由を残して停止します。旧タスクの順番待ちに残っている入力(まだ送られていない物)は、後継が作業を続けた後に、順番を保って後継の順番待ちへ運びます(0.16.12から。それより前の版は、ここで引き継ぎを止めていました)。失敗時はローカルの説明ページを開きます。新タスクだけで容量が尽きる場合も、新タスクを増やし続けません。結果不明の指示は自動で再送しません。
37
37
 
38
38
  ```bash
39
39
  throughline auto-handoff status --operation <handoff-id> --json
package/README.md CHANGED
@@ -32,7 +32,7 @@ throughline auto-handoff disable
32
32
 
33
33
  記憶は引き継ぎ全体の直近20ターンをL2全文、それより古いターンをL1で渡します。元のユーザー依頼と中断地点を保持し、tool結果とThinkingは注入しません。本文内の`auto-handoff detail`コマンドで、凍結したL2/L3を引き継ぎID・origin・turnから取得できます。A→B→Cの連続引き継ぎでも祖先の詳細を取得できます。
34
34
 
35
- 設定不一致、未処理入力、実行中の子agentや既知のnativeコマンド、追跡されていない旧handoff記憶では固定理由を残して停止します。失敗時はローカルの説明ページを開きます。新タスクだけで容量が尽きる場合も、新タスクを増やし続けません。結果不明の指示は自動で再送しません。
35
+ 設定不一致、実行中の子agentや既知のnativeコマンド、追跡されていない旧handoff記憶では固定理由を残して停止します。旧タスクの順番待ちに残っている入力(まだ送られていない物)は、後継が作業を続けた後に、順番を保って後継の順番待ちへ運びます(0.16.12から。それより前の版は、ここで引き継ぎを止めていました)。失敗時はローカルの説明ページを開きます。新タスクだけで容量が尽きる場合も、新タスクを増やし続けません。結果不明の指示は自動で再送しません。
36
36
 
37
37
  ```bash
38
38
  throughline auto-handoff status --operation <handoff-id> --json
@@ -0,0 +1,52 @@
1
+ # ADR 0045: Codex の旧タスクの順番待ちに残った入力は、引き継ぎを断らずに後継へ運ぶ
2
+
3
+ 日付: 2026-10-10
4
+
5
+ ## Context
6
+
7
+ Codex Desktop の自動継続は、旧タスクの公式の順番待ち(`thread/queue/list`)に入力が残っていると、
8
+ `handoff_source_input_pending` で引き継ぎを止めていた。後継を作る前に、未処理の入力を取りこぼさないための決まりだった。
9
+
10
+ 2026-10-09、Windows の実機で、この理由の失敗が2つのタスクに7回続いた。どちらのタスクも、そのまま使われなくなった。
11
+
12
+ - 1つ目のタスク: 13:17 と 14:43 に止まり、14:45 が最後の書き込み。
13
+ - 2つ目のタスク: 20:55 に止まり、21:06〜21:07 の4回の入力も全部止まった。21:08 が最後の書き込み。
14
+
15
+ 原因は、止める順番と Codex の順番待ちの決まりの組み合わせにあった。
16
+
17
+ - 自動継続は、`PreCompact(auto)` の hook でターンを止めてから、worker が順番待ちを見る。
18
+ - Codex は、順番待ちの入力を「その入力でターンを始めた時」に消す(`codex-rs/ext/queue/src/service.rs` の
19
+ `dispatch_if_idle`。`StartIfIdleSubmission::Started` の後に `delete_locked`)。順番待ちに残っている入力は、まだ送られていない。
20
+ - 途中で止めたタスク(`AgentStatus::Interrupted`)では、Codex は順番待ちを動かさない(同じ file の `wake_if_loaded` と
21
+ `on_thread_idle`)。次に人が送ったターンが普通に終わるまで動かない。
22
+ - 旧タスクは文脈が上限に達しているので、次に人が送ったターンも `PreCompact(auto)` で止まる。順番待ちは空にならず、
23
+ 引き継ぎは同じ理由で止まり続ける。利用者には、何を打ってもタスクが止まるように見える。
24
+
25
+ 順番待ちに入力が入るのは、ターンが動いている間に届いた物(利用者が続けて打った文、ほかの道具が
26
+ `thread/queue/add` で入れた通知や返信)。長いターンの間に1つ届くだけで、このタスクは引き継げなくなる。
27
+
28
+ Codex の app-server には、順番待ちを読む・入れる・消す口がある(`thread/queue/list`・`thread/queue/add`・
29
+ `thread/queue/delete`)。別の process からも使える。
30
+
31
+ ## Decision
32
+
33
+ 1. 旧タスクの順番待ちに入力が残っていても、引き継ぎを断らない。`handoff_source_input_pending` は出さない。
34
+ 2. 後継が作業を続けたのを確かめた後(`continued` の直後)に、旧タスクの順番待ちの入力を、順番を保って後継の順番待ちへ運ぶ。
35
+ 後継へ `thread/queue/add`(`input` と `clientUserMessageId` はそのまま)で入れてから、旧タスクから `thread/queue/delete` で消す。
36
+ 後継の最初のターン(継続の指示)は始まっているので、運んだ入力はその後ろに並び、ターンが終わるたびに1つずつ始まる。
37
+ 3. 二重に送らない。運ぶ入力の ID を、入れる前に引き継ぎの記録(`runtime_json.queueCarry.moving`)へ書き、入った後に
38
+ `moved` へ移す。入れた結果が分からない入力(応答が切れた、途中で worker が終わった)は `unknown` へ入れ、入れ直さない。
39
+ その入力は旧タスクの順番待ちに残る。Codex がはっきり断った入力も旧タスクに残す。
40
+ 4. 運べなくても、引き継ぎの `state` は変えない。後継はもう作業を続けている。理由と数は worker のログに残す。
41
+ 5. 後継がさらに引き継ぐ時も同じ。運んだ入力がまだ後継の順番待ちに残っていれば、次の後継へ運ぶ。
42
+ 6. 途中で止まった引き継ぎ(`failed`・`unknown`)では、順番待ちを動かさない。やり直しで `continued` になった時に運ぶ。
43
+ 7. 引き継ぎ済みの旧タスクへ後から届く入力の扱い(ADR 0039)は変えない。この ADR が扱うのは、引き継ぎの時点で残っていた入力だけ。
44
+
45
+ ## Consequences
46
+
47
+ - 順番待ちに入力があるタスクも引き継げる。0.16.11 までで止まっていたタスクは、次の入力でやり直しが動き、引き継がれる
48
+ (その時点で順番待ちに残っている入力は、全部後継へ運ばれる)。
49
+ - 運んだ入力は、後継の継続の指示のターンが終わった後に実行される。旧タスクで待っていた順番と同じ。
50
+ - ほかの道具が旧タスクの ID で持っている配送の記録は、後継の ID へは書き換わらない。入力そのものは後継で実行される。
51
+ - 入れた結果が分からない入力は、旧タスクの順番待ちに残る。旧タスクは引き継ぎ済みなので、その入力は実行されない。
52
+ 数は `auto-handoff status --operation <ID>` では出ないので、worker のログ(`queue carried`)で読む。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "throughline",
3
- "version": "0.16.11",
3
+ "version": "0.16.12",
4
4
  "type": "module",
5
5
  "description": "Persistent memory hooks for Claude Code, Codex, Grok, and Cursor (/clear-safe context compression)",
6
6
  "keywords": [
@@ -241,9 +241,11 @@ async function sourceNativeState(operation, runtime) {
241
241
  if (thread?.id !== operation.source_thread_id || thread.parentThreadId || thread.canAcceptDirectInput === false ||
242
242
  thread.source?.subAgent) throw error('handoff_source_not_primary');
243
243
  if (!sameProjectPath(thread.cwd, operation.project_path)) throw error('handoff_source_project_mismatch');
244
+ // 順番待ちに残っている入力は、まだ送られていない(Codex は、ターンを始めた時に順番待ちから消す)。
245
+ // 止めた旧タスクでは順番待ちが動かないので、ここで断ると何度入力しても同じ理由で止まり続ける。
246
+ // 断らずに進み、後継が作業を続けた後で後継の順番待ちへ運ぶ(carryAutoHandoffQueue)。
244
247
  const queue = await request('thread/queue/list', { threadId: operation.source_thread_id, limit: 1 });
245
248
  if (!Array.isArray(queue.data)) throw error('handoff_queue_shape_invalid');
246
- if (queue.data.length) throw error('handoff_source_input_pending');
247
249
  const children = await request('thread/list', { ancestorThreadId: operation.source_thread_id,
248
250
  sourceKinds: ['subAgent'], limit: 100, archived: false });
249
251
  if (!Array.isArray(children.data) || children.nextCursor) throw error('handoff_children_unavailable');
@@ -306,6 +308,59 @@ export async function markAutoHandoffSource(operation, runtime, { connect = with
306
308
  }
307
309
  }
308
310
 
311
+ /**
312
+ * 止めた時に旧タスクの順番待ちに残っていた入力(まだ送られていない)を、順番を保って後継の順番待ちへ運ぶ。
313
+ * 後継へ入れてから旧タスクの順番待ちから消す。後継へ入れた結果が分からない入力は、二重に送らないために
314
+ * 入れ直さず、旧タスクの順番待ちに残す。運べなくても引き継ぎは止めない(後継はもう作業を続けている)。
315
+ * @returns {Promise<{moved: number, unknown: number, left: number}>} left は、断られて旧タスクに残った数
316
+ */
317
+ export async function carryAutoHandoffQueue(db, operation, runtime, { connect = withCodexReceiver } = {}) {
318
+ const sourceId = operation.source_thread_id; const targetId = operation.target_thread_id;
319
+ const stored = getAutoHandoff(db, operation.handoff_id).runtime?.queueCarry ?? {};
320
+ const carry = { moved: [...(stored.moved ?? [])], unknown: [...(stored.unknown ?? [])], left: 0 };
321
+ // 前の worker が、後継へ入れる途中で終わった。入ったかどうかが分からない。
322
+ if (stored.moving && !carry.moved.includes(stored.moving)) carry.unknown.push(stored.moving);
323
+ const save = moving => updateAutoHandoff(db, operation.handoff_id, { runtime_json: {
324
+ ...(getAutoHandoff(db, operation.handoff_id).runtime ?? {}), queueCarry: { moved: carry.moved, unknown: carry.unknown, moving } } });
325
+ const summary = () => ({ moved: carry.moved.length, unknown: carry.unknown.length, left: carry.left });
326
+ try {
327
+ if (stored.moving) save(null);
328
+ await connect(autoHandoffDeliveryProfile, { thread_id: sourceId, codex_home: operation.codex_home }, async request => {
329
+ const items = [];
330
+ for (let cursor = null, page = 0; page < 50; page++) {
331
+ const listed = await request('thread/queue/list', { threadId: sourceId, cursor, limit: 100 });
332
+ if (!Array.isArray(listed.data)) throw error('handoff_queue_shape_invalid');
333
+ items.push(...listed.data);
334
+ cursor = listed.nextCursor ?? null;
335
+ if (!cursor) break;
336
+ }
337
+ for (const item of items) {
338
+ if (carry.unknown.includes(item.id)) continue;
339
+ if (!carry.moved.includes(item.id)) {
340
+ save(item.id);
341
+ try {
342
+ await request('thread/queue/add', { threadId: targetId, input: item.input, clientUserMessageId: item.clientUserMessageId });
343
+ } catch (cause) {
344
+ // はっきり断られた入力は後継に入っていない。旧タスクに残す。それ以外は結果不明として扱う。
345
+ if (cause?.delivery_code === 'CODEX_RECEIVER_REJECTED') { carry.left++; save(null); continue; }
346
+ carry.unknown.push(item.id); save(null);
347
+ throw cause;
348
+ }
349
+ carry.moved.push(item.id);
350
+ save(null);
351
+ }
352
+ await request('thread/queue/delete', { threadId: sourceId, queuedSubmissionId: item.id });
353
+ }
354
+ }, runtime);
355
+ } catch (cause) {
356
+ process.stderr.write(`[auto-handoff] queue carry failed: ${cause?.delivery_code ?? cause?.code ?? 'unknown'}\n`);
357
+ }
358
+ if (carry.moved.length || carry.unknown.length || carry.left) {
359
+ process.stderr.write(`[auto-handoff] queue carried: ${JSON.stringify(summary())}\n`);
360
+ }
361
+ return summary();
362
+ }
363
+
309
364
  /** 旧タスクが、名前を付けない版の作った後継だった時の名前。その後継を作った引き継ぎから、後継の名前を作り直す。 */
310
365
  export function autoHandoffSourceFallbackTitle(db, operation) {
311
366
  const creator = findAutoHandoffForTarget(db, operation.source_thread_id);
@@ -467,6 +522,7 @@ export async function runAutoHandoffWorker(id, { db = getDb(), resume = false, d
467
522
  const deps = { processes: readRuntimeProcesses, readSource: sourceState,
468
523
  nativeState: sourceNativeState, capture: captureCodexRolloutToDb, summaries: ensureAutoHandoffSummaries,
469
524
  createTarget, readTarget: targetState, openTarget, verify: verifyCodexParent, markSource: markAutoHandoffSource,
525
+ carryQueue: carryAutoHandoffQueue,
470
526
  submit: submitCodexParentAnswer, notify: showAutoHandoffFailure, wait: waitForHandoff,
471
527
  executable: () => platformDesktopFinder()(), liveSuccessor: findLiveAutoHandoffSuccessor, ...dependencies };
472
528
  let operation = getAutoHandoff(db, id);
@@ -581,6 +637,8 @@ export async function runAutoHandoffWorker(id, { db = getDb(), resume = false, d
581
637
  return target.correlatedTurnId && target.progress ? target : null;
582
638
  }, { timeoutMs: 180_000, timeoutCode: 'handoff_target_progress_unconfirmed' });
583
639
  update({ state: 'continued', started_turn_id: target.correlatedTurnId, resume_state: null, error_code: null });
640
+ // 旧タスクの順番待ちに残った入力を後継へ運ぶ。後継の最初のターン(継続の指示)が始まった後なので、順番は変わらない。
641
+ await deps.carryQueue(db, operation, runtime);
584
642
  // 後継が作業を続けたのを確かめてから付ける。途中で止まった引き継ぎの旧タスクには付けない。
585
643
  await deps.markSource(operation, runtime, { fallbackTitle: autoHandoffSourceFallbackTitle(db, operation) });
586
644
  }
@@ -14,7 +14,7 @@ import { collectAutoHandoffMemory, ensureAutoHandoffSummaries, renderAutoHandoff
14
14
  import { readCodexHandoffState, settingsMatch, threadStartSettings, resolvePreparedSettings } from './hosts/codex-handoff-state.mjs';
15
15
  import { runAutoHandoffWorker, requestCodexAutoHandoff, sourceBoundary,
16
16
  autoHandoffTargetName, nameAutoHandoffTarget, findLiveAutoHandoffSuccessor,
17
- markAutoHandoffSource, markAutoHandoffSources, autoHandoffSourceFallbackTitle } from './codex-auto-handoff.mjs';
17
+ markAutoHandoffSource, markAutoHandoffSources, autoHandoffSourceFallbackTitle, carryAutoHandoffQueue } from './codex-auto-handoff.mjs';
18
18
  import { parseAutoHandoffArgs } from './cli/auto-handoff.mjs';
19
19
 
20
20
  async function withDb(fn) {
@@ -116,6 +116,7 @@ function workerDependencies(db, settings, submit, counters) {
116
116
  readTarget: operation => ({ settings, latestTurnId: ['submitted', 'unknown'].includes(operation.state) ? 'new-turn' : null,
117
117
  correlatedTurnId: ['submitted', 'unknown'].includes(operation.state) ? 'new-turn' : null, progress: true }),
118
118
  openTarget: () => {}, verify: async () => {}, submit,
119
+ carryQueue: async (db, operation) => { (counters.carried ??= []).push(`${operation.source_thread_id}:${operation.state}`); return { moved: 0, unknown: 0, left: 0 }; },
119
120
  markSource: async (operation, runtime, options) => {
120
121
  (counters.marked ??= []).push(`${operation.source_thread_id}:${operation.state}`);
121
122
  assert.ok('fallbackTitle' in options);
@@ -135,6 +136,7 @@ test('停止→記憶→作成→配送→進捗を確認し、重複workerは
135
136
  await runAutoHandoffWorker(operation.handoff_id, { db, dependencies: deps });
136
137
  assert.equal(counters.created, 1); assert.equal(counters.submitted, 1); assert.equal(counters.notified, 0);
137
138
  assert.deepEqual(counters.marked, ['worker-source:continued'], '後継が作業を続けたのを確かめた後に、旧タスクへ印を1回だけ付ける');
139
+ assert.deepEqual(counters.carried, ['worker-source:continued'], '後継が作業を続けたのを確かめた後に、順番待ちを1回だけ運ぶ');
138
140
  }));
139
141
 
140
142
  test('配送結果不明は再送せず、実際の入力・開始を観測して同じ後継から回復する', async () => withDb(async db => {
@@ -177,8 +179,8 @@ test('作成応答を失った時は結果不明を保存し、再開でも後
177
179
  assert.equal(counters.created, 1); assert.equal(counters.submitted, 0);
178
180
  }));
179
181
 
180
- test('未処理入力・実行中の子・出所不明の継承記憶では後継を作らない', async () => withDb(async db => {
181
- for (const code of ['handoff_source_input_pending', 'handoff_native_child_pending', 'handoff_memory_lineage_untracked']) {
182
+ test('実行中の子・出所不明の継承記憶では後継を作らない', async () => withDb(async db => {
183
+ for (const code of ['handoff_native_child_pending', 'handoff_memory_lineage_untracked']) {
182
184
  const op = request(db, code, { now: 1 }).operation;
183
185
  const counters = { created: 0, submitted: 0, notified: 0 };
184
186
  const deps = workerDependencies(db, {}, async () => { counters.submitted++; }, counters);
@@ -584,6 +586,65 @@ test('名前の無い旧タスク(名前を付けない版が作った後継
584
586
  assert.deepEqual(sent.at(-1), ['thread/name/set', { threadId: 'B', name: '【引き継ぎ済み】BellTeam|ベルチームの改良(自動引き継ぎ)' }]);
585
587
  }));
586
588
 
589
+ test('旧タスクの順番待ちに残った入力を、順番を保って後継へ運び、旧タスクから消す', async () => withDb(async db => {
590
+ const operation = updateAutoHandoff(db, request(db, 'S').operation.handoff_id, { state: 'continued', target_thread_id: 'T' }).operation;
591
+ const queues = { S: [{ id: 'q1', input: [{ type: 'text', text: '1つ目' }], clientUserMessageId: 'c1' },
592
+ { id: 'q2', input: [{ type: 'text', text: '2つ目' }], clientUserMessageId: 'c2' }], T: [{ id: 't0', input: [], clientUserMessageId: 'continuation' }] };
593
+ const calls = [];
594
+ const receiver = (fail = () => null) => async (profile, parent, action) => action(async (method, params) => {
595
+ calls.push(`${method}:${params.threadId}:${params.queuedSubmissionId ?? params.clientUserMessageId ?? ''}`);
596
+ const failure = fail(method, params);
597
+ if (failure) throw failure;
598
+ if (method === 'thread/queue/list') return { data: queues[params.threadId], nextCursor: null };
599
+ if (method === 'thread/queue/add') { queues[params.threadId].push({ id: `t-${params.clientUserMessageId}`, input: params.input, clientUserMessageId: params.clientUserMessageId }); return { queuedSubmission: {} }; }
600
+ if (method === 'thread/queue/delete') { queues[params.threadId] = queues[params.threadId].filter(item => item.id !== params.queuedSubmissionId); return {}; }
601
+ throw Error(method);
602
+ });
603
+ assert.deepEqual(await carryAutoHandoffQueue(db, operation, {}, { connect: receiver() }), { moved: 2, unknown: 0, left: 0 });
604
+ assert.deepEqual(calls, ['thread/queue/list:S:', 'thread/queue/add:T:c1', 'thread/queue/delete:S:q1', 'thread/queue/add:T:c2', 'thread/queue/delete:S:q2']);
605
+ assert.deepEqual(queues.T.map(item => item.clientUserMessageId), ['continuation', 'c1', 'c2'], '継続の指示の後ろへ、元の順番で並ぶ');
606
+ assert.deepEqual(queues.S, []);
607
+ assert.deepEqual(getAutoHandoff(db, operation.handoff_id).runtime.queueCarry, { moved: ['q1', 'q2'], unknown: [], moving: null });
608
+ assert.equal(getAutoHandoff(db, operation.handoff_id).state, 'continued');
609
+
610
+ // もう一度呼んでも、運んだ入力を入れ直さない
611
+ calls.length = 0;
612
+ assert.deepEqual(await carryAutoHandoffQueue(db, operation, {}, { connect: receiver() }), { moved: 2, unknown: 0, left: 0 });
613
+ assert.deepEqual(calls, ['thread/queue/list:S:']);
614
+ }));
615
+
616
+ test('後継へ入れた結果が分からない入力は入れ直さず、断られた入力は旧タスクに残す。どちらも引き継ぎは止めない', async () => withDb(async db => {
617
+ const make = name => updateAutoHandoff(db, request(db, name).operation.handoff_id, { state: 'continued', target_thread_id: `${name}-T` }).operation;
618
+ const queue = () => [{ id: 'q1', input: [], clientUserMessageId: 'c1' }, { id: 'q2', input: [], clientUserMessageId: 'c2' }];
619
+ const receiver = (items, added, fail) => async (profile, parent, action) => action(async (method, params) => {
620
+ if (method === 'thread/queue/list') return { data: items, nextCursor: null };
621
+ if (method === 'thread/queue/add') { const failure = fail(params); if (failure) throw failure; added.push(params.clientUserMessageId); return {}; }
622
+ if (method === 'thread/queue/delete') { items.splice(items.findIndex(item => item.id === params.queuedSubmissionId), 1); return {}; }
623
+ throw Error(method);
624
+ });
625
+ // 応答が途中で切れた(入ったかどうかが分からない)。そこで止め、次に呼ばれても入れ直さない
626
+ const lost = make('lost'); let items = queue(); let added = [];
627
+ const timeout = () => Object.assign(new Error('timeout'), { delivery_code: 'CODEX_RECEIVER_TIMEOUT' });
628
+ assert.deepEqual(await carryAutoHandoffQueue(db, lost, {}, { connect: receiver(items, added, params => params.clientUserMessageId === 'c1' ? timeout() : null) }),
629
+ { moved: 0, unknown: 1, left: 0 });
630
+ assert.deepEqual(await carryAutoHandoffQueue(db, lost, {}, { connect: receiver(items, added, () => null) }), { moved: 1, unknown: 1, left: 0 });
631
+ assert.deepEqual(added, ['c2']); assert.deepEqual(items.map(item => item.id), ['q1'], '結果不明の入力は旧タスクに残る');
632
+ assert.equal(getAutoHandoff(db, lost.handoff_id).state, 'continued');
633
+
634
+ // 前の worker が、入れる途中で終わっていた
635
+ const crashed = make('crashed'); items = queue(); added = [];
636
+ updateAutoHandoff(db, crashed.handoff_id, { runtime_json: { ...(crashed.runtime ?? {}), queueCarry: { moved: [], unknown: [], moving: 'q1' } } });
637
+ assert.deepEqual(await carryAutoHandoffQueue(db, crashed, {}, { connect: receiver(items, added, () => null) }), { moved: 1, unknown: 1, left: 0 });
638
+ assert.deepEqual(added, ['c2']);
639
+
640
+ // はっきり断られた入力は後継に入っていない。旧タスクに残し、次の入力は運ぶ
641
+ const rejected = make('rejected'); items = queue(); added = [];
642
+ const reject = () => Object.assign(new Error('rejected'), { delivery_code: 'CODEX_RECEIVER_REJECTED' });
643
+ assert.deepEqual(await carryAutoHandoffQueue(db, rejected, {}, { connect: receiver(items, added, params => params.clientUserMessageId === 'c1' ? reject() : null) }),
644
+ { moved: 1, unknown: 0, left: 1 });
645
+ assert.deepEqual(added, ['c2']); assert.deepEqual(items.map(item => item.id), ['q1']);
646
+ }));
647
+
587
648
  // 元turn(止めた)の後に、旧タスクへ来た入力のturnが続くrollout。laterは後続turnの行。
588
649
  function sourceRollout(home, thread, turn, later = [], stoppedAt = '2026-10-07T00:49:01.000Z') {
589
650
  const dir = join(home, 'codex', 'sessions'); mkdirSync(dir, { recursive: true });
@@ -784,5 +845,6 @@ test('要約のbackendが使えない時、workerは固定の理由で止まり
784
845
  assert.equal(result.state, 'failed'); assert.equal(result.error_code, expected); assert.equal(result.resume_state, 'source_stopped');
785
846
  assert.equal(counters.created, 0); assert.equal(counters.submitted, 0); assert.equal(counters.notified, 1);
786
847
  assert.equal(counters.marked, undefined, '途中で止まった引き継ぎの旧タスクには印を付けない');
848
+ assert.equal(counters.carried, undefined, '途中で止まった引き継ぎでは、順番待ちを動かさない');
787
849
  }
788
850
  }));