@fluidframework/container-loader 2.100.0 → 2.101.1

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 (94) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/container-loader.legacy.alpha.api.md +13 -1
  3. package/dist/captureReferencedContents.d.ts +154 -0
  4. package/dist/captureReferencedContents.d.ts.map +1 -0
  5. package/dist/captureReferencedContents.js +349 -0
  6. package/dist/captureReferencedContents.js.map +1 -0
  7. package/dist/connectionManager.d.ts.map +1 -1
  8. package/dist/connectionManager.js +25 -7
  9. package/dist/connectionManager.js.map +1 -1
  10. package/dist/connectionStateHandler.d.ts.map +1 -1
  11. package/dist/connectionStateHandler.js +3 -1
  12. package/dist/connectionStateHandler.js.map +1 -1
  13. package/dist/container.d.ts.map +1 -1
  14. package/dist/container.js +6 -1
  15. package/dist/container.js.map +1 -1
  16. package/dist/containerStorageAdapter.d.ts +19 -1
  17. package/dist/containerStorageAdapter.d.ts.map +1 -1
  18. package/dist/containerStorageAdapter.js.map +1 -1
  19. package/dist/createAndLoadContainerUtils.d.ts +95 -0
  20. package/dist/createAndLoadContainerUtils.d.ts.map +1 -1
  21. package/dist/createAndLoadContainerUtils.js +137 -11
  22. package/dist/createAndLoadContainerUtils.js.map +1 -1
  23. package/dist/frozenServices.d.ts +113 -30
  24. package/dist/frozenServices.d.ts.map +1 -1
  25. package/dist/frozenServices.js +236 -58
  26. package/dist/frozenServices.js.map +1 -1
  27. package/dist/index.d.ts +2 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +5 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/legacyAlpha.d.ts +2 -0
  32. package/dist/loaderLayerCompatState.d.ts +1 -1
  33. package/dist/packageVersion.d.ts +1 -1
  34. package/dist/packageVersion.js +1 -1
  35. package/dist/packageVersion.js.map +1 -1
  36. package/dist/pendingLocalStateStore.d.ts.map +1 -1
  37. package/dist/pendingLocalStateStore.js +9 -3
  38. package/dist/pendingLocalStateStore.js.map +1 -1
  39. package/dist/serializedStateManager.d.ts +16 -1
  40. package/dist/serializedStateManager.d.ts.map +1 -1
  41. package/dist/serializedStateManager.js +11 -1
  42. package/dist/serializedStateManager.js.map +1 -1
  43. package/lib/captureReferencedContents.d.ts +154 -0
  44. package/lib/captureReferencedContents.d.ts.map +1 -0
  45. package/lib/captureReferencedContents.js +338 -0
  46. package/lib/captureReferencedContents.js.map +1 -0
  47. package/lib/connectionManager.d.ts.map +1 -1
  48. package/lib/connectionManager.js +26 -8
  49. package/lib/connectionManager.js.map +1 -1
  50. package/lib/connectionStateHandler.d.ts.map +1 -1
  51. package/lib/connectionStateHandler.js +3 -1
  52. package/lib/connectionStateHandler.js.map +1 -1
  53. package/lib/container.d.ts.map +1 -1
  54. package/lib/container.js +6 -1
  55. package/lib/container.js.map +1 -1
  56. package/lib/containerStorageAdapter.d.ts +19 -1
  57. package/lib/containerStorageAdapter.d.ts.map +1 -1
  58. package/lib/containerStorageAdapter.js.map +1 -1
  59. package/lib/createAndLoadContainerUtils.d.ts +95 -0
  60. package/lib/createAndLoadContainerUtils.d.ts.map +1 -1
  61. package/lib/createAndLoadContainerUtils.js +128 -3
  62. package/lib/createAndLoadContainerUtils.js.map +1 -1
  63. package/lib/frozenServices.d.ts +113 -30
  64. package/lib/frozenServices.d.ts.map +1 -1
  65. package/lib/frozenServices.js +233 -57
  66. package/lib/frozenServices.js.map +1 -1
  67. package/lib/index.d.ts +2 -1
  68. package/lib/index.d.ts.map +1 -1
  69. package/lib/index.js +2 -1
  70. package/lib/index.js.map +1 -1
  71. package/lib/legacyAlpha.d.ts +2 -0
  72. package/lib/loaderLayerCompatState.d.ts +1 -1
  73. package/lib/packageVersion.d.ts +1 -1
  74. package/lib/packageVersion.js +1 -1
  75. package/lib/packageVersion.js.map +1 -1
  76. package/lib/pendingLocalStateStore.d.ts.map +1 -1
  77. package/lib/pendingLocalStateStore.js +9 -3
  78. package/lib/pendingLocalStateStore.js.map +1 -1
  79. package/lib/serializedStateManager.d.ts +16 -1
  80. package/lib/serializedStateManager.d.ts.map +1 -1
  81. package/lib/serializedStateManager.js +11 -1
  82. package/lib/serializedStateManager.js.map +1 -1
  83. package/package.json +11 -11
  84. package/src/captureReferencedContents.ts +446 -0
  85. package/src/connectionManager.ts +30 -8
  86. package/src/connectionStateHandler.ts +14 -9
  87. package/src/container.ts +6 -0
  88. package/src/containerStorageAdapter.ts +20 -1
  89. package/src/createAndLoadContainerUtils.ts +229 -2
  90. package/src/frozenServices.ts +285 -64
  91. package/src/index.ts +7 -0
  92. package/src/packageVersion.ts +1 -1
  93. package/src/pendingLocalStateStore.ts +8 -1
  94. package/src/serializedStateManager.ts +28 -1
