@rljson/fs-agent 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.
@@ -239,6 +239,35 @@ export declare class PartialRestoreError extends RestoreIncompleteError {
239
239
  readonly lockedPaths: string[];
240
240
  constructor(lockedPaths: string[]);
241
241
  }
242
+ /**
243
+ * Thrown when a restore finished but at least one file's bytes could not be
244
+ * fetched at all.
245
+ *
246
+ * The difference from {@link PartialRestoreError} is "not yet" versus "never".
247
+ * A locked file's bytes exist and the file is merely busy, so retrying is the
248
+ * right answer. A blob that cannot be retrieved may never become retrievable —
249
+ * a file larger than the transport's `maxHttpBufferSize` is the case that
250
+ * produced this class, and no number of retries makes 63 MB fit through a
251
+ * 50 MB socket.
252
+ *
253
+ * It exists because the failure used to be a bare `throw` in the middle of
254
+ * `_restoreTree`, which abandoned the ENTIRE tree: no other file in it was
255
+ * written, and — the part that actually hurt — `_pruneExtraneous` never ran,
256
+ * so no deletion in that tree was ever applied. The node then retried, failed
257
+ * on the same blob, and its state never advanced past that ref. Once its
258
+ * ancestry no longer matched any state its peers were in, every later apply
259
+ * came through with `mayPrune=false`, and it accepted additions forever while
260
+ * silently ignoring every delete.
261
+ *
262
+ * Measured on four nodes: one 63 MB file (120% of the cap) left three of them
263
+ * holding a file the fourth had deleted, permanently, and `projekte-shape`'s
264
+ * deletion had still not propagated after 300 seconds. The customer's largest
265
+ * file is 45.9 MB against the same 50 MB cap.
266
+ */
267
+ export declare class BlobUnavailableError extends RestoreIncompleteError {
268
+ readonly unavailablePaths: string[];
269
+ constructor(unavailablePaths: string[]);
270
+ }
242
271
  /**
243
272
  * Thrown when `cleanTarget` would have deleted most of the folder.
244
273
  *
@@ -327,15 +356,6 @@ export declare class FsAgent {
327
356
  * tree that lacks it is not deleting it — it simply predates it.
328
357
  */
329
358
  private readonly _announcedFiles;
330
- /**
331
- * Files this node wrote because a peer sent them.
332
- *
333
- * Permission only: it is never consulted to decide whether the prune gate is
334
- * armed, only to answer "may this particular file be pruned". A file the
335
- * network handed us is one the network knows about, so the peer that sent it
336
- * may later take it away.
337
- */
338
- private readonly _restoredFiles;
339
359
  /**
340
360
  * Files this restore DELETED.
341
361
  *
@@ -348,6 +368,12 @@ export declare class FsAgent {
348
368
  private _restorePruned;
349
369
  /** Paths the current {@link restore} could not write because they were held open. */
350
370
  private _restoreLocked;
371
+ /**
372
+ * Paths the current {@link restore} could not write because their blob could
373
+ * not be fetched — collected rather than thrown, so one unfetchable file
374
+ * cannot abandon the rest of the tree and, above all, cannot stop the prune.
375
+ */
376
+ private _restoreUnavailable;
351
377
  /**
352
378
  * What this agent last wrote to each absolute path, so a repeat restore can
353
379
  * recognise its own work without re-reading the file.
package/dist/fs-agent.js CHANGED
@@ -1124,6 +1124,15 @@ class PartialRestoreError extends RestoreIncompleteError {
1124
1124
  this.name = "PartialRestoreError";
1125
1125
  }
1126
1126
  }
1127
+ class BlobUnavailableError extends RestoreIncompleteError {
1128
+ constructor(unavailablePaths) {
1129
+ super(
1130
+ `restore could not fetch ${unavailablePaths.length} blob${unavailablePaths.length === 1 ? "" : "s"}: ${unavailablePaths.join(", ")}`
1131
+ );
1132
+ this.unavailablePaths = unavailablePaths;
1133
+ this.name = "BlobUnavailableError";
1134
+ }
1135
+ }
1127
1136
  class MassDeleteRefusedError extends RestoreIncompleteError {
1128
1137
  constructor(wouldPrune, totalFiles, incomingFiles) {
1129
1138
  super(
@@ -1207,15 +1216,6 @@ class FsAgent {
1207
1216
  * tree that lacks it is not deleting it — it simply predates it.
1208
1217
  */
1209
1218
  _announcedFiles = /* @__PURE__ */ new Set();
1210
- /**
1211
- * Files this node wrote because a peer sent them.
1212
- *
1213
- * Permission only: it is never consulted to decide whether the prune gate is
1214
- * armed, only to answer "may this particular file be pruned". A file the
1215
- * network handed us is one the network knows about, so the peer that sent it
1216
- * may later take it away.
1217
- */
1218
- _restoredFiles = /* @__PURE__ */ new Set();
1219
1219
  /**
1220
1220
  * Files this restore DELETED.
1221
1221
  *
@@ -1228,6 +1228,12 @@ class FsAgent {
1228
1228
  _restorePruned = 0;
1229
1229
  /** Paths the current {@link restore} could not write because they were held open. */
1230
1230
  _restoreLocked = [];
