@indigoai-us/hq-cloud 6.18.1-alpha.5 → 6.18.1-alpha.7

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 (70) hide show
  1. package/dist/bandwidth.d.ts +11 -45
  2. package/dist/bandwidth.d.ts.map +1 -1
  3. package/dist/bandwidth.js +18 -231
  4. package/dist/bandwidth.js.map +1 -1
  5. package/dist/bandwidth.test.js +4 -124
  6. package/dist/bandwidth.test.js.map +1 -1
  7. package/dist/bin/sync-runner-company.d.ts +0 -2
  8. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  9. package/dist/bin/sync-runner-company.js +0 -6
  10. package/dist/bin/sync-runner-company.js.map +1 -1
  11. package/dist/bin/sync-runner-manifest.d.ts +2 -0
  12. package/dist/bin/sync-runner-manifest.d.ts.map +1 -1
  13. package/dist/bin/sync-runner-manifest.js +439 -1
  14. package/dist/bin/sync-runner-manifest.js.map +1 -1
  15. package/dist/bin/sync-runner-manifest.test.js +374 -16
  16. package/dist/bin/sync-runner-manifest.test.js.map +1 -1
  17. package/dist/bin/sync-runner-watch-loop.d.ts +1 -26
  18. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  19. package/dist/bin/sync-runner-watch-loop.js +3 -217
  20. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  21. package/dist/bin/sync-runner.d.ts +2 -26
  22. package/dist/bin/sync-runner.d.ts.map +1 -1
  23. package/dist/bin/sync-runner.js +5 -14
  24. package/dist/bin/sync-runner.js.map +1 -1
  25. package/dist/bin/sync-runner.test.js +1 -107
  26. package/dist/bin/sync-runner.test.js.map +1 -1
  27. package/dist/cli/share.d.ts +6 -18
  28. package/dist/cli/share.d.ts.map +1 -1
  29. package/dist/cli/share.js +47 -92
  30. package/dist/cli/share.js.map +1 -1
  31. package/dist/cli/share.test.js +3 -3
  32. package/dist/cli/share.test.js.map +1 -1
  33. package/dist/cli/sync.d.ts +4 -17
  34. package/dist/cli/sync.d.ts.map +1 -1
  35. package/dist/cli/sync.js +27 -155
  36. package/dist/cli/sync.js.map +1 -1
  37. package/dist/cli/sync.test.js +1 -315
  38. package/dist/cli/sync.test.js.map +1 -1
  39. package/dist/manifest/upload-manifest.d.ts +6 -0
  40. package/dist/manifest/upload-manifest.d.ts.map +1 -1
  41. package/dist/manifest/upload-manifest.js +18 -3
  42. package/dist/manifest/upload-manifest.js.map +1 -1
  43. package/dist/object-io.d.ts +7 -33
  44. package/dist/object-io.d.ts.map +1 -1
  45. package/dist/object-io.js +140 -326
  46. package/dist/object-io.js.map +1 -1
  47. package/dist/object-io.test.js +1 -377
  48. package/dist/object-io.test.js.map +1 -1
  49. package/dist/s3.d.ts +3 -8
  50. package/dist/s3.d.ts.map +1 -1
  51. package/dist/s3.js +27 -304
  52. package/dist/s3.js.map +1 -1
  53. package/dist/s3.test.js +0 -163
  54. package/dist/s3.test.js.map +1 -1
  55. package/dist/sync/inbound-event-admission.d.ts.map +1 -1
  56. package/dist/sync/inbound-event-admission.js +0 -3
  57. package/dist/sync/inbound-event-admission.js.map +1 -1
  58. package/dist/sync/inbound-event-admission.test.js +0 -6
  59. package/dist/sync/inbound-event-admission.test.js.map +1 -1
  60. package/dist/sync-core.d.ts +1 -2
  61. package/dist/sync-core.d.ts.map +1 -1
  62. package/dist/sync-core.js +10 -5
  63. package/dist/sync-core.js.map +1 -1
  64. package/dist/sync-core.test.js +0 -16
  65. package/dist/sync-core.test.js.map +1 -1
  66. package/package.json +1 -1
  67. package/dist/s3-download-stream-hash.test.d.ts +0 -2
  68. package/dist/s3-download-stream-hash.test.d.ts.map +0 -1
  69. package/dist/s3-download-stream-hash.test.js +0 -70
  70. package/dist/s3-download-stream-hash.test.js.map +0 -1
@@ -12,9 +12,9 @@
12
12
  * existing adaptive default.
