agent-recall-core 3.4.51 → 3.5.2

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 (104) hide show
  1. package/README.md +559 -330
  2. package/dist/embeddings/config.d.ts.map +1 -1
  3. package/dist/embeddings/config.js +17 -4
  4. package/dist/embeddings/config.js.map +1 -1
  5. package/dist/helpers/alignment-patterns.d.ts +46 -0
  6. package/dist/helpers/alignment-patterns.d.ts.map +1 -1
  7. package/dist/helpers/alignment-patterns.js +103 -2
  8. package/dist/helpers/alignment-patterns.js.map +1 -1
  9. package/dist/helpers/journal-files.d.ts +12 -6
  10. package/dist/helpers/journal-files.d.ts.map +1 -1
  11. package/dist/helpers/journal-files.js +13 -7
  12. package/dist/helpers/journal-files.js.map +1 -1
  13. package/dist/index.d.ts +8 -4
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +15 -4
  16. package/dist/index.js.map +1 -1
  17. package/dist/prompts/consolidation-prompt.js +14 -14
  18. package/dist/retrieval/candidates.d.ts +17 -0
  19. package/dist/retrieval/candidates.d.ts.map +1 -1
  20. package/dist/retrieval/candidates.js +4 -2
  21. package/dist/retrieval/candidates.js.map +1 -1
  22. package/dist/retrieval/contradiction.d.ts +42 -0
  23. package/dist/retrieval/contradiction.d.ts.map +1 -1
  24. package/dist/retrieval/contradiction.js +126 -7
  25. package/dist/retrieval/contradiction.js.map +1 -1
  26. package/dist/retrieval/lexical-index.d.ts +150 -0
  27. package/dist/retrieval/lexical-index.d.ts.map +1 -0
  28. package/dist/retrieval/lexical-index.js +514 -0
  29. package/dist/retrieval/lexical-index.js.map +1 -0
  30. package/dist/retrieval/query-memory.d.ts +17 -7
  31. package/dist/retrieval/query-memory.d.ts.map +1 -1
  32. package/dist/retrieval/query-memory.js +274 -68
  33. package/dist/retrieval/query-memory.js.map +1 -1
  34. package/dist/storage/classification.d.ts.map +1 -1
  35. package/dist/storage/classification.js +4 -1
  36. package/dist/storage/classification.js.map +1 -1
  37. package/dist/storage/content-guard.d.ts +26 -0
  38. package/dist/storage/content-guard.d.ts.map +1 -1
  39. package/dist/storage/content-guard.js +450 -48
  40. package/dist/storage/content-guard.js.map +1 -1
  41. package/dist/storage/corrections.d.ts.map +1 -1
  42. package/dist/storage/corrections.js +47 -66
  43. package/dist/storage/corrections.js.map +1 -1
  44. package/dist/storage/cwd-allowlist.d.ts +28 -2
  45. package/dist/storage/cwd-allowlist.d.ts.map +1 -1
  46. package/dist/storage/cwd-allowlist.js +61 -13
  47. package/dist/storage/cwd-allowlist.js.map +1 -1
  48. package/dist/storage/filelock.d.ts +26 -8
  49. package/dist/storage/filelock.d.ts.map +1 -1
  50. package/dist/storage/filelock.js +202 -26
  51. package/dist/storage/filelock.js.map +1 -1
  52. package/dist/storage/fs-utils.d.ts +51 -0
  53. package/dist/storage/fs-utils.d.ts.map +1 -1
  54. package/dist/storage/fs-utils.js +123 -2
  55. package/dist/storage/fs-utils.js.map +1 -1
  56. package/dist/storage/memory-protocol.js +55 -55
  57. package/dist/storage/paths.d.ts.map +1 -1
  58. package/dist/storage/paths.js +7 -2
  59. package/dist/storage/paths.js.map +1 -1
  60. package/dist/storage/project.d.ts.map +1 -1
  61. package/dist/storage/project.js +9 -2
  62. package/dist/storage/project.js.map +1 -1
  63. package/dist/storage/store-manifest.js +57 -57
  64. package/dist/supabase/embedding.d.ts.map +1 -1
  65. package/dist/supabase/embedding.js +7 -0
  66. package/dist/supabase/embedding.js.map +1 -1
  67. package/dist/supabase/sync.d.ts.map +1 -1
  68. package/dist/supabase/sync.js +42 -18
  69. package/dist/supabase/sync.js.map +1 -1
  70. package/dist/tools-logic/bootstrap.d.ts.map +1 -1
  71. package/dist/tools-logic/bootstrap.js +4 -2
  72. package/dist/tools-logic/bootstrap.js.map +1 -1
  73. package/dist/tools-logic/check.d.ts +7 -0
  74. package/dist/tools-logic/check.d.ts.map +1 -1
  75. package/dist/tools-logic/check.js +54 -44
  76. package/dist/tools-logic/check.js.map +1 -1
  77. package/dist/tools-logic/dream-admission.js +29 -29
  78. package/dist/tools-logic/recall-backend.d.ts.map +1 -1
  79. package/dist/tools-logic/recall-backend.js +3 -1
  80. package/dist/tools-logic/recall-backend.js.map +1 -1
  81. package/dist/tools-logic/smart-recall.d.ts +52 -0
  82. package/dist/tools-logic/smart-recall.d.ts.map +1 -1
  83. package/dist/tools-logic/smart-recall.js +202 -31
  84. package/dist/tools-logic/smart-recall.js.map +1 -1
  85. package/dist/tools-logic/smart-remember-vector.d.ts +3 -1
  86. package/dist/tools-logic/smart-remember-vector.d.ts.map +1 -1
  87. package/dist/tools-logic/smart-remember-vector.js +3 -1
  88. package/dist/tools-logic/smart-remember-vector.js.map +1 -1
  89. package/dist/tools-logic/smart-remember.d.ts.map +1 -1
  90. package/dist/tools-logic/smart-remember.js +6 -2
  91. package/dist/tools-logic/smart-remember.js.map +1 -1
  92. package/dist/types.d.ts +17 -2
  93. package/dist/types.d.ts.map +1 -1
  94. package/dist/types.js +31 -3
  95. package/dist/types.js.map +1 -1
  96. package/dist/vector/embedding.d.ts +20 -1
  97. package/dist/vector/embedding.d.ts.map +1 -1
  98. package/dist/vector/embedding.js +27 -1
  99. package/dist/vector/embedding.js.map +1 -1
  100. package/dist/vector/local-vector-backend.d.ts +4 -1
  101. package/dist/vector/local-vector-backend.d.ts.map +1 -1
  102. package/dist/vector/local-vector-backend.js +7 -3
  103. package/dist/vector/local-vector-backend.js.map +1 -1
  104. package/package.json +59 -59
