@seanhogg/builderforce-memory 2026.10.52 → 2026.10.54
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/dist/knowledge/backfillNoExtract.d.ts +2 -2
- package/dist/knowledge/backfillNoExtract.d.ts.map +1 -1
- package/dist/knowledge/backfillNoExtract.js +10 -7
- package/dist/knowledge/backfillNoExtract.js.map +1 -1
- package/dist/knowledge/extractFile.d.ts.map +1 -1
- package/dist/knowledge/extractFile.js +11 -4
- package/dist/knowledge/extractFile.js.map +1 -1
- package/dist/knowledge/extractJob.d.ts +11 -0
- package/dist/knowledge/extractJob.d.ts.map +1 -1
- package/dist/knowledge/extractJob.js +10 -0
- package/dist/knowledge/extractJob.js.map +1 -1
- package/dist/knowledge/index.d.ts +1 -1
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/owedFiles.d.ts +10 -1
- package/dist/knowledge/owedFiles.d.ts.map +1 -1
- package/dist/knowledge/owedFiles.js +12 -3
- package/dist/knowledge/owedFiles.js.map +1 -1
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +16 -10
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewFailure.d.ts +37 -0
- package/dist/knowledge/reviewFailure.d.ts.map +1 -0
- package/dist/knowledge/reviewFailure.js +37 -0
- package/dist/knowledge/reviewFailure.js.map +1 -0
- package/dist/knowledge/reviewPrefetch.d.ts +3 -2
- package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.js +7 -6
- package/dist/knowledge/reviewPrefetch.js.map +1 -1
- package/package.json +3 -3
- package/src/contract/exports.snapshot.json +1 -0
- package/src/contract/regression.recheck.test.ts +228 -0
- package/src/contract/regression.review.test.ts +1 -93
- package/src/contract/regression.store.test.ts +13 -0
- package/src/contract/types.contract.test.ts +2 -1
- package/src/knowledge/backfillNoExtract.ts +6 -4
- package/src/knowledge/extractFile.ts +6 -4
- package/src/knowledge/extractJob.ts +11 -0
- package/src/knowledge/index.ts +1 -1
- package/src/knowledge/owedFiles.ts +15 -3
- package/src/knowledge/review.ts +20 -8
- package/src/knowledge/reviewFailure.ts +51 -0
- package/src/knowledge/reviewPrefetch.ts +8 -7
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* - binary by CONTENT (a NUL): unknowable without reading. A replica that holds a file back, or is told by the server that a
|
|
12
12
|
* body is missing, calls `store.markRecheck(hashes)`; the review reads ONLY the unchanged planned files with those hashes.
|
|
13
13
|
* Binary → `[]`. Anything else (text, a document) → queued for extraction this run (`changed`). A hash only a SKIPPED
|
|
14
|
-
* prior entry carries is never extracted by any review: `[]`. Hashes settled HERE are cleared here
|
|
15
|
-
* once its body
|
|
14
|
+
* prior entry carries is never extracted by any review: `[]`. Hashes settled HERE are cleared here. A queued one (or one whose read
|
|
15
|
+
* threw here) is cleared by the review only once its body is stored or a FINAL failure is recorded; a transient failure or a stop keeps the request.
|
|
16
16
|
*
|
|
17
17
|
* A healthy root has no body missing and an empty recheck set: it reads nothing and costs only in-memory lookups.
|
|
18
18
|
*/
|
|
@@ -66,7 +66,7 @@ export async function backfillNoExtract(args: { store: KnowledgeStore; source: D
|
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
68
68
|
const todo = files.filter((f) => !f.changed && detail.prior.get(f.path) === f.hash);
|
|
69
|
-
if (todo.length === 0)
|
|
69
|
+
if (todo.length === 0) continue; // a changed file is handled by this review, which clears the request once its work is done (`settledRecheck`)
|
|
70
70
|
// Pass 2 works only on `only`: a file it will not process is not queued here, and its hash stays asked for the run that will.
|
|
71
71
|
if (args.only && !todo.some((t) => args.only!.includes(t.path))) continue;
|
|
72
72
|
const f = todo[0]!;
|
|
@@ -75,7 +75,9 @@ export async function backfillNoExtract(args: { store: KnowledgeStore; source: D
|
|
|
75
75
|
const doc = await source.read(f.path);
|
|
76
76
|
binary = doc.content.kind === 'text' && isBinaryText(doc.content.text);
|
|
77
77
|
} catch {
|
|
78
|
-
|
|
78
|
+
// Unreadable says nothing final about the file: it goes through the review's one failure path (reported, kept asked, made owed).
|
|
79
|
+
for (const t of todo) { t.changed = true; out.queued.push(t.path); }
|
|
80
|
+
continue;
|
|
79
81
|
}
|
|
80
82
|
if (binary) { await putNoExtract(store, hash); out.recorded += 1; done.add(hash); }
|
|
81
83
|
else for (const t of todo) { t.changed = true; out.queued.push(t.path); } // asked for until the review has stored its body (see `settledRecheck`)
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { ParsedSection, SourceDocument } from '../ingest/types.js';
|
|
10
10
|
import type { Extracted, KnowledgePack, KnowledgeParser, KnowledgeStore, NodeRef } from './model.js';
|
|
11
|
-
import { BinaryContent, jobOf, runExtractor, type ExtractPool } from './extractJob.js';
|
|
11
|
+
import { BinaryContent, CHANGED_SINCE_PLAN, ExtractFailed, jobOf, runExtractor, type ExtractPool } from './extractJob.js';
|
|
12
12
|
import { srcRef } from './refs.js';
|
|
13
13
|
import { entityName, knownKeysOf, resolveEntities } from './resolve.js';
|
|
14
14
|
import { asPathSource, composePacks, EXTRACTOR_VERSION, resolveRelativePath, stubSource, type ComposedPacks } from './sources.js';
|
|
@@ -88,7 +88,9 @@ export async function extractFileDetailed(a: ExtractFileArgs): Promise<FileExtra
|
|
|
88
88
|
const ref = srcRef(a.rootId, a.path);
|
|
89
89
|
// With a pool the main thread never parses: the worker returns the sections when the file will be judged.
|
|
90
90
|
const wants = !!a.pool && !!a.wantsSections?.(hit.pack);
|
|
91
|
-
|
|
91
|
+
// The parser and the extractor run in this thread only without a pool; their errors are the PROVEN-final failures (ExtractFailed).
|
|
92
|
+
const proven = <T>(work: () => T): T => { try { return work(); } catch (error) { throw new ExtractFailed(error instanceof Error ? error.message : String(error), { cause: error }); } };
|
|
93
|
+
let sections: ParsedSection[] = a.pool ? [] : proven(() => hit.parser.parse(src));
|
|
92
94
|
const tLookup = Date.now();
|
|
93
95
|
const cached = await a.store.getExtracted?.(a.hash);
|
|
94
96
|
const lookupMs = Date.now() - tLookup;
|
|
@@ -117,14 +119,14 @@ export async function extractFileDetailed(a: ExtractFileArgs): Promise<FileExtra
|
|
|
117
119
|
const mine = out.extracted.find((e) => e.sourceRef === ref);
|
|
118
120
|
if (!mine) throw new Error(`extract pool returned no extract for ${a.path}`);
|
|
119
121
|
// The pool read other bytes than the plan hashed: nothing is stored under the planned hash.
|
|
120
|
-
if (mine.sourceHash !== a.hash) throw new Error(
|
|
122
|
+
if (mine.sourceHash !== a.hash) throw new Error(CHANGED_SINCE_PLAN); // transient: the bytes may settle
|
|
121
123
|
if (wants) {
|
|
122
124
|
if (!out.sections) throw new Error(`extract pool returned no sections for ${a.path}`);
|
|
123
125
|
sections = out.sections;
|
|
124
126
|
}
|
|
125
127
|
extracted = mine;
|
|
126
128
|
} else {
|
|
127
|
-
extracted = runExtractor(hit, src, sections, { rootId: a.rootId, knownKeys, resolvePath: resolveRelativePath }, a);
|
|
129
|
+
extracted = proven(() => runExtractor(hit, src, sections, { rootId: a.rootId, knownKeys, resolvePath: resolveRelativePath }, a));
|
|
128
130
|
}
|
|
129
131
|
if (a.writeCache !== false) await putExtract(a.store, a.hash, extracted, cached ?? []);
|
|
130
132
|
return { extracted, parser: hit.parser, pack: hit.pack, sections, cached: false };
|
|
@@ -40,6 +40,17 @@ export type ExtractJobSource =
|
|
|
40
40
|
|
|
41
41
|
export type ExtractJob = ExtractJobBase & ExtractJobSource;
|
|
42
42
|
|
|
43
|
+
/** The planned bytes are not the bytes read: nothing is stored under the planned hash. Always TRANSIENT (the bytes may settle). */
|
|
44
|
+
export const CHANGED_SINCE_PLAN = 'changed since plan';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A failure PROVEN final: the parser or extractor itself threw on these bytes (in-thread, or a pool's worker reporting it). Every other
|
|
48
|
+
* failure (a read, a timeout, a crashed or disposed worker, a failing store, a changed-since-plan) is transient: the file may extract next time.
|
|
49
|
+
*/
|
|
50
|
+
export class ExtractFailed extends Error {
|
|
51
|
+
constructor(message: string, options?: { cause?: unknown }) { super(message); this.name = 'ExtractFailed'; if (options?.cause !== undefined) (this as { cause?: unknown }).cause = options.cause; }
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
/** Thrown by the extract stage when the pool found the file binary; the review records a `skipped` step. */
|
|
44
55
|
export class BinaryContent extends Error {
|
|
45
56
|
constructor() { super('binary'); this.name = 'BinaryContent'; }
|
package/src/knowledge/index.ts
CHANGED
|
@@ -49,7 +49,7 @@ export { orderForJudging } from './judgePriority.js';
|
|
|
49
49
|
export type { JudgeSignals } from './judgePriority.js';
|
|
50
50
|
export { extractFile, extractFileDetailed, knownKeysOfEntities } from './extractFile.js';
|
|
51
51
|
export type { ExtractFileArgs, FileExtraction } from './extractFile.js';
|
|
52
|
-
export { extractJob, jobOf } from './extractJob.js';
|
|
52
|
+
export { ExtractFailed, extractJob, jobOf } from './extractJob.js';
|
|
53
53
|
export type { ExtractJob, ExtractJobResult, ExtractPool } from './extractJob.js';
|
|
54
54
|
export { putExtract, putNoExtract } from './extractFile.js';
|
|
55
55
|
export { createModelLimiter, isRateLimit } from './modelLimiter.js';
|
|
@@ -31,6 +31,7 @@ import { EXTRACTOR_VERSION, extractorManifestKey } from './sources.js';
|
|
|
31
31
|
|
|
32
32
|
const VERSION_ID = 'version';
|
|
33
33
|
const OWED_PREFIX = 'owed:';
|
|
34
|
+
const FAIL_PREFIX = 'fail:';
|
|
34
35
|
/** What a version upgrade costs per file: the one new section a re-extraction may add (an upper bound). */
|
|
35
36
|
const UPGRADE_CALLS = 1;
|
|
36
37
|
|
|
@@ -39,21 +40,27 @@ export interface ExtractorState {
|
|
|
39
40
|
version: number | undefined;
|
|
40
41
|
/** Paths a previous run left unfinished under that version → model calls each still costs. */
|
|
41
42
|
owed: ReadonlyMap<string, number>;
|
|
43
|
+
/** Consecutive transient failures of a path at one content hash (stored beside its owed entry); a success or a new hash resets it. */ failures: ReadonlyMap<string, { hash: string; count: number }>;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export async function loadExtractorState(manifest: IngestManifest, rootId: string): Promise<ExtractorState> {
|
|
45
47
|
let version: number | undefined;
|
|
46
48
|
const owed = new Map<string, number>();
|
|
49
|
+
const failures = new Map<string, { hash: string; count: number }>();
|
|
47
50
|
for (const { id, hash } of (await manifest.get(extractorManifestKey(rootId))) ?? []) {
|
|
48
51
|
if (id === VERSION_ID) {
|
|
49
52
|
const v = Number(hash);
|
|
50
53
|
if (Number.isFinite(v)) version = v;
|
|
54
|
+
} else if (id.startsWith(FAIL_PREFIX)) {
|
|
55
|
+
const at = hash.indexOf(':');
|
|
56
|
+
const count = Number(hash.slice(0, at));
|
|
57
|
+
if (at > 0 && Number.isInteger(count) && count > 0) failures.set(id.slice(FAIL_PREFIX.length), { hash: hash.slice(at + 1), count });
|
|
51
58
|
} else if (id.startsWith(OWED_PREFIX)) {
|
|
52
59
|
const calls = Number(hash);
|
|
53
60
|
owed.set(id.slice(OWED_PREFIX.length), Number.isFinite(calls) && calls >= 0 ? calls : UPGRADE_CALLS);
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
|
-
return { version, owed };
|
|
63
|
+
return { version, owed, failures };
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
/** True when `path` is owed a re-extraction: another extractor version than today's, or left unfinished before. */
|
|
@@ -88,21 +95,26 @@ export function owedAfterRun(a: {
|
|
|
88
95
|
finished: ReadonlySet<string>;
|
|
89
96
|
carried: readonly string[];
|
|
90
97
|
live: ReadonlyMap<string, string>;
|
|
98
|
+
/** Files whose read or extraction failed for a reason that says nothing final about them (same bytes as the manifest): owed even though their content did not change. */
|
|
99
|
+
unreadable?: ReadonlySet<string>;
|
|
91
100
|
/** Calls a file this run reached but did not finish still costs. */
|
|
92
101
|
measured: ReadonlyMap<string, number>;
|
|
93
102
|
}): Map<string, number> {
|
|
94
103
|
const out = new Map<string, number>();
|
|
95
104
|
for (const f of a.changed) {
|
|
96
|
-
if ((f.owed || a.prior.get(f.path) !== f.hash) && !a.finished.has(f.path)) out.set(f.path, a.measured.get(f.path) ?? owedCalls(a.state, f.path));
|
|
105
|
+
if ((f.owed || a.prior.get(f.path) !== f.hash || a.unreadable?.has(f.path)) && !a.finished.has(f.path)) out.set(f.path, a.measured.get(f.path) ?? owedCalls(a.state, f.path));
|
|
97
106
|
}
|
|
98
107
|
for (const p of a.carried) if (a.live.has(p)) out.set(p, owedCalls(a.state, p));
|
|
99
108
|
return out;
|
|
100
109
|
}
|
|
101
110
|
|
|
102
111
|
/** Records today's version and exactly the files still owed after this run. */
|
|
103
|
-
export async function saveExtractorState(
|
|
112
|
+
export async function saveExtractorState(
|
|
113
|
+
manifest: IngestManifest, rootId: string, owed: ReadonlyMap<string, number>, failures: ReadonlyMap<string, { hash: string; count: number }> = new Map(),
|
|
114
|
+
): Promise<void> {
|
|
104
115
|
await manifest.set(extractorManifestKey(rootId), [
|
|
105
116
|
{ id: VERSION_ID, hash: String(EXTRACTOR_VERSION) },
|
|
106
117
|
...[...owed].sort((a, b) => compareStr(a[0], b[0])).map(([path, calls]) => ({ id: `${OWED_PREFIX}${path}`, hash: String(calls) })),
|
|
118
|
+
...[...failures].filter(([path]) => owed.has(path)).sort((a, b) => compareStr(a[0], b[0])).map(([path, f]) => ({ id: `${FAIL_PREFIX}${path}`, hash: `${f.count}:${f.hash}` })),
|
|
107
119
|
]);
|
|
108
120
|
}
|
package/src/knowledge/review.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { planDetail, refreshPlan } from './plan.js';
|
|
|
33
33
|
import { composePacks, filesManifestKey, judgedManifestKey, manifestMap, saveManifestMap } from './sources.js';
|
|
34
34
|
import { knownKeysOfEntities, putExtract, putNoExtract } from './extractFile.js';
|
|
35
35
|
import { backfillCandidates, backfillNoExtract } from './backfillNoExtract.js';
|
|
36
|
+
import { recordFailure } from './reviewFailure.js';
|
|
36
37
|
import { prefetchOrdered } from './orderedPool.js';
|
|
37
38
|
import {
|
|
38
39
|
DEFAULT_REVIEW_CONCURRENCY, DEFAULT_REVIEW_JUDGE_CONCURRENCY, DEFAULT_REVIEW_MODEL_CALLS, JUDGE_CONCURRENCY, JudgedBatch,
|
|
@@ -171,6 +172,10 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
|
|
|
171
172
|
// Changed files this run finished (or had nothing to do for); an owed file not in it stays owed,
|
|
172
173
|
// at the model calls it still costs where this run could measure that (see owedFiles.ts).
|
|
173
174
|
const finished = new Set<string>();
|
|
175
|
+
/** Files that failed for a reason that says nothing final about them, at the manifest's own bytes: owed, so the next review retries them. */
|
|
176
|
+
const unreadable = new Set<string>();
|
|
177
|
+
/** Consecutive transient failures by path at one hash (saved beside the owed record). */
|
|
178
|
+
const failures = new Map(detail.extractor.failures);
|
|
174
179
|
const measured = new Map<string, number>();
|
|
175
180
|
// Read + binary check + extract run ahead with bounded concurrency (extraction only reads `knownKeys`,
|
|
176
181
|
// fixed above, and the content-hash extract cache); with `args.extractPool` the width is the pool's.
|
|
@@ -211,13 +216,12 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
|
|
|
211
216
|
if (job.kind === 'read-error') report.readErrors += 1; else report.extractErrors += 1;
|
|
212
217
|
fail(f.path, 'extract', job.kind === 'read-error' ? `read: ${job.reason}` : job.reason);
|
|
213
218
|
measured.set(f.path, owedCalls(detail.extractor, f.path)); // learns nothing: keep what it was owed
|
|
214
|
-
// The
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
const known = detail.prior.get(f.path);
|
|
218
|
-
if (known) { await putNoExtract(store, known); await settledRecheck(known); }
|
|
219
|
+
// The ONE failure path (reviewFailure.ts): a transient failure keeps the re-check request and makes the file owed; only a proven-final
|
|
220
|
+
// one (or the third in a row at the same bytes) is answered with a terminal `[]`.
|
|
221
|
+
await recordFailure({ store, detail, stopped: () => runSignal.aborted, unreadable, failures, settledRecheck }, f, job);
|
|
219
222
|
return true;
|
|
220
223
|
}
|
|
224
|
+
failures.delete(f.path); // it read and extracted (or was decided): the run of failures at this hash ends
|
|
221
225
|
// Recorded, so a file found binary on read is not re-read by every later review.
|
|
222
226
|
if (job.kind === 'binary') {
|
|
223
227
|
filesNow.set(f.path, f.hash);
|
|
@@ -228,7 +232,13 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
|
|
|
228
232
|
report.staleMarked += 1;
|
|
229
233
|
return true;
|
|
230
234
|
}
|
|
231
|
-
if (job.kind === 'none') {
|
|
235
|
+
if (job.kind === 'none') {
|
|
236
|
+
// No pack accepts the file: nothing will ever be extracted for it, so say so (and answer any re-check of it).
|
|
237
|
+
finished.add(f.path);
|
|
238
|
+
await putNoExtract(store, f.hash);
|
|
239
|
+
await settledRecheck(f.hash);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
232
242
|
report.extracted += 1;
|
|
233
243
|
// The extract cache is written HERE, in plan order, so the cache, the counts and the order match a sequential run.
|
|
234
244
|
if (!job.extraction.cached) await putExtract(store, f.hash, job.extraction.extracted);
|
|
@@ -302,6 +312,8 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
|
|
|
302
312
|
await Promise.allSettled(queue.map((s) => s.judge?.result)); // nothing outlives the run
|
|
303
313
|
}
|
|
304
314
|
if (applied < work.length) report.aborted = true;
|
|
315
|
+
// A Stop ends the run: the file in hand was finished and applied above, but nothing after it (retire, analyzers, the digest stamp) runs.
|
|
316
|
+
report.aborted ||= runSignal.aborted;
|
|
305
317
|
|
|
306
318
|
// Pass 2 (`only`) is judging alone: the map pass already retired the removed files and ran the analyzers.
|
|
307
319
|
if (!report.aborted && !args.only) {
|
|
@@ -360,8 +372,8 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
|
|
|
360
372
|
// After every run: today's version and every file still owed a re-extraction — the unfinished ones,
|
|
361
373
|
// content-changed or not, and the owed paths the plan did not list that the manifest still holds.
|
|
362
374
|
await saveExtractorState(manifest, rootId, owedAfterRun({
|
|
363
|
-
state: detail.extractor, changed, prior: detail.prior, finished, carried: detail.carried, live: filesNow, measured,
|
|
364
|
-
}));
|
|
375
|
+
state: detail.extractor, changed, prior: detail.prior, finished, carried: detail.carried, live: filesNow, measured, unreadable,
|
|
376
|
+
}), failures);
|
|
365
377
|
await write(report.aborted ? scopeRecord : { ...scopeRecord, lastDigest: report.digest, lastReviewedAt: new Date(now()).toISOString() });
|
|
366
378
|
report.durationMs = now() - started;
|
|
367
379
|
progress({ phase: 'done', done: work.length, total: work.length });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/reviewFailure.ts — what a review does with a file whose read or extraction failed (the ONE failure path).
|
|
3
|
+
*
|
|
4
|
+
* A failure is TRANSIENT unless proven final (see {@link ExtractFailed}): a read, a timeout, a crashed or disposed worker, a failing store, a stop.
|
|
5
|
+
* A replica that holds the file back and asks about it needs an answer, but only a final one may be terminal (`[]` = nothing extracted):
|
|
6
|
+
*
|
|
7
|
+
* - final: the manifest's bytes are gone (the hash moved), or the parser/extractor threw on them. `[]` is stored under the manifest's hash
|
|
8
|
+
* and the request is settled — unless an unchanged planned file still carries that hash (its content is readable: do not hide it);
|
|
9
|
+
* - transient at the manifest's own bytes: the request is kept and the path is made OWED, so the next normal review retries it;
|
|
10
|
+
* after {@link MAX_TRANSIENT_FAILURES} in a row at the same hash it is treated as final, so a file that never reads cannot hold a root forever;
|
|
11
|
+
* - never anything when the run was stopped.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { putNoExtract } from './extractFile.js';
|
|
15
|
+
import type { KnowledgeStore } from './model.js';
|
|
16
|
+
import type { PlanDetail } from './plan.js';
|
|
17
|
+
import type { Prefetch } from './reviewPrefetch.js';
|
|
18
|
+
|
|
19
|
+
/** Consecutive transient failures at one hash after which the failure is recorded as final. */
|
|
20
|
+
export const MAX_TRANSIENT_FAILURES = 3;
|
|
21
|
+
|
|
22
|
+
export interface FailureContext {
|
|
23
|
+
store: KnowledgeStore;
|
|
24
|
+
detail: PlanDetail;
|
|
25
|
+
stopped: () => boolean;
|
|
26
|
+
/** Paths to record as owed (a transient failure at the manifest's own bytes). */
|
|
27
|
+
unreadable: Set<string>;
|
|
28
|
+
/** Consecutive transient failures by path (persisted beside the owed entry). */
|
|
29
|
+
failures: Map<string, { hash: string; count: number }>;
|
|
30
|
+
settledRecheck: (hash: string) => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function recordFailure(ctx: FailureContext, f: { path: string; hash: string }, job: Extract<Prefetch, { kind: 'read-error' | 'failed' }>): Promise<void> {
|
|
34
|
+
const known = ctx.detail.prior.get(f.path);
|
|
35
|
+
if (!known || ctx.stopped()) return;
|
|
36
|
+
const transient = job.kind === 'read-error' || job.transient === true;
|
|
37
|
+
if (known === f.hash && transient) {
|
|
38
|
+
const prev = ctx.failures.get(f.path);
|
|
39
|
+
const count = (prev?.hash === known ? prev.count : 0) + 1;
|
|
40
|
+
if (count < MAX_TRANSIENT_FAILURES) {
|
|
41
|
+
ctx.failures.set(f.path, { hash: known, count });
|
|
42
|
+
ctx.unreadable.add(f.path);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
ctx.failures.delete(f.path);
|
|
47
|
+
// An unchanged planned file that still carries `known` is readable content: a terminal `[]` would hide it.
|
|
48
|
+
if (ctx.detail.files.some((g) => g.path !== f.path && !g.changed && g.hash === known)) return;
|
|
49
|
+
await putNoExtract(ctx.store, known);
|
|
50
|
+
await ctx.settledRecheck(known);
|
|
51
|
+
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import type { SourceDocument } from '../ingest/types.js';
|
|
13
13
|
import type { KnowledgePack, KnowledgeStore, NodeRef, ReviewArgs } from './model.js';
|
|
14
14
|
import { extractFileDetailed, type FileExtraction } from './extractFile.js';
|
|
15
|
-
import { BinaryContent } from './extractJob.js';
|
|
15
|
+
import { BinaryContent, CHANGED_SINCE_PLAN, ExtractFailed } from './extractJob.js';
|
|
16
16
|
import { judgesPack } from './reviewJudge.js';
|
|
17
17
|
import { createDeadlines } from './jobDeadline.js';
|
|
18
18
|
import { createModelLimiter } from './modelLimiter.js';
|
|
@@ -25,7 +25,7 @@ export type Prefetch = (
|
|
|
25
25
|
| { kind: 'binary' }
|
|
26
26
|
| { kind: 'none' }
|
|
27
27
|
| { kind: 'extracted'; doc?: SourceDocument; extraction: FileExtraction }
|
|
28
|
-
| { kind: 'failed'; reason: string }
|
|
28
|
+
| { kind: 'failed'; reason: string; transient?: true }
|
|
29
29
|
) & { ms: number; lane: number; parts?: NonNullable<ReviewStep['parts']> };
|
|
30
30
|
|
|
31
31
|
export interface PrefetchContext {
|
|
@@ -58,8 +58,7 @@ export function extractStepOf(path: string, job: Prefetch): ReviewStep {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
export const CHANGED_SINCE_PLAN = 'changed since plan';
|
|
61
|
+
export { CHANGED_SINCE_PLAN };
|
|
63
62
|
|
|
64
63
|
/** Per-job ceilings of the extract path (PRD 41 A10 rule 2). */
|
|
65
64
|
export const DEFAULT_READ_TIMEOUT_MS = 5_000;
|
|
@@ -79,7 +78,7 @@ export function createPrefetch(c: PrefetchContext): (f: { path: string; hash: st
|
|
|
79
78
|
|
|
80
79
|
const run = async (f: { path: string; hash: string }, parts: NonNullable<ReviewStep['parts']>, held: { lane: number }): Promise<Outcome> => {
|
|
81
80
|
// A stopped run starts nothing: a job that has not begun settles at once. Once the read has begun the job finishes (its slot wait below is signal-free for a file already read).
|
|
82
|
-
if (c.signal.aborted) return { kind: 'failed', reason: reasonOf(c.signal.reason) };
|
|
81
|
+
if (c.signal.aborted) return { kind: 'failed', reason: reasonOf(c.signal.reason), transient: true };
|
|
83
82
|
let doc: SourceDocument | undefined;
|
|
84
83
|
const t0 = Date.now();
|
|
85
84
|
if (!byPool) {
|
|
@@ -104,11 +103,13 @@ export function createPrefetch(c: PrefetchContext): (f: { path: string; hash: st
|
|
|
104
103
|
// stored, the bytes read must be the bytes planned: hashed once, from the text already in hand. The review writes the
|
|
105
104
|
// extract cache only for an 'extracted' job, so nothing is stored under the stale hash.
|
|
106
105
|
const hashOf = c.args.source.hashOf;
|
|
107
|
-
if (hashOf && doc && doc.content.kind === 'text' && hashOf(doc.content.text) !== f.hash) return { kind: 'failed', reason: CHANGED_SINCE_PLAN };
|
|
106
|
+
if (hashOf && doc && doc.content.kind === 'text' && hashOf(doc.content.text) !== f.hash) return { kind: 'failed', reason: CHANGED_SINCE_PLAN, transient: true };
|
|
108
107
|
return { kind: 'extracted', ...(doc ? { doc } : {}), extraction };
|
|
109
108
|
} catch (error) {
|
|
110
109
|
if (error instanceof BinaryContent) return { kind: 'binary' };
|
|
111
|
-
|
|
110
|
+
// Transient UNLESS proven final: only the parser or extractor throwing on these bytes (ExtractFailed) is. A read, a timeout, a crashed or
|
|
111
|
+
// disposed worker, a failing store, a stop: all say nothing final about the file.
|
|
112
|
+
return { kind: 'failed', reason: reasonOf(error), ...(error instanceof ExtractFailed && !c.signal.aborted ? {} : { transient: true as const }) };
|
|
112
113
|
}
|
|
113
114
|
};
|
|
114
115
|
|