13
13
  * - `HQ_SYNC_BANDWIDTH_PERCENT` — integer 1..100; adaptive mode. The
14
14
  * governor keeps a rolling estimate of link capacity (max observed
15
- * throughput while network reads are pending over the last 10 minutes;
16
- * token-bucket waits are excluded) and paces to percent/100 × that estimate,
17
- * floored at 64 KiB/s so sync always progresses. When both PERCENT and
15
+ * aggregate throughput over the last 10 minutes, measured during actual
16
+ * transfers) and paces to percent/100 × that estimate, floored at
17
+ * 64 KiB/s so sync always progresses. When both PERCENT and
18
18
  * MAX_BYTES_PER_SEC are set, the smaller resulting cap wins.
19
19
  *
20
20
  * Only DATA-plane transfers are paced (upload bodies, download streams).
@@ -42,11 +42,6 @@ export interface BandwidthPolicy {
42
42
  /** Transfer-pool clamp; undefined = keep the adaptive default. */
43
43
  maxConcurrency?: number;
44
44
  }
45
- export interface BandwidthDiagnostics {
46
- effectiveRateBps: number | null;
47
- activeChoreTransfers: number;
48
- governorWaitMs: number;
49
- }
50
45
  /**
51
46
  * Parse the env contract. Invalid, zero, or unset values disable the
52
47
  * corresponding knob rather than erroring — a misconfigured desktop app must
@@ -54,21 +49,18 @@ export interface BandwidthDiagnostics {
54
49
  */
55
50
  export declare function parseBandwidthPolicy(env?: Record<string, string | undefined>): BandwidthPolicy;
56
51
  /**
57
- * Rolling link-capacity estimate: max observed raw throughput over the last
58
- * {@link ESTIMATOR_WINDOW_MS}. Network-read samples are bytes divided by the
59
- * time spent waiting for the read; governor waits are outside those samples.
60
- * A tiny always-current accumulator — at most 600 live entries, pruned on
61
- * every touch.
52
+ * Rolling link-capacity estimate: max observed aggregate throughput over the
53
+ * last {@link ESTIMATOR_WINDOW_MS}. Bytes are recorded into per-second
54
+ * buckets as transfers deliver them; capacity is the largest bucket in the
55
+ * window (bytes in one second = B/s). A tiny always-current accumulator —
56
+ * at most 600 live entries, pruned on every touch.
62
57
  */
63
58
  export declare class ThroughputEstimator {
64
59
  private readonly now;
65
60
  private readonly buckets;
66
- private readonly rawRates;
67
61
  constructor(now?: () => number);
68
62
  private prune;
69
63
  record(bytes: number): void;
70
- /** Record bytes divided by the wall time spent in the network read. */
71
- recordRawThroughput(bytes: number, readDurationMs: number): void;
72
64
  /** Max observed B/s in the window; undefined before any observation. */
73
65
  capacityBps(): number | undefined;
74
66
  }
