my-durable 0.0.65 → 0.0.67

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.
@@ -25,6 +25,11 @@ export interface GcIo {
25
25
  readFile: (path: string) => string;
26
26
  homedir: () => string;
27
27
  now: () => number;
28
+ /** R13 P3-1: the pending-sweep marker's writer — optional so test fakes can
29
+ * omit it (a missing writer just means the retry hint degrades to the
30
+ * message, never a crash). */
31
+ writeFile?: (path: string, data: string) => void;
32
+ remove?: (path: string) => void;
28
33
  }
29
34
 
30
35
  export const defaultGcIo = (): GcIo => ({
@@ -39,10 +44,13 @@ export const defaultGcIo = (): GcIo => ({
39
44
  const HELP = `dpi gc — retention for archived sessions
40
45
 
41
46
  dpi gc --closed-before 30d [--dry-run | --yes] [--home <dir>] [--data-dir <dir>]
47
+ dpi gc --sweep [--home <dir>] [--data-dir <dir>]
42
48
 
43
49
  --closed-before D age cutoff: 90m, 12h, 30d, 2w
44
50
  --dry-run show what would be deleted (the default)
45
51
  --yes actually delete it
52
+ --sweep retry a pending dangling-ref sweep (after a delete whose
53
+ sweep failed — deletes nothing by itself)
46
54
  --home <dir> device home (default: $DPI_HOME, else ~/.dpi)
47
55
  --data-dir <dir> device data dir (default: <home>/backend)
48
56
 
@@ -88,7 +96,7 @@ export async function gcCli(args: GcArgs, io: GcIo = defaultGcIo()): Promise<num
88
96
  io.print(HELP);
89
97
  return 0;
90
98
  }
91
- const known = new Set(["--closed-before", "--dry-run", "--yes", "--home", "--data-dir"]);
99
+ const known = new Set(["--closed-before", "--dry-run", "--yes", "--sweep", "--home", "--data-dir"]);
92
100
  for (const arg of argv) {
93
101
  if (arg.startsWith("-") && !known.has(arg)) {
94
102
  io.printErr(`dpi gc: unknown flag '${arg}'\n\n${HELP}`);
@@ -96,6 +104,34 @@ export async function gcCli(args: GcArgs, io: GcIo = defaultGcIo()): Promise<num
96
104
  }
97
105
  }
98
106
  const at = argv.indexOf("--closed-before");
107
+ // R13 P3-1: `--sweep` is a standalone retry of a pending ref sweep — it
108
+ // needs no cutoff (it deletes nothing; it only clears refs left behind by
109
+ // an earlier delete-ok/sweep-fail pass).
110
+ if (argv.includes("--sweep")) {
111
+ let dataDir0: string;
112
+ try {
113
+ dataDir0 = resolveDataDir(argv, io);
114
+ } catch (e) {
115
+ io.printErr(`dpi gc: ${e instanceof Error ? e.message : String(e)}`);
116
+ return 1;
117
+ }
118
+ const pending0 = readPendingIds(io, pendingSweepPath(dataDir0));
119
+ if (!pending0.length) {
120
+ io.print("no pending ref sweep.");
121
+ return 0;
122
+ }
123
+ try {
124
+ await sweepRefs(dataDir0, pending0, io, deviceToken(io));
125
+ io.remove?.(pendingSweepPath(dataDir0));
126
+ io.print(`swept ${pending0.length} pending ref id(s); marker cleared.`);
127
+ return 0;
128
+ } catch (e) {
129
+ io.printErr(
130
+ `dpi gc: pending sweep failed: ${e instanceof Error ? e.message : String(e)} (marker kept — retry with --sweep)`,
131
+ );
132
+ return 1;
133
+ }
134
+ }
99
135
  if (at < 0 || !argv[at + 1]) {
100
136
  io.printErr(`dpi gc: --closed-before DURATION is required (e.g. 30d)\n\n${HELP}`);
101
137
  return 2;
@@ -118,6 +154,9 @@ export async function gcCli(args: GcArgs, io: GcIo = defaultGcIo()): Promise<num
118
154
  return 1;
119
155
  }
120
156
  const options = { closedBeforeDays: days, now: io.now() };
157
+ const dataDir = dataDirOf(archiveDir);
158
+ const pendingFile = pendingSweepPath(dataDir);
159
+ const pending = readPendingIds(io, pendingFile);
121
160
 
122
161
  // The plan/apply calls live inside the pretty-error path (R5 finding 6): a bad
123
162
  // cutoff or unreadable archive used to escape as a raw stack trace.
@@ -141,25 +180,40 @@ export async function gcCli(args: GcArgs, io: GcIo = defaultGcIo()): Promise<num
141
180
  `sweep would clear ${plan.danglingRefs.schedules} schedule ref(s) and ${plan.danglingRefs.graphRuns} graph-run ref(s) pointing at the deletions.`,
142
181
  );
143
182
  }
183
+ if (pending.length > 0)
184
+ io.print(
185
+ `${pending.length} pending ref id(s) from an earlier failed sweep — re-run with --yes (or --sweep) to retry.`,
186
+ );
144
187
  return 0;
145
188
  }
146
189
 
147
190
  const { removed, bytes } = await gcApply(archiveDir, options);
148
191
  io.print(`deleted ${removed.length} archived session(s), ${humanBytes(bytes)} freed.`);
149
192
 
150
- // R10 Design B: sweep refs pointing at what we just removed. Daemon-first
151
- // (registry mutations happen in-process, no file race); offline falls back
152
- // to the same advisory lock Store.open takes.
153
- const ids = removedSessionIds(removed);
193
+ // R10 Design B: sweep refs pointing at what we just removed — MERGED with
194
+ // any ids a previous failed sweep left behind (R13 P3-1: the retry used to
195
+ // be a dead end — a re-run with nothing to delete never swept again, so
196
+ // refs stayed dangling forever while the operator read success).
197
+ // Daemon-first (registry mutations happen in-process, no file race);
198
+ // offline falls back to the same advisory lock Store.open takes.
199
+ const ids = [...new Set([...pending, ...removedSessionIds(removed)])];
154
200
  if (ids.length > 0) {
155
201
  try {
156
- await sweepRefs(dataDirOf(archiveDir), ids, io, deviceToken(io));
202
+ await sweepRefs(dataDir, ids, io, deviceToken(io));
203
+ if (pending.length > 0) {
204
+ io.remove?.(pendingFile);
205
+ io.print(`(included ${pending.length} pending ref id(s) from an earlier failed sweep — marker cleared.)`);
206
+ }
157
207
  } catch (e) {
208
+ writePendingIds(io, pendingFile, ids);
158
209
  io.printErr(
159
210
  `dpi gc: deleted ${ids.length} session(s) but the ref sweep failed: ${
160
211
  e instanceof Error ? e.message : String(e)
161
- } (re-run later — the sweep is idempotent)`,
212
+ } (ids kept for retry: dpi gc --sweep — the sweep is idempotent)`,
162
213
  );
214
+ // R12 P2-3: cron/scripts gate on the exit code — a failed sweep after
215
+ // a real delete must not read as success.
216
+ return 1;
163
217
  }
164
218
  }
165
219
  return 0;
@@ -171,6 +225,30 @@ export async function gcCli(args: GcArgs, io: GcIo = defaultGcIo()): Promise<num
171
225
 
172
226
  const dataDirOf = (archiveDir: string) => archiveDir.slice(0, archiveDir.length - "/archive".length);
173
227
 
228
+ /** R13 P3-1: the pending-sweep marker — ids a delete-ok/sweep-fail pass left
229
+ * behind. Session UUIDs only (not secret); written best-effort, read
230
+ * tolerantly, cleared on the first successful sweep. */
231
+ const pendingSweepPath = (dataDir: string) => join(dataDir, "gc-pending-sweep.json");
232
+
233
+ const readPendingIds = (io: GcIo, path: string): string[] => {
234
+ try {
235
+ const doc = JSON.parse(io.readFile(path)) as { ids?: unknown };
236
+ return Array.isArray(doc.ids)
237
+ ? [...new Set(doc.ids.filter((id): id is string => typeof id === "string" && id.length > 0))]
238
+ : [];
239
+ } catch {
240
+ return []; // absent/corrupt — nothing pending
241
+ }
242
+ };
243
+
244
+ const writePendingIds = (io: GcIo, path: string, ids: string[]): void => {
245
+ try {
246
+ io.writeFile?.(path, `${JSON.stringify({ ids }, null, 2)}\n`);
247
+ } catch {
248
+ /* best-effort — the printed remedy still names --sweep */
249
+ }
250
+ };
251
+
174
252
  /** The device token, from the process env or the env file (DPI_ENV_FILE) —
175
253
  * only needed for the daemon-first sweep route. */
176
254
  function deviceToken(io: GcIo): string | undefined {
@@ -204,8 +282,16 @@ async function sweepRefs(dataDir: string, ids: string[], io: GcIo, token?: strin
204
282
  io.print(`swept ${cleared.schedules} schedule ref(s), ${cleared.graphRuns} graph-run ref(s).`);
205
283
  return;
206
284
  }
207
- // A non-OK from a LIVE device is a real fault — fall through to the
208
- // offline path would race the daemon; surface it instead.
285
+ // R12 P3-6: name the two skew shapes an operator can actually hit —
286
+ // anything else is a real fault; falling through to the offline path
287
+ // would race the daemon, so surface it instead.
288
+ if (res.status === 404)
289
+ throw new Error(
290
+ "device predates the sweep route — upgrade it (npm i -g my-durable) and re-run dpi gc " +
291
+ "(or DPI_PORT points at another local service — check it)",
292
+ );
293
+ if (res.status === 401)
294
+ throw new Error("device refused the sweep token — stale DPI_TOKEN in the env file; refresh it and re-run dpi gc");
209
295
  throw new Error(`device answered ${res.status} to the sweep route`);
210
296
  } catch (e) {
211
297
  if (e instanceof TypeError || (e instanceof Error && /fetch|network|ECONN/i.test(e.message))) {
@@ -120,9 +120,21 @@ export function danglingRefCounts(
120
120
  let graphRuns = 0;
121
121
  try {
122
122
  const doc = JSON.parse(readFile(join(dataDir, "schedules.json"))) as {
123
- schedules?: Array<{ lastSessionId?: string }>;
123
+ schedules?: Array<{ lastSessionId?: string; keepRuns?: unknown; recentSessionIds?: string[] }>;
124
124
  };
125
- for (const s of doc.schedules ?? []) if (s.lastSessionId && ids.has(s.lastSessionId)) schedules += 1;
125
+ // R12 P3-11: count what the sweep actually clears — the retention ring
126
+ // too (clearSessionRefs deletes ring entries alongside lastSessionId), so
127
+ // the dry-run's "would clear N" stops under-promising. R13 P3-2: ring
128
+ // refs count ONLY when keepRuns parses in-range — the registry coercion
129
+ // DROPS junk keepRuns together with its ring (schedules.ts), so counting
130
+ // a doomed ring here would dry-run-promise what the sweep never clears.
131
+ const keepRunsParses = (v: unknown) =>
132
+ typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= 100;
133
+ for (const s of doc.schedules ?? []) {
134
+ if (s.lastSessionId && ids.has(s.lastSessionId)) schedules += 1;
135
+ else if (keepRunsParses(s.keepRuns) && (s.recentSessionIds ?? []).some((id) => ids.has(id)))
136
+ schedules += 1;
137
+ }
126
138
  } catch {
127
139
  /* absent or unreadable — nothing countable */
128
140
  }
@@ -705,7 +705,9 @@ export class GraphRegistry {
705
705
  }
706
706
  return touched ? { ...run, tasks } : run;
707
707
  });
708
- await this.commit(new Map(this.graphs), runs);
708
+ // R12 P3-7: no-op sweeps skip the commit — the schedules twin guards the
709
+ // same way; a no-op must not churn graphs.json (+ its .bak) forever.
710
+ if (cleared > 0) await this.commit(new Map(this.graphs), runs);
709
711
  });