@@ -18,19 +18,52 @@ import { palaceDir, projectsRootDir } from "./paths.js";
18
18
  import { ensureDir } from "./fs-utils.js";
19
19
  /**
20
20
  * Normalize a filesystem path for stable matching:
21
- * - Resolve symlinks (handles macOS /tmp → /private/tmp)
21
+ * - Resolve symlinks/junctions (handles macOS /tmp → /private/tmp)
22
+ * - Resolve win32 8.3 short-name aliases to the canonical long form and
23
+ * canonicalize on-disk component case: fs.realpathSync.native uses the
24
+ * OS final-path lookup, while the JS fs.realpathSync only follows
25
+ * symlinks and passes `RUNNER~1`-style aliases through VERBATIM. That
26
+ * gap broke the CRITICAL-2 directory-identity gate on GitHub's
27
+ * windows-latest runner (CI run 38230438655, 2026-10-12), whose TEMP is
28
+ * C:\Users\RUNNER~1\…: the allowlist stored one spelling of the project
29
+ * root, `git rev-parse --show-toplevel` produced the other, and the
30
+ * strict compare fell through to raw git identity.
31
+ * - Canonicalize separators to forward slashes (Windows realpath returns
32
+ * backslashes; stored allowlist entries and the "+ '/'" prefix checks
33
+ * below assume one canonical separator)
22
34
  * - Strip trailing slash
23
- * Falls back to the input if realpath fails (path doesn't exist yet).
35
+ * Falls back to the JS realpath, then to the input, if resolution fails
36
+ * (path doesn't exist on disk yet).
37
+ *
38
+ * NOTE: output keeps the canonical ON-DISK case — never lowercase it here
39
+ * (stored entries stay human-readable). COMPARISONS must additionally fold
40
+ * case on win32: use `pathCompareKey`.
24
41
  */
25
42
  export function normalizePath(p) {
26
43
  let normalized = p;
27
44
  try {
28
- normalized = fs.realpathSync(p);
45
+ normalized = fs.realpathSync.native(p);
29
46
  }
30
47
  catch {
31
- // path may not exist on disk yet; use the literal string
48
+ try {
49
+ normalized = fs.realpathSync(p);
50
+ }
51
+ catch {
52
+ // path may not exist on disk yet; use the literal string
53
+ }
32
54
  }
33
- return normalized.replace(/\/+$/, "");
55
+ return normalized.replace(/\\/g, "/").replace(/\/+$/, "");
56
+ }
57
+ /**
58
+ * Comparison key for an already-normalizePath'd path: folded to lower case on
59
+ * win32 (NTFS resolves names case-insensitively, so two spellings of the same
60
+ * directory must compare equal — part of the 2026-10-12 CI fix above) and
61
+ * kept exact elsewhere (POSIX filesystems are case-sensitive). Every equality
62
+ * or prefix check against allowlist entries must go through this key, never
63
+ * raw string comparison.
64
+ */
65
+ export function pathCompareKey(p) {
66
+ return process.platform === "win32" ? p.toLowerCase() : p;
34
67
  }