1231
+ /**
1232
+ * Paths the current {@link restore} could not write because their blob could
1233
+ * not be fetched — collected rather than thrown, so one unfetchable file
1234
+ * cannot abandon the rest of the tree and, above all, cannot stop the prune.
1235
+ */
1236
+ _restoreUnavailable = [];
1231
1237
  /**
1232
1238
  * What this agent last wrote to each absolute path, so a repeat restore can
1233
1239
  * recognise its own work without re-reading the file.
@@ -1558,17 +1564,13 @@ ${err.stack}` : String(err);
1558
1564
  this._restoreSkipped = 0;
1559
1565
  this._restorePruned = 0;
1560
1566
  this._restoreLocked = [];
1567
+ this._restoreUnavailable = [];
1561
1568
  await this._restoreTree(
1562
1569
  tree.rootHash,
1563
1570
  tree.trees,
1564
1571
  target,
1565
1572
  target === this._rootPath
1566
1573
  );
1567
- if (this._restoreSkipped > 0 || this._restorePruned > 0) {
1568
- console.log(
1569
- `[FsAgent] restore: wrote ${this._restoreWritten}, left ${this._restoreSkipped} already-correct file${this._restoreSkipped === 1 ? "" : "s"} untouched` + (this._restorePruned > 0 ? `, DELETED ${this._restorePruned}` : "")
1570
- );
1571
- }
1572
1574
  if (options?.cleanTarget) {
1573
1575
  let wouldPrune = 0;
1574
1576
  for (const existing of preRestore) {
@@ -1597,9 +1599,17 @@ ${err.stack}` : String(err);
1597
1599
  preRestore
1598
1600
  );
1599
1601
  }
1602
+ if (this._restoreSkipped > 0 || this._restorePruned > 0) {
1603
+ console.log(
1604
+ `[FsAgent] restore: wrote ${this._restoreWritten}, left ${this._restoreSkipped} already-correct file${this._restoreSkipped === 1 ? "" : "s"} untouched` + (this._restorePruned > 0 ? `, DELETED ${this._restorePruned}` : "")
1605
+ );
1606
+ }
1600
1607
  if (this._restoreLocked.length > 0) {
1601
1608
  throw new PartialRestoreError([...this._restoreLocked]);
1602
1609
  }
1610
+ if (this._restoreUnavailable.length > 0) {
1611
+ throw new BlobUnavailableError([...this._restoreUnavailable]);
1612
+ }
1603
1613
  }
1604
1614
  /**
1605
1615
  * Recursively collects the absolute paths of all files under `currentDir`.
@@ -1658,20 +1668,23 @@ ${err.stack}` : String(err);
1658
1668
  try {
1659
1669
  fileBlob = await this._bs.getBlob(meta.blobId);
1660
1670
  } catch (error) {
1661
- throw new Error(
1662
- `Failed to retrieve blob for file "${meta.relativePath}" (blobId: ${meta.blobId}): ${error instanceof Error ? error.message : String(error)}`
1671
+ console.warn(
1672
+ `[FsAgent] cannot fetch blob for "${meta.relativePath}" (blobId: ${meta.blobId}): ${error instanceof Error ? error.message : String(error)} — skipping this file and applying the rest of the tree.`
1663
1673
  );
1674
+ this._restoreUnavailable.push(meta.relativePath);
1675
+ return;
1664
1676
  }
1665
1677
  if (!fileBlob || !fileBlob.content) {
1666
- throw new Error(
1667
- `Missing blob content for file "${meta.relativePath}" (blobId: ${meta.blobId}). The blob may have been deleted or not synced properly.`
1678
+ console.warn(
1679
+ `[FsAgent] missing blob content for "${meta.relativePath}" (blobId: ${meta.blobId}) — skipping this file and applying the rest of the tree.`
1668
1680
  );
1681
+ this._restoreUnavailable.push(meta.relativePath);
1682
+ return;
1669
1683
  }
1670
1684
  await mkdir(dirname(filePath), { recursive: true });
1671
1685
  try {
1672
1686
  await FsAgent._atomicWriteFile(filePath, fileBlob.content);
1673
1687
  this._restoreWritten++;
1674
- this._restoredFiles.add(filePath);
1675
1688
  if (meta.mtime) {
1676
1689
  const mtime = new Date(meta.mtime);
1677
1690
  await utimes(filePath, mtime, mtime);
@@ -2026,7 +2039,7 @@ ${err.stack}` : String(err);
2026
2039
  }
2027
2040
  }
2028
2041
  } else if (!expectedFiles.has(fullPath) && preRestore.has(fullPath)) {
2029
- if (this._announcedFiles.size > 0 && !this._announcedFiles.has(fullPath) && !this._restoredFiles.has(fullPath)) {
2042
+ if (this._announcedFiles.size > 0 && !this._announcedFiles.has(fullPath)) {
2030
2043
  continue;
2031
2044
  }
2032
2045
  await rm(fullPath, { force: true });
@@ -2700,7 +2713,7 @@ ${err.stack}` : String(err);
2700
2713
  await this._readvertiseAfterRefusal(connector);
2701
2714
  return;
2702
2715
  }
2703
- if (err instanceof PartialRestoreError) {
2716
+ if (err instanceof PartialRestoreError || err instanceof BlobUnavailableError) {
2704
2717
  try {
2705
2718
  const halfApplied = await this._scanner.scan();
2706
2719
  this._lastSentContentKey = this._contentKeyFromTree(halfApplied);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/fs-agent",
3
- "version": "0.0.65",
3
+ "version": "0.0.67",
4
4
  "description": "Rljson fs-agent description",
5
5
  "homepage": "https://github.com/rljson/fs-agent",
6
6
  "bugs": "https://github.com/rljson/fs-agent/issues",