throughline 0.16.3 → 0.16.4
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 +21 -1
- package/docs/adr/0041-l1-summarizer-backend-unrecovered.md +77 -0
- package/package.json +1 -1
- package/src/cli/codex-hook.mjs +18 -2
- package/src/codex-auto-handoff.mjs +9 -1
- package/src/codex-auto-handoff.test.mjs +17 -0
- package/src/l1-backend-recovery.mjs +74 -0
- package/src/runtime-error-hook.test.mjs +41 -7
- package/src/runtime-error-observer.mjs +5 -2
- package/src/runtime-error-store.mjs +24 -5
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,25 @@ shipped to npm but were not individually tagged on GitHub.
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [0.16.4] — 2026-10-07
|
|
14
|
+
|
|
15
|
+
### 変更
|
|
16
|
+
|
|
17
|
+
- Codex StopのL1要約backend(Codex CLI)の失敗を、1回ごとにruntime errorとして数えるのをやめる([ADR 0041](docs/adr/0041-l1-summarizer-backend-unrecovered.md))。この失敗は、通信の断、利用上限、認証切れ、利用者の取り消しでも起きる。会話の取り込みは済んでいて、要約は次のStopがやり直し、recallはL2の本文を返すので、修理の対象として自動で登録しない。理由と外部CLIのstderrの末尾は、今までどおり端末の`hook-failures.log`に残る。hookの終了codeとstderrは変えない。
|
|
18
|
+
- 最初の失敗から24時間を過ぎても成功を確認できない時だけ、`L1_SUMMARIZER_BACKEND_UNRECOVERED`(`warn`)で数える。要約が成功したら、その記録を`recovered`で解決にする。
|
|
19
|
+
- Codexの自動継続のworkerは、要約のbackendの失敗を`handoff_summarizer_backend_failed`で止める(今までは汎用の`handoff_worker_failed`)。失敗の画面に、通信の断・利用上限・認証切れで起きる事、記録と入力が失われていない事、再開の仕方を書く。
|
|
20
|
+
|
|
21
|
+
### 変わらない事
|
|
22
|
+
|
|
23
|
+
- BugHubへ送る本文の形。項目は足していない。
|
|
24
|
+
- hook処理の失敗(`HOOK_*_FAILED`)の数え方と重大度。これらの経路に通信は無い。
|
|
25
|
+
- BugHubへの送信の失敗は、今までどおり送信の状態にだけ残し、runtime errorには数えない。
|
|
26
|
+
|
|
27
|
+
### 確認していない範囲
|
|
28
|
+
|
|
29
|
+
- 要約が失敗し続ける間のCodexの画面への影響。
|
|
30
|
+
- 本物のCodex CLIが、通信の断・利用上限・認証切れのそれぞれで返す終了codeとstderr。
|
|
31
|
+
|
|
13
32
|
## [0.16.3] — 2026-10-07
|
|
14
33
|
|
|
15
34
|
### 修正
|
|
@@ -1940,7 +1959,8 @@ two attempts, instrument first instead of patching again.
|
|
|
1940
1959
|
|
|
1941
1960
|
---
|
|
1942
1961
|
|
|
1943
|
-
[Unreleased]: https://github.com/kitepon/Throughline/compare/v0.16.
|
|
1962
|
+
[Unreleased]: https://github.com/kitepon/Throughline/compare/v0.16.4...HEAD
|
|
1963
|
+
[0.16.4]: https://github.com/kitepon/Throughline/compare/v0.16.3...v0.16.4
|
|
1944
1964
|
[0.16.3]: https://github.com/kitepon/Throughline/compare/v0.16.2...v0.16.3
|
|
1945
1965
|
[0.16.2]: https://github.com/kitepon/Throughline/compare/v0.16.1...v0.16.2
|
|
1946
1966
|
[0.16.1]: https://github.com/kitepon/Throughline/compare/v0.16.0...v0.16.1
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# ADR 0041: L1 要約 backend の失敗は、復帰を確認できない時だけ数える
|
|
2
|
+
|
|
3
|
+
日付: 2026-10-07
|
|
4
|
+
|
|
5
|
+
## Context
|
|
6
|
+
|
|
7
|
+
オーナーは、通信失敗の報告・重大度・担当の決まりを定めた(2026-10-07、BugHub の `NETWORK_REPORTING.md`)。
|
|
8
|
+
通信環境そのものの不調と、その状態への製品の対処不良を分ける。通常のオフライン、正常な取り消し、
|
|
9
|
+
適切に処理された一時的な失敗を、自動で製品の欠陥として登録しない。必要な診断は保持する。重大度は
|
|
10
|
+
エラーコードや回数だけで固定せず、機能停止・データの喪失・重複・復帰の可否を根拠に付ける。
|
|
11
|
+
|
|
12
|
+
Throughline が runtime error として数える code は7つで、通信の失敗が入るのは `L1_SUMMARIZER_BACKEND_FAILED`
|
|
13
|
+
(ADR 0028)だけだった。Codex Stop の要約は外部 CLI(`codex exec`)を呼ぶ。通信の断、利用上限、認証切れ、
|
|
14
|
+
model の失敗、利用者の取り消しによる停止で、CLI は非0で終わるか空を返す。0.16.3 までは、この失敗を
|
|
15
|
+
1回ごとに `warn` で数え、BugHub へ未解決の記録として送っていた。
|
|
16
|
+
|
|
17
|
+
この失敗への Throughline の対処は、次のとおり(ADR 0015・0016・0028)。
|
|
18
|
+
|
|
19
|
+
- 会話の取り込みは、要約の前に commit している。記憶は失われない。
|
|
20
|
+
- 要約は、次の Stop が同じ turn からやり直す。重複は作らない。
|
|
21
|
+
- L1 が無い間、recall は L2 の本文を返す。
|
|
22
|
+
- hook は終了 code 1 と stderr で失敗を示す。理由と外部 CLI の stderr の末尾は、端末の `hook-failures.log` に残る。
|
|
23
|
+
|
|
24
|
+
1回ごとの失敗は「適切に処理された一時的な失敗」に当たり、修理の対象として登録する物ではない。
|
|
25
|
+
一方、backend が使えないまま続く端末では、古い turn の要約が作られず、Codex の自動継続は要約を作れずに
|
|
26
|
+
止まる。この影響を隠さない。
|
|
27
|
+
|
|
28
|
+
他の通信の扱いは、次のとおりで、変えない。
|
|
29
|
+
|
|
30
|
+
- BugHub への送信の失敗(`unreachable` など)は、送信の状態(`runtime-errors report-status`)にだけ残し、
|
|
31
|
+
runtime error には数えない。次の時機に、その時点の累計を送り直す。hook の結果は変えない。
|
|
32
|
+
- Claude Code の要約は、Codex CLI → Haiku → L2 の本文の、宣言済みの fallback。backend の失敗では throw せず、数えない。
|
|
33
|
+
- `self-update` の npm の失敗は、呼び出し元へ結果として返す。runtime error には数えない。
|
|
34
|
+
- hook 処理の失敗(`HOOK_*_FAILED`)の経路に、通信は無い。
|
|
35
|
+
|
|
36
|
+
## Decision
|
|
37
|
+
|
|
38
|
+
1. `L1_SUMMARIZER_BACKEND_FAILED` を、runtime error として数えるのをやめる。失敗の理由と stderr の末尾は、
|
|
39
|
+
今までどおり `hook-failures.log` に、この code の名前で残す(端末内だけ)。hook の終了 code と stderr は変えない。
|
|
40
|
+
2. 端末ごとに、成功を確認できていない間の最初と最後の失敗の時刻を持つ
|
|
41
|
+
(`~/.throughline/l1-backend-recovery.json`。会話の内容も失敗の文面も書かない)。
|
|
42
|
+
3. 最初の失敗から24時間を過ぎた後の失敗は、`L1_SUMMARIZER_BACKEND_UNRECOVERED` として数える。
|
|
43
|
+
component は `codex_l1_summarizer`、template は
|
|
44
|
+
`Throughline L1 summarizer backend (Codex CLI) has not recovered for over 24 hours`、severity は `warn`。
|
|
45
|
+
4. severity を `warn` にする根拠は影響。記憶は失われていない(取り込みは済み、recall は L2 を返す)。重複は無い。
|
|
46
|
+
backend が戻れば、次の Stop で自動で復帰する。機能が止まるのは、Codex の自動継続が古い turn の要約を
|
|
47
|
+
作れない時で、その時は5の画面が出て、入力と記録は残り、再開できる。
|
|
48
|
+
5. Codex の自動継続の worker は、要約の backend の失敗を、汎用の `handoff_worker_failed` ではなく
|
|
49
|
+
`handoff_summarizer_backend_failed` で止める。失敗の画面に、通信の断・利用上限・認証切れで起きる事、
|
|
50
|
+
記録と入力が失われていない事、backend が使える様になった後に旧タスクへ入力すると引き継ぎを始め直す事を書く。
|
|
51
|
+
6. backend が要約を返したら、2の記録を消す。3を数えていた時は、その記録を `recovered` で解決にする
|
|
52
|
+
(製品の明示の解決。BugHub へは次の送信で届く)。復帰の後の失敗は、また最初から数える。
|
|
53
|
+
7. 前の版が `L1_SUMMARIZER_BACKEND_FAILED` を記録した store を読める様に、その定義は残す。
|
|
54
|
+
8. 送信の本文の形(BugHub の契約)は変えない。項目を足さない。
|
|
55
|
+
|
|
56
|
+
ADR 0028 の1(1回ごとに数える)と5(severity の根拠のうち、数える条件)は、この ADR で置き換える。
|
|
57
|
+
ADR 0028 の2(対象の error)・3(終了 code と stderr)・4(`hook-failures.log`)は変えない。
|
|
58
|
+
|
|
59
|
+
## Consequences
|
|
60
|
+
|
|
61
|
+
- 通信の一時的な断、利用上限、取り消しで要約が1回失敗しても、BugHub には何も出ない。端末の `hook-failures.log` で読める。
|
|
62
|
+
- backend が使えないままの端末は、最初の失敗から24時間を過ぎた後の失敗で、BugHub に `warn` の未解決として出る。
|
|
63
|
+
これは「復帰を確認できていない」という事実で、原因が通信環境か、認証か、製品かは決めていない。
|
|
64
|
+
記録の担当は Throughline の保守だが、通信環境や認証の修理は、その環境を管理する担当へ渡す。
|
|
65
|
+
- 「24時間」は、最初の失敗からの経過で見る。その間ずっと失敗し続けていた証明ではない(間に Stop が無ければ、
|
|
66
|
+
試していない)。記録は成功で自動で解決になる。
|
|
67
|
+
- 要約が成功したかを見るのは、要約を実際に行った Stop だけ。20 turn 以内のスレッドの Stop は、復帰の証拠にしない。
|
|
68
|
+
- runtime error store は、知らない code を持つ記録を schema invalid として拒否する。この版で
|
|
69
|
+
`L1_SUMMARIZER_BACKEND_UNRECOVERED` を記録した端末を 0.16.3 以前へ戻すと、store を読めなくなる。
|
|
70
|
+
- 0.16.3 までに `L1_SUMMARIZER_BACKEND_FAILED` を記録した端末の記録は、そのまま残る。書き換えない。
|
|
71
|
+
保守の担当が、端末の正規の入口(`runtime-errors resolve`)で、根拠を付けて閉じる。
|
|
72
|
+
|
|
73
|
+
## 確認していない範囲
|
|
74
|
+
|
|
75
|
+
- 要約が失敗し続ける間、Codex の Stop hook は毎回 exit 1 になる。Codex の画面への影響は調べていない(ADR 0028 と同じ)。
|
|
76
|
+
- 本物の Codex CLI が、通信の断・利用上限・認証切れのそれぞれで、どの終了 code と stderr を返すか。
|
|
77
|
+
試験は、非0で終わる代わりの CLI で行った。
|
package/package.json
CHANGED
package/src/cli/codex-hook.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { recordRuntimeErrorBestEffort } from '../runtime-error-store.mjs';
|
|
1
|
+
import { recordRuntimeErrorBestEffort, resolveRecoveredRuntimeErrorBestEffort } from '../runtime-error-store.mjs';
|
|
2
2
|
import { logHookFailure } from '../hook-failure-log.mjs';
|
|
3
3
|
|
|
4
4
|
function parseArgs(argv) {
|
|
@@ -422,6 +422,13 @@ export async function run(argv = []) {
|
|
|
422
422
|
payload,
|
|
423
423
|
env: process.env,
|
|
424
424
|
});
|
|
425
|
+
// backend が要約を返した。失敗の後なら、復帰を確認できた(ADR 0041)。失敗の記録が無い時は、ファイルの有無を見るだけ。
|
|
426
|
+
if (result.summarized?.summarized?.some((turn) => turn.source === 'codex-cli')) {
|
|
427
|
+
const { noteL1BackendSuccess } = await import('../l1-backend-recovery.mjs');
|
|
428
|
+
if (noteL1BackendSuccess().reported) {
|
|
429
|
+
resolveRecoveredRuntimeErrorBestEffort('L1_SUMMARIZER_BACKEND_UNRECOVERED', { env: process.env });
|
|
430
|
+
}
|
|
431
|
+
}
|
|
425
432
|
}
|
|
426
433
|
if (parsed.event === 'pre-compact' && result.continue === false) {
|
|
427
434
|
process.stdout.write(JSON.stringify({ continue: false, stopReason: result.stopReason }) + '\n');
|
|
@@ -434,7 +441,16 @@ export async function run(argv = []) {
|
|
|
434
441
|
process.exit(result.continue === false || result.status === 'ok' || result.status === 'skipped' ? 0 : 1);
|
|
435
442
|
} catch (err) {
|
|
436
443
|
const code = codexHookFailureCode(err);
|
|
437
|
-
|
|
444
|
+
if (code === 'L1_SUMMARIZER_BACKEND_FAILED') {
|
|
445
|
+
// 取り込みは済み、要約は次の Stop がやり直す。1回ごとの失敗(通信の断・利用上限・取り消しを含む)は
|
|
446
|
+
// 端末の診断(hook-failures.log)にだけ残す。復帰を24時間確認できていない時だけ数える(ADR 0041)。
|
|
447
|
+
const { noteL1BackendFailure } = await import('../l1-backend-recovery.mjs');
|
|
448
|
+
if (noteL1BackendFailure().unrecovered) {
|
|
449
|
+
recordRuntimeErrorBestEffort('L1_SUMMARIZER_BACKEND_UNRECOVERED', { env: process.env });
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
recordRuntimeErrorBestEffort(code, { env: process.env });
|
|
453
|
+
}
|
|
438
454
|
logHookFailure(code, err);
|
|
439
455
|
const msg = err instanceof Error ? err.message : 'unknown';
|
|
440
456
|
if (parsed.json) {
|
|
@@ -342,6 +342,7 @@ export function showAutoHandoffFailure(operation) {
|
|
|
342
342
|
<h1>自動継続を完了できませんでした</h1><p>引き継ぎは下記の工程で止まっています。タスクと記録を確認してください。</p>
|
|
343
343
|
<p><a href="codex://threads/${escape(operation.source_thread_id)}">旧タスクを開く</a>${operation.target_thread_id ? ` / <a href="codex://threads/${escape(operation.target_thread_id)}">後継タスクを開く</a>` : ''}</p>
|
|
344
344
|
<p>理由: <code>${escape(operation.error_code)}</code></p><p>引き継ぎID: <code>${escape(operation.handoff_id)}</code></p>
|
|
345
|
+
${operation.error_code === 'handoff_summarizer_backend_failed' ? '<p>記憶の要約に使うCodex CLIが失敗しました。通信の断、利用上限、認証切れなどで起きます。会話の記録と入力は失われていません。Codex CLIが使える様になった後、旧タスクへ入力すると、引き継ぎをもう一度始めます。</p>' : ''}
|
|
345
346
|
<p>状態: ${escape(operation.state)} / 停止した工程: ${escape(operation.resume_state)}</p>
|
|
346
347
|
<p>確認: <code>throughline auto-handoff status --operation ${escape(operation.handoff_id)}</code></p>
|
|
347
348
|
<p>原因を解消した後の再開: <code>throughline auto-handoff resume --operation ${escape(operation.handoff_id)}</code></p>
|
|
@@ -408,7 +409,14 @@ export async function runAutoHandoffWorker(id, { db = getDb(), resume = false, d
|
|
|
408
409
|
const state = deps.readSource(operation);
|
|
409
410
|
update({ snapshot_json: freezeCodexMemory(db, operation, operation.settings, state) });
|
|
410
411
|
}
|
|
411
|
-
deps.summaries(db, operation);
|
|
412
|
+
try { deps.summaries(db, operation); }
|
|
413
|
+
catch (cause) {
|
|
414
|
+
// 古いturnの要約を作るbackend(Codex CLI)が使えない。通信の断・利用上限・認証切れでも起きる。
|
|
415
|
+
// 汎用の理由にせず、固定の理由で止める。失敗の画面に、失われた物が無い事と再開の仕方を書く(ADR 0041)。
|
|
416
|
+
if ((cause?.source === 'codex-cli' && ['codex_cli_failed', 'empty_output'].includes(cause.reason)) ||
|
|
417
|
+
cause?.message === 'handoff_l1_unavailable') throw error('handoff_summarizer_backend_failed');
|
|
418
|
+
throw cause;
|
|
419
|
+
}
|
|
412
420
|
update({ state: 'memory_ready' });
|
|
413
421
|
}
|
|
414
422
|
if (operation.state === 'memory_ready') {
|
|
@@ -614,3 +614,20 @@ test('引き継ぎの最中に旧タスクへ来た入力は、凍結する記
|
|
|
614
614
|
assert.equal(freezeCodexMemory(db, operation, {}, { stoppedAt: 305, laterTurns: later }).bodies.length, 3);
|
|
615
615
|
assert.equal(freezeCodexMemory(db, operation, {}, { stoppedAt: 200, laterTurns: [later[0]] }).bodies.length, 3);
|
|
616
616
|
}));
|
|
617
|
+
|
|
618
|
+
test('要約のbackendが使えない時、workerは固定の理由で止まり、後継を作らない', async () => withDb(async db => {
|
|
619
|
+
const backend = reason => Object.assign(new Error('Codex CLI summarizer failed: exit 1'), { source: 'codex-cli', reason });
|
|
620
|
+
const cases = [[backend('codex_cli_failed'), 'handoff_summarizer_backend_failed'], [backend('empty_output'), 'handoff_summarizer_backend_failed'],
|
|
621
|
+
[new Error('handoff_l1_unavailable'), 'handoff_summarizer_backend_failed'],
|
|
622
|
+
// 製品側の誤り(要約の呼び方の間違い)と、他の失敗は、今までどおり汎用の理由。
|
|
623
|
+
[backend('recursion_guard'), 'handoff_worker_failed'], [new Error('別の失敗'), 'handoff_worker_failed']];
|
|
624
|
+
for (const [index, [cause, expected]] of cases.entries()) {
|
|
625
|
+
const operation = request(db, `summarizer-${index}`, { now: 1 }).operation;
|
|
626
|
+
const counters = { created: 0, submitted: 0, notified: 0 };
|
|
627
|
+
const deps = workerDependencies(db, {}, async () => { counters.submitted++; }, counters);
|
|
628
|
+
deps.summaries = () => { throw cause; };
|
|
629
|
+
const result = await runAutoHandoffWorker(operation.handoff_id, { db, dependencies: deps });
|
|
630
|
+
assert.equal(result.state, 'failed'); assert.equal(result.error_code, expected); assert.equal(result.resume_state, 'source_stopped');
|
|
631
|
+
assert.equal(counters.created, 0); assert.equal(counters.submitted, 0); assert.equal(counters.notified, 1);
|
|
632
|
+
}
|
|
633
|
+
}));
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* l1-backend-recovery.mjs — L1 要約の backend(Codex CLI)が失敗してから、復帰を確認できたかの記録 (ADR 0041)
|
|
3
|
+
*
|
|
4
|
+
* Codex Stop の要約は外部 CLI を呼ぶ。通信の断、利用上限、認証切れ、利用者の取り消しでも失敗する。
|
|
5
|
+
* 会話の取り込みは済んでいて、要約は次の Stop がやり直すので、1回ごとの失敗は修理の対象として数えない。
|
|
6
|
+
* 最初の失敗から期限(24時間)を過ぎても成功を確認できていない時だけ、runtime error として数える。
|
|
7
|
+
*
|
|
8
|
+
* 端末ごとに1つのファイル(~/.throughline/l1-backend-recovery.json)に、成功を確認できていない間の
|
|
9
|
+
* 最初と最後の失敗の時刻だけを持つ。会話の内容も失敗の文面も書かない(文面は hook-failures.log に残る)。
|
|
10
|
+
* 読み書きの失敗は stderr に出し、hook の結果を変えない。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
import { randomUUID } from 'node:crypto';
|
|
17
|
+
|
|
18
|
+
export const L1_BACKEND_RECOVERY_SCHEMA = 'throughline.l1_backend_recovery.v1';
|
|
19
|
+
export const L1_BACKEND_UNRECOVERED_MS = 24 * 60 * 60 * 1000;
|
|
20
|
+
|
|
21
|
+
export function l1BackendRecoveryPath({ home = homedir() } = {}) {
|
|
22
|
+
return join(home, '.throughline', 'l1-backend-recovery.json');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function read(path) {
|
|
26
|
+
try {
|
|
27
|
+
const state = JSON.parse(readFileSync(path, 'utf8'));
|
|
28
|
+
if (state?.schema !== L1_BACKEND_RECOVERY_SCHEMA || !Number.isFinite(state.first_failure_at)) return null;
|
|
29
|
+
return state;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error.code !== 'ENOENT') process.stderr.write(`[l1-backend-recovery] ${error.message}\n`);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* backend の失敗を1回記す。最初の失敗から期限を過ぎていれば unrecovered を返す。
|
|
38
|
+
* @returns {{ unrecovered: boolean, firstFailureAt: number|null }}
|
|
39
|
+
*/
|
|
40
|
+
export function noteL1BackendFailure({ home, now = Date.now() } = {}) {
|
|
41
|
+
const path = l1BackendRecoveryPath({ home });
|
|
42
|
+
try {
|
|
43
|
+
const previous = read(path);
|
|
44
|
+
const firstFailureAt = previous?.first_failure_at ?? now;
|
|
45
|
+
const unrecovered = now - firstFailureAt >= L1_BACKEND_UNRECOVERED_MS;
|
|
46
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
47
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
48
|
+
writeFileSync(temporary, `${JSON.stringify({ schema: L1_BACKEND_RECOVERY_SCHEMA, first_failure_at: firstFailureAt,
|
|
49
|
+
last_failure_at: now, reported: Boolean(previous?.reported) || unrecovered })}\n`, { mode: 0o600 });
|
|
50
|
+
renameSync(temporary, path);
|
|
51
|
+
return { unrecovered, firstFailureAt };
|
|
52
|
+
} catch (error) {
|
|
53
|
+
process.stderr.write(`[l1-backend-recovery] ${error.message}\n`);
|
|
54
|
+
return { unrecovered: false, firstFailureAt: null };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* backend が要約を返した。失敗の記録があれば消す。期限を過ぎて runtime error に数えていた時は reported を返す。
|
|
60
|
+
* 記録が無い時(ふだん)は、ファイルの有無を1回見るだけで終わる。
|
|
61
|
+
* @returns {{ recovered: boolean, reported: boolean }}
|
|
62
|
+
*/
|
|
63
|
+
export function noteL1BackendSuccess({ home } = {}) {
|
|
64
|
+
const path = l1BackendRecoveryPath({ home });
|
|
65
|
+
if (!existsSync(path)) return { recovered: false, reported: false };
|
|
66
|
+
try {
|
|
67
|
+
const previous = read(path);
|
|
68
|
+
rmSync(path, { force: true });
|
|
69
|
+
return { recovered: true, reported: Boolean(previous?.reported) };
|
|
70
|
+
} catch (error) {
|
|
71
|
+
process.stderr.write(`[l1-backend-recovery] ${error.message}\n`);
|
|
72
|
+
return { recovered: false, reported: false };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -144,7 +144,7 @@ function makeBin(dir, name, body) {
|
|
|
144
144
|
return command;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
test('Codex Stop
|
|
147
|
+
test('Codex StopのL1要約backendの失敗は1回ごとには数えず、24時間復帰を確認できない時だけ数え、成功で解決にする', () => {
|
|
148
148
|
const { root, env } = createEnabledEnvironment('throughline-runtime-hook-summarizer-');
|
|
149
149
|
const threadId = '019dfaba-f87e-7f41-a144-d5ca7c6dd7f9';
|
|
150
150
|
const project = join(root, 'project');
|
|
@@ -168,20 +168,29 @@ test('Codex StopでL1要約backendが失敗した時、取り込みは残り、
|
|
|
168
168
|
mkdirSync(binDir, { recursive: true });
|
|
169
169
|
const codex = makeBin(binDir, 'codex', "process.stderr.write('ERROR: usage limit reached\\n');\nprocess.exit(42);\n");
|
|
170
170
|
|
|
171
|
-
const
|
|
172
|
-
env: { ...env, CODEX_HOME: codexHome, THROUGHLINE_CODEX_CLI_BIN:
|
|
171
|
+
const stop = (bin) => spawnSync(process.execPath, [BIN, 'codex-hook', 'stop'], {
|
|
172
|
+
env: { ...env, CODEX_HOME: codexHome, THROUGHLINE_CODEX_CLI_BIN: bin },
|
|
173
173
|
input: JSON.stringify({ session_id: threadId, transcript_path: rolloutPath, cwd: project }),
|
|
174
174
|
encoding: 'utf8',
|
|
175
175
|
});
|
|
176
|
+
const records = () => {
|
|
177
|
+
const storePath = defaultRuntimeErrorStorePath(env);
|
|
178
|
+
if (!existsSync(storePath)) return [];
|
|
179
|
+
return JSON.parse(readFileSync(storePath, 'utf8')).records
|
|
180
|
+
.map((record) => [record.error_code, record.component, record.severity, record.count, record.status, record.reason_code]);
|
|
181
|
+
};
|
|
182
|
+
const recoveryPath = join(root, '.throughline', 'l1-backend-recovery.json');
|
|
183
|
+
const result = stop(codex);
|
|
176
184
|
|
|
177
185
|
// hook は明示して失敗する(終了 code と stderr は変えない)。
|
|
178
186
|
assert.equal(result.status, 1, result.stderr);
|
|
179
187
|
assert.match(result.stderr, /\[codex-hook\] Codex CLI summarizer failed: exit 42/);
|
|
180
188
|
|
|
181
|
-
|
|
182
|
-
assert.deepEqual(
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
// 1回の失敗は、修理の対象として数えない。通信の断・利用上限・取り消しでも起き、次の Stop がやり直す。
|
|
190
|
+
assert.deepEqual(records(), []);
|
|
191
|
+
const first = JSON.parse(readFileSync(recoveryPath, 'utf8'));
|
|
192
|
+
assert.equal(first.schema, 'throughline.l1_backend_recovery.v1'); assert.equal(first.reported, false);
|
|
193
|
+
assert.deepEqual(Object.keys(first).sort(), ['first_failure_at', 'last_failure_at', 'reported', 'schema']);
|
|
185
194
|
|
|
186
195
|
// 取り込みは要約の前に commit 済み。
|
|
187
196
|
const db = new DatabaseSync(join(root, '.throughline', 'throughline.db'));
|
|
@@ -198,6 +207,31 @@ test('Codex StopでL1要約backendが失敗した時、取り込みは残り、
|
|
|
198
207
|
assert.equal(entry.code, 'L1_SUMMARIZER_BACKEND_FAILED');
|
|
199
208
|
assert.equal(entry.reason, 'codex_cli_failed');
|
|
200
209
|
assert.match(entry.stderr, /usage limit reached/);
|
|
210
|
+
|
|
211
|
+
// 続けて失敗しても、最初の失敗から24時間に届くまでは数えない。
|
|
212
|
+
assert.equal(stop(codex).status, 1);
|
|
213
|
+
assert.deepEqual(records(), []);
|
|
214
|
+
assert.equal(JSON.parse(readFileSync(recoveryPath, 'utf8')).first_failure_at, first.first_failure_at);
|
|
215
|
+
|
|
216
|
+
// 最初の失敗から24時間を過ぎても成功を確認できていない。warn で数える。
|
|
217
|
+
writeFileSync(recoveryPath, JSON.stringify({ ...first, first_failure_at: Date.now() - 25 * 3_600_000 }));
|
|
218
|
+
assert.equal(stop(codex).status, 1);
|
|
219
|
+
assert.deepEqual(records(), [['L1_SUMMARIZER_BACKEND_UNRECOVERED', 'codex_l1_summarizer', 'warn', 1, 'open', null]]);
|
|
220
|
+
assert.equal(JSON.parse(readFileSync(recoveryPath, 'utf8')).reported, true);
|
|
221
|
+
assert.equal(stop(codex).status, 1);
|
|
222
|
+
assert.deepEqual(records(), [['L1_SUMMARIZER_BACKEND_UNRECOVERED', 'codex_l1_summarizer', 'warn', 2, 'open', null]]);
|
|
223
|
+
|
|
224
|
+
// backend が要約を返した。失敗の記録を消し、数えていた記録を recovered で解決にする。
|
|
225
|
+
const working = makeBin(binDir, 'codex-ok', "process.stdout.write('要約\\n');\n");
|
|
226
|
+
const recovered = stop(working);
|
|
227
|
+
assert.equal(recovered.status, 0, recovered.stderr);
|
|
228
|
+
assert.equal(existsSync(recoveryPath), false);
|
|
229
|
+
assert.deepEqual(records(), [['L1_SUMMARIZER_BACKEND_UNRECOVERED', 'codex_l1_summarizer', 'warn', 2, 'resolved', 'recovered']]);
|
|
230
|
+
|
|
231
|
+
// 復帰した後の失敗は、また最初から数える(すぐには数えない)。
|
|
232
|
+
assert.equal(stop(codex).status, 1);
|
|
233
|
+
assert.deepEqual(records(), [['L1_SUMMARIZER_BACKEND_UNRECOVERED', 'codex_l1_summarizer', 'warn', 2, 'resolved', 'recovered']]);
|
|
234
|
+
assert.equal(JSON.parse(readFileSync(recoveryPath, 'utf8')).reported, false);
|
|
201
235
|
});
|
|
202
236
|
|
|
203
237
|
test('store failure preserves product failure and emits only fixed storage diagnostic', () => {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { observeRuntimeError } from './runtime-error-store.mjs';
|
|
1
|
+
import { observeRuntimeError, resolveRuntimeError, runtimeErrorFingerprint } from './runtime-error-store.mjs';
|
|
2
2
|
|
|
3
3
|
try {
|
|
4
|
-
|
|
4
|
+
// 第2引数が recovered の時は、その code の記録を「復帰を確認した」として解決にする(ADR 0041)。
|
|
5
|
+
const result = process.argv[3] === 'recovered'
|
|
6
|
+
? resolveRuntimeError(runtimeErrorFingerprint(process.argv[2]), { reasonCode: 'recovered' })
|
|
7
|
+
: observeRuntimeError({ code: process.argv[2] });
|
|
5
8
|
process.exitCode = result.status === 'disabled' ? 3 : 0;
|
|
6
9
|
} catch {
|
|
7
10
|
process.exitCode = 1;
|
|
@@ -64,14 +64,30 @@ const DEFINITIONS = Object.freeze({
|
|
|
64
64
|
template: 'Throughline Codex hook processing failed',
|
|
65
65
|
}),
|
|
66
66
|
// Codex Stop の取り込みは済み、L1 要約の backend(Codex CLI)だけが失敗した(ADR 0028)。
|
|
67
|
+
// 0.16.4 からは数えない(ADR 0041)。1回ごとの失敗は、通信の断・利用上限・取り消しでも起き、次の Stop がやり直す。
|
|
68
|
+
// 前の版が記録した store を読める様に、定義は残す。
|
|
67
69
|
L1_SUMMARIZER_BACKEND_FAILED: Object.freeze({
|
|
68
70
|
component: 'codex_l1_summarizer',
|
|
69
71
|
// BugHub が受ける severity は fatal・high・warn・info だけ。他の値は report 全体が 422 になる。
|
|
70
72
|
severity: 'warn',
|
|
71
73
|
template: 'Throughline L1 summarizer backend (Codex CLI) failed',
|
|
72
74
|
}),
|
|
75
|
+
// L1 要約の backend が失敗し、最初の失敗から24時間を過ぎても成功を確認できていない(ADR 0041)。
|
|
76
|
+
// 記憶は失われていない(取り込みは済み、recall は L2 を返す)。要約が成功した時に、recovered で解決にする。
|
|
77
|
+
L1_SUMMARIZER_BACKEND_UNRECOVERED: Object.freeze({
|
|
78
|
+
component: 'codex_l1_summarizer',
|
|
79
|
+
severity: 'warn',
|
|
80
|
+
template: 'Throughline L1 summarizer backend (Codex CLI) has not recovered for over 24 hours',
|
|
81
|
+
}),
|
|
73
82
|
});
|
|
74
83
|
|
|
84
|
+
/** 定型 code の fingerprint。記録は code ごとに1つ。 */
|
|
85
|
+
export function runtimeErrorFingerprint(code) {
|
|
86
|
+
const definition = DEFINITIONS[code];
|
|
87
|
+
if (!definition) throw new TypeError('未登録の runtime error code です');
|
|
88
|
+
return createHash('sha256').update(['throughline', definition.component, code, definition.template].join('\0')).digest('hex');
|
|
89
|
+
}
|
|
90
|
+
|
|
75
91
|
export function defaultRuntimeErrorConfigPath(env = process.env) {
|
|
76
92
|
if (isWindows(env)) {
|
|
77
93
|
return join(windowsLocalAppData(env), 'throughline', 'runtime-errors.config.json');
|
|
@@ -143,9 +159,7 @@ export function observeRuntimeError(input, options = {}) {
|
|
|
143
159
|
return withStoreLock(options, (privateDirectory) => {
|
|
144
160
|
const now = normalizeTimestamp(input.now);
|
|
145
161
|
const version = normalizeVersion(options.version ?? PACKAGE_VERSION);
|
|
146
|
-
const fingerprint =
|
|
147
|
-
.update(['throughline', definition.component, input.code, definition.template].join('\0'))
|
|
148
|
-
.digest('hex');
|
|
162
|
+
const fingerprint = runtimeErrorFingerprint(input.code);
|
|
149
163
|
const store = readStore(options, { privateDirectory });
|
|
150
164
|
const existing = store.records.find((record) => record.fingerprint === fingerprint);
|
|
151
165
|
const sequence = nextSequence(store);
|
|
@@ -307,10 +321,15 @@ export function getRuntimeErrorDiagnostics(options = {}) {
|
|
|
307
321
|
}
|
|
308
322
|
}
|
|
309
323
|
|
|
324
|
+
/** 復帰を確認できた記録を、recovered で解決にする。記録が無い時と、解決済みの時は何もしない。 */
|
|
325
|
+
export function resolveRecoveredRuntimeErrorBestEffort(code, options = {}) {
|
|
326
|
+
return recordRuntimeErrorBestEffort(code, { ...options, action: 'recovered' });
|
|
327
|
+
}
|
|
328
|
+
|
|
310
329
|
export function recordRuntimeErrorBestEffort(code, options = {}) {
|
|
311
|
-
const { stderr = process.stderr, ...storeOptions } = options;
|
|
330
|
+
const { stderr = process.stderr, action = null, ...storeOptions } = options;
|
|
312
331
|
try {
|
|
313
|
-
const child = childProcess.spawnSync(process.execPath, [fileURLToPath(new URL('./runtime-error-observer.mjs', import.meta.url)), code], {
|
|
332
|
+
const child = childProcess.spawnSync(process.execPath, [fileURLToPath(new URL('./runtime-error-observer.mjs', import.meta.url)), code, ...(action ? [action] : [])], {
|
|
314
333
|
env: storeOptions.env ?? process.env,
|
|
315
334
|
encoding: 'utf8',
|
|
316
335
|
stdio: 'ignore',
|