35
68
  function allowlistPath(slug) {
36
69
  return path.join(palaceDir(slug), "cwd-allowlist.json");
@@ -47,7 +80,15 @@ export function readCwdAllowlist(slug) {
47
80
  const parsed = JSON.parse(raw);
48
81
  if (!parsed || !Array.isArray(parsed.paths))
49
82
  return { paths: [] };
50
- return { paths: parsed.paths.filter((s) => typeof s === "string" && s.startsWith("/")) };
83
+ return {
84
+ // Re-normalize at read time: entries written before the realpath.native
85
+ // fix (or on a machine where the dir did not exist yet at write time)
86
+ // may carry an 8.3 short-name or stale-case spelling — healing them
87
+ // here keeps every comparison downstream canonical without a migration.
88
+ paths: parsed.paths
89
+ .filter((s) => typeof s === "string" && path.isAbsolute(s))
90
+ .map((s) => normalizePath(s)),
91
+ };
51
92
  }
52
93
  catch {
53
94
  return { paths: [] };
@@ -58,11 +99,12 @@ export function readCwdAllowlist(slug) {
58
99
  * Normalizes the path (trailing slash removed).
59
100
  */
60
101
  export function addCwdToAllowlist(slug, cwdPath) {
61
- if (!cwdPath || !cwdPath.startsWith("/"))
102
+ if (!cwdPath || !path.isAbsolute(cwdPath))
62
103
  return;
63
104
  const normalized = normalizePath(cwdPath);
64
105
  const current = readCwdAllowlist(slug);
65
- if (current.paths.includes(normalized))
106
+ // Case-folded dedupe (win32): two spellings of one directory are one entry.
107
+ if (current.paths.some((p) => pathCompareKey(p) === pathCompareKey(normalized)))
66
108
  return;
67
109
  const next = { paths: [...current.paths, normalized].sort() };
68
110
  const dir = palaceDir(slug);
@@ -84,9 +126,10 @@ export function addCwdToAllowlist(slug, cwdPath) {
84
126
  * storage/project.ts, for how the `exact` flag is used).
85
127
  */
86
128
  function matchCwd(cwd) {
87
- if (!cwd || !cwd.startsWith("/"))
129
+ if (!cwd || !path.isAbsolute(cwd))
88
130
  return null;
89
131
  const normalized = normalizePath(cwd);
132
+ const cwdKey = pathCompareKey(normalized);
90
133
  const projectsDir = projectsRootDir();
91
134
  if (!fs.existsSync(projectsDir))
92
135
  return null;
@@ -94,10 +137,11 @@ function matchCwd(cwd) {
94
137
  for (const entry of fs.readdirSync(projectsDir)) {
95
138
  if (entry.startsWith("_archived_") || entry.startsWith("."))
96
139
  continue;
97
- const list = readCwdAllowlist(entry);
140
+ const list = readCwdAllowlist(entry); // entries arrive re-normalized (realpath'd)
98
141
  for (const p of list.paths) {
99
- // Exact match OR cwd lives strictly under p
100
- if (normalized === p || normalized.startsWith(p + "/")) {
142
+ // Exact match OR cwd lives strictly under p — case-folded on win32.
143
+ const pKey = pathCompareKey(p);
144
+ if (cwdKey === pKey || cwdKey.startsWith(pKey + "/")) {
101
145
  if (!bestMatch || p.length > bestMatch.matchedPath.length) {
102
146
  bestMatch = { slug: entry, matchedPath: p };
103
147
  }
@@ -106,7 +150,11 @@ function matchCwd(cwd) {
106
150
  }
107
151
  if (!bestMatch)
108
152
  return null;
109
- return { slug: bestMatch.slug, exact: bestMatch.matchedPath === normalized, matchedPath: bestMatch.matchedPath };
153
+ return {
154
+ slug: bestMatch.slug,
155
+ exact: pathCompareKey(bestMatch.matchedPath) === cwdKey,
156
+ matchedPath: bestMatch.matchedPath,
157
+ };
110
158
  }
111
159
  /**
112
160
  * Scan every project's allowlist; return the slug whose allowlist contains a
@@ -1 +1 @@
1
- {"version":3,"file":"cwd-allowlist.js","sourceRoot":"","sources":["../../src/storage/cwd-allowlist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAM1C;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,CAAS;IACrC,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,CAAC;QACH,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,yDAAyD;IAC3D,CAAC;IACD,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAA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,IAAI,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;oBAC1D,SAAS,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;gBAC9C,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,KAAK,EAAE,cAAc,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,MAAM;QACvD,WAAW,EAAE,SAAS,CAAC,WAAW;KACnC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,IAAI,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,6BAA6B,CAAC,GAAW;IACvD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC"}
@@ -88,18 +88,36 @@ export declare class LockContentionError extends Error {
88
88
  readonly heldForMs: number | null;
89
89
  constructor(lockName: string, holderPid: number | null, heldForMs: number | null);
90
90
  }
91
- /**
92
- * Acquire a named lock. Retries with async (event-loop-friendly) backoff
93
- * until LOCK_TIMEOUT_MS; reclaims dead-holder / legacy-stale locks; throws
94
- * LockContentionError if the holder is alive at timeout.
95
- * Returns a release function (idempotent).
96
- */
97
- export declare function acquireLock(name: string): Promise<() => void>;
91
+ export interface AcquireLockOptions {
92
+ /**
93
+ * Wait as long as the holder PID probes ALIVE (and from this boot) instead
94
+ * of applying the 5s no-progress ("wedged holder") deadline. Dead holders
95
+ * are still reclaimed promptly; the maxTotalWaitMs hard cap still applies.
96
+ *
97
+ * CI windows-latest regression (2026-10-12): on a starved 2-vCPU runner a
98
+ * perfectly healthy holder can sit DESCHEDULED past the no-progress
99
+ * deadline, so recordOutcome's materialized-counter pass skipped 190/480
100
+ * updates. For callers whose critical section only rewrites state that is
101
+ * re-derivable from an authoritative source (the _outcomes.jsonl ledger),
102
+ * losing the pass to a starvation misdiagnosis is strictly worse than
103
+ * waiting out a live holder — opt in here. Hot paths that must stay
104
+ * responsive to a genuinely wedged (alive-but-stuck) holder keep the
105
+ * default.
106
+ */
107
+ waitForLiveHolder?: boolean;
108
+ /**
109
+ * Hard cap on the total wait (default MAX_TOTAL_WAIT_MS = 60s). Exists for
110
+ * tests and callers that need a tighter liveness bound; the default is the
111
+ * documented absolute worst case.
112
+ */
113
+ maxTotalWaitMs?: number;
114
+ }
115
+ export declare function acquireLock(name: string, opts?: AcquireLockOptions): Promise<() => void>;
98
116
  /**
99
117
  * Execute a function while holding a lock.
100
118
  * Lock is always released, even on error. Prefer a synchronous fn (bounded
101
119
  * hold); an async fn is allowed only for the documented awareness nesting —
102
120
  * see the header's lock-ordering section.
103
121
  */
104
- export declare function withLock<T>(name: string, fn: () => T | Promise<T>): Promise<T>;
122
+ export declare function withLock<T>(name: string, fn: () => T | Promise<T>, opts?: AcquireLockOptions): Promise<T>;
105
123
  //# sourceMappingURL=filelock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filelock.d.ts","sourceRoot":"","sources":["../../src/storage/filelock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AASH;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,QAAQ,CAAC;AAgBnC;;;;kCAIkC;AAClC,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEtB,QAAQ,EAAE,MAAM,EAAE,SAAS,EA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EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,GAAE,kBAAuB,GAAG,OAAO,CAAC,CAAC,CAAC,CAOnH"}
@@ -72,7 +72,7 @@ import * as fs from "node:fs";
72
72
  import * as os from "node:os";
73
73
  import * as path from "node:path";
74
74
  import { getRoot } from "../types.js";
75
- import { ensureDir } from "./fs-utils.js";
75
+ import { ensureDir, lockDebug } from "./fs-utils.js";
76
76
  const LOCK_TIMEOUT_MS = 5000;
77
77
  /**
78
78
  * A lock dir with NO readable owner.json (legacy pre-pid code, or a crash in
@@ -141,18 +141,25 @@ function readOwner(dir) {
141
141
  return null;
142
142
  }
143
143
  }
144
- /** Signal-0 liveness probe. EPERM means "alive but not ours" — still alive. */
145
- function isPidAlive(pid) {
144
+ /** Signal-0 liveness probe. EPERM means "alive but not ours" — still alive
145
+ * (fail closed: only a definitive ESRCH-class "no such process" reads as
146
+ * dead). Returns the errno so the A14 debug channel can report WHY a reclaim
147
+ * decision was made. */
148
+ function probePid(pid) {
146
149
  if (!Number.isInteger(pid) || pid <= 0)
147
- return false;
150
+ return { alive: false, errno: "bad-pid" };
148
151
  try {
149
152
  process.kill(pid, 0);
150
- return true;
153
+ return { alive: true };
151
154
  }
152
155
  catch (err) {
153
- return err.code === "EPERM";
156
+ const code = err.code;
157
+ return { alive: code === "EPERM", errno: code };
154
158
  }
155
159
  }
160
+ function isPidAlive(pid) {
161
+ return probePid(pid).alive;
162
+ }
156
163
  /**
157
164
  * Review MEDIUM-1 (2026-09-11): pid liveness alone cannot distinguish the
158
165
  * original holder from an UNRELATED process that recycled the pid after a
@@ -182,8 +189,21 @@ function tryReclaim(dir) {
182
189
  // Live holder from THIS boot — NEVER steal. A pre-boot acquired_at means
183
190
  // the "live" pid is a post-reboot recycle, not the holder (see
184
191
  // predatesBoot's doc comment).
185
- if (isPidAlive(owner.pid) && !predatesBoot(owner.acquired_at))
192
+ const probe = probePid(owner.pid);
193
+ const preBoot = predatesBoot(owner.acquired_at);
194
+ // released:true = the holder COMPLETED its critical section but could not
195
+ // remove the dir (see LockOwner.released) — reclaimable regardless of
196
+ // pid liveness; there is no mid-write to protect.
197
+ if (!owner.released && probe.alive && !preBoot)
186
198
  return false;
199
+ lockDebug("reclaim", {
200
+ lock: path.basename(dir),
201
+ reason: owner.released ? "released-tombstone" : probe.alive ? "pre-boot-pid" : "dead-pid",
202
+ owner_pid: owner.pid,
203
+ probe_alive: probe.alive,
204
+ probe_errno: probe.errno,
205
+ acquired_at: owner.acquired_at,
206
+ });
187
207
  }
188
208
  else {
189
209
  // No owner record: legacy lock or crash inside the mkdir→owner-write
@@ -197,6 +217,11 @@ function tryReclaim(dir) {
197
217
  }
198
218
  if (Date.now() - stat.mtimeMs <= STALE_LOCK_MS)
199
219
  return false;
220
+ lockDebug("reclaim", {
221
+ lock: path.basename(dir),
222
+ reason: "legacy-stale",
223
+ age_ms: Math.round(Date.now() - stat.mtimeMs),
224
+ });
200
225
  }
201
226
  const trash = `${dir}.reclaim-${process.pid}-${Date.now()}`;
202
227
  try {
@@ -247,8 +272,21 @@ function tryReclaim(dir) {
247
272
  * Only EEXIST means "contended"; ENOENT (store root vanished) is repaired and
248
273
  * retried; any OTHER error (EACCES/EROFS/EMFILE, …) is rethrown immediately —
249
274
  * spinning 5 s on a read-only store and then reporting "held by a live
250
- * process" would misdiagnose an environment problem as contention. */
251
- function tryAcquire(dir) {
275
+ * process" would misdiagnose an environment problem as contention.
276
+ *
277
+ * win32 EXCEPTION (A10, 2026-10-11): on Windows, mkdir of a name whose
278
+ * previous incarnation is DELETE-PENDING (another process's release/reclaim
279
+ * rmSync has started but the handle isn't fully closed) fails with EPERM,
280
+ * not EEXIST — a transient contention artefact of NTFS delete semantics,
281
+ * observed crashing audit-outcome-concurrency workers once the
282
+ * progress-aware deadline increased acquire/release churn. On win32 ONLY,
283
+ * EPERM is therefore treated as "contended" (retry), recorded in the
284
+ * optional `diag` out-param; acquireLock rethrows the ORIGINAL EPERM at
285
+ * timeout when no owner record was ever observed during the whole wait
286
+ * (a genuinely permission-denied store, not contention — A10 review FIX 1),
287
+ * so the error type stays truthful on both platforms. POSIX behavior is
288
+ * unchanged (strict immediate rethrow). */
289
+ function tryAcquire(dir, diag) {
252
290
  try {
253
291
  fs.mkdirSync(dir, { recursive: false });
254
292
  }
@@ -272,14 +310,31 @@ function tryAcquire(dir) {
272
310
  else if (code === "EEXIST") {
273
311
  return null;
274
312
  }
313
+ else if (code === "EPERM" && process.platform === "win32") {
314
+ // Delete-pending collision — see doc comment above. Record the error
315
+ // so acquireLock can tell a genuine permission failure (EPERM retried
316
+ // for the whole wait with NO owner ever observed) from real contention
317
+ // and rethrow the original at timeout (A10 review FIX 1).
318
+ if (diag)
319
+ diag.eperm = err;
320
+ return null;
321
+ }
275
322
  else {
276
323
  throw err;
277
324
  }
278
325
  }
326
+ // Kept for the release closure's tombstone TOCTOU check (A14 review FIX 3):
327
+ // the tombstone may only be written over EXACTLY this record.
328
+ let myOwner = { pid: process.pid, acquired_at: new Date().toISOString() };
279
329
  try {
280
- fs.writeFileSync(ownerPath(dir), JSON.stringify({ pid: process.pid, acquired_at: new Date().toISOString() }), "utf-8");
330
+ fs.writeFileSync(ownerPath(dir), JSON.stringify(myOwner), "utf-8");
281
331
  }
282
- catch {
332
+ catch (err) {
333
+ myOwner = null; // identity unverifiable — the release closure never tombstones
334
+ lockDebug("owner-write-failed", {
335
+ lock: path.basename(dir),
336
+ errno: err.code,
337
+ });
283
338
  // Owner record is advisory: without it the lock degrades to the legacy
284
339
  // mtime staleness rule instead of pid-liveness. NOTE (review LOW-2): in
285
340
  // this degraded mode a LIVE holder that keeps the lock past STALE_LOCK_MS
@@ -298,10 +353,55 @@ function tryAcquire(dir) {
298
353
  if (owner && owner.pid !== process.pid)
299
354
  return;
300
355
  try {
301
- fs.rmSync(dir, { recursive: true, force: true });
356
+ // maxRetries is best-effort belt-and-braces (bounded, ~10*20ms linear
357
+ // backoff); in the observed failure shapes (dir pinned by a CWD or an
358
+ // AV scan) the retries do NOT ride out the pin — the tombstone below is
359
+ // the mechanism that actually heals the lock (A14 review).
360
+ fs.rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
302
361
  }
303
- catch {
304
- /* already released */
362
+ catch (err) {
363
+ const errno = err.code;
364
+ // A14 root cause (CI run 38255969731): swallowing this left a stale
365
+ // lock dir that waiters misdiagnosed for 5-60s each, and check()'s
366
+ // contention-skip dropped 28/40 alignment records. Tombstone the owner
367
+ // record (released: true) so the very next reclaim attempt may take the
368
+ // lock the moment the external pin lifts — and say it loudly; a silent
369
+ // release failure costs every other process real time.
370
+ let tombstoned = false;
371
+ if (fs.existsSync(dir)) {
372
+ // TOCTOU re-read (A14 review FIX 3, mirrors tryReclaim's rename-aside
373
+ // verify): between this closure's entry read and here, the wreckage
374
+ // may have been reclaimed and RE-ACQUIRED — by this very pid, too
375
+ // (another async task in this process), which the entry pid-guard
376
+ // cannot distinguish. Tombstone only when owner.json still holds
377
+ // EXACTLY the record this acquire wrote (pid + acquired_at); marking
378
+ // anyone else's live hold released would steal their lock. The
379
+ // ownerless shape (our rmSync removed owner.json before failing on
380
+ // the dir) is also left alone — indistinguishable from a fresh
381
+ // holder's mkdir→owner-write window; it falls back to the
382
+ // STALE_LOCK_MS mtime rule, and the DATA is safe either way (the
383
+ // append fallback in check()/processFeedback).
384
+ const current = readOwner(dir);
385
+ const stillOurs = myOwner !== null && current !== null &&
386
+ current.pid === myOwner.pid && current.acquired_at === myOwner.acquired_at;
387
+ if (stillOurs) {
388
+ try {
389
+ fs.writeFileSync(ownerPath(dir), JSON.stringify({ ...myOwner, released: true }), "utf-8");
390
+ tombstoned = true;
391
+ }
392
+ catch {
393
+ /* tombstone write blocked too — mtime staleness remains the backstop */
394
+ }
395
+ }
396
+ console.error(`[agent-recall] filelock: release of "${path.basename(dir)}" could not remove the lock dir ` +
397
+ `(${errno}) — ${tombstoned ? "tombstoned for immediate reclaim" : `not tombstoned (record no longer ours, or write blocked); reclaim falls back to the ${STALE_LOCK_MS}ms staleness rule`}.`);
398
+ }
399
+ lockDebug("release-failed", {
400
+ lock: path.basename(dir),
401
+ errno,
402
+ dir_still_exists: fs.existsSync(dir),
403
+ tombstoned,
404
+ });
305
405
  }
306
406
  };
307
407
  }
@@ -314,30 +414,106 @@ function sleep(ms) {
314
414
  return new Promise((resolve) => setTimeout(resolve, ms));
315
415
  }
316
416
  /**
317
- * Acquire a named lock. Retries with async (event-loop-friendly) backoff
318
- * until LOCK_TIMEOUT_MS; reclaims dead-holder / legacy-stale locks; throws
319
- * LockContentionError if the holder is alive at timeout.
417
+ * Acquire a named lock. Retries with async (event-loop-friendly) backoff;
418
+ * reclaims dead-holder / legacy-stale locks; throws LockContentionError only
419
+ * when the lock makes NO PROGRESS for LOCK_TIMEOUT_MS (same holder the whole
420
+ * time — a wedged process), or after MAX_TOTAL_WAIT_MS outright.
421
+ *
422
+ * PROGRESS-AWARE DEADLINE (A10 Linux-CI fix, 2026-10-11): the old fixed
423
+ * `now + 5s` deadline measured TOTAL wait, so under heavy-but-healthy
424
+ * contention (N processes serializing short critical sections through one
425
+ * lock — the audit-outcome-concurrency stress shape) a waiter near the back
426
+ * of the herd timed out even though the lock was changing hands every few
427
+ * milliseconds. Callers like recordOutcome treat LockContentionError as
428
+ * "skip the materialized-counter update" (by design: ledger stays lossless),
429
+ * so every such spurious timeout became a silently lost counter increment
430
+ * (reproduced: 480-event stress runs materialized 461-476). The timeout's
431
+ * actual job is detecting a WEDGED holder, so the deadline now resets every
432
+ * time the observed owner (pid + acquired_at) changes: a live, churning lock
433
+ * is waited on; a holder that sits on the lock for LOCK_TIMEOUT_MS without
434
+ * releasing still times out exactly as before (the "never steal from a live
435
+ * holder" filelock test is unchanged). MAX_TOTAL_WAIT_MS bounds the absolute
436
+ * worst case so a hot path can never hang indefinitely behind a pathological
437
+ * ping-pong.
320
438
  * Returns a release function (idempotent).
321
439
  */
322
- export async function acquireLock(name) {
440
+ const MAX_TOTAL_WAIT_MS = 60_000;
441
+ export async function acquireLock(name, opts = {}) {
323
442
  const dir = lockDir(name);
324
- const deadline = Date.now() + LOCK_TIMEOUT_MS;
443
+ const startedAt = Date.now();
444
+ let deadline = startedAt + LOCK_TIMEOUT_MS;
445
+ const hardDeadline = startedAt + (opts.maxTotalWaitMs ?? MAX_TOTAL_WAIT_MS);
446
+ let lastOwnerKey = null;
447
+ let polls = 0;
448
+ let reclaimed = false;
325
449
  // Ensure root dir exists before attempting lock
326
450
  ensureDir(path.dirname(dir));
327
451
  let delay = 5;
452
+ const diag = {};
328
453
  for (;;) {
329
- const release = tryAcquire(dir);
330
- if (release)
454
+ const release = tryAcquire(dir, diag);
455
+ if (release) {
456
+ lockDebug("acquired", {
457
+ lock: name,
458
+ path: polls === 0 ? "immediate" : reclaimed ? "reclaimed" : "waited",
459
+ wait_ms: Date.now() - startedAt,
460
+ polls,
461
+ last_holder: lastOwnerKey,
462
+ });
331
463
  return release;
332
- // Deadline is checked BEFORE the reclaim-retry shortcut so the loop is
464
+ }
465
+ polls += 1;
466
+ // Progress detection: a change of owner (pid or acquired_at) since the
467
+ // last look means the lock is live — reset the no-progress deadline.
468
+ // An unreadable owner.json (legacy/crash lock) never counts as progress,
469
+ // so that branch keeps the original fixed-timeout behavior.
470
+ const owner = readOwner(dir);
471
+ const ownerKey = owner ? `${owner.pid}:${owner.acquired_at}` : null;
472
+ if (ownerKey !== null && ownerKey !== lastOwnerKey) {
473
+ if (lastOwnerKey !== null)
474
+ deadline = Date.now() + LOCK_TIMEOUT_MS;
475
+ lastOwnerKey = ownerKey;
476
+ }
477
+ // waitForLiveHolder mode: a holder that probes alive (and is from this
478
+ // boot — predatesBoot pids are recycles, handled by tryReclaim below) is
479
+ // WAITED ON, not misdiagnosed as wedged; keep pushing the no-progress
480
+ // deadline while it lives. The hardDeadline check below still bounds the
481
+ // absolute worst case, and an unreadable owner record (legacy/crash lock)
482
+ // deliberately gets NO reset — same as the progress detector above.
483
+ if (opts.waitForLiveHolder && owner && !owner.released &&
484
+ isPidAlive(owner.pid) && !predatesBoot(owner.acquired_at)) {
485
+ deadline = Date.now() + LOCK_TIMEOUT_MS;
486
+ }
487
+ // Deadlines are checked BEFORE the reclaim-retry shortcut so the loop is
333
488
  // always bounded — a pathological reclaim-always-true state (e.g. the
334
489
  // store root being deleted out from under us) can never spin forever.
335
- if (Date.now() >= deadline) {
490
+ if (Date.now() >= deadline || Date.now() >= hardDeadline) {
491
+ // A wait that expires having NEVER seen an owner record, with EPERM
492
+ // being retried as "delete-pending contention", was not contended at
493
+ // all — it is a genuine win32 permission problem (read-only store,
494
+ // ACL deny). Surface the original error instead of a fabricated
495
+ // contention claim. (A truly churning lock writes owner.json on every
496
+ // handoff, so some poll in the 5 s window reads one; delete-pending
497
+ // transients last milliseconds, never 5 s.) A10 review FIX 1.
498
+ lockDebug("contention", {
499
+ lock: name,
500
+ waited_ms: Date.now() - startedAt,
501
+ polls,
502
+ hard_cap_hit: Date.now() >= hardDeadline,
503
+ last_holder: lastOwnerKey,
504
+ owner_now: owner ? `${owner.pid}:${owner.acquired_at}` : null,
505
+ eperm_seen: Boolean(diag.eperm),
506
+ wait_for_live_holder: Boolean(opts.waitForLiveHolder),
507
+ });
508
+ if (lastOwnerKey === null && diag.eperm)
509
+ throw diag.eperm;
336
510
  throw contentionError(name, dir);
337
511
  }
338
512
  // Held. Dead holder (or legacy-stale dir) → reclaim and retry at once.
339
- if (tryReclaim(dir))
513
+ if (tryReclaim(dir)) {
514
+ reclaimed = true;
340
515
  continue;
516
+ }
341
517
  await sleep(Math.min(delay, Math.max(1, deadline - Date.now())));
342
518
  delay = Math.min(delay * 2, MAX_BACKOFF_MS);
343
519
  }
@@ -348,8 +524,8 @@ export async function acquireLock(name) {
348
524
  * hold); an async fn is allowed only for the documented awareness nesting —
349
525
  * see the header's lock-ordering section.
350
526
  */
351
- export async function withLock(name, fn) {
352
- const release = await acquireLock(name);
527
+ export async function withLock(name, fn, opts = {}) {
528
+ const release = await acquireLock(name, opts);
353
529
  try {
354
530
  return await fn();
355
531
  }
@@ -1 +1 @@
1
- {"version":3,"file":"filelock.js","sourceRoot":"","sources":["../../src/storage/filelock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AACnC,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC;;;;;GAKG;AACH,MAAM,aAAa,GAAG,OAAO,CAAC;AAO9B;;;;kCAIkC;AAClC,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,QAAQ,CAAS;IACjB,SAAS,CAAgB;IACzB,SAAS,CAAgB;IAElC,YAAY,QAAgB,EAAE,SAAwB,EAAE,SAAwB;QAC9E,MAAM,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC;QACpF,sEAAsE;QACtE,yEAAyE;QACzE,mEAAmE;QACnE,cAAc;QACd,MAAM,KAAK,GAAG,SAAS,KAAK,IAAI;YAC9B,CAAC,CAAC,kCAAkC,SAAS,cAAc,IAAI,GAAG;YAClE,CAAC,CAAC,gFAAgF,IAAI,GAAG,CAAC;QAC5F,KAAK,CACH,SAAS,QAAQ,KAAK,KAAK,eAAe;YAC1C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(class-not-instance).
15
15
  */
16
16
  export declare function safeIsoDateOrToday(date: string | undefined | null): string;
17
+ /** True when the file's content starts with a JSON array bracket — the
18
+ * legacy whole-array format of the append-only NDJSON stores (A14:
19
+ * alignment-log.json, feedback-log.json). Reads 16 bytes, not the file. */
20
+ export declare function isLegacyJsonArrayFile(p: string): boolean;
17
21
  export declare function readJsonSafe<T>(filePath: string): T | null;
22
+ /**
23
+ * A14 diagnostics channel (2026-10-12, CI run 38255969731): one NDJSON line
24
+ * per event on stderr, prefix "ARLOCKDBG", gated on AGENT_RECALL_LOCK_DEBUG=1.
25
+ * Shared by filelock.ts (acquire path / reclaim decision / contention /
26
+ * release failure) and renameAtomic (retry storms) so a failing concurrency
27
+ * run on an unreachable CI runner tells us WHICH mechanism lost the records
28
+ * instead of only how many. Read lazily (not at module load) so tests that
29
+ * set the env after import still get the stream. Never throws.
30
+ */
31
+ export declare function lockDebug(ev: string, fields: Record<string, unknown>): void;
32
+ /**
33
+ * Total win32 transient-rename retry budget. 5s, not the original ~1s (A13,
34
+ * CI run 38251553161): on a loaded 2-vCPU GitHub runner, a holder that
35
+ * intended a ~400ms window kept the destination open past the entire ~1s
36
+ * backoff (the rename-retry test's own PowerShell reader — its close drifted
37
+ * >600ms under scheduler pressure; even idle on a fast desktop the drift
38
+ * measures ~80ms). Real-world holders are no gentler: antivirus/indexer
39
+ * scans commonly pin a just-written file for 100ms–2s. The 5s worst case is
40
+ * only ever PAID when the rename is genuinely blocked the whole time —
41
+ * uncontended renames (the overwhelmingly common case) succeed on the first
42
+ * attempt and never sleep — and after the budget the original error still
43
+ * surfaces (exported so the regression test derives its assertions from the
44
+ * real value instead of a copy that can drift).
45
+ */
46
+ export declare const RENAME_RETRY_BUDGET_MS = 5000;
47
+ /**
48
+ * renameSync with a BOUNDED win32-only retry for transient sharing-violation
49
+ * errors (CI/parallel-suite flake, 2026-10-12): every atomic write here is
50
+ * tmp-write + rename, and readers of these files are deliberately LOCK-FREE
51
+ * (readAlignmentLog in session_start, readCorrections on hot paths, check()'s
52
+ * similar-past-deltas scan). On NTFS, renaming OVER a destination that any
53
+ * process holds open without FILE_SHARE_DELETE — a concurrent lock-free
54
+ * reader, an antivirus/indexer scan — fails with EPERM/EACCES/EBUSY for the
55
+ * few ms the handle lives. That is a TRANSIENT, not a permission problem
56
+ * (same NTFS semantics as filelock.ts's A10 delete-pending EPERM note), and
57
+ * it intermittently failed alignment-log-concurrency under full-suite load:
58
+ * EPERM: operation not permitted, rename '…alignment-log.json.tmp.N' →
59
+ * '…alignment-log.json'
60
+ * Exponential backoff 10→250ms (capped), 5s total (see
61
+ * RENAME_RETRY_BUDGET_MS for why ~1s lost to a slow CI runner), then rethrow
62
+ * — anything outlasting the budget is a real environment problem the caller
63
+ * must see. The budget counts REQUESTED sleep, not wall clock, so a
64
+ * descheduled process still waits at least the full budget. POSIX renames
65
+ * over open files simply succeed, so the retry path is unreachable there
66
+ * (hence "atomic on POSIX" never needed this).
67
+ */
68
+ export declare function renameAtomic(oldPath: string, newPath: string): void;
18
69
  export declare function writeJsonAtomic(filePath: string, data: unknown): void;
19
70
  /**
20
71
  * Atomic PRE-SERIALIZED text write (tmp + rename) — for callers that must
@@ -1 +1 @@
1
- {"version":3,"file":"fs-utils.d.ts","sourceRoot":"","sources":["../../src/storage/fs-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI3C;AAED,wBAAgB,QAAQ,IAAI,MAAM,CAEjC;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAE1E;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAO1D;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAKrE;AAED;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