@rljson/fs-agent 0.0.66 → 0.0.68

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
  *
@@ -339,6 +368,12 @@ export declare class FsAgent {
339
368
  private _restorePruned;
340
369
  /** Paths the current {@link restore} could not write because they were held open. */
341
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;
342
377
  /**
343
378
  * What this agent last wrote to each absolute path, so a repeat restore can
344
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(
@@ -1219,6 +1228,12 @@ class FsAgent {
1219
1228
  _restorePruned = 0;
1220
1229
  /** Paths the current {@link restore} could not write because they were held open. */
1221
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 = [];
1222
1237
  /**
1223
1238
  * What this agent last wrote to each absolute path, so a repeat restore can
1224
1239
  * recognise its own work without re-reading the file.
@@ -1549,6 +1564,7 @@ ${err.stack}` : String(err);
1549
1564
  this._restoreSkipped = 0;
1550
1565
  this._restorePruned = 0;
1551
1566
  this._restoreLocked = [];
1567
+ this._restoreUnavailable = [];
1552
1568
  await this._restoreTree(
1553
1569
  tree.rootHash,
1554
1570
  tree.trees,
@@ -1591,6 +1607,9 @@ ${err.stack}` : String(err);
1591
1607
  if (this._restoreLocked.length > 0) {
1592
1608
  throw new PartialRestoreError([...this._restoreLocked]);
1593
1609
  }
1610
+ if (this._restoreUnavailable.length > 0) {
1611
+ throw new BlobUnavailableError([...this._restoreUnavailable]);
1612
+ }
1594
1613
  }
1595
1614
  /**
1596
1615
  * Recursively collects the absolute paths of all files under `currentDir`.
@@ -1649,14 +1668,18 @@ ${err.stack}` : String(err);
1649
1668
  try {
1650
1669
  fileBlob = await this._bs.getBlob(meta.blobId);
1651
1670
  } catch (error) {
1652
- throw new Error(
1653
- `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.`
1654
1673
  );
1674
+ this._restoreUnavailable.push(meta.relativePath);
1675
+ return;
1655
1676
  }
1656
1677
  if (!fileBlob || !fileBlob.content) {
1657
- throw new Error(
1658
- `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.`
1659
1680
  );
1681
+ this._restoreUnavailable.push(meta.relativePath);
1682
+ return;
1660
1683
  }
1661
1684
  await mkdir(dirname(filePath), { recursive: true });
1662
1685
  try {
@@ -2690,7 +2713,7 @@ ${err.stack}` : String(err);
2690
2713
  await this._readvertiseAfterRefusal(connector);
2691
2714
  return;
2692
2715
  }
2693
- if (err instanceof PartialRestoreError) {
2716
+ if (err instanceof PartialRestoreError || err instanceof BlobUnavailableError) {
2694
2717
  try {
2695
2718
  const halfApplied = await this._scanner.scan();
2696
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.66",
3
+ "version": "0.0.68",
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",
@@ -50,12 +50,12 @@
50
50
  "vitest-dom": "^0.1.1"
51
51
  },
52
52
  "dependencies": {
53
- "@rljson/bs": "^0.0.21",
54
- "@rljson/db": "0.0.36",
55
- "@rljson/hash": "^0.0.18",
56
- "@rljson/io": "^0.0.66",
57
- "@rljson/json": "^0.0.23",
58
- "@rljson/rljson": "^0.0.78",
53
+ "@rljson/bs": "0.0.25",
54
+ "@rljson/db": "0.0.38",
55
+ "@rljson/hash": "0.0.19",
56
+ "@rljson/io": "0.0.73",
57
+ "@rljson/json": "0.0.23",
58
+ "@rljson/rljson": "0.0.80",
59
59
  "socket.io": "^4.8.3",
60
60
  "socket.io-client": "^4.8.3"
61
61
  },