@@ -0,0 +1,154 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { IDocumentStorageService, ISequencedDocumentMessage, ISnapshot, ISnapshotTree } from "@fluidframework/driver-definitions/internal";
6
+ import type { IBase64BlobContents, ISerializableBlobContents } from "./containerStorageAdapter.js";
7
+ /**
8
+ * Wire-format constants this module needs to walk and filter snapshots.
9
+ * Authoritative definitions live in `container-runtime` and
10
+ * `runtime-definitions`; the values are duplicated here to avoid a
11
+ * loader → runtime layering dependency. A contract test in
12
+ * `packages/test/local-server-tests` asserts these match the authoritative
13
+ * values; do not change them in isolation.
14
+ *
15
+ * Authoritative sources:
16
+ * - `blobsTreeName`, `redirectTableBlobName`: `packages/runtime/container-runtime/src/blobManager/blobManagerSnapSum.ts`
17
+ * - `blobManagerBasePath`: `packages/runtime/container-runtime/src/blobManager/blobManager.ts`
18
+ * - `gcTreeKey`, `gcBlobPrefix`, `gcTombstoneBlobKey`, `gcDeletedBlobKey`: `packages/runtime/runtime-definitions/src/garbageCollectionDefinitions.ts`
19
+ *
20
+ * @internal
21
+ */
22
+ export declare const wireFormatConstants: {
23
+ readonly blobsTreeName: ".blobs";
24
+ readonly redirectTableBlobName: ".redirectTable";
25
+ readonly blobManagerBasePath: "_blobs";
26
+ readonly gcTreeKey: "gc";
27
+ readonly gcBlobPrefix: "__gc";
28
+ readonly gcTombstoneBlobKey: "__tombstones";
29
+ readonly gcDeletedBlobKey: "__deletedNodes";
30
+ };
31
+ interface IGcNodeData {
32
+ outboundRoutes: string[];
33
+ unreferencedTimestampMs?: number;
34
+ }
35
+ interface IGcState {
36
+ gcNodes: {
37
+ [id: string]: IGcNodeData;
38
+ };
39
+ }
40
+ /**
41
+ * The parsed subset of the `gc` subtree that drives reachability decisions.
42
+ */
43
+ export interface IGcSnapshotData {
44
+ gcState: IGcState | undefined;
45
+ tombstones: string[] | undefined;
46
+ deletedNodes: string[] | undefined;
47
+ }
48
+ /**
49
+ * Runs `fn` over `items` with at most `limit` promises in flight. Preserves
50
+ * input order on output (not that any caller depends on it today).
51
+ *
52
+ * Exported for unit tests; not part of the package public API.
53
+ *
54
+ * @internal
55
+ */
56
+ export declare function mapWithConcurrency<T, R>(items: readonly T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]>;
57
+ /**
58
+ * Parses the `gc` subtree of a base snapshot. Returns `undefined` if the
59
+ * snapshot has no GC tree (GC disabled or pre-GC document).
60
+ */
61
+ export declare function parseGcSnapshotData(baseSnapshot: ISnapshotTree, storage: Pick<IDocumentStorageService, "readBlob">): Promise<IGcSnapshotData | undefined>;
62
+ /**
63
+ * Walks a snapshot and inlines the contents of every blob reachable without
64
+ * crossing an `unreferenced` subtree boundary. Subtrees flagged
65
+ * `unreferenced: true` are skipped entirely — the summarizer sets that flag
66
+ * from GC state, so honouring it filters out dead subtrees without a
67
+ * separate GC-path traversal.
68
+ *
69
+ * The root-level `.blobs` subtree is special-cased: only its `.redirectTable`
70
+ * blob is read, because attachment blob contents are captured separately via
71
+ * {@link captureReferencedAttachmentBlobs}.
72
+ */
73
+ export declare function readReferencedSnapshotBlobs(snapshot: ISnapshot | ISnapshotTree, storage: Pick<IDocumentStorageService, "readBlob">): Promise<ISerializableBlobContents>;
74
+ /**
75
+ * Fetches attachment blob contents from a snapshot, filtered by GC
76
+ * reachability. Blobs GC has explicitly marked unreferenced, tombstoned, or
77
+ * deleted are skipped. Blobs absent from the GC graph are kept — GC state
78
+ * lags behind recent attachments and dropping them would lose live data.
79
+ * If `gcData` is `undefined`, every attachment blob is returned.
80
+ *
81
+ * The returned map is keyed by attachment blob storage id. Values are the
82
+ * raw bytes encoded as **base64** strings — attachment blobs may carry
83
+ * arbitrary binary payloads (images, encrypted data, etc.) and a
84
+ * UTF-8 round-trip would silently corrupt non-UTF-8 byte sequences with
85
+ * replacement characters. The runtime's own pending-blob serializer uses
86
+ * base64 for the same reason. This diverges from the structural-blob path
87
+ * in {@link readReferencedSnapshotBlobs}, which encodes UTF-8 because those
88
+ * blobs are JSON or other text the runtime authored. Callers must keep the
89
+ * two encodings on separate fields of the pending state so the load side
90
+ * can decode each correctly.
91
+ */
92
+ export declare function captureReferencedAttachmentBlobs(baseSnapshot: ISnapshotTree, storage: Pick<IDocumentStorageService, "readBlob">, gcData: IGcSnapshotData | undefined): Promise<IBase64BlobContents>;
93
+ /**
94
+ * A blob reference extracted from a `BlobAttach` op. `localId` is the
95
+ * `BlobManager` GC identity for the blob; `storageId` is the id used for
96
+ * `IDocumentStorageService.readBlob`.
97
+ *
98
+ * @internal
99
+ */
100
+ export interface IBlobAttachReference {
101
+ readonly localId: string;
102
+ readonly storageId: string;
103
+ }
104
+ /**
105
+ * Extracts every `BlobAttach` reference an op carries. Returns an empty array
106
+ * for non-blobAttach ops.
107
+ *
108
+ * This is the single place in the loader that interprets the BlobAttach
109
+ * wire format. Capture and load-side reasoning about ops should call into
110
+ * this function rather than reading `op.metadata` directly, so a future
111
+ * protocol change touches one site.
112
+ *
113
+ * BlobAttach ops carry `(localId, storageId)` directly on
114
+ * `ISequencedDocumentMessage.metadata` and are not grouped — the container
115
+ * runtime routes them through a separate `outbox.submitBlobAttach` lane,
116
+ * and `OpGroupingManager.groupBatch` asserts (0x5dd) that no op carrying
117
+ * non-batch metadata enters a grouped batch. If either guarantee changes,
118
+ * extend this function rather than each call site.
119
+ *
120
+ * @internal
121
+ */
122
+ export declare function extractBlobAttachReferences(op: Pick<ISequencedDocumentMessage, "metadata">): IBlobAttachReference[];
123
+ /**
124
+ * Set of attachment-blob localIds that GC has marked unreferenced,
125
+ * tombstoned, or deleted in the base snapshot. `undefined` if `gcData`
126
+ * is `undefined` (GC disabled / pre-GC document).
127
+ *
128
+ * @internal
129
+ */
130
+ export declare function unreferencedAttachmentBlobLocalIds(gcData: IGcSnapshotData | undefined): Set<string> | undefined;
131
+ /**
132
+ * Inline attachment blob contents for the given `(localId, storageId)`
133
+ * references. Skips entries already present in `existing` (de-dupe with
134
+ * the snapshot path) and entries whose `localId` is in
135
+ * `unreferencedLocalIds`. Returns only the freshly-read entries; the
136
+ * caller merges them into the existing map.
137
+ *
138
+ * @internal
139
+ */
140
+ export declare function inlineAttachmentBlobsByReference(references: readonly IBlobAttachReference[], storage: Pick<IDocumentStorageService, "readBlob">, unreferencedLocalIds: ReadonlySet<string> | undefined, existing: Readonly<IBase64BlobContents>): Promise<IBase64BlobContents>;
141
+ /**
142
+ * Returns true if any referenced subtree of `baseSnapshot` declares a
143
+ * `groupId` — the snapshot-tree wire field that carries the runtime's
144
+ * loading-group identifier. Subtrees flagged `unreferenced` are skipped —
145
+ * a dead subtree's `groupId` would not be loaded by the runtime either.
146
+ *
147
+ * `captureFullContainerState` does not yet support loading groups: prefetching
148
+ * per-group snapshots adds a code path that has no end-to-end coverage and no
149
+ * known production consumer. Callers use this to fail fast with a `UsageError`
150
+ * rather than silently producing a pending state that omits group data.
151
+ */
152
+ export declare function snapshotHasLoadingGroups(baseSnapshot: ISnapshotTree): boolean;
153
+ export {};
154
+ //# sourceMappingURL=captureReferencedContents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captureReferencedContents.d.ts","sourceRoot":"","sources":["../src/captureReferencedContents.ts"],"names":[],"mappings":"AAAA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;;;;;;;;;;;GAiBG;AACH,wBAAsB,gCAAgC,CACrD,YAAY,EAAE,aAAa,EAC3B,OAAO,EAAE,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,EAClD,MAAM,EAAE,eAAe,GAAG,SAAS,GACjC,OAAO,CAAC,mBAAmB,CAAC,CA0B9B;AAwDD;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAeD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,2BAA2B,CAC1C,EAAE,EAAE,IAAI,CAAC,yBAAyB,EAAE,UAAU,CAAC,GAC7C,oBAAoB,EAAE,CAKxB;AAED;;;;;;GAMG;AACH,wBAAgB,kCAAkC,CACjD,MAAM,EAAE,eAAe,GAAG,SAAS,GACjC,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,CAEzB;AAED;;;;;;;;GAQG;AACH,wBAAsB,gCAAgC,CACrD,UAAU,EAAE,SAAS,oBAAoB,EAAE,EAC3C,OAAO,EAAE,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,EAClD,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,EACrD,QAAQ,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GACrC,OAAO,CAAC,mBAAmB,CAAC,CAoB9B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,aAAa,GAAG,OAAO,CAa7E"}
@@ -0,0 +1,338 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { bufferToString } from "@fluid-internal/client-utils";
6
+ import { readAndParse } from "@fluidframework/driver-utils/internal";
7
+ /**
8
+ * Wire-format constants this module needs to walk and filter snapshots.
9
+ * Authoritative definitions live in `container-runtime` and
10
+ * `runtime-definitions`; the values are duplicated here to avoid a
11
+ * loader → runtime layering dependency. A contract test in
12
+ * `packages/test/local-server-tests` asserts these match the authoritative
13
+ * values; do not change them in isolation.
14
+ *
15
+ * Authoritative sources:
16
+ * - `blobsTreeName`, `redirectTableBlobName`: `packages/runtime/container-runtime/src/blobManager/blobManagerSnapSum.ts`
17
+ * - `blobManagerBasePath`: `packages/runtime/container-runtime/src/blobManager/blobManager.ts`
18
+ * - `gcTreeKey`, `gcBlobPrefix`, `gcTombstoneBlobKey`, `gcDeletedBlobKey`: `packages/runtime/runtime-definitions/src/garbageCollectionDefinitions.ts`
19
+ *
20
+ * @internal
21
+ */
22
+ export const wireFormatConstants = {
23
+ blobsTreeName: ".blobs",
24
+ redirectTableBlobName: ".redirectTable",
25
+ blobManagerBasePath: "_blobs",
26
+ gcTreeKey: "gc",
27
+ gcBlobPrefix: "__gc",
28
+ gcTombstoneBlobKey: "__tombstones",
29
+ gcDeletedBlobKey: "__deletedNodes",
30
+ };
31
+ const { blobsTreeName, redirectTableBlobName, blobManagerBasePath, gcTreeKey, gcBlobPrefix, gcTombstoneBlobKey, gcDeletedBlobKey, } = wireFormatConstants;
32
+ /**
33
+ * Upper bound on concurrent `readBlob` calls. Driver/service back-pressure is
34
+ * real for large documents, and unbounded `Promise.all` can trigger throttling
35
+ * or spike memory. The value is a pragmatic middle ground — high enough to
36
+ * keep a typical driver's request pipeline full, low enough to avoid storms.
37
+ */
38
+ const maxReadConcurrency = 32;
39
+ /**
40
+ * Runs `fn` over `items` with at most `limit` promises in flight. Preserves
41
+ * input order on output (not that any caller depends on it today).
42
+ *
43
+ * Exported for unit tests; not part of the package public API.
44
+ *
45
+ * @internal
46
+ */
47
+ export async function mapWithConcurrency(items, limit, fn) {
48
+ const results = Array.from({ length: items.length });
49
+ let cursor = 0;
50
+ const workerCount = Math.min(limit, items.length);
51
+ const workers = Array.from({ length: workerCount }, async () => {
52
+ while (cursor < items.length) {
53
+ const index = cursor++;
54
+ const item = items[index];
55
+ if (item !== undefined) {
56
+ results[index] = await fn(item);
57
+ }
58
+ }
59
+ });
60
+ await Promise.all(workers);
61
+ return results;
62
+ }
63
+ /**
64
+ * Parses the `gc` subtree of a base snapshot. Returns `undefined` if the
65
+ * snapshot has no GC tree (GC disabled or pre-GC document).
66
+ */
67
+ export async function parseGcSnapshotData(baseSnapshot, storage) {
68
+ const gcSnapshotTree = baseSnapshot.trees[gcTreeKey];
69
+ if (gcSnapshotTree === undefined) {
70
+ return undefined;
71
+ }
72
+ let gcState;
73
+ let tombstones;
74
+ let deletedNodes;
75
+ for (const [key, blobId] of Object.entries(gcSnapshotTree.blobs)) {
76
+ if (key === gcDeletedBlobKey) {
77
+ deletedNodes = await readAndParse(storage, blobId);
78
+ }
79
+ else if (key === gcTombstoneBlobKey) {
80
+ tombstones = await readAndParse(storage, blobId);
81
+ }
82
+ else if (key.startsWith(gcBlobPrefix)) {
83
+ const partial = await readAndParse(storage, blobId);
84
+ if (gcState === undefined) {
85
+ gcState = { gcNodes: { ...partial.gcNodes } };
86
+ }
87
+ else {
88
+ for (const [nodeId, nodeData] of Object.entries(partial.gcNodes)) {
89
+ gcState.gcNodes[nodeId] ??= nodeData;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ return { gcState, tombstones, deletedNodes };
95
+ }
96
+ /**
97
+ * Walks a snapshot and inlines the contents of every blob reachable without
98
+ * crossing an `unreferenced` subtree boundary. Subtrees flagged
99
+ * `unreferenced: true` are skipped entirely — the summarizer sets that flag
100
+ * from GC state, so honouring it filters out dead subtrees without a
101
+ * separate GC-path traversal.
102
+ *
103
+ * The root-level `.blobs` subtree is special-cased: only its `.redirectTable`
104
+ * blob is read, because attachment blob contents are captured separately via
105
+ * {@link captureReferencedAttachmentBlobs}.
106
+ */
107
+ export async function readReferencedSnapshotBlobs(snapshot, storage) {
108
+ const { tree, read } = toTreeAndReader(snapshot, storage);
109
+ const ids = new Set();
110
+ collectReferencedBlobIds(tree, true, ids);
111
+ const blobs = {};
112
+ await mapWithConcurrency([...ids], maxReadConcurrency, async (id) => {
113
+ const data = await read(id);
114
+ blobs[id] = bufferToString(data, "utf8");
115
+ });
116
+ return blobs;
117
+ }
118
+ /**
119
+ * Synchronously walks the snapshot tree and gathers the set of blob ids that
120
+ * should be inlined. Subtrees flagged `unreferenced: true` are skipped
121
+ * entirely. The root-level `.blobs` subtree is special-cased: only its
122
+ * `.redirectTable` id is collected, because attachment blob contents are
123
+ * captured separately via {@link captureReferencedAttachmentBlobs}.
124
+ */
125
+ function collectReferencedBlobIds(tree, isRoot, ids) {
126
+ if (tree.unreferenced === true) {
127
+ return;
128
+ }
129
+ for (const blobId of Object.values(tree.blobs)) {
130
+ ids.add(blobId);
131
+ }
132
+ for (const [key, subTree] of Object.entries(tree.trees)) {
133
+ if (isRoot && key === blobsTreeName) {
134
+ const tableBlobId = subTree.blobs[redirectTableBlobName];
135
+ if (tableBlobId !== undefined) {
136
+ ids.add(tableBlobId);
137
+ }
138
+ }
139
+ else {
140
+ collectReferencedBlobIds(subTree, false, ids);
141
+ }
142
+ }
143
+ }
144
+ function toTreeAndReader(snapshot, storage) {
145
+ if ("snapshotTree" in snapshot) {
146
+ const blobContents = snapshot.blobContents;
147
+ return {
148
+ tree: snapshot.snapshotTree,
149
+ read: async (id) => blobContents.get(id) ?? storage.readBlob(id),
150
+ };
151
+ }
152
+ return { tree: snapshot, read: async (id) => storage.readBlob(id) };
153
+ }
154
+ /**
155
+ * Fetches attachment blob contents from a snapshot, filtered by GC
156
+ * reachability. Blobs GC has explicitly marked unreferenced, tombstoned, or
157
+ * deleted are skipped. Blobs absent from the GC graph are kept — GC state
158
+ * lags behind recent attachments and dropping them would lose live data.
159
+ * If `gcData` is `undefined`, every attachment blob is returned.
160
+ *
161
+ * The returned map is keyed by attachment blob storage id. Values are the
162
+ * raw bytes encoded as **base64** strings — attachment blobs may carry
163
+ * arbitrary binary payloads (images, encrypted data, etc.) and a
164
+ * UTF-8 round-trip would silently corrupt non-UTF-8 byte sequences with
165
+ * replacement characters. The runtime's own pending-blob serializer uses
166
+ * base64 for the same reason. This diverges from the structural-blob path
167
+ * in {@link readReferencedSnapshotBlobs}, which encodes UTF-8 because those
168
+ * blobs are JSON or other text the runtime authored. Callers must keep the
169
+ * two encodings on separate fields of the pending state so the load side
170
+ * can decode each correctly.
171
+ */
172
+ export async function captureReferencedAttachmentBlobs(baseSnapshot, storage, gcData) {
173
+ const blobsTree = baseSnapshot.trees[blobsTreeName];
174
+ if (blobsTree === undefined) {
175
+ return {};
176
+ }
177
+ const localIdToStorageId = await readRedirectTable(blobsTree, storage);
178
+ if (localIdToStorageId.size === 0) {
179
+ return {};
180
+ }
181
+ const unreferencedLocalIds = gcData === undefined ? undefined : collectUnreferencedBlobLocalIds(gcData);
182
+ const storageIdsToFetch = new Set();
183
+ for (const [localId, storageId] of localIdToStorageId) {
184
+ if (unreferencedLocalIds?.has(localId) !== true) {
185
+ storageIdsToFetch.add(storageId);
186
+ }
187
+ }
188
+ const contents = {};
189
+ await mapWithConcurrency([...storageIdsToFetch], maxReadConcurrency, async (storageId) => {
190
+ const buffer = await storage.readBlob(storageId);
191
+ contents[storageId] = bufferToString(buffer, "base64");
192
+ });
193
+ return contents;
194
+ }
195
+ /**
196
+ * Reconstructs the BlobManager's redirect table from a `.blobs` subtree.
197
+ * Mirrors `toRedirectTable` in blobManagerSnapSum.ts.
198
+ */
199
+ async function readRedirectTable(blobsTree, storage) {
200
+ const redirectTable = new Map();
201
+ const tableBlobId = blobsTree.blobs[redirectTableBlobName];
202
+ if (tableBlobId !== undefined) {
203
+ const entries = await readAndParse(storage, tableBlobId);
204
+ for (const [localId, storageId] of entries) {
205
+ redirectTable.set(localId, storageId);
206
+ }
207
+ }
208
+ for (const [key, storageId] of Object.entries(blobsTree.blobs)) {
209
+ if (key !== redirectTableBlobName) {
210
+ // Identity mapping: storage ids referenced directly in handles (legacy).
211
+ redirectTable.set(storageId, storageId);
212
+ }
213
+ }
214
+ return redirectTable;
215
+ }
216
+ /**
217
+ * Collects the set of blob localIds that GC has explicitly marked as
218
+ * unreferenced (via `unreferencedTimestampMs` on a gc node), tombstoned, or
219
+ * deleted. Tombstones and deletedNodes are applied regardless of whether
220
+ * `gcState` is present — they are authoritative on their own and must not
221
+ * be silently dropped when gc state is absent but tombstone/deleted lists
222
+ * exist.
223
+ */
224
+ function collectUnreferencedBlobLocalIds(gcData) {
225
+ const blobPathPrefix = `/${blobManagerBasePath}/`;
226
+ const unreferenced = new Set();
227
+ if (gcData.gcState !== undefined) {
228
+ for (const [nodePath, nodeData] of Object.entries(gcData.gcState.gcNodes)) {
229
+ if (nodePath.startsWith(blobPathPrefix) &&
230
+ nodeData.unreferencedTimestampMs !== undefined) {
231
+ unreferenced.add(nodePath.slice(blobPathPrefix.length));
232
+ }
233
+ }
234
+ }
235
+ for (const nodePath of [...(gcData.tombstones ?? []), ...(gcData.deletedNodes ?? [])]) {
236
+ if (nodePath.startsWith(blobPathPrefix)) {
237
+ unreferenced.add(nodePath.slice(blobPathPrefix.length));
238
+ }
239
+ }
240
+ return unreferenced;
241
+ }
242
+ function isBlobAttachLikeMetadata(metadata) {
243
+ if (typeof metadata !== "object" || metadata === null) {
244
+ return false;
245
+ }
246
+ const candidate = metadata;
247
+ return typeof candidate.localId === "string" && typeof candidate.blobId === "string";
248
+ }
249
+ /**
250
+ * Extracts every `BlobAttach` reference an op carries. Returns an empty array
251
+ * for non-blobAttach ops.
252
+ *
253
+ * This is the single place in the loader that interprets the BlobAttach
254
+ * wire format. Capture and load-side reasoning about ops should call into
255
+ * this function rather than reading `op.metadata` directly, so a future
256
+ * protocol change touches one site.
257
+ *
258
+ * BlobAttach ops carry `(localId, storageId)` directly on
259
+ * `ISequencedDocumentMessage.metadata` and are not grouped — the container
260
+ * runtime routes them through a separate `outbox.submitBlobAttach` lane,
261
+ * and `OpGroupingManager.groupBatch` asserts (0x5dd) that no op carrying
262
+ * non-batch metadata enters a grouped batch. If either guarantee changes,
263
+ * extend this function rather than each call site.
264
+ *
265
+ * @internal
266
+ */
267
+ export function extractBlobAttachReferences(op) {
268
+ if (!isBlobAttachLikeMetadata(op.metadata)) {
269
+ return [];
270
+ }
271
+ return [{ localId: op.metadata.localId, storageId: op.metadata.blobId }];
272
+ }
273
+ /**
274
+ * Set of attachment-blob localIds that GC has marked unreferenced,
275
+ * tombstoned, or deleted in the base snapshot. `undefined` if `gcData`
276
+ * is `undefined` (GC disabled / pre-GC document).
277
+ *
278
+ * @internal
279
+ */
280
+ export function unreferencedAttachmentBlobLocalIds(gcData) {
281
+ return gcData === undefined ? undefined : collectUnreferencedBlobLocalIds(gcData);
282
+ }
283
+ /**
284
+ * Inline attachment blob contents for the given `(localId, storageId)`
285
+ * references. Skips entries already present in `existing` (de-dupe with
286
+ * the snapshot path) and entries whose `localId` is in
287
+ * `unreferencedLocalIds`. Returns only the freshly-read entries; the
288
+ * caller merges them into the existing map.
289
+ *
290
+ * @internal
291
+ */
292
+ export async function inlineAttachmentBlobsByReference(references, storage, unreferencedLocalIds, existing) {
293
+ const storageIdsToFetch = new Set();
294
+ for (const { localId, storageId } of references) {
295
+ if (unreferencedLocalIds?.has(localId) === true) {
296
+ continue;
297
+ }
298
+ if (existing[storageId] !== undefined) {
299
+ continue;
300
+ }
301
+ storageIdsToFetch.add(storageId);
302
+ }
303
+ const added = {};
304
+ if (storageIdsToFetch.size === 0) {
305
+ return added;
306
+ }
307
+ await mapWithConcurrency([...storageIdsToFetch], maxReadConcurrency, async (storageId) => {
308
+ const buffer = await storage.readBlob(storageId);
309
+ added[storageId] = bufferToString(buffer, "base64");
310
+ });
311
+ return added;
312
+ }
313
+ /**
314
+ * Returns true if any referenced subtree of `baseSnapshot` declares a
315
+ * `groupId` — the snapshot-tree wire field that carries the runtime's
316
+ * loading-group identifier. Subtrees flagged `unreferenced` are skipped —
317
+ * a dead subtree's `groupId` would not be loaded by the runtime either.
318
+ *
319
+ * `captureFullContainerState` does not yet support loading groups: prefetching
320
+ * per-group snapshots adds a code path that has no end-to-end coverage and no
321
+ * known production consumer. Callers use this to fail fast with a `UsageError`
322
+ * rather than silently producing a pending state that omits group data.
323
+ */
324
+ export function snapshotHasLoadingGroups(baseSnapshot) {
325
+ if (baseSnapshot.unreferenced === true) {
326
+ return false;
327
+ }
328
+ if (baseSnapshot.groupId !== undefined) {
329
+ return true;
330
+ }
331
+ for (const child of Object.values(baseSnapshot.trees)) {
332
+ if (snapshotHasLoadingGroups(child)) {
333
+ return true;
334
+ }
335
+ }
336
+ return false;
337
+ }
338
+ //# sourceMappingURL=captureReferencedContents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captureReferencedContents.js","sourceRoot":"","sources":["../src/captureReferencedContents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAO9D,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAOrE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,aAAa,EAAE,QAAQ;IACvB,qBAAqB,EAAE,gBAAgB;IACvC,mBAAmB,EAAE,QAAQ;IAC7B,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,MAAM;IACpB,kBAAkB,EAAE,cAAc;IAClC,gBAAgB,EAAE,gBAAgB;CACzB,CAAC;AAEX,MAAM,EACL,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,GAChB,GAAG,mBAAmB,CAAC;AAuBxB;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,KAAmB,EACnB,KAAa,EACb,EAA2B;IAE3B,MAAM,OAAO,GAAQ,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1D,IAAI,MAAM,GAAG,CAAC,CAAC;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AI,wBAAwB,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport type {\n\tIDocumentStorageService,\n\tISequencedDocumentMessage,\n\tISnapshot,\n\tISnapshotTree,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { readAndParse } from \"@fluidframework/driver-utils/internal\";\n\nimport type {\n\tIBase64BlobContents,\n\tISerializableBlobContents,\n} from \"./containerStorageAdapter.js\";\n\n/**\n * Wire-format constants this module needs to walk and filter snapshots.\n * Authoritative definitions live in `container-runtime` and\n * `runtime-definitions`; the values are duplicated here to avoid a\n * loader → runtime layering dependency. A contract test in\n * `packages/test/local-server-tests` asserts these match the authoritative\n * values; do not change them in isolation.\n *\n * Authoritative sources:\n * - `blobsTreeName`, `redirectTableBlobName`: `packages/runtime/container-runtime/src/blobManager/blobManagerSnapSum.ts`\n * - `blobManagerBasePath`: `packages/runtime/container-runtime/src/blobManager/blobManager.ts`\n * - `gcTreeKey`, `gcBlobPrefix`, `gcTombstoneBlobKey`, `gcDeletedBlobKey`: `packages/runtime/runtime-definitions/src/garbageCollectionDefinitions.ts`\n *\n * @internal\n */\nexport const wireFormatConstants = {\n\tblobsTreeName: \".blobs\",\n\tredirectTableBlobName: \".redirectTable\",\n\tblobManagerBasePath: \"_blobs\",\n\tgcTreeKey: \"gc\",\n\tgcBlobPrefix: \"__gc\",\n\tgcTombstoneBlobKey: \"__tombstones\",\n\tgcDeletedBlobKey: \"__deletedNodes\",\n} as const;\n\nconst {\n\tblobsTreeName,\n\tredirectTableBlobName,\n\tblobManagerBasePath,\n\tgcTreeKey,\n\tgcBlobPrefix,\n\tgcTombstoneBlobKey,\n\tgcDeletedBlobKey,\n} = wireFormatConstants;\n\ninterface IGcNodeData {\n\toutboundRoutes: string[];\n\tunreferencedTimestampMs?: number;\n}\n\ninterface IGcState {\n\tgcNodes: { [id: string]: IGcNodeData };\n}\n\n/**\n * The parsed subset of the `gc` subtree that drives reachability decisions.\n */\nexport interface IGcSnapshotData {\n\tgcState: IGcState | undefined;\n\ttombstones: string[] | undefined;\n\tdeletedNodes: string[] | undefined;\n}\n\n/** Reader that returns a blob's contents for a given storage id. */\ntype BlobReader = (id: string) => Promise<ArrayBufferLike>;\n\n/**\n * Upper bound on concurrent `readBlob` calls. Driver/service back-pressure is\n * real for large documents, and unbounded `Promise.all` can trigger throttling\n * or spike memory. The value is a pragmatic middle ground — high enough to\n * keep a typical driver's request pipeline full, low enough to avoid storms.\n */\nconst maxReadConcurrency = 32;\n\n/**\n * Runs `fn` over `items` with at most `limit` promises in flight. Preserves\n * input order on output (not that any caller depends on it today).\n *\n * Exported for unit tests; not part of the package public API.\n *\n * @internal\n */\nexport async function mapWithConcurrency<T, R>(\n\titems: readonly T[],\n\tlimit: number,\n\tfn: (item: T) => Promise<R>,\n): Promise<R[]> {\n\tconst results: R[] = Array.from({ length: items.length });\n\tlet cursor = 0;\n\tconst workerCount = Math.min(limit, items.length);\n\tconst workers = Array.from({ length: workerCount }, async () => {\n\t\twhile (cursor < items.length) {\n\t\t\tconst index = cursor++;\n\t\t\tconst item = items[index];\n\t\t\tif (item !== undefined) {\n\t\t\t\tresults[index] = await fn(item);\n\t\t\t}\n\t\t}\n\t});\n\tawait Promise.all(workers);\n\treturn results;\n}\n\n/**\n * Parses the `gc` subtree of a base snapshot. Returns `undefined` if the\n * snapshot has no GC tree (GC disabled or pre-GC document).\n */\nexport async function parseGcSnapshotData(\n\tbaseSnapshot: ISnapshotTree,\n\tstorage: Pick<IDocumentStorageService, \"readBlob\">,\n): Promise<IGcSnapshotData | undefined> {\n\tconst gcSnapshotTree: ISnapshotTree | undefined = baseSnapshot.trees[gcTreeKey];\n\tif (gcSnapshotTree === undefined) {\n\t\treturn undefined;\n\t}\n\tlet gcState: IGcState | undefined;\n\tlet tombstones: string[] | undefined;\n\tlet deletedNodes: string[] | undefined;\n\tfor (const [key, blobId] of Object.entries(gcSnapshotTree.blobs)) {\n\t\tif (key === gcDeletedBlobKey) {\n\t\t\tdeletedNodes = await readAndParse<string[]>(storage, blobId);\n\t\t} else if (key === gcTombstoneBlobKey) {\n\t\t\ttombstones = await readAndParse<string[]>(storage, blobId);\n\t\t} else if (key.startsWith(gcBlobPrefix)) {\n\t\t\tconst partial = await readAndParse<IGcState>(storage, blobId);\n\t\t\tif (gcState === undefined) {\n\t\t\t\tgcState = { gcNodes: { ...partial.gcNodes } };\n\t\t\t} else {\n\t\t\t\tfor (const [nodeId, nodeData] of Object.entries(partial.gcNodes)) {\n\t\t\t\t\tgcState.gcNodes[nodeId] ??= nodeData;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn { gcState, tombstones, deletedNodes };\n}\n\n/**\n * Walks a snapshot and inlines the contents of every blob reachable without\n * crossing an `unreferenced` subtree boundary. Subtrees flagged\n * `unreferenced: true` are skipped entirely — the summarizer sets that flag\n * from GC state, so honouring it filters out dead subtrees without a\n * separate GC-path traversal.\n *\n * The root-level `.blobs` subtree is special-cased: only its `.redirectTable`\n * blob is read, because attachment blob contents are captured separately via\n * {@link captureReferencedAttachmentBlobs}.\n */\nexport async function readReferencedSnapshotBlobs(\n\tsnapshot: ISnapshot | ISnapshotTree,\n\tstorage: Pick<IDocumentStorageService, \"readBlob\">,\n): Promise<ISerializableBlobContents> {\n\tconst { tree, read } = toTreeAndReader(snapshot, storage);\n\tconst ids = new Set<string>();\n\tcollectReferencedBlobIds(tree, true, ids);\n\tconst blobs: ISerializableBlobContents = {};\n\tawait mapWithConcurrency([...ids], maxReadConcurrency, async (id) => {\n\t\tconst data = await read(id);\n\t\tblobs[id] = bufferToString(data, \"utf8\");\n\t});\n\treturn blobs;\n}\n\n/**\n * Synchronously walks the snapshot tree and gathers the set of blob ids that\n * should be inlined. Subtrees flagged `unreferenced: true` are skipped\n * entirely. The root-level `.blobs` subtree is special-cased: only its\n * `.redirectTable` id is collected, because attachment blob contents are\n * captured separately via {@link captureReferencedAttachmentBlobs}.\n */\nfunction collectReferencedBlobIds(\n\ttree: ISnapshotTree,\n\tisRoot: boolean,\n\tids: Set<string>,\n): void {\n\tif (tree.unreferenced === true) {\n\t\treturn;\n\t}\n\tfor (const blobId of Object.values(tree.blobs)) {\n\t\tids.add(blobId);\n\t}\n\tfor (const [key, subTree] of Object.entries(tree.trees)) {\n\t\tif (isRoot && key === blobsTreeName) {\n\t\t\tconst tableBlobId = subTree.blobs[redirectTableBlobName];\n\t\t\tif (tableBlobId !== undefined) {\n\t\t\t\tids.add(tableBlobId);\n\t\t\t}\n\t\t} else {\n\t\t\tcollectReferencedBlobIds(subTree, false, ids);\n\t\t}\n\t}\n}\n\nfunction toTreeAndReader(\n\tsnapshot: ISnapshot | ISnapshotTree,\n\tstorage: Pick<IDocumentStorageService, \"readBlob\">,\n): { tree: ISnapshotTree; read: BlobReader } {\n\tif (\"snapshotTree\" in snapshot) {\n\t\tconst blobContents = snapshot.blobContents;\n\t\treturn {\n\t\t\ttree: snapshot.snapshotTree,\n\t\t\tread: async (id) => blobContents.get(id) ?? storage.readBlob(id),\n\t\t};\n\t}\n\treturn { tree: snapshot, read: async (id) => storage.readBlob(id) };\n}\n\n/**\n * Fetches attachment blob contents from a snapshot, filtered by GC\n * reachability. Blobs GC has explicitly marked unreferenced, tombstoned, or\n * deleted are skipped. Blobs absent from the GC graph are kept — GC state\n * lags behind recent attachments and dropping them would lose live data.\n * If `gcData` is `undefined`, every attachment blob is returned.\n *\n * The returned map is keyed by attachment blob storage id. Values are the\n * raw bytes encoded as **base64** strings — attachment blobs may carry\n * arbitrary binary payloads (images, encrypted data, etc.) and a\n * UTF-8 round-trip would silently corrupt non-UTF-8 byte sequences with\n * replacement characters. The runtime's own pending-blob serializer uses\n * base64 for the same reason. This diverges from the structural-blob path\n * in {@link readReferencedSnapshotBlobs}, which encodes UTF-8 because those\n * blobs are JSON or other text the runtime authored. Callers must keep the\n * two encodings on separate fields of the pending state so the load side\n * can decode each correctly.\n */\nexport async function captureReferencedAttachmentBlobs(\n\tbaseSnapshot: ISnapshotTree,\n\tstorage: Pick<IDocumentStorageService, \"readBlob\">,\n\tgcData: IGcSnapshotData | undefined,\n): Promise<IBase64BlobContents> {\n\tconst blobsTree: ISnapshotTree | undefined = baseSnapshot.trees[blobsTreeName];\n\tif (blobsTree === undefined) {\n\t\treturn {};\n\t}\n\tconst localIdToStorageId = await readRedirectTable(blobsTree, storage);\n\tif (localIdToStorageId.size === 0) {\n\t\treturn {};\n\t}\n\n\tconst unreferencedLocalIds =\n\t\tgcData === undefined ? undefined : collectUnreferencedBlobLocalIds(gcData);\n\n\tconst storageIdsToFetch = new Set<string>();\n\tfor (const [localId, storageId] of localIdToStorageId) {\n\t\tif (unreferencedLocalIds?.has(localId) !== true) {\n\t\t\tstorageIdsToFetch.add(storageId);\n\t\t}\n\t}\n\n\tconst contents: IBase64BlobContents = {};\n\tawait mapWithConcurrency([...storageIdsToFetch], maxReadConcurrency, async (storageId) => {\n\t\tconst buffer = await storage.readBlob(storageId);\n\t\tcontents[storageId] = bufferToString(buffer, \"base64\");\n\t});\n\treturn contents;\n}\n\n/**\n * Reconstructs the BlobManager's redirect table from a `.blobs` subtree.\n * Mirrors `toRedirectTable` in blobManagerSnapSum.ts.\n */\nasync function readRedirectTable(\n\tblobsTree: ISnapshotTree,\n\tstorage: Pick<IDocumentStorageService, \"readBlob\">,\n): Promise<Map<string, string>> {\n\tconst redirectTable = new Map<string, string>();\n\tconst tableBlobId: string | undefined = blobsTree.blobs[redirectTableBlobName];\n\tif (tableBlobId !== undefined) {\n\t\tconst entries = await readAndParse<[string, string][]>(storage, tableBlobId);\n\t\tfor (const [localId, storageId] of entries) {\n\t\t\tredirectTable.set(localId, storageId);\n\t\t}\n\t}\n\tfor (const [key, storageId] of Object.entries(blobsTree.blobs)) {\n\t\tif (key !== redirectTableBlobName) {\n\t\t\t// Identity mapping: storage ids referenced directly in handles (legacy).\n\t\t\tredirectTable.set(storageId, storageId);\n\t\t}\n\t}\n\treturn redirectTable;\n}\n\n/**\n * Collects the set of blob localIds that GC has explicitly marked as\n * unreferenced (via `unreferencedTimestampMs` on a gc node), tombstoned, or\n * deleted. Tombstones and deletedNodes are applied regardless of whether\n * `gcState` is present — they are authoritative on their own and must not\n * be silently dropped when gc state is absent but tombstone/deleted lists\n * exist.\n */\nfunction collectUnreferencedBlobLocalIds(gcData: IGcSnapshotData): Set<string> {\n\tconst blobPathPrefix = `/${blobManagerBasePath}/`;\n\tconst unreferenced = new Set<string>();\n\tif (gcData.gcState !== undefined) {\n\t\tfor (const [nodePath, nodeData] of Object.entries(gcData.gcState.gcNodes)) {\n\t\t\tif (\n\t\t\t\tnodePath.startsWith(blobPathPrefix) &&\n\t\t\t\tnodeData.unreferencedTimestampMs !== undefined\n\t\t\t) {\n\t\t\t\tunreferenced.add(nodePath.slice(blobPathPrefix.length));\n\t\t\t}\n\t\t}\n\t}\n\tfor (const nodePath of [...(gcData.tombstones ?? []), ...(gcData.deletedNodes ?? [])]) {\n\t\tif (nodePath.startsWith(blobPathPrefix)) {\n\t\t\tunreferenced.add(nodePath.slice(blobPathPrefix.length));\n\t\t}\n\t}\n\treturn unreferenced;\n}\n\n/**\n * A blob reference extracted from a `BlobAttach` op. `localId` is the\n * `BlobManager` GC identity for the blob; `storageId` is the id used for\n * `IDocumentStorageService.readBlob`.\n *\n * @internal\n */\nexport interface IBlobAttachReference {\n\treadonly localId: string;\n\treadonly storageId: string;\n}\n\ninterface IBlobAttachLikeMetadata {\n\treadonly localId: string;\n\treadonly blobId: string;\n}\n\nfunction isBlobAttachLikeMetadata(metadata: unknown): metadata is IBlobAttachLikeMetadata {\n\tif (typeof metadata !== \"object\" || metadata === null) {\n\t\treturn false;\n\t}\n\tconst candidate = metadata as { localId?: unknown; blobId?: unknown };\n\treturn typeof candidate.localId === \"string\" && typeof candidate.blobId === \"string\";\n}\n\n/**\n * Extracts every `BlobAttach` reference an op carries. Returns an empty array\n * for non-blobAttach ops.\n *\n * This is the single place in the loader that interprets the BlobAttach\n * wire format. Capture and load-side reasoning about ops should call into\n * this function rather than reading `op.metadata` directly, so a future\n * protocol change touches one site.\n *\n * BlobAttach ops carry `(localId, storageId)` directly on\n * `ISequencedDocumentMessage.metadata` and are not grouped — the container\n * runtime routes them through a separate `outbox.submitBlobAttach` lane,\n * and `OpGroupingManager.groupBatch` asserts (0x5dd) that no op carrying\n * non-batch metadata enters a grouped batch. If either guarantee changes,\n * extend this function rather than each call site.\n *\n * @internal\n */\nexport function extractBlobAttachReferences(\n\top: Pick<ISequencedDocumentMessage, \"metadata\">,\n): IBlobAttachReference[] {\n\tif (!isBlobAttachLikeMetadata(op.metadata)) {\n\t\treturn [];\n\t}\n\treturn [{ localId: op.metadata.localId, storageId: op.metadata.blobId }];\n}\n\n/**\n * Set of attachment-blob localIds that GC has marked unreferenced,\n * tombstoned, or deleted in the base snapshot. `undefined` if `gcData`\n * is `undefined` (GC disabled / pre-GC document).\n *\n * @internal\n */\nexport function unreferencedAttachmentBlobLocalIds(\n\tgcData: IGcSnapshotData | undefined,\n): Set<string> | undefined {\n\treturn gcData === undefined ? undefined : collectUnreferencedBlobLocalIds(gcData);\n}\n\n/**\n * Inline attachment blob contents for the given `(localId, storageId)`\n * references. Skips entries already present in `existing` (de-dupe with\n * the snapshot path) and entries whose `localId` is in\n * `unreferencedLocalIds`. Returns only the freshly-read entries; the\n * caller merges them into the existing map.\n *\n * @internal\n */\nexport async function inlineAttachmentBlobsByReference(\n\treferences: readonly IBlobAttachReference[],\n\tstorage: Pick<IDocumentStorageService, \"readBlob\">,\n\tunreferencedLocalIds: ReadonlySet<string> | undefined,\n\texisting: Readonly<IBase64BlobContents>,\n): Promise<IBase64BlobContents> {\n\tconst storageIdsToFetch = new Set<string>();\n\tfor (const { localId, storageId } of references) {\n\t\tif (unreferencedLocalIds?.has(localId) === true) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (existing[storageId] !== undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tstorageIdsToFetch.add(storageId);\n\t}\n\tconst added: IBase64BlobContents = {};\n\tif (storageIdsToFetch.size === 0) {\n\t\treturn added;\n\t}\n\tawait mapWithConcurrency([...storageIdsToFetch], maxReadConcurrency, async (storageId) => {\n\t\tconst buffer = await storage.readBlob(storageId);\n\t\tadded[storageId] = bufferToString(buffer, \"base64\");\n\t});\n\treturn added;\n}\n\n/**\n * Returns true if any referenced subtree of `baseSnapshot` declares a\n * `groupId` — the snapshot-tree wire field that carries the runtime's\n * loading-group identifier. Subtrees flagged `unreferenced` are skipped —\n * a dead subtree's `groupId` would not be loaded by the runtime either.\n *\n * `captureFullContainerState` does not yet support loading groups: prefetching\n * per-group snapshots adds a code path that has no end-to-end coverage and no\n * known production consumer. Callers use this to fail fast with a `UsageError`\n * rather than silently producing a pending state that omits group data.\n */\nexport function snapshotHasLoadingGroups(baseSnapshot: ISnapshotTree): boolean {\n\tif (baseSnapshot.unreferenced === true) {\n\t\treturn false;\n\t}\n\tif (baseSnapshot.groupId !== undefined) {\n\t\treturn true;\n\t}\n\tfor (const child of Object.values(baseSnapshot.trees)) {\n\t\tif (snapshotHasLoadingGroups(child)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connectionManager.d.ts","sourceRoot":"","sources":["../src/connectionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,KAAK,EACX,WAAW,EACX,YAAY,EACZ,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,KAAK,wBAAwB,EAAY,MAAM,iCAAiC,CAAC;AAI1F,OAAO,KAAK,EACX,cAAc,EACd,OAAO,EACP,cAAc,EACd,MAAM,oCAAoC,CAAC;AAC5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AE,uBAAuB,EAAE,gBAAgB,GAAE,OAAc,GAAG,IAAI;IA4BvF;;;OAGG;IACI,gBAAgB,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,4BAA4B,GAAG,IAAI;IAcxF;;OAEG;IACI,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAoC7C,OAAO,CAAC,uBAAuB;IAWxB,OAAO,CAAC,MAAM,EAAE,4BAA4B,EAAE,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI;YAO7E,WAAW;IAgPzB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;OAKG;IACH,OAAO,CAAC,yBAAyB;IAyCjC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAiBxB;;;;OAIG;IACH,OAAO,CAAC,4BAA4B;IA0JpC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAMxB;;;;;;OAMG;YACW,SAAS;IA8DhB,oBAAoB,CAC1B,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,GACrD,gBAAgB,GAAG,SAAS;IAuCxB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ5D,YAAY,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,IAAI;IAkDhD,0BAA0B,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI;IAgD3E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAMxB;IAEF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAI5B;IAGF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAkB1B;IAGF,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAIxC;IAEF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAE3B;CACF"}
@@ -11,7 +11,7 @@ import { calculateMaxWaitTime, canRetryOnError, createGenericNetworkError, creat
11
11
  import { GenericError, UsageError, formatTick, generateStack, isFluidError, normalizeError, } from "@fluidframework/telemetry-utils/internal";
12
12
  import { ReconnectMode, } from "./contracts.js";
13
13
  import { DeltaQueue } from "./deltaQueue.js";
14
- import { FrozenDeltaStream, isFrozenDeltaStreamConnection } from "./frozenServices.js";
14
+ import { FrozenDeltaStream, isFrozenDeltaStreamConnection, isWritableFrozenDeltaStreamConnection, } from "./frozenServices.js";
15
15
  import { SignalType } from "./protocol.js";
16
16
  import { isDeltaStreamConnectionForbiddenError } from "./utils.js";
17
17
  // We double this value in first try in when we calculate time to wait for in "calculateMaxWaitTime" function.
@@ -418,20 +418,19 @@ export class ConnectionManager {
418
418
  connected: connection !== undefined && connection.disposed === false,
419
419
  }, undefined, LogLevel.verbose);
420
420
  if (isDeltaStreamConnectionForbiddenError(origError)) {
421
- connection = new FrozenDeltaStream(origError.storageOnlyReason, {
422
- text: origError.message,
423
- error: origError,
421
+ connection = new FrozenDeltaStream({
422
+ storageOnlyReason: origError.storageOnlyReason,
423
+ readonlyConnectionReason: { text: origError.message, error: origError },
424
424
  });
425
425
  requestedMode = "read";
426
426
  break;
427
427
  }
428
428
  else if (isFluidError(origError) &&
429
429
  origError.errorType === DriverErrorTypes.outOfStorageError) {
430
- // If we get out of storage error from calling joinsession, then use the NoDeltaStream object so
430
+ // If we get out of storage error from calling joinsession, then use the FrozenDeltaStream object so
431
431
  // that user can at least load the container.
432
- connection = new FrozenDeltaStream(undefined, {
433
- text: origError.message,
434
- error: origError,
432
+ connection = new FrozenDeltaStream({
433
+ readonlyConnectionReason: { text: origError.message, error: origError },
435
434
  });
436
435
  requestedMode = "read";
437
436
  break;
@@ -804,6 +803,25 @@ export class ConnectionManager {
804
803
  }
805
804
  sendMessages(messages) {
806
805
  assert(this.connected, 0x2b4 /* "not connected on sending ops!" */);
806
+ // WritableFrozenDeltaStream short-circuit: writable-frozen containers
807
+ // (`loadFrozenContainerFromPendingState({ readOnly: false })`) attach a
808
+ // WritableFrozenDeltaStream as the live connection. Its `mode` is "read" (advertising
809
+ // "write" would imply quorum membership we cannot honor), so a runtime submit
810
+ // would otherwise fall into the read-mode reconnect branch below. That branch
811
+ // schedules `reconnect("write")`, which under `ReconnectMode.Never`
812
+ // (`allowReconnect: false`) calls `closeHandler` and closes the container — the
813
+ // opposite of what writable-frozen wants. Drop the messages here: the runtime's
814
+ // outbox keeps them in `pendingStateManager` so `getPendingLocalState()` can
815
+ // capture them, which is the entire point of the writable-frozen flow.
816
+ //
817
+ // Match only the writable variant (a sibling class, not a subclass) so the read-only
818
+ // `FrozenDeltaStream` retains its `submit` 403-nack tripwire — a stray submit on a
819
+ // storage-only frozen connection signals an upstream invariant break and should
820
+ // remain observable. The read-only variant shouldn't reach here in normal flow anyway
821
+ // (its `storageOnly` policy keeps the runtime from submitting).
822
+ if (isWritableFrozenDeltaStreamConnection(this.connection)) {
823
+ return;
824
+ }
807
825
  // If connection is "read" or implicit "read" (got leave op for "write" connection),
808
826
  // then op can't make it through - we will get a nack if op is sent.
809
827
  // We can short-circuit this process.