@seanhogg/builderforce-memory 2026.10.53 → 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.
Files changed (41) hide show
  1. package/dist/knowledge/backfillNoExtract.d.ts +2 -2
  2. package/dist/knowledge/backfillNoExtract.js +2 -2
  3. package/dist/knowledge/extractFile.d.ts.map +1 -1
  4. package/dist/knowledge/extractFile.js +11 -4
  5. package/dist/knowledge/extractFile.js.map +1 -1
  6. package/dist/knowledge/extractJob.d.ts +11 -0
  7. package/dist/knowledge/extractJob.d.ts.map +1 -1
  8. package/dist/knowledge/extractJob.js +10 -0
  9. package/dist/knowledge/extractJob.js.map +1 -1
  10. package/dist/knowledge/index.d.ts +1 -1
  11. package/dist/knowledge/index.d.ts.map +1 -1
  12. package/dist/knowledge/index.js +1 -1
  13. package/dist/knowledge/index.js.map +1 -1
  14. package/dist/knowledge/owedFiles.d.ts +8 -1
  15. package/dist/knowledge/owedFiles.d.ts.map +1 -1
  16. package/dist/knowledge/owedFiles.js +11 -2
  17. package/dist/knowledge/owedFiles.js.map +1 -1
  18. package/dist/knowledge/review.d.ts.map +1 -1
  19. package/dist/knowledge/review.js +10 -15
  20. package/dist/knowledge/review.js.map +1 -1
  21. package/dist/knowledge/reviewFailure.d.ts +37 -0
  22. package/dist/knowledge/reviewFailure.d.ts.map +1 -0
  23. package/dist/knowledge/reviewFailure.js +37 -0
  24. package/dist/knowledge/reviewFailure.js.map +1 -0
  25. package/dist/knowledge/reviewPrefetch.d.ts +2 -2
  26. package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
  27. package/dist/knowledge/reviewPrefetch.js +6 -6
  28. package/dist/knowledge/reviewPrefetch.js.map +1 -1
  29. package/package.json +3 -3
  30. package/src/contract/exports.snapshot.json +1 -0
  31. package/src/contract/regression.recheck.test.ts +228 -0
  32. package/src/contract/regression.review.test.ts +1 -143
  33. package/src/contract/types.contract.test.ts +2 -1
  34. package/src/knowledge/backfillNoExtract.ts +2 -2
  35. package/src/knowledge/extractFile.ts +6 -4
  36. package/src/knowledge/extractJob.ts +11 -0
  37. package/src/knowledge/index.ts +1 -1
  38. package/src/knowledge/owedFiles.ts +12 -2
  39. package/src/knowledge/review.ts +10 -10
  40. package/src/knowledge/reviewFailure.ts +51 -0
  41. package/src/knowledge/reviewPrefetch.ts +6 -6
@@ -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. */
@@ -102,9 +109,12 @@ export function owedAfterRun(a: {
102
109
  }
103
110
 
104
111
  /** Records today's version and exactly the files still owed after this run. */
105
- export async function saveExtractorState(manifest: IngestManifest, rootId: string, owed: ReadonlyMap<string, number>): Promise<void> {
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> {
106
115
  await manifest.set(extractorManifestKey(rootId), [
107
116
  { id: VERSION_ID, hash: String(EXTRACTOR_VERSION) },
108
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}` })),
109
119
  ]);
110
120
  }
@@ -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,
@@ -173,6 +174,8 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
173
174
  const finished = new Set<string>();
174
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. */
175
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);
176
179
  const measured = new Map<string, number>();
177
180
  // Read + binary check + extract run ahead with bounded concurrency (extraction only reads `knownKeys`,
178
181
  // fixed above, and the content-hash extract cache); with `args.extractPool` the width is the pool's.
@@ -213,17 +216,12 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
213
216
  if (job.kind === 'read-error') report.readErrors += 1; else report.extractErrors += 1;
214
217
  fail(f.path, 'extract', job.kind === 'read-error' ? `read: ${job.reason}` : job.reason);
215
218
  measured.set(f.path, owedCalls(detail.extractor, f.path)); // learns nothing: keep what it was owed
216
- // A FINAL failure gets a terminal answer, so a replica does not hold the file back and ask for it forever: the manifest's bytes are
217
- // gone (the hash moved), or the extraction failed deterministically (not a timeout, a stop or a changed-since-plan). Never when the
218
- // run was stopped. A transient failure at the manifest's own bytes keeps the re-check request AND makes the file owed, so the next
219
- // normal review retries it. (`[]` rather than a sibling member: the reason is already in `report.failures`.)
220
- const known = detail.prior.get(f.path);
221
- const transient = job.kind === 'read-error' || job.transient === true; // a read error says nothing final about the bytes
222
- if (known && !runSignal.aborted) {
223
- if (known !== f.hash || !transient) { await putNoExtract(store, known); await settledRecheck(known); } else unreadable.add(f.path);
224
- }
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);
225
222
  return true;
226
223
  }
224
+ failures.delete(f.path); // it read and extracted (or was decided): the run of failures at this hash ends
227
225
  // Recorded, so a file found binary on read is not re-read by every later review.
228
226
  if (job.kind === 'binary') {
229
227
  filesNow.set(f.path, f.hash);
@@ -314,6 +312,8 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
314
312
  await Promise.allSettled(queue.map((s) => s.judge?.result)); // nothing outlives the run
315
313
  }
316
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;
317
317
 
318
318
  // Pass 2 (`only`) is judging alone: the map pass already retired the removed files and ran the analyzers.
319
319
  if (!report.aborted && !args.only) {
@@ -373,7 +373,7 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
373
373
  // content-changed or not, and the owed paths the plan did not list that the manifest still holds.
374
374
  await saveExtractorState(manifest, rootId, owedAfterRun({
375
375
  state: detail.extractor, changed, prior: detail.prior, finished, carried: detail.carried, live: filesNow, measured, unreadable,
376
- }));
376
+ }), failures);
377
377
  await write(report.aborted ? scopeRecord : { ...scopeRecord, lastDigest: report.digest, lastReviewedAt: new Date(now()).toISOString() });
378
378
  report.durationMs = now() - started;
379
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,9 +12,9 @@
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
- import { createDeadlines, JobTimeout } from './jobDeadline.js';
17
+ import { createDeadlines } from './jobDeadline.js';
18
18
  import { createModelLimiter } from './modelLimiter.js';
19
19
  import { Lanes, reasonOf, type ReviewStep } from './reviewRunModel.js';
20
20
  import { isBinaryText, type ComposedPacks } from './sources.js';
@@ -58,8 +58,7 @@ export function extractStepOf(path: string, job: Prefetch): ReviewStep {
58
58
  }
59
59
  }
60
60
 
61
- /** The failure reason of a file whose bytes no longer match the planned hash. */
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;
@@ -108,8 +107,9 @@ export function createPrefetch(c: PrefetchContext): (f: { path: string; hash: st
108
107
  return { kind: 'extracted', ...(doc ? { doc } : {}), extraction };
109
108
  } catch (error) {
110
109
  if (error instanceof BinaryContent) return { kind: 'binary' };
111
- // A timeout or a stop says nothing final about the file; any other extraction error is deterministic.
112
- return { kind: 'failed', reason: reasonOf(error), ...(error instanceof JobTimeout || c.signal.aborted ? { transient: true as const } : {}) };
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 }) };
113
113
  }
114
114
  };
115
115