@sentropic/artifacts 0.2.10 → 0.2.12

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.12
4
+
5
+ - Bounded concurrency in multi-file publication blob staging (#art-conc, P1):
6
+ `publishFinalized` no longer issues one `putBlob` per file in a sequential
7
+ loop and `verifyStagedBlobs` no longer issues one `getBlob` per file
8
+ sequentially. Both now run through a shared worker pool with a default of 6
9
+ in-flight operations, configurable via `blobConcurrency` on the publication
10
+ service deps and clamped to at most 8 (`MAX_BLOB_CONCURRENCY`), so no
11
+ unbounded parallelism is possible. On slow S3 hosts (e.g. OVH BHS at
12
+ 1.1–1.5 s per request) a 30-file `artifacts_publish` now takes about
13
+ ceil(n/k) round trips instead of n, staying inside the host blob budget
14
+ instead of returning 503 `provider_unavailable`.
15
+ - The pool keeps the sequential loop's guarantees: all-or-nothing publication
16
+ (intent, pins, cleanup and finalization paths unchanged), the same
17
+ per-operation error projection (the first fatal error is rethrown unchanged,
18
+ so provider error codes and failure mapping are identical), and one shared
19
+ deadline across the whole batch when `blobDeadlineMs` is configured — no new
20
+ blob operation starts after it, and expiry classifies exactly like a
21
+ provider timeout (503 `provider_unavailable`). MCP tool definitions are
22
+ byte-identical.
23
+
3
24
  ## 0.2.10
4
25
 
5
26
  - G1 sharing access model: artifacts carry an explicit `access_mode`
@@ -10,7 +10,7 @@ export { createRadarKeyDerivation } from './server/command-identity.js';
10
10
  export type { ArtifactKeyDerivationBinding } from './server/command-identity.js';
11
11
  export declare const ARTIFACTS_PROVIDER_ID = "sentropic.artifacts";
12
12
  export declare const ARTIFACTS_APP_ID = "sentropic-artifacts";
13
- export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.10";
13
+ export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.12";
14
14
  export declare const ARTIFACTS_TOOL_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert"];
15
15
  export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
16
16
  export interface ArtifactsToolDefinition {
package/dist/mcp-core.js CHANGED
@@ -6,7 +6,7 @@ export * from './profile/index.js';
6
6
  export { createRadarKeyDerivation } from './server/command-identity.js';
7
7
  export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
8
8
  export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
9
- export const ARTIFACTS_PROVIDER_VERSION = '0.2.10';
9
+ export const ARTIFACTS_PROVIDER_VERSION = '0.2.12';
10
10
  export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
11
11
  // ---------------------------------------------------------------------------
12
12
  // Byte-stable tool definitions (MCP tool-definition stability rule).
@@ -62,6 +62,35 @@ export interface PublishResult {
62
62
  releaseId: string;
63
63
  manifest: string;
64
64
  }
65
+ /** Default bounded in-flight blob operations per publish batch. */
66
+ export declare const DEFAULT_BLOB_CONCURRENCY = 6;
67
+ /** Hard ceiling for the configurable blob concurrency: no unbounded parallelism. */
68
+ export declare const MAX_BLOB_CONCURRENCY = 8;
69
+ /** Resolve the bounded blob-operation concurrency: default 6, clamped to 8, never below 1. */
70
+ export declare function resolveBlobConcurrency(value: number | undefined): number;
71
+ export interface BlobPoolOptions {
72
+ /** Resolved max operations in flight (1..MAX_BLOB_CONCURRENCY). */
73
+ readonly concurrency: number;
74
+ /** One deadline (epoch ms) shared by every operation of the batch; no new operation starts after it. */
75
+ readonly deadlineAt?: number;
76
+ /** Checked before each operation starts; a throw becomes the batch's first fatal error. */
77
+ readonly beforeEach?: () => void | Promise<void>;
78
+ }
79
+ /**
80
+ * Run one async operation per item with bounded concurrency. At most
81
+ * `concurrency` operations are in flight at any time; every operation of the
82
+ * batch shares the same `deadlineAt`; the first fatal error stops scheduling
83
+ * (in-flight operations run to completion — the blob-store port has no abort
84
+ * signal) and is rethrown unchanged, so the per-operation error projection is
85
+ * identical to the sequential loop.
86
+ */
87
+ export declare function runBlobPool<T>(items: readonly T[], options: BlobPoolOptions, operation: (item: T) => Promise<void>): Promise<void>;
88
+ export interface VerifyStagedOptions {
89
+ /** Bounded in-flight read-backs; defaults to DEFAULT_BLOB_CONCURRENCY, clamped to MAX_BLOB_CONCURRENCY. */
90
+ readonly concurrency?: number;
91
+ /** Shared deadline (epoch ms) for the whole read-back batch. */
92
+ readonly deadlineAt?: number;
93
+ }
65
94
  export interface PublicationService {
66
95
  readonly limits?: Readonly<PublicationLimits>;
67
96
  /** The host source store participates in the idempotent commit when a source is supplied. */
@@ -78,6 +107,8 @@ export declare function createPublicationService(deps: {
78
107
  intents: IntentStore;
79
108
  idempotency?: IdempotencyStore;
80
109
  limits?: Partial<PublicationLimits>;
110
+ /** Bounded in-flight blob read-backs per publish; default 6, clamped to 8. */
111
+ blobConcurrency?: number;
81
112
  }): PublicationService;
82
113
  /**
83
114
  * L4 (immo #861) — guarded publication through the L3 atomic finalization
@@ -155,6 +186,10 @@ export interface GuardedPublicationDeps {
155
186
  readonly noteAbandoned?: (attemptId: string) => void | Promise<void>;
156
187
  readonly cleanupWindowMs?: number;
157
188
  readonly limits?: Partial<PublicationLimits>;
189
+ /** Bounded in-flight blob PUTs/read-backs per publish; default 6, clamped to 8. */
190
+ readonly blobConcurrency?: number;
191
+ /** Per-publish blob-staging budget in ms; one shared deadline for every concurrent blob operation. */
192
+ readonly blobDeadlineMs?: number;
158
193
  }
159
194
  export interface GuardedPublicationService {
160
195
  replayFinalized(input: Omit<GuardedPublishInput, 'files' | 'source' | 'profile'>): Promise<FinalizeResult | undefined>;
@@ -105,9 +105,68 @@ function preparePublication(input) {
105
105
  const manifest = canonicalManifest({ ...body, digest });
106
106
  return { entries, digest, manifest };
107
107
  }
108
- /** Read-back verification shared by the split and finalized paths. */
109
- async function verifyStagedBlobs(blobs, entries) {
110
- for (const { key, bytes } of entries) {
108
+ /** Default bounded in-flight blob operations per publish batch. */
109
+ export const DEFAULT_BLOB_CONCURRENCY = 6;
110
+ /** Hard ceiling for the configurable blob concurrency: no unbounded parallelism. */
111
+ export const MAX_BLOB_CONCURRENCY = 8;
112
+ /** Resolve the bounded blob-operation concurrency: default 6, clamped to 8, never below 1. */
113
+ export function resolveBlobConcurrency(value) {
114
+ if (value === undefined)
115
+ return DEFAULT_BLOB_CONCURRENCY;
116
+ if (!Number.isSafeInteger(value) || value < 1)
117
+ throw new Error('invalid blob concurrency');
118
+ return Math.min(value, MAX_BLOB_CONCURRENCY);
119
+ }
120
+ /** Deadline expiry is projected exactly like a provider timeout (failures.ts TIMEOUT_NAMES). */
121
+ function blobDeadlineError() {
122
+ const error = new Error('blob staging deadline exceeded');
123
+ error.name = 'TimeoutError';
124
+ return error;
125
+ }
126
+ /**
127
+ * Run one async operation per item with bounded concurrency. At most
128
+ * `concurrency` operations are in flight at any time; every operation of the
129
+ * batch shares the same `deadlineAt`; the first fatal error stops scheduling
130
+ * (in-flight operations run to completion — the blob-store port has no abort
131
+ * signal) and is rethrown unchanged, so the per-operation error projection is
132
+ * identical to the sequential loop.
133
+ */
134
+ export async function runBlobPool(items, options, operation) {
135
+ let next = 0;
136
+ let fatal;
137
+ const worker = async () => {
138
+ for (;;) {
139
+ if (fatal !== undefined)
140
+ return;
141
+ if (options.deadlineAt !== undefined && Date.now() >= options.deadlineAt) {
142
+ fatal = { error: blobDeadlineError() };
143
+ return;
144
+ }
145
+ const index = next++;
146
+ if (index >= items.length)
147
+ return;
148
+ try {
149
+ if (options.beforeEach !== undefined)
150
+ await options.beforeEach();
151
+ await operation(items[index]);
152
+ }
153
+ catch (error) {
154
+ fatal = { error };
155
+ return;
156
+ }
157
+ }
158
+ };
159
+ const workers = Array.from({ length: Math.max(1, Math.min(options.concurrency, items.length)) }, () => worker());
160
+ await Promise.all(workers);
161
+ if (fatal !== undefined)
162
+ throw fatal.error;
163
+ }
164
+ /** Read-back verification shared by the split and finalized paths (bounded concurrency). */
165
+ async function verifyStagedBlobs(blobs, entries, options = {}) {
166
+ await runBlobPool(entries, {
167
+ concurrency: resolveBlobConcurrency(options.concurrency),
168
+ ...(options.deadlineAt === undefined ? {} : { deadlineAt: options.deadlineAt }),
169
+ }, async ({ key, bytes }) => {
111
170
  const stored = await blobs.getBlob(key);
112
171
  if (stored === undefined || shaHex(stored) !== shaHex(bytes)) {
113
172
  throw new Error(`publication digest mismatch for ${key}: read-back failed`);
@@ -115,11 +174,12 @@ async function verifyStagedBlobs(blobs, entries) {
115
174
  if (stored.length !== bytes.length) {
116
175
  throw new Error(`publication size mismatch for ${key}: read-back failed`);
117
176
  }
118
- }
177
+ });
119
178
  }
120
179
  /** Create a publication service over injected stores (no driver imports). */
121
180
  export function createPublicationService(deps) {
122
181
  const limits = publicationLimits(deps.limits);
182
+ const blobConcurrency = resolveBlobConcurrency(deps.blobConcurrency);
123
183
  async function commitOnce(input, prepared, sources) {
124
184
  const releaseId = crypto.randomUUID();
125
185
  const { entries, digest, manifest } = prepared;
@@ -132,7 +192,7 @@ export function createPublicationService(deps) {
132
192
  for (const { key, bytes } of entries) {
133
193
  await deps.blobs.putBlob(key, bytes);
134
194
  }
135
- await verifyStagedBlobs(deps.blobs, entries);
195
+ await verifyStagedBlobs(deps.blobs, entries, { concurrency: blobConcurrency });
136
196
  await deps.state.putRelease({
137
197
  releaseId,
138
198
  artifactId: input.artifactId,
@@ -272,6 +332,11 @@ export function createGuardedPublicationService(deps) {
272
332
  const cleanupWindowMs = deps.cleanupWindowMs ?? DEFAULT_CLEANUP_WINDOW_MS;
273
333
  if (!Number.isSafeInteger(cleanupWindowMs) || cleanupWindowMs < 1)
274
334
  throw new Error('invalid preparation lifetime');
335
+ const blobConcurrency = resolveBlobConcurrency(deps.blobConcurrency);
336
+ const blobDeadlineMs = deps.blobDeadlineMs;
337
+ if (blobDeadlineMs !== undefined && (!Number.isSafeInteger(blobDeadlineMs) || blobDeadlineMs < 1)) {
338
+ throw new Error('invalid blob deadline');
339
+ }
275
340
  const guard = (client, authorizeCommit) => async (context, transaction) => {
276
341
  const { state, acl } = await deps.createUnitWriter(client()).readAuthorization(context.artifactId);
277
342
  const verdict = decidePublishAuthorization({ lifecycleState: state, acl, actorId: context.actorId });
@@ -342,15 +407,27 @@ export function createGuardedPublicationService(deps) {
342
407
  pinned.push(digest);
343
408
  }
344
409
  await deps.coordinator.testObserver?.arrive('before_blob_put', invocationId);
345
- for (const { key, bytes } of prepared.entries) {
346
- if ((await deps.intents.get(intent.intentId))?.state !== 'pending') {
347
- throw new Error('preparation abandoned before blob PUT');
348
- }
410
+ // Bounded concurrency over the staged PUTs: one shared deadline for the
411
+ // whole batch, the intent-pending check before every PUT, and the first
412
+ // fatal error stops scheduling and propagates unchanged.
413
+ const deadlineAt = blobDeadlineMs === undefined ? undefined : nowMs + blobDeadlineMs;
414
+ await runBlobPool(prepared.entries, {
415
+ concurrency: blobConcurrency,
416
+ ...(deadlineAt === undefined ? {} : { deadlineAt }),
417
+ beforeEach: async () => {
418
+ if ((await deps.intents.get(intent.intentId))?.state !== 'pending') {
419
+ throw new Error('preparation abandoned before blob PUT');
420
+ }
421
+ },
422
+ }, async ({ key, bytes }) => {
349
423
  await deps.blobs.putBlob(key, bytes);
350
- }
424
+ });
351
425
  await deps.coordinator.testObserver?.arrive('after_blob_put_before_verify', invocationId);
352
426
  await deps.coordinator.testObserver?.arrive('before_blob_readback', invocationId);
353
- await verifyStagedBlobs(deps.blobs, prepared.entries);
427
+ await verifyStagedBlobs(deps.blobs, prepared.entries, {
428
+ concurrency: blobConcurrency,
429
+ ...(deadlineAt === undefined ? {} : { deadlineAt }),
430
+ });
354
431
  const addedRefs = [];
355
432
  const source = input.source === undefined ? undefined : parseSourceRef(input.source);
356
433
  let finalizationClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentropic/artifacts",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "Generic configurable artifacts MCP and artifact service: StorageScope/Artifact/Binding/Release model, canonical manifests, object authorization, idempotent intents (spec-v8 §9).",
5
5
  "type": "module",
6
6
  "license": "MIT",