710
712
  return cleared;
711
713
  }
@@ -197,11 +197,9 @@ export async function scheduleCli(argv: readonly string[], io: ScheduleIo = defa
197
197
  io.printErr(`dpi schedule: ${ran.error}`);
198
198
  return 1;
199
199
  }
200
- io.print(
201
- ran.data.running
202
- ? `run started (watch \`dpi schedule list\` for the outcome); next ${when(ran.data.nextRunAt)}`
203
- : `armed; next ${when(ran.data.nextRunAt)}`,
204
- );
200
+ // R12 P3-9: `running` is always true here — the guard-add runs
201
+ // synchronously before the 202 is built — so no ternary.
202
+ io.print(`run started (watch \`dpi schedule list\` for the outcome); next ${when(ran.data.nextRunAt)}`);
205
203
  return 0;
206
204
  }
207
205
  if (sub === "remove") {
@@ -385,15 +385,22 @@ function coerceRecord(raw: unknown, now: number): ScheduleRecord {
385
385
  if (isOutcome(source.lastOutcome)) record.lastOutcome = source.lastOutcome;
386
386
  const lastError = nonEmptyString(source.lastError);
387
387
  if (lastError) record.lastError = lastError;
388
- // R10 Design A: retention window — defensive parse (bounds enforced, ring
389
- // trimmed, junk entries dropped) so a hand-edited or future file cannot
390
- // unbound the registry.
391
- if (typeof source.keepRuns === "number" && Number.isInteger(source.keepRuns)) {
392
- const keepRuns = Math.min(Math.max(source.keepRuns, MIN_KEEP_RUNS), MAX_KEEP_RUNS);
393
- record.keepRuns = keepRuns;
388
+ // R10 Design A: retention window — defensive parse (junk dropped, ring
389
+ // trimmed) so a hand-edited or future file cannot unbound the registry.
390
+ // R12 P3-8: out-of-range keepRuns is DROPPED, not clamped — create/patch
391
+ // reject those values at the API, so the parse path must not silently ARM
392
+ // (or sharpen) auto-archive from garbage; dropped reads as "no retention",
393
+ // the safe direction.
394
+ if (
395
+ typeof source.keepRuns === "number" &&
396
+ Number.isInteger(source.keepRuns) &&
397
+ source.keepRuns >= MIN_KEEP_RUNS &&
398
+ source.keepRuns <= MAX_KEEP_RUNS
399
+ ) {
400
+ record.keepRuns = source.keepRuns;
394
401
  if (Array.isArray(source.recentSessionIds)) {
395
402
  const ring = source.recentSessionIds.filter((id): id is string => typeof id === "string" && id.length > 0);
396
- const unique = [...new Set(ring)].slice(-keepRuns);
403
+ const unique = [...new Set(ring)].slice(-source.keepRuns);
397
404
  if (unique.length > 0) record.recentSessionIds = unique;
398
405
  }
399
406
  }
@@ -1596,10 +1596,20 @@ export class Store {
1596
1596
  // R10 5.2: single-flight per session — two routes opening one corrupt db
1597
1597
  // (UI refresh fetching git-files + agents) used to spawn two salvage
1598
1598
  // workers racing on shared scratch; both attempts now share ONE outcome.
1599
- const inFlight = this.salvageInFlight.get(row.id) ?? salvageSessionDb(row.dbPath).then((outcome) => {
1600
- this.salvageInFlight.delete(row.id);
1601
- return outcome;
1602
- });
1599
+ const inFlight = this.salvageInFlight.get(row.id) ?? salvageSessionDb(row.dbPath).then(
1600
+ (outcome) => {
1601
+ this.salvageInFlight.delete(row.id);
1602
+ return outcome;
1603
+ },
1604
+ // R12 P3-10: clear on rejection too — a cached rejected promise would
1605
+ // permanently disable salvage for this session. (Unreachable today:
1606
+ // salvageSessionDb resolves on every path — but the map must not
1607
+ // depend on that staying true.)
1608
+ (error: unknown) => {
1609
+ this.salvageInFlight.delete(row.id);
1610
+ throw error;
1611
+ },
1612
+ );
1603
1613
  this.salvageInFlight.set(row.id, inFlight);
1604
1614
  const outcome = await inFlight;
1605
1615
  if (!outcome.recovered) {
@@ -2597,6 +2607,10 @@ export class Store {
2597
2607
 
2598
2608
  async removeSchedule(id: string): Promise<{ removed: boolean }> {
2599
2609
  const removed = await this.schedules.remove(id);
2610
+ // R12 P3-4: the schedule is gone — its degraded-episode markers must not
2611
+ // linger in the sets forever (random ids, never reused).
2612
+ this.scheduleRegistryDegraded.delete(id);
2613
+ this.schedulePruneDegraded.delete(id);
2600
2614
  this.notify();
2601
2615
  return { removed };
2602
2616
  }
@@ -2658,6 +2672,10 @@ export class Store {
2658
2672
  * unwritable — each is reported ONCE per degraded episode, not per tick. */
2659
2673
  private scheduleRegistryDegraded = new Set<string>();
2660
2674
 
2675
+ /** R12 P2-1: schedules whose retention prune could not archive an evicted
2676
+ * run — reported once per episode; a later successful prune ends it. */
2677
+ private schedulePruneDegraded = new Set<string>();
2678
+
2661
2679
  /** R10 5.2: per-session salvage single-flight — concurrent openers of one
2662
2680
  * corrupt session share ONE bounded attempt instead of racing scratch files. */
2663
2681
  private salvageInFlight = new Map<string, Promise<import("./salvage.js").SalvageOutcome>>();
@@ -2706,8 +2724,10 @@ export class Store {
2706
2724
  const started: string[] = [];
2707
2725
  for (const record of this.schedules.due(at)) {
2708
2726
  if (this.scheduleInFlight.has(record.id)) continue;
2709
- started.push(record.id);
2710
- await this.dispatchSchedule(record).catch(() => undefined);
2727
+ // R12 P3-5: only ids that actually DISPATCHED are reported — an
2728
+ // intent-marker skip (degraded registry) must not read as "started".
2729
+ const ran = await this.dispatchSchedule(record).catch(() => false);
2730
+ if (ran) started.push(record.id);
2711
2731
  }
2712
2732
  return started;
2713
2733
  }
@@ -2726,8 +2746,11 @@ export class Store {
2726
2746
  * BEFORE the session is created, so a crash in the create→outcome window
2727
2747
  * leaves a visible "interrupted" record after restart instead of silently
2728
2748
  * re-firing the same minute.
2749
+ *
2750
+ * R12 P3-5: returns true when the dispatch ran (attempted past the intent
2751
+ * marker), false when skipped — runDueSchedules reports only the true ones.
2729
2752
  */
2730
- private async dispatchSchedule(record: ScheduleRecord): Promise<void> {
2753
+ private async dispatchSchedule(record: ScheduleRecord): Promise<boolean> {
2731
2754
  if (this.scheduleInFlight.has(record.id)) {
2732
2755
  throw new ApiFault("busy", `Schedule "${record.name}" is already running`);
2733
2756
  }
@@ -2760,7 +2783,7 @@ export class Store {
2760
2783
  data: { scheduleId: record.id },
2761
2784
  });
2762
2785
  }
2763
- return;
2786
+ return false;
2764
2787
  }
2765
2788
  if (this.scheduleRegistryDegraded.delete(record.id)) {
2766
2789
  void this.notifyEvent({
@@ -2771,6 +2794,7 @@ export class Store {
2771
2794
  });
2772
2795
  }
2773
2796
  await this.dispatchBounded(record);
2797
+ return true;
2774
2798
  } finally {
2775
2799
  this.scheduleInFlight.delete(record.id);
2776
2800
  this.notify();
@@ -2845,7 +2869,8 @@ export class Store {
2845
2869
  SCHEDULE_REGISTRY_IO_MS,
2846
2870
  "schedule registry write timed out (ok)",
2847
2871
  ).catch(() => undefined);
2848
- if (okRecord?.keepRuns) void this.pruneScheduleSessions(okRecord, ringBefore).catch(() => undefined);
2872
+ if (okRecord?.keepRuns)
2873
+ void this.pruneScheduleSessions(okRecord, ringBefore).catch(() => this.markPruneDegraded(okRecord));
2849
2874
  void this.notifyEvent({
2850
2875
  kind: "schedule.ok",
2851
2876
  title: `Schedule ran: ${record.name}`,
@@ -2880,16 +2905,54 @@ export class Store {
2880
2905
  * archived via the existing store.archive path (abort-open → atomic rename
2881
2906
  * to archive/ → catalog row deleted — nothing deleted, restorable, ages into
2882
2907
  * the gc plan). Archive failure leaves the session live; the id is already
2883
- * gone from the ring, but the session stays restorable and the operator can
2884
- * archive it manually — at most keepRuns stragglers can overstay (bounded). */
2908
+ * gone from the ring, so a PERSISTENT failure accumulates one straggler
2909
+ * per run until recovery — unbounded while the fault lasts, which is why
2910
+ * R12 P2-1 reports the degraded episode instead of swallowing it. */
2911
+ /** R12 P2-1: the once-per-episode signal for a retention prune that could
2912
+ * not archive an evicted run — shared by the prune's own failure path and
2913
+ * the void-caller's outer catch. */
2914
+ private markPruneDegraded(record: ScheduleRecord): void {
2915
+ if (this.schedulePruneDegraded.has(record.id)) return;
2916
+ this.schedulePruneDegraded.add(record.id);
2917
+ void this.notifyEvent({
2918
+ kind: "schedule.failed",
2919
+ title: `Retention paused: ${record.name}`,
2920
+ body: `an evicted run's session could not be archived (archive/ unwritable or disk full?) — it stays live; ` +
2921
+ `retention resumes when archiving works again`,
2922
+ data: { scheduleId: record.id },
2923
+ });
2924
+ }
2925
+
2885
2926
  private async pruneScheduleSessions(record: ScheduleRecord, ringBefore: string[]): Promise<void> {
2886
2927
  if (typeof record.keepRuns !== "number") return;
2887
2928
  const ringNow = new Set(record.recentSessionIds ?? []);
2888
2929
  const evicted = [...new Set(ringBefore)].filter((id) => !ringNow.has(id));
2889
- for (const id of evicted) {
2890
- const row = this.catalog.prepare("SELECT * FROM sessions WHERE id=?").get(id) as SessionRow | undefined;
2891
- if (!row) continue; // already gone (archived/corrupt-removed) — nothing to do
2892
- await this.archive(row);
2930
+ let archived = 0;
2931
+ try {
2932
+ for (const id of evicted) {
2933
+ const row = this.catalog.prepare("SELECT * FROM sessions WHERE id=?").get(id) as SessionRow | undefined;
2934
+ if (!row) continue; // already gone (archived/corrupt-removed) — nothing to do
2935
+ await this.archive(row);
2936
+ archived += 1;
2937
+ }
2938
+ } catch {
2939
+ // R12 P2-1: a persistent archive failure (archive/ unwritable, disk full)
2940
+ // used to be swallowed silently — and since markRun already trimmed the
2941
+ // ring, every later run left one more live session behind FOREVER, the
2942
+ // exact growth this feature exists to prevent, with zero signal.
2943
+ this.markPruneDegraded(record);
2944
+ return;
2945
+ }
2946
+ if (evicted.length > 0 && this.schedulePruneDegraded.delete(record.id)) {
2947
+ void this.notifyEvent({
2948
+ kind: "schedule.ok",
2949
+ title: `Retention resumed: ${record.name}`,
2950
+ body:
2951
+ archived > 0
2952
+ ? `archived ${archived} evicted run(s); the window is healthy again`
2953
+ : `archiving works again (the evicted run(s) were already gone); the window is healthy`,
2954
+ data: { scheduleId: record.id },
2955
+ });
2893
2956
  }
2894
2957
  }
2895
2958
 
@@ -757,6 +757,11 @@ export class DeviceConnector {
757
757
  // Small responses ride one frame; large ones chunk (hub reassembles).
758
758
  // Textual bodies keep the legacy UTF-8 string envelope; binaries are
759
759
  // base64-flagged so the hub can serve bytes byte-exact (R8 export).
760
+ // R13 (R9-6.3 FE): the device's idempotency replay verdict rides the
761
+ // envelope as an optional literal — old hubs ignore it (rest-response
762
+ // is de-Strict by design), new hubs surface the header so clients can
763
+ // tell a replay from a fresh create.
764
+ const replayed = res.headers.get("idempotent-replay") === "true" ? { idempotentReplay: true } : {};
760
765
  const envelope = textual
761
766
  ? ({
762
767
  type: "rest-response",
@@ -764,6 +769,7 @@ export class DeviceConnector {
764
769
  status: res.status,
765
770
  contentType: resCt,
766
771
  body: read.bytes.toString("utf8"),
772
+ ...replayed,
767
773
  } as const)
768
774
  : ({
769
775
  type: "rest-response",
@@ -773,6 +779,7 @@ export class DeviceConnector {
773
779
  body: read.bytes.toString("base64"),
774
780
  bodyEncoding: "base64",
775
781
  contentDisposition: safeHeaderValue(res.headers.get("content-disposition")),
782
+ ...replayed,
776
783
  } as const);
777
784
  const serialized = JSON.stringify(envelope);
778
785
  if (Buffer.byteLength(serialized, "utf8") <= INLINE_FRAME_MAX_BYTES) {
@@ -237,6 +237,11 @@ const tempZipPath = (baseDir: string) => join(baseDir, `.dpi-export-${process.pi
237
237
  * own data dir (R11 1.1) → the OS temp dir. Dot-prefixed so a casual `ls`
238
238
  * of the data dir does not read as a session artifact. */
239
239
  export function exportTempDir(dataDir: string): string {
240
+ // R12 P3-12 (known coupling): the spill shares the data volume with the
241
+ // registries — a 12-256 MB export on a nearly-full disk can push registry
242
+ // writes into ENOSPC (schedules degrade gracefully: R11 2.2 skips runs and
243
+ // reports once) until the export finishes and unlinks. Self-healing by
244
+ // design; noted here so nobody "fixes" it back to tmpfs.
240
245
  return process.env.DPI_EXPORT_TMPDIR || dataDir || tmpdir();
241
246
  }
242
247