@framers/agentos-ext-account-sources 0.4.0 → 0.6.0
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/README.md +114 -3
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/sync/AccountSourceSync.d.ts +136 -0
- package/dist/sync/AccountSourceSync.d.ts.map +1 -0
- package/dist/sync/AccountSourceSync.js +387 -0
- package/dist/sync/AccountSourceSync.js.map +1 -0
- package/dist/sync/SourceQuota.d.ts +134 -0
- package/dist/sync/SourceQuota.d.ts.map +1 -0
- package/dist/sync/SourceQuota.js +336 -0
- package/dist/sync/SourceQuota.js.map +1 -0
- package/dist/sync/SqlAccountSourceSyncStore.d.ts +42 -2
- package/dist/sync/SqlAccountSourceSyncStore.d.ts.map +1 -1
- package/dist/sync/SqlAccountSourceSyncStore.js +109 -12
- package/dist/sync/SqlAccountSourceSyncStore.js.map +1 -1
- package/dist/sync/coordinatorState.d.ts +40 -0
- package/dist/sync/coordinatorState.d.ts.map +1 -0
- package/dist/sync/coordinatorState.js +22 -0
- package/dist/sync/coordinatorState.js.map +1 -0
- package/dist/sync/types.d.ts +1 -1
- package/dist/sync/types.d.ts.map +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The resumable synchronization coordinator for account sources: it runs one connection's sync under
|
|
3
|
+
* the SQL store's lease, from its durable checkpoint, through a supplied provider, with durable attempt counts and
|
|
4
|
+
* retry times, and runs expiry and recovery apart from provider polling.
|
|
5
|
+
* @module account-sources/sync/AccountSourceSync
|
|
6
|
+
*/
|
|
7
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
8
|
+
import { SourceSyncFault } from './state.js';
|
|
9
|
+
import { sourceRetryAt } from './SourceQuota.js';
|
|
10
|
+
class SyncStale extends Error {
|
|
11
|
+
constructor() { super('source_sync_stale'); }
|
|
12
|
+
}
|
|
13
|
+
class SyncYield extends Error {
|
|
14
|
+
constructor() { super('source_sync_yield'); }
|
|
15
|
+
}
|
|
16
|
+
class SyncDeferred extends Error {
|
|
17
|
+
reason;
|
|
18
|
+
retryAt;
|
|
19
|
+
constructor(reason, retryAt) {
|
|
20
|
+
super('source_sync_deferred');
|
|
21
|
+
this.reason = reason;
|
|
22
|
+
this.retryAt = retryAt;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const retryReasons = ['network', 'rate_limited', 'provider_unavailable', 'storage_unavailable'];
|
|
26
|
+
const retriable = (fault) => retryReasons.includes(fault.code);
|
|
27
|
+
const digest = (parts) => createHash('sha256').update(JSON.stringify(parts)).digest('hex');
|
|
28
|
+
/**
|
|
29
|
+
* One lease at a time; all durable state and authorization remain in the SQL store.
|
|
30
|
+
*
|
|
31
|
+
* `run` performs one connection's sync from its durable checkpoint and yields within its budgets; any coordinator on
|
|
32
|
+
* the same tables resumes it. `maintain` runs purge recovery and expiry for every connection, apart from provider
|
|
33
|
+
* polling. The coordinator holds no state between calls.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam Prepared - The host's in-memory value for one document, passed to the store's `write` binding.
|
|
36
|
+
*/
|
|
37
|
+
export class AccountSourceSync {
|
|
38
|
+
options;
|
|
39
|
+
store;
|
|
40
|
+
clock;
|
|
41
|
+
runBudget;
|
|
42
|
+
operationTimeout;
|
|
43
|
+
/**
|
|
44
|
+
* @param options - The store, provider factory, preparation, lifecycle binding and optional settings.
|
|
45
|
+
* @throws {Error} `invalid_source_coordinator_policy` unless `runBudgetMs` is an integer from 1 to 90,000 and
|
|
46
|
+
* `operationTimeoutMs` one from 1 to 60,000.
|
|
47
|
+
*/
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.options = options;
|
|
50
|
+
this.store = options.store;
|
|
51
|
+
this.clock = options.clock ?? Date.now;
|
|
52
|
+
this.runBudget = options.runBudgetMs ?? 90_000;
|
|
53
|
+
this.operationTimeout = options.operationTimeoutMs ?? 30_000;
|
|
54
|
+
if (![this.runBudget, this.operationTimeout].every((n) => Number.isSafeInteger(n) && n >= 1)
|
|
55
|
+
|| this.runBudget > 90_000 || this.operationTimeout > 60_000)
|
|
56
|
+
throw new Error('invalid_source_coordinator_policy');
|
|
57
|
+
}
|
|
58
|
+
now() {
|
|
59
|
+
const now = this.clock();
|
|
60
|
+
if (!Number.isSafeInteger(now) || now < 0)
|
|
61
|
+
throw new SourceSyncFault('invalid_response');
|
|
62
|
+
return now;
|
|
63
|
+
}
|
|
64
|
+
emit(state, n, started) {
|
|
65
|
+
const event = { kind: 'source_sync', state, n,
|
|
66
|
+
...(started === undefined ? {} : { ms: Math.max(0, this.now() - started) }) };
|
|
67
|
+
try {
|
|
68
|
+
this.options.events?.(event);
|
|
69
|
+
}
|
|
70
|
+
catch { /* A diagnostic sink cannot alter a content transaction. */ }
|
|
71
|
+
}
|
|
72
|
+
async stored(work) {
|
|
73
|
+
try {
|
|
74
|
+
return await work();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof SourceSyncFault)
|
|
78
|
+
throw error;
|
|
79
|
+
throw new SourceSyncFault('storage_unavailable');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
at(fault, attempt, pollMs) {
|
|
83
|
+
const now = this.now();
|
|
84
|
+
return Math.max(sourceRetryAt(now, Math.min(5, Math.max(1, attempt)), null, this.options.random?.() ?? Math.random()), fault.retryAt ?? 0, attempt >= 5 ? now + pollMs : now + 1);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Runs one connection's sync under a claimed lease. It recovers the host's purges and the store's controls, claims
|
|
88
|
+
* the lease, opens a cycle when none is open (`bootstrap` without a cursor, `reconcile` once `reconcileMs` has
|
|
89
|
+
* passed since the last non-incremental cycle, otherwise `incremental`), drains the queued reads before asking for
|
|
90
|
+
* the next page, and commits the cursor once every item is terminal. It yields with the checkpoint kept after the
|
|
91
|
+
* policy's changed-item or history-page budget, the run budget or an aborted signal, and never waits out a retry.
|
|
92
|
+
*
|
|
93
|
+
* @param scope - The connection.
|
|
94
|
+
* @param trigger - A scheduled poll or a person's request.
|
|
95
|
+
* @param signal - Aborting it ends the run with `yielded` and aborts the call in flight.
|
|
96
|
+
* @returns How the run ended; `unavailable` claims no recorded retry.
|
|
97
|
+
*/
|
|
98
|
+
async run(scope, trigger, signal) {
|
|
99
|
+
if (signal?.aborted)
|
|
100
|
+
return { kind: 'yielded' };
|
|
101
|
+
const started = this.now();
|
|
102
|
+
let handle = null;
|
|
103
|
+
let snapshot = null;
|
|
104
|
+
let checkpoint = null;
|
|
105
|
+
let changed = 0;
|
|
106
|
+
let historyPages = 0;
|
|
107
|
+
let recovered = false;
|
|
108
|
+
const checkBudget = () => {
|
|
109
|
+
if (signal?.aborted || this.now() - started >= this.runBudget)
|
|
110
|
+
throw new SyncYield();
|
|
111
|
+
};
|
|
112
|
+
const needHandle = () => { if (!handle)
|
|
113
|
+
throw new SyncStale(); return handle; };
|
|
114
|
+
const renew = async () => {
|
|
115
|
+
checkBudget();
|
|
116
|
+
const current = needHandle();
|
|
117
|
+
handle = await this.stored(() => this.store.renew(current));
|
|
118
|
+
if (!handle)
|
|
119
|
+
throw new SyncStale();
|
|
120
|
+
};
|
|
121
|
+
const context = (cycleId, cutoff, child) => ({
|
|
122
|
+
scope, generation: needHandle().lease.generation, cycleId, cutoff, policy: snapshot.policy, signal: child,
|
|
123
|
+
});
|
|
124
|
+
const external = async (work, failure) => {
|
|
125
|
+
await renew();
|
|
126
|
+
const timeout = Math.min(this.operationTimeout, this.runBudget - (this.now() - started), needHandle().lease.expiresAt - this.now() - 1000);
|
|
127
|
+
if (timeout <= 0)
|
|
128
|
+
throw new SyncYield();
|
|
129
|
+
const controller = new AbortController();
|
|
130
|
+
const abort = () => controller.abort();
|
|
131
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
132
|
+
if (signal?.aborted)
|
|
133
|
+
abort();
|
|
134
|
+
const timer = setTimeout(abort, timeout);
|
|
135
|
+
try {
|
|
136
|
+
if (controller.signal.aborted)
|
|
137
|
+
throw new SyncYield();
|
|
138
|
+
const value = await work(controller.signal);
|
|
139
|
+
if (signal?.aborted)
|
|
140
|
+
throw new SyncYield();
|
|
141
|
+
if (controller.signal.aborted)
|
|
142
|
+
throw new SourceSyncFault(failure === 'storage_unavailable' ? failure : 'network');
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (signal?.aborted)
|
|
147
|
+
throw new SyncYield();
|
|
148
|
+
if (controller.signal.aborted)
|
|
149
|
+
throw new SourceSyncFault(failure === 'storage_unavailable' ? failure : 'network');
|
|
150
|
+
if (error instanceof SyncYield || error instanceof SourceSyncFault)
|
|
151
|
+
throw error;
|
|
152
|
+
throw new SourceSyncFault(failure);
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
signal?.removeEventListener('abort', abort);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const operation = async (key, work) => {
|
|
160
|
+
await renew();
|
|
161
|
+
const current = needHandle();
|
|
162
|
+
const reserved = await this.stored(() => this.store.reserveOperation(current, key));
|
|
163
|
+
if (!reserved)
|
|
164
|
+
throw new SyncStale();
|
|
165
|
+
if (reserved.kind === 'deferred')
|
|
166
|
+
throw new SyncDeferred(reserved.reason, reserved.retryAt);
|
|
167
|
+
try {
|
|
168
|
+
return await external(work, 'invalid_response');
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (!(error instanceof SourceSyncFault) || !retriable(error))
|
|
172
|
+
throw error;
|
|
173
|
+
const reason = error.code;
|
|
174
|
+
const retryAt = this.at(error, reserved.attempt, snapshot.policy.pollMs);
|
|
175
|
+
if (!await this.stored(() => this.store.deferOperation(needHandle(), key, reserved.attempt, reason, retryAt))) {
|
|
176
|
+
throw new SyncStale();
|
|
177
|
+
}
|
|
178
|
+
throw new SyncDeferred(error.code, retryAt);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const deferRead = async (work, fault) => {
|
|
182
|
+
const retryAt = this.at(fault, work.attempts, snapshot.policy.pollMs);
|
|
183
|
+
const result = await this.stored(() => this.store.applyResult(needHandle(), work, { kind: 'retry', id: work.sourceId, reason: fault.code, retryAt }, null));
|
|
184
|
+
if (!result)
|
|
185
|
+
throw new SyncStale();
|
|
186
|
+
handle = result.handle;
|
|
187
|
+
throw new SyncDeferred(fault.code, retryAt);
|
|
188
|
+
};
|
|
189
|
+
try {
|
|
190
|
+
await this.stored(() => this.options.lifecycle.recover(scope));
|
|
191
|
+
await this.stored(() => this.store.recoverControl(scope));
|
|
192
|
+
handle = await this.stored(() => this.store.claim(scope, trigger));
|
|
193
|
+
if (!handle)
|
|
194
|
+
return { kind: 'idle' };
|
|
195
|
+
snapshot = await this.stored(() => this.store.snapshot(scope));
|
|
196
|
+
if (!snapshot || snapshot.state.generation !== handle.lease.generation)
|
|
197
|
+
throw new SyncStale();
|
|
198
|
+
checkpoint = snapshot.checkpoint;
|
|
199
|
+
this.emit('started', 0);
|
|
200
|
+
if (!await this.stored(() => this.store.progress(needHandle())))
|
|
201
|
+
throw new SyncStale();
|
|
202
|
+
let source;
|
|
203
|
+
try {
|
|
204
|
+
source = await this.options.provider(needHandle);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
if (error instanceof SourceSyncFault)
|
|
208
|
+
throw error;
|
|
209
|
+
throw new SourceSyncFault('storage_unavailable');
|
|
210
|
+
}
|
|
211
|
+
const open = async (mode, replace = false) => {
|
|
212
|
+
const cutoff = this.now();
|
|
213
|
+
const cycleId = randomUUID();
|
|
214
|
+
const anchor = mode === 'incremental' ? snapshot.state.cursor : await operation(digest(['begin', handle.lease.generation, mode, snapshot.state.cursor,
|
|
215
|
+
snapshot.state.lastSyncAt, checkpoint?.cycleId ?? null, checkpoint?.revision ?? null]), (child) => source.begin(context(cycleId, cutoff, child)));
|
|
216
|
+
// A reconcile reads its anchor before the scan but replays history from the committed cursor: history ids
|
|
217
|
+
// only increase, so that replay also covers the changes between the cursor and the anchor, which the bounded
|
|
218
|
+
// scan may not list.
|
|
219
|
+
const fromCursor = mode === 'reconcile' ? snapshot.state.cursor ?? anchor : anchor;
|
|
220
|
+
const next = await this.stored(() => this.store.openCycle(needHandle(), { mode, fromCursor, cutoff, cycleId }, replace));
|
|
221
|
+
if (!next)
|
|
222
|
+
throw new SyncStale();
|
|
223
|
+
return next;
|
|
224
|
+
};
|
|
225
|
+
if (!checkpoint) {
|
|
226
|
+
const mode = snapshot.state.cursor === null ? 'bootstrap'
|
|
227
|
+
: snapshot.lastReconcileAt === null || this.now() - snapshot.lastReconcileAt >= snapshot.policy.reconcileMs
|
|
228
|
+
? 'reconcile' : 'incremental';
|
|
229
|
+
checkpoint = await open(mode);
|
|
230
|
+
}
|
|
231
|
+
for (;;) {
|
|
232
|
+
checkBudget();
|
|
233
|
+
await renew();
|
|
234
|
+
if (changed >= snapshot.policy.maxChangedPerLease)
|
|
235
|
+
throw new SyncYield();
|
|
236
|
+
const work = await this.stored(() => this.store.takeWork(needHandle()));
|
|
237
|
+
if (work) {
|
|
238
|
+
changed++;
|
|
239
|
+
try {
|
|
240
|
+
let result;
|
|
241
|
+
if (await this.stored(() => this.store.isExcluded(scope, work.sourceId))) {
|
|
242
|
+
result = { kind: 'skipped', id: work.sourceId, reason: 'excluded' };
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
const cp = checkpoint;
|
|
246
|
+
result = await external((child) => source.readSource(context(cp.cycleId, cp.cutoff, child), work.sourceId), 'invalid_response');
|
|
247
|
+
}
|
|
248
|
+
if (result.kind === 'retry') {
|
|
249
|
+
if (result.id !== work.sourceId)
|
|
250
|
+
throw new SourceSyncFault('invalid_response');
|
|
251
|
+
throw new SourceSyncFault(result.reason, result.retryAt);
|
|
252
|
+
}
|
|
253
|
+
let prepared = null;
|
|
254
|
+
if (result.kind === 'document') {
|
|
255
|
+
const cp = checkpoint;
|
|
256
|
+
const document = result.document;
|
|
257
|
+
prepared = await external((child) => this.options.prepare(context(cp.cycleId, cp.cutoff, child), document), 'storage_unavailable');
|
|
258
|
+
if (prepared === null)
|
|
259
|
+
throw new SourceSyncFault('invalid_response');
|
|
260
|
+
}
|
|
261
|
+
const applied = await this.stored(() => this.store.applyResult(needHandle(), work, result, prepared));
|
|
262
|
+
if (!applied)
|
|
263
|
+
throw new SyncStale();
|
|
264
|
+
handle = applied.handle;
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (error instanceof SourceSyncFault && retriable(error))
|
|
268
|
+
await deferRead(work, error);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
const progress = await this.stored(() => this.store.progress(needHandle()));
|
|
272
|
+
if (!progress)
|
|
273
|
+
throw new SyncStale();
|
|
274
|
+
this.emit('progress', progress.progress.committed);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const pending = await this.stored(() => this.store.pendingRetry(needHandle()));
|
|
278
|
+
if (pending)
|
|
279
|
+
throw new SyncDeferred(pending.reason, Math.max(this.now() + 1, pending.retryAt));
|
|
280
|
+
if (checkpoint.phase === 'apply') {
|
|
281
|
+
const cp = checkpoint;
|
|
282
|
+
const state = await this.stored(() => this.store.finish(needHandle(), cp));
|
|
283
|
+
if (!state)
|
|
284
|
+
throw new SyncStale();
|
|
285
|
+
handle = null;
|
|
286
|
+
this.emit('succeeded', state.progress.committed, started);
|
|
287
|
+
return { kind: 'completed', examined: state.progress.examined,
|
|
288
|
+
committed: state.progress.committed, bounded: state.progress.bounded };
|
|
289
|
+
}
|
|
290
|
+
if (checkpoint.phase === 'history' && historyPages >= snapshot.policy.maxHistoryPagesPerLease)
|
|
291
|
+
throw new SyncYield();
|
|
292
|
+
const cp = checkpoint;
|
|
293
|
+
try {
|
|
294
|
+
if (cp.phase === 'history')
|
|
295
|
+
historyPages++;
|
|
296
|
+
const page = await operation(digest(['page', cp.generation, cp.cycleId, cp.revision, cp.phase]), (child) => cp.phase === 'scan'
|
|
297
|
+
? source.scanPage(context(cp.cycleId, cp.cutoff, child), cp.nextPageToken)
|
|
298
|
+
: source.historyPage(context(cp.cycleId, cp.cutoff, child), cp.fromCursor, cp.nextPageToken));
|
|
299
|
+
checkpoint = await this.stored(() => this.store.page(needHandle(), cp, page));
|
|
300
|
+
if (!checkpoint)
|
|
301
|
+
throw new SyncStale();
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (error instanceof SourceSyncFault && error.code === 'history_expired' && cp.phase === 'history') {
|
|
305
|
+
if (recovered)
|
|
306
|
+
throw new SyncDeferred('provider_unavailable', this.now() + snapshot.policy.pollMs);
|
|
307
|
+
recovered = true;
|
|
308
|
+
checkpoint = await open('recovery', true);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
if (error instanceof SyncStale)
|
|
317
|
+
return { kind: 'stale' };
|
|
318
|
+
if (!handle)
|
|
319
|
+
return { kind: 'unavailable' };
|
|
320
|
+
try {
|
|
321
|
+
if (error instanceof SyncYield || (error instanceof SourceSyncFault && error.code === 'cancelled')) {
|
|
322
|
+
if (!await this.stored(() => this.store.release(needHandle())))
|
|
323
|
+
return { kind: 'stale' };
|
|
324
|
+
this.emit('yielded', changed, started);
|
|
325
|
+
return { kind: 'yielded' };
|
|
326
|
+
}
|
|
327
|
+
if (error instanceof SourceSyncFault && (error.code === 'grant_rejected' || error.code === 'insufficient_scope')) {
|
|
328
|
+
const reason = error.code;
|
|
329
|
+
if (!await this.stored(() => this.options.lifecycle.loseGrant(needHandle(), reason)))
|
|
330
|
+
return { kind: 'stale' };
|
|
331
|
+
this.emit('reconnect', 0, started);
|
|
332
|
+
return { kind: 'reconnect' };
|
|
333
|
+
}
|
|
334
|
+
if (error instanceof SourceSyncFault && (error.code === 'domain_policy' || error.code === 'invalid_response')) {
|
|
335
|
+
const reason = error.code;
|
|
336
|
+
if (!await this.stored(() => this.store.release(needHandle(), { type: 'sync_failed', reason })))
|
|
337
|
+
return { kind: 'stale' };
|
|
338
|
+
return { kind: 'failed', reason: error.code };
|
|
339
|
+
}
|
|
340
|
+
const deferred = error instanceof SyncDeferred ? error : {
|
|
341
|
+
reason: 'storage_unavailable',
|
|
342
|
+
retryAt: Math.max(this.now() + (snapshot?.policy.pollMs ?? 900_000), error instanceof SourceSyncFault ? error.retryAt ?? 0 : 0),
|
|
343
|
+
};
|
|
344
|
+
const retryAt = Math.max(this.now() + 1, deferred.retryAt);
|
|
345
|
+
if (!await this.stored(() => this.store.release(needHandle(), { type: 'sync_deferred', reason: deferred.reason, retryAt })))
|
|
346
|
+
return { kind: 'stale' };
|
|
347
|
+
this.emit('retry', changed, started);
|
|
348
|
+
return { kind: 'deferred', reason: deferred.reason, retryAt };
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
return { kind: 'unavailable' };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* A bounded scheduler batch. The host persists next between ticks to avoid starving high keys.
|
|
357
|
+
*
|
|
358
|
+
* Visits up to `limit` connections after `after` in key order, paused, blocked and disconnected ones included, and
|
|
359
|
+
* for each runs the lifecycle's recovery, the store's control recovery and the expiry of up to 100 sources. A
|
|
360
|
+
* failure is counted and the next connection still runs. No provider is called.
|
|
361
|
+
*
|
|
362
|
+
* @param after - The `next` of the previous batch, or null to start from the first connection.
|
|
363
|
+
* @param limit - At most this many connections, an integer from 1 to 1,000.
|
|
364
|
+
* @throws {SourceSyncFault} `storage_unavailable` when the connections cannot be listed, a `limit` outside that
|
|
365
|
+
* range included.
|
|
366
|
+
*/
|
|
367
|
+
async maintain(after = null, limit = 100) {
|
|
368
|
+
const scopes = await this.stored(() => this.store.scopes(after, limit));
|
|
369
|
+
let expired = 0;
|
|
370
|
+
let failed = 0;
|
|
371
|
+
for (const scope of scopes) {
|
|
372
|
+
try {
|
|
373
|
+
await this.stored(() => this.options.lifecycle.recover(scope));
|
|
374
|
+
await this.stored(() => this.store.recoverControl(scope));
|
|
375
|
+
expired += await this.stored(() => this.store.expire(scope, 100));
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
failed++;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (expired > 0)
|
|
382
|
+
this.emit('purged', expired);
|
|
383
|
+
return { scanned: scopes.length, expired, failed,
|
|
384
|
+
next: scopes.length === limit ? scopes[scopes.length - 1] : null };
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
//# sourceMappingURL=AccountSourceSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountSourceSync.js","sourceRoot":"","sources":["../../src/sync/AccountSourceSync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AASrD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAmEjD,MAAM,SAAU,SAAQ,KAAK;IAAG,gBAAgB,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;CAAE;AAC/E,MAAM,SAAU,SAAQ,KAAK;IAAG,gBAAgB,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;CAAE;AAC/E,MAAM,YAAa,SAAQ,KAAK;IACT;IAAwC;IAA7D,YAAqB,MAA6B,EAAW,OAAe;QAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAAzF,WAAM,GAAN,MAAM,CAAuB;QAAW,YAAO,GAAP,OAAO,CAAQ;IAAmC,CAAC;CACjH;AACD,MAAM,YAAY,GAAqC,CAAC,SAAS,EAAE,cAAc,EAAE,sBAAsB,EAAE,qB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QAChC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC/D,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC1D,OAAO,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;YACpE,CAAC;YAAC,MAAM,CAAC;gBAAC,MAAM,EAAE,CAAC;YAAC,CAAC;QACvB,CAAC;QACD,IAAI,OAAO,GAAG,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM;YAC9C,IAAI,EAAE,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACxE,CAAC;CACF"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Persistent weighted request quotas on PostgreSQL through `@framers/sql-storage-adapter`: three
|
|
3
|
+
* released core spend meters (a project's rolling minute, a mailbox's rolling minute and a project's UTC day),
|
|
4
|
+
* request slots that every worker shares and that expire after a process dies, and durable provider retry times.
|
|
5
|
+
* @module account-sources/sync/SourceQuota
|
|
6
|
+
*/
|
|
7
|
+
import type { StorageAdapter } from '@framers/sql-storage-adapter';
|
|
8
|
+
/** The kind of provider call a request makes; the policy gives each kind its weight. */
|
|
9
|
+
export type SourceQuotaMethod = 'list' | 'read' | 'changes' | 'profile' | 'labels';
|
|
10
|
+
/**
|
|
11
|
+
* Budgets and limits that every worker sharing the tables holds identically. Every value is a positive safe integer,
|
|
12
|
+
* `timeoutMs` is at most 60,000, `slotGraceMs` lies between `timeoutMs` and 120,000, and `mailboxConcurrency` is at
|
|
13
|
+
* most `projectConcurrency`; `SourceQuota` throws `invalid_source_quota_policy` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export interface SourceQuotaPolicy {
|
|
16
|
+
/** Weighted units a project may consume in any rolling 60-second window. */
|
|
17
|
+
readonly projectMinute: number;
|
|
18
|
+
/** Weighted units one mailbox may consume in any rolling 60-second window. */
|
|
19
|
+
readonly mailboxMinute: number;
|
|
20
|
+
/** Weighted units a project may consume in one UTC day. */
|
|
21
|
+
readonly projectDay: number;
|
|
22
|
+
/** Requests a project may have in flight across every worker. */
|
|
23
|
+
readonly projectConcurrency: number;
|
|
24
|
+
/** Requests one mailbox may have in flight across every worker. */
|
|
25
|
+
readonly mailboxConcurrency: number;
|
|
26
|
+
/** Milliseconds after dispatch before the request's signal aborts. */
|
|
27
|
+
readonly timeoutMs: number;
|
|
28
|
+
/** Milliseconds a slot outlives its request's deadline, so a process that dies mid-request frees it. */
|
|
29
|
+
readonly slotGraceMs: number;
|
|
30
|
+
/** Units each kind of call consumes. */
|
|
31
|
+
readonly weights: Readonly<Record<SourceQuotaMethod, number>>;
|
|
32
|
+
}
|
|
33
|
+
/** One provider request attempt. Keys are opaque strings of 1 to 512 characters, never an address. */
|
|
34
|
+
export interface SourceQuotaRequest {
|
|
35
|
+
/** The project whose budgets and slots every worker shares. */
|
|
36
|
+
readonly projectKey: string;
|
|
37
|
+
/** A stable key for the mailbox inside the project. */
|
|
38
|
+
readonly mailboxKey: string;
|
|
39
|
+
/** The kind of call, which sets the attempt's weight. */
|
|
40
|
+
readonly method: SourceQuotaMethod;
|
|
41
|
+
/** Unique for one HTTP attempt. A network retry needs a new id. */
|
|
42
|
+
readonly attemptId: string;
|
|
43
|
+
}
|
|
44
|
+
/** Why a request was deferred: a budget without room, a full concurrency limit or a recorded provider wait. */
|
|
45
|
+
export type SourceQuotaReason = 'project_minute' | 'mailbox_minute' | 'project_day' | 'project_concurrency' | 'mailbox_concurrency' | 'provider_wait';
|
|
46
|
+
/**
|
|
47
|
+
* What `SourceQuota.run` answers: the transport's value; a deferral with the earliest time, in epoch milliseconds, to
|
|
48
|
+
* try again, nothing sent; `late` when the call could not start within a second of its reservation, after a long wait
|
|
49
|
+
* for the project's lock or a stalled process: nothing was sent and the units stay spent, and the attempt is retryable
|
|
50
|
+
* by a new `run` with a new attempt id from `retryAt`, in epoch milliseconds, a second after the late start was found;
|
|
51
|
+
* or `duplicate` for an attempt id seen before, which never sends.
|
|
52
|
+
*/
|
|
53
|
+
export type SourceQuotaResult<T> = {
|
|
54
|
+
readonly kind: 'completed';
|
|
55
|
+
readonly value: T;
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: 'deferred';
|
|
58
|
+
readonly reason: SourceQuotaReason;
|
|
59
|
+
readonly retryAt: number;
|
|
60
|
+
} | {
|
|
61
|
+
readonly kind: 'late';
|
|
62
|
+
readonly retryAt: number;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: 'duplicate';
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* What one `SourceQuota.compact` call deleted. Each table gives up at most 1,000 rows a call: `more` is true when one
|
|
68
|
+
* gave that many, so a further call may find more to delete, and false when every table gave fewer.
|
|
69
|
+
*/
|
|
70
|
+
export interface SourceQuotaCompaction {
|
|
71
|
+
/** Attempt records deleted a day after their slots expired. */
|
|
72
|
+
readonly attempts: number;
|
|
73
|
+
/** Mailbox provider waits deleted once passed. */
|
|
74
|
+
readonly mailboxWaits: number;
|
|
75
|
+
/** Reservations settled more than a day ago, deleted from the three budgets' meters together. */
|
|
76
|
+
readonly reservations: number;
|
|
77
|
+
/** The two minute budgets' account rows idle for a day, deleted together. */
|
|
78
|
+
readonly windows: number;
|
|
79
|
+
/** Whether a table gave a full page of 1,000 rows; a host calls `compact` again while it is true. */
|
|
80
|
+
readonly more: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** The quota's table prefix, policy and clock. */
|
|
83
|
+
export interface SourceQuotaOptions {
|
|
84
|
+
/** Prefix of the quota tables, the one given to `sourceQuotaSchema`; `agentos_source_quota` unless given. */
|
|
85
|
+
readonly tablePrefix?: string;
|
|
86
|
+
/** The budgets and limits, the same in every worker. */
|
|
87
|
+
readonly policy: SourceQuotaPolicy;
|
|
88
|
+
/** Tests may inject a clock; production uses the database clock across workers. */
|
|
89
|
+
readonly clock?: (tx: StorageAdapter) => Promise<number>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The quota tables' DDL under a prefix of a lower-case letter and at most 27 lower-case letters, digits or underscores
|
|
93
|
+
* (`agentos_source_quota` unless given), as seven scripts for the host's migration to run with `exec`: the project,
|
|
94
|
+
* mailbox and attempt tables, the attempts' index, then a core spend meter's tables and indexes for each budget under
|
|
95
|
+
* `<prefix>_pm`, `<prefix>_mm` and `<prefix>_pd`. Throws `invalid_source_quota_prefix` for another prefix.
|
|
96
|
+
*/
|
|
97
|
+
export declare function sourceQuotaSchema(prefix?: string): readonly string[];
|
|
98
|
+
/** Combines released meters; this class never reimplements their accounting SQL. */
|
|
99
|
+
export declare class SourceQuota {
|
|
100
|
+
private readonly db;
|
|
101
|
+
private readonly options;
|
|
102
|
+
private readonly t;
|
|
103
|
+
private readonly policy;
|
|
104
|
+
private readonly fingerprint;
|
|
105
|
+
/**
|
|
106
|
+
* Takes a PostgreSQL adapter with transactions and runs no DDL. Throws `source_quota_requires_postgres` for another
|
|
107
|
+
* adapter, `invalid_source_quota_prefix` for a bad prefix and `invalid_source_quota_policy` for a bad policy.
|
|
108
|
+
*/
|
|
109
|
+
constructor(db: StorageAdapter, options: SourceQuotaOptions);
|
|
110
|
+
private now;
|
|
111
|
+
private project;
|
|
112
|
+
private meter;
|
|
113
|
+
private reserve;
|
|
114
|
+
private begin;
|
|
115
|
+
private release;
|
|
116
|
+
/**
|
|
117
|
+
* Consume weighted capacity and call the transport once. No inline HTTP retries: a retry, after a deferral or a
|
|
118
|
+
* `late` answer among others, is a new `run` with a new attempt id.
|
|
119
|
+
*/
|
|
120
|
+
run<T>(request: SourceQuotaRequest, send: (signal: AbortSignal) => Promise<T>, parent?: AbortSignal): Promise<SourceQuotaResult<T>>;
|
|
121
|
+
/** A longer provider wait survives restarts, generation changes and shorter updates. */
|
|
122
|
+
defer(scope: {
|
|
123
|
+
readonly projectKey: string;
|
|
124
|
+
readonly mailboxKey?: string;
|
|
125
|
+
}, retryAt: number): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Remove expired attempt evidence after 24 hours and safely old meter records, at most 1,000 rows of each table a
|
|
128
|
+
* call. Daily totals remain. Answers what it removed; while `more` is true, a further call may remove more.
|
|
129
|
+
*/
|
|
130
|
+
compact(): Promise<SourceQuotaCompaction>;
|
|
131
|
+
}
|
|
132
|
+
/** Retry-After is never clamped down to the local exponential-backoff ceiling. */
|
|
133
|
+
export declare function sourceRetryAt(now: number, attempt: number, retryAfter: string | null, random?: number): number;
|
|
134
|
+
//# sourceMappingURL=SourceQuota.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SourceQuota.d.ts","sourceRoot":"","sources":["../../src/sync/SourceQuota.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAInE,wFAAwF;AACxF,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AACnF;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,8EAA8E;IAC9E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAA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