@@ -100,10 +92,6 @@ export declare class BandwidthGovernor {
100
92
  readonly policy: BandwidthPolicy;
101
93
  private readonly estimator;
102
94
  private readonly bucket;
103
- private readonly now;
104
- private governorWaitMs;
105
- private activeChoreTransfers;
106
- private readonly choreTransferWaiters;
107
95
  constructor(policy: BandwidthPolicy, opts?: ClockOpts);
108
96
  /** True when any payload pacing is configured. */
109
97
  isPacing(): boolean;
@@ -115,38 +103,16 @@ export declare class BandwidthGovernor {
115
103
  */
116
104
  effectiveRateBps(): number | undefined;
117
105
  /**
118
- * Pace `bytes` of payload through the shared bucket. Instant when pacing is
119
- * off; time spent waiting here is excluded from the capacity estimate.
106
+ * Pace `bytes` of payload through the shared bucket and feed the capacity
107
+ * estimator. Instant when pacing is off.
120
108
  */
121
109
  acquire(bytes: number): Promise<void>;
122
- /** Observe bytes as a Node readable receives them, before consumer pacing. */
123
- observeRawBody(body: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
124
- /** Build a raw-read sampler that can subtract downstream source-pause time. */
125
- createRawReadObserver(excludedDurationMs?: () => number): (bytes: number) => void;
126
- /** Add one transport sample to the rolling capacity estimate. */
127
- recordRawThroughputSample(bytes: number, durationMs: number): void;
128
- /** Measure a successful upload request after token waits have completed. */
129
- measureRawTransfer<T>(bytes: number, work: () => Promise<T>): Promise<T>;
130
- /** Current transfer pressure and cumulative token-bucket wait for diagnostics. */
131
- getDiagnostics(): BandwidthDiagnostics;
132
- private choreTransferLimit;
133
- private makeChoreTransferRelease;
134
- private admitWaitingChoreTransfers;
135
- private acquireChoreTransfer;
136
- /** Reserve a chore slot before opening its payload request, if configured. */
137
- reserveChoreTransfer(): Promise<(() => void) | undefined>;
138
110
  /**
139
111
  * Wrap a download body so each chunk acquires tokens before it is yielded.
140
112
  * Delivers every byte unmodified; returns the original iterable when
141
113
  * pacing is off (zero overhead on the default path).
142
114
  */
143
- throttleBody(body: AsyncIterable<Uint8Array>, reservedRelease?: () => void): AsyncIterable<Uint8Array>;
144
- /** Apply pacing when enabled, or count active GET bodies for cadence diagnostics. */
145
- governBody(body: AsyncIterable<Uint8Array>, reservedRelease?: () => void): AsyncIterable<Uint8Array>;
146
- private trackChoreBody;
147
- /** Hold a chore transfer slot around an upload request or other payload leg. */
148
- withChoreTransfer<T>(work: () => Promise<T>): Promise<T>;
149
- private throttleBodyWithPacing;
115
+ throttleBody(body: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
150
116
  /** Clamp the transfer pool size with HQ_SYNC_MAX_CONCURRENCY (if set). */
151
117
  clampConcurrency(poolSize: number): number;
152
118
  /** One-line human description of the effective policy for startup logs. */
@@ -1 +1 @@
1
- {"version":3,"file":"bandwidth.d.ts","sourceRoot":"","sources":["../src/bandwidth.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AACjE,eAAO,MAAM,mBAAmB,4BAA4B,CAAC;AAC7D,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AAEjE,iEAAiE;AACjE,eAAO,MAAM,0BAA0B,QAAY,CAAC;AAWpD,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;CACxB;AAWD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,eAAe,CASjB;AAED;;;;;;GAMG;AACH,qBAAa,mBAAmB;IAIlB,OAA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Q,EAAE,iBAAiB,GAAG,IAAI,GACjC,IAAI,CAEN"}
package/dist/bandwidth.js CHANGED
@@ -1,4 +1,3 @@
1
- import { Transform } from "node:stream";
2
1
  /**
3
2
  * Bandwidth governor — process-wide pacing for S3 payload transfers.
4
3
  *
@@ -13,9 +12,9 @@ import { Transform } from "node:stream";
13
12
  * existing adaptive default.
14
13
  * - `HQ_SYNC_BANDWIDTH_PERCENT` — integer 1..100; adaptive mode. The
15
14
  * governor keeps a rolling estimate of link capacity (max observed
16
- * throughput while network reads are pending over the last 10 minutes;
17
- * token-bucket waits are excluded) and paces to percent/100 × that estimate,
18
- * floored at 64 KiB/s so sync always progresses. When both PERCENT and
15
+ * aggregate throughput over the last 10 minutes, measured during actual
16
+ * transfers) and paces to percent/100 × that estimate, floored at
17
+ * 64 KiB/s so sync always progresses. When both PERCENT and
19
18
  * MAX_BYTES_PER_SEC are set, the smaller resulting cap wins.
20
19
  *
21
20
  * Only DATA-plane transfers are paced (upload bodies, download streams).
@@ -35,10 +34,6 @@ export const MAX_CONCURRENCY_ENV = "HQ_SYNC_MAX_CONCURRENCY";
35
34
  export const BANDWIDTH_PERCENT_ENV = "HQ_SYNC_BANDWIDTH_PERCENT";
36
35
  /** Adaptive-mode floor: sync always progresses at ≥ 64 KiB/s. */
37
36
  export const MIN_ADAPTIVE_BYTES_PER_SEC = 64 * 1024;
38
- /** Reserve at least this much of the governed budget for each chore stream. */
39
- const MIN_CHORE_TRANSFER_RATE_BPS = 64 * 1024;
40
- /** Hard ceiling on payload readers; the normal sync pool is also at most 64. */
41
- const MAX_CHORE_TRANSFER_CONCURRENCY = 64;
42
37
  /** Rolling window the link-capacity estimate looks back over. */
43
38
  const ESTIMATOR_WINDOW_MS = 10 * 60 * 1000;
44
39
  /** Estimator bucket granularity: per-second byte counts. */
@@ -66,16 +61,15 @@ export function parseBandwidthPolicy(env = process.env) {
66
61
  return { maxBytesPerSec, percent, maxConcurrency };
67
62
  }
68
63
  /**
69
- * Rolling link-capacity estimate: max observed raw throughput over the last
70
- * {@link ESTIMATOR_WINDOW_MS}. Network-read samples are bytes divided by the
71
- * time spent waiting for the read; governor waits are outside those samples.
72
- * A tiny always-current accumulator — at most 600 live entries, pruned on
73
- * every touch.
64
+ * Rolling link-capacity estimate: max observed aggregate throughput over the
65
+ * last {@link ESTIMATOR_WINDOW_MS}. Bytes are recorded into per-second
66
+ * buckets as transfers deliver them; capacity is the largest bucket in the
67
+ * window (bytes in one second = B/s). A tiny always-current accumulator —
68
+ * at most 600 live entries, pruned on every touch.
74
69
  */
75
70
  export class ThroughputEstimator {
76
71
  now;
77
72
  buckets = new Map();
78
- rawRates = new Map();
79
73
  constructor(now = Date.now) {
80
74
  this.now = now;
81
75
  }
@@ -85,10 +79,6 @@ export class ThroughputEstimator {
85
79
  if (key < oldest)
86
80
  this.buckets.delete(key);
87
81
  }
88
- for (const key of this.rawRates.keys()) {
89
- if (key < oldest)
90
- this.rawRates.delete(key);
91
- }
92
82
  }
93
83
  record(bytes) {
94
84
  if (bytes <= 0)
@@ -98,16 +88,6 @@ export class ThroughputEstimator {
98
88
  const bucket = Math.floor(nowMs / ESTIMATOR_BUCKET_MS);
99
89
  this.buckets.set(bucket, (this.buckets.get(bucket) ?? 0) + bytes);
100
90
  }
101
- /** Record bytes divided by the wall time spent in the network read. */
102
- recordRawThroughput(bytes, readDurationMs) {
103
- if (bytes <= 0 || readDurationMs <= 0)
104
- return;
105
- const nowMs = this.now();
106
- this.prune(nowMs);
107
- const bucket = Math.floor(nowMs / ESTIMATOR_BUCKET_MS);
108
- const rateBps = (bytes * 1000) / readDurationMs;
109
- this.rawRates.set(bucket, Math.max(this.rawRates.get(bucket) ?? 0, rateBps));
110
- }
111
91
  /** Max observed B/s in the window; undefined before any observation. */
112
92
  capacityBps() {
113
93
  this.prune(this.now());
@@ -116,10 +96,6 @@ export class ThroughputEstimator {
116
96
  if (max === undefined || bytes > max)
117
97
  max = bytes;
118
98
  }
119
- for (const rateBps of this.rawRates.values()) {
120
- if (max === undefined || rateBps > max)
121
- max = rateBps;
122
- }
123
99
  return max;
124
100
  }
125
101
  }
@@ -176,14 +152,9 @@ export class BandwidthGovernor {
176
152
  policy;
177
153
  estimator;
178
154
  bucket;
179
- now;
180
- governorWaitMs = 0;
181
- activeChoreTransfers = 0;
182
- choreTransferWaiters = [];
183
155
  constructor(policy, opts = {}) {
184
156
  this.policy = policy;
185
- this.now = opts.now ?? Date.now;
186
- this.estimator = new ThroughputEstimator(this.now);
157
+ this.estimator = new ThroughputEstimator(opts.now ?? Date.now);
187
158
  this.bucket = new TokenBucket(() => this.effectiveRateBps(), opts);
188
159
  }
189
160
  /** True when any payload pacing is configured. */
@@ -212,214 +183,30 @@ export class BandwidthGovernor {
212
183
  return fixed ?? adaptive;
213
184
  }
214
185
  /**
215
- * Pace `bytes` of payload through the shared bucket. Instant when pacing is
216
- * off; time spent waiting here is excluded from the capacity estimate.
186
+ * Pace `bytes` of payload through the shared bucket and feed the capacity
187
+ * estimator. Instant when pacing is off.
217
188
  */
218
189
  async acquire(bytes) {
219
190
  if (!this.isPacing() || bytes <= 0)
220
191
  return;
221
- const startedAt = this.now();
222
192
  await this.bucket.acquire(bytes);
223
- this.governorWaitMs += Math.max(0, this.now() - startedAt);
224
- }
225
- /** Observe bytes as a Node readable receives them, before consumer pacing. */
226
- observeRawBody(body) {
227
- if (this.policy.percent === undefined)
228
- return body;
229
- const source = body;
230
- if (typeof source.pipe !== "function")
231
- return body;
232
- let pauseStartedAt;
233
- let pausedDurationMs = 0;
234
- const onPause = () => {
235
- if (pauseStartedAt === undefined)
236
- pauseStartedAt = this.now();
237
- };
238
- const onResume = () => {
239
- if (pauseStartedAt === undefined)
240
- return;
241
- pausedDurationMs += Math.max(0, this.now() - pauseStartedAt);
242
- pauseStartedAt = undefined;
243
- };
244
- const recordRawRead = this.createRawReadObserver(() => {
245
- const duration = pausedDurationMs;
246
- pausedDurationMs = 0;
247
- return duration;
248
- });
249
- const observed = new Transform({
250
- transform: (chunk, encoding, callback) => {
251
- const size = Buffer.isBuffer(chunk)
252
- ? chunk.byteLength
253
- : Buffer.byteLength(chunk, encoding);
254
- recordRawRead(size);
255
- callback(null, chunk);
256
- },
257
- });
258
- source.on?.("pause", onPause);
259
- source.on?.("resume", onResume);
260
- source.pipe(observed);
261
- source.once?.("error", (error) => observed.destroy(error));
262
- observed.once("close", () => {
263
- source.removeListener?.("pause", onPause);
264
- source.removeListener?.("resume", onResume);
265
- if (!source.destroyed && !source.readableEnded)
266
- source.destroy?.();
267
- });
268
- return observed;
269
- }
270
- /** Build a raw-read sampler that can subtract downstream source-pause time. */
271
- createRawReadObserver(excludedDurationMs = () => 0) {
272
- let previousAt = this.now();
273
- return (bytes) => {
274
- const now = this.now();
275
- this.recordRawThroughputSample(bytes, Math.max(0, now - previousAt - excludedDurationMs()));
276
- previousAt = now;
277
- };
278
- }
279
- /** Add one transport sample to the rolling capacity estimate. */
280
- recordRawThroughputSample(bytes, durationMs) {
281
- if (this.policy.percent === undefined)
282
- return;
283
- this.estimator.recordRawThroughput(bytes, durationMs);
284
- this.admitWaitingChoreTransfers();
285
- }
286
- /** Measure a successful upload request after token waits have completed. */
287
- async measureRawTransfer(bytes, work) {
288
- if (this.policy.percent === undefined)
289
- return work();
290
- const startedAt = this.now();
291
- const result = await work();
292
- this.recordRawThroughputSample(bytes, this.now() - startedAt);
293
- return result;
294
- }
295
- /** Current transfer pressure and cumulative token-bucket wait for diagnostics. */
296
- getDiagnostics() {
297
- return {
298
- effectiveRateBps: this.effectiveRateBps() ?? null,
299
- activeChoreTransfers: this.activeChoreTransfers,
300
- governorWaitMs: this.governorWaitMs,
301
- };
302
- }
303
- choreTransferLimit() {
304
- if (!this.isPacing()) {
305
- return Math.min(MAX_CHORE_TRANSFER_CONCURRENCY, this.policy.maxConcurrency ?? MAX_CHORE_TRANSFER_CONCURRENCY);
306
- }
307
- const budget = this.effectiveRateBps() ?? MIN_CHORE_TRANSFER_RATE_BPS;
308
- const rateLimit = Math.max(1, Math.floor(budget / MIN_CHORE_TRANSFER_RATE_BPS));
309
- return Math.min(MAX_CHORE_TRANSFER_CONCURRENCY, this.policy.maxConcurrency ?? MAX_CHORE_TRANSFER_CONCURRENCY, rateLimit);
310
- }
311
- makeChoreTransferRelease() {
312
- let released = false;
313
- return () => {
314
- if (released)
315
- return;
316
- released = true;
317
- this.activeChoreTransfers--;
318
- this.admitWaitingChoreTransfers();
319
- };
320
- }
321
- admitWaitingChoreTransfers() {
322
- const limit = this.choreTransferLimit();
323
- while (this.activeChoreTransfers < limit &&
324
- this.choreTransferWaiters.length > 0) {
325
- const resolve = this.choreTransferWaiters.shift();
326
- if (!resolve)
327
- return;
328
- this.activeChoreTransfers++;
329
- resolve(this.makeChoreTransferRelease());
330
- }
331
- }
332
- acquireChoreTransfer() {
333
- return new Promise((resolve) => {
334
- if (this.choreTransferWaiters.length === 0 &&
335
- this.activeChoreTransfers < this.choreTransferLimit()) {
336
- this.activeChoreTransfers++;
337
- resolve(this.makeChoreTransferRelease());
338
- return;
339
- }
340
- const queuedAt = this.now();
341
- this.choreTransferWaiters.push((release) => {
342
- this.governorWaitMs += Math.max(0, this.now() - queuedAt);
343
- resolve(release);
344
- });
345
- });
346
- }
347
- /** Reserve a chore slot before opening its payload request, if configured. */
348
- async reserveChoreTransfer() {
349
- if (!this.isPacing() && this.policy.maxConcurrency === undefined) {
350
- return undefined;
351
- }
352
- return this.acquireChoreTransfer();
193
+ this.estimator.record(bytes);
353
194
  }
354
195
  /**
355
196
  * Wrap a download body so each chunk acquires tokens before it is yielded.
356
197
  * Delivers every byte unmodified; returns the original iterable when
357
198
  * pacing is off (zero overhead on the default path).
358
199
  */
359
- throttleBody(body, reservedRelease) {
200
+ throttleBody(body) {
360
201
  if (!this.isPacing())
361
202
  return body;
362
- return this.throttleBodyWithPacing(this.observeRawBody(body), reservedRelease);
363
- }
364
- /** Apply pacing when enabled, or count active GET bodies for cadence diagnostics. */
365
- governBody(body, reservedRelease) {
366
- if (this.isPacing())
367
- return this.throttleBody(body, reservedRelease);
368
- if (reservedRelease)
369
- return this.trackChoreBody(body, reservedRelease);
370
- if (this.policy.maxConcurrency === undefined)
371
- return body;
372
- return this.trackChoreBody(body);
373
- }
374
- async *trackChoreBody(body, reservedRelease) {
375
- const release = reservedRelease ?? (await this.acquireChoreTransfer());
376
- try {
377
- for await (const chunk of body)
203
+ const acquire = (n) => this.acquire(n);
204
+ return (async function* () {
205
+ for await (const chunk of body) {
206
+ await acquire(chunk.byteLength);
378
207
  yield chunk;
379
- }
380
- finally {
381
- release();
382
- }
383
- }
384
- /** Hold a chore transfer slot around an upload request or other payload leg. */
385
- async withChoreTransfer(work) {
386
- if (!this.isPacing() && this.policy.maxConcurrency === undefined)
387
- return work();
388
- const release = await this.acquireChoreTransfer();
389
- try {
390
- return await work();
391
- }
392
- finally {
393
- release();
394
- }
395
- }
396
- async *throttleBodyWithPacing(body, reservedRelease) {
397
- const releaseTransfer = reservedRelease ?? (await this.acquireChoreTransfer());
398
- let iterator;
399
- let complete = false;
400
- try {
401
- iterator = body[Symbol.asyncIterator]();
402
- while (true) {
403
- const item = await iterator.next();
404
- if (item.done) {
405
- complete = true;
406
- return;
407
- }
408
- await this.acquire(item.value.byteLength);
409
- yield item.value;
410
- }
411
- }
412
- finally {
413
- if (!complete && iterator) {
414
- try {
415
- await iterator.return?.();
416
- }
417
- catch {
418
- // Preserve the transfer error as the authoritative result.
419
- }
420
208
  }
421
- releaseTransfer();
422
- }
209
+ })();
423
210
  }
424
211
  /** Clamp the transfer pool size with HQ_SYNC_MAX_CONCURRENCY (if set). */
425
212
  clampConcurrency(poolSize) {
@@ -1 +1 @@
1
- {"version":3,"file":"bandwidth.js","sourceRoot":"","sources":["../src/bandwidth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,2BAA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AAC;IAC5D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAC5C,QAAkC;IAElC,SAAS,GAAG,QAAQ,IAAI,SAAS,CAAC;AACpC,CAAC"}
@@ -1,4 +1,3 @@
1
- import { Readable } from "node:stream";
2
1
  import { describe, expect, it } from "vitest";
3
2
  import { BANDWIDTH_PERCENT_ENV, BandwidthGovernor, MAX_BYTES_PER_SEC_ENV, MAX_CONCURRENCY_ENV, MIN_ADAPTIVE_BYTES_PER_SEC, ThroughputEstimator, TokenBucket, parseBandwidthPolicy, } from "./bandwidth.js";
4
3
  /**
@@ -18,18 +17,6 @@ function virtualClock(startMs = 0) {
18
17
  time: () => t,
19
18
  };
20
19
  }
21
- async function observeRawLink(governor, clock, bytes, readDurationMs) {
22
- const body = (async function* () {
23
- clock.advance(readDurationMs);
24
- governor.recordRawThroughputSample(bytes, readDurationMs);
25
- yield new Uint8Array(bytes);
26
- })();
27
- let delivered = 0;
28
- for await (const chunk of governor.throttleBody(body)) {
29
- delivered += chunk.byteLength;
30
- }
31
- return delivered;
32
- }
33
20
  describe("parseBandwidthPolicy", () => {
34
21
  it("returns all-off for an empty env", () => {
35
22
  expect(parseBandwidthPolicy({})).toEqual({
@@ -158,60 +145,13 @@ describe("BandwidthGovernor.effectiveRateBps", () => {
158
145
  it("percent mode paces to percent × observed capacity", async () => {
159
146
  const clock = virtualClock(1_000_000);
160
147
  const gov = new BandwidthGovernor({ percent: 50 }, clock);
161
- await observeRawLink(gov, clock, 1_000_000, 1000); // 1 MB/s raw read
148
+ await gov.acquire(1_000_000); // observe ~1 MB/s in one second-bucket
162
149
  expect(gov.effectiveRateBps()).toBe(500_000);
163
150
  });
164
- it("keeps the raw link estimate near source speed after sustained throttled use", async () => {
165
- const clock = virtualClock(1_000_000);
166
- const gov = new BandwidthGovernor({ percent: 60 }, clock);
167
- const chunkBytes = 10_000;
168
- const readMs = 10;
169
- const linkRateBps = (chunkBytes * 1000) / readMs;
170
- const body = (async function* () {
171
- for (let i = 0; i < 80; i++) {
172
- clock.advance(readMs);
173
- gov.recordRawThroughputSample(chunkBytes, readMs);
174
- yield new Uint8Array(chunkBytes);
175
- }
176
- })();
177
- let bytesDelivered = 0;
178
- for await (const chunk of gov.throttleBody(body)) {
179
- bytesDelivered += chunk.byteLength;
180
- }
181
- expect(bytesDelivered).toBe(chunkBytes * 80);
182
- expect(clock.time()).toBeGreaterThan(1_000_000 + 80 * readMs);
183
- expect(gov.effectiveRateBps()).toBeGreaterThanOrEqual(linkRateBps * 0.5);
184
- expect(gov.effectiveRateBps()).toBeLessThanOrEqual(linkRateBps * 0.7);
185
- });
186
- it("excludes Node readable backpressure pauses from adaptive capacity samples", async () => {
187
- const clock = virtualClock(1_000_000);
188
- const governor = new BandwidthGovernor({ percent: 10 }, clock);
189
- const chunk = Buffer.alloc(1_000_000);
190
- const chunkCount = 70;
191
- let sent = 0;
192
- const source = new Readable({
193
- read() {
194
- if (sent === chunkCount) {
195
- this.push(null);
196
- return;
197
- }
198
- clock.advance(1_000); // the raw link delivers 1 MB/s while it is reading
199
- sent++;
200
- this.push(chunk);
201
- },
202
- });
203
- let delivered = 0;
204
- for await (const bodyChunk of governor.throttleBody(source)) {
205
- delivered += bodyChunk.byteLength;
206
- }
207
- expect(delivered).toBe(chunk.byteLength * chunkCount);
208
- expect(clock.time() - 1_000_000).toBeGreaterThan(10 * 60 * 1_000);
209
- expect(governor.effectiveRateBps()).toBeGreaterThanOrEqual(80_000);
210
- });
211
151
  it("floors the adaptive cap at 64 KiB/s", async () => {
212
152
  const clock = virtualClock(1_000_000);
213
153
  const gov = new BandwidthGovernor({ percent: 1 }, clock);
214
- await observeRawLink(gov, clock, 100_000, 1000); // 100 kB/s raw read
154
+ await gov.acquire(100_000); // 1% of 100 kB/s = 1 kB/s → floored
215
155
  expect(gov.effectiveRateBps()).toBe(MIN_ADAPTIVE_BYTES_PER_SEC);
216
156
  });
217
157
  it("uses the smaller of fixed and adaptive caps when both are set", async () => {
@@ -219,10 +159,10 @@ describe("BandwidthGovernor.effectiveRateBps", () => {
219
159
  const gov = new BandwidthGovernor({ maxBytesPerSec: 300_000, percent: 50 }, clock);
220
160
  // No observation yet → fixed cap governs.
221
161
  expect(gov.effectiveRateBps()).toBe(300_000);
222
- await observeRawLink(gov, clock, 1_000_000, 1000); // adaptive = 500 kB/s
162
+ await gov.acquire(1_000_000); // adaptive = 500 kB/s > fixed 300 kB/s
223
163
  expect(gov.effectiveRateBps()).toBe(300_000);
224
164
  const gov2 = new BandwidthGovernor({ maxBytesPerSec: 300_000, percent: 10 }, clock);
225
- await observeRawLink(gov2, clock, 1_000_000, 1000); // adaptive = 100 kB/s
165
+ await gov2.acquire(1_000_000); // adaptive = 100 kB/s < fixed
226
166
  expect(gov2.effectiveRateBps()).toBe(100_000);
227
167
  });
228
168
  });
@@ -275,47 +215,6 @@ describe("BandwidthGovernor.throttleBody", () => {
275
215
  const ideal = (total / rate) * 1000;
276
216
  expect(clock.time()).toBeGreaterThanOrEqual(ideal - 1000);
277
217
  });
278
- it("scales chore fan-out to the byte budget across 50 queued 7 MiB files", async () => {
279
- const clock = virtualClock();
280
- const perFileMinimumBps = 64 * 1024;
281
- const governor = new BandwidthGovernor({ maxBytesPerSec: perFileMinimumBps }, clock);
282
- const chunk = new Uint8Array(64 * 1024);
283
- const fileSize = 7 * 1024 * 1024;
284
- const files = Array.from({ length: 50 }, () => ({
285
- startedAt: undefined,
286
- finishedAt: undefined,
287
- }));
288
- let activeReaders = 0;
289
- let maxActiveReaders = 0;
290
- async function* fileBody(index) {
291
- const file = files[index];
292
- file.startedAt = clock.time();
293
- activeReaders++;
294
- maxActiveReaders = Math.max(maxActiveReaders, activeReaders);
295
- try {
296
- for (let sent = 0; sent < fileSize; sent += chunk.byteLength) {
297
- yield chunk;
298
- }
299
- }
300
- finally {
301
- file.finishedAt = clock.time();
302
- activeReaders--;
303
- }
304
- }
305
- await Promise.all(files.map(async (_file, index) => {
306
- for await (const _chunk of governor.throttleBody(fileBody(index))) {
307
- // Drain each file without allocating a second copy of its payload.
308
- }
309
- }));
310
- expect(maxActiveReaders).toBe(1);
311
- for (const [index, file] of files.entries()) {
312
- expect(file.startedAt, `file ${index} started`).toBeDefined();
313
- expect(file.finishedAt, `file ${index} finished`).toBeDefined();
314
- const durationMs = file.finishedAt - file.startedAt;
315
- const rateBps = (fileSize * 1000) / durationMs;
316
- expect(rateBps, `file ${index} rate`).toBeGreaterThanOrEqual(perFileMinimumBps);
317
- }
318
- });
319
218
  });
320
219
  describe("BandwidthGovernor.clampConcurrency", () => {
321
220
  it("passes the pool size through when unset", () => {
@@ -329,25 +228,6 @@ describe("BandwidthGovernor.clampConcurrency", () => {
329
228
  expect(loose.clampConcurrency(64)).toBe(64);
330
229
  });
331
230
  });
332
- describe("BandwidthGovernor.withChoreTransfer", () => {
333
- it("shares the configured max concurrency with upload transfers", async () => {
334
- const governor = new BandwidthGovernor({ maxConcurrency: 2 });
335
- let active = 0;
336
- let maximumActive = 0;
337
- let releaseTransfers;
338
- const transfersReleased = new Promise((resolve) => {
339
- releaseTransfers = resolve;
340
- });
341
- setImmediate(releaseTransfers);
342
- await Promise.all(Array.from({ length: 4 }, () => governor.withChoreTransfer(async () => {
343
- active++;
344
- maximumActive = Math.max(maximumActive, active);
345
- await transfersReleased;
346
- active--;
347
- })));
348
- expect(maximumActive).toBe(2);
349
- });
350
- });
351
231
  describe("BandwidthGovernor.describePolicy", () => {
352
232
  it("reports off when nothing is configured", () => {
353
233
  expect(new BandwidthGovernor({}).describePolicy()).toBe("bandwidth governor: off");