@vorionsys/atsf-core 0.4.1 → 0.4.3
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/dist/basis/parser.d.ts +74 -74
- package/dist/basis/parser.js +3 -3
- package/dist/basis/parser.js.map +1 -1
- package/dist/common/config.d.ts +16 -16
- package/dist/enforce/fast-path.d.ts +134 -0
- package/dist/enforce/fast-path.d.ts.map +1 -0
- package/dist/enforce/fast-path.js +257 -0
- package/dist/enforce/fast-path.js.map +1 -0
- package/dist/enforce/pipeline-optimizer.d.ts +111 -0
- package/dist/enforce/pipeline-optimizer.d.ts.map +1 -0
- package/dist/enforce/pipeline-optimizer.js +370 -0
- package/dist/enforce/pipeline-optimizer.js.map +1 -0
- package/dist/enforce/policy-cache.d.ts +92 -0
- package/dist/enforce/policy-cache.d.ts.map +1 -0
- package/dist/enforce/policy-cache.js +186 -0
- package/dist/enforce/policy-cache.js.map +1 -0
- package/dist/enforce/trust-cache.d.ts +118 -0
- package/dist/enforce/trust-cache.d.ts.map +1 -0
- package/dist/enforce/trust-cache.js +218 -0
- package/dist/enforce/trust-cache.js.map +1 -0
- package/dist/paramesphere/gpu-svd.d.ts +102 -0
- package/dist/paramesphere/gpu-svd.d.ts.map +1 -0
- package/dist/paramesphere/gpu-svd.js +668 -0
- package/dist/paramesphere/gpu-svd.js.map +1 -0
- package/dist/paramesphere/index.d.ts +2 -0
- package/dist/paramesphere/index.d.ts.map +1 -1
- package/dist/paramesphere/index.js +1 -0
- package/dist/paramesphere/index.js.map +1 -1
- package/dist/paramesphere/paramesphere-engine.d.ts +40 -3
- package/dist/paramesphere/paramesphere-engine.d.ts.map +1 -1
- package/dist/paramesphere/paramesphere-engine.js +133 -6
- package/dist/paramesphere/paramesphere-engine.js.map +1 -1
- package/dist/paramesphere/scheduled-verifier.d.ts +136 -0
- package/dist/paramesphere/scheduled-verifier.d.ts.map +1 -0
- package/dist/paramesphere/scheduled-verifier.js +338 -0
- package/dist/paramesphere/scheduled-verifier.js.map +1 -0
- package/dist/paramesphere/svd-worker-pool.d.ts +37 -0
- package/dist/paramesphere/svd-worker-pool.d.ts.map +1 -0
- package/dist/paramesphere/svd-worker-pool.js +144 -0
- package/dist/paramesphere/svd-worker-pool.js.map +1 -0
- package/dist/paramesphere/svd-worker.d.ts +2 -0
- package/dist/paramesphere/svd-worker.d.ts.map +1 -0
- package/dist/paramesphere/svd-worker.js +103 -0
- package/dist/paramesphere/svd-worker.js.map +1 -0
- package/dist/paramesphere/types.d.ts +14 -0
- package/dist/paramesphere/types.d.ts.map +1 -1
- package/dist/paramesphere/types.js.map +1 -1
- package/dist/phase6/types.d.ts +257 -257
- package/dist/phase6/types.js +1 -1
- package/dist/phase6/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2024-2026 Vorion LLC
|
|
3
|
+
/**
|
|
4
|
+
* Scheduled ParameSphere Batch Verifier
|
|
5
|
+
*
|
|
6
|
+
* Runs I(θ) verification on a configurable schedule instead of on-demand,
|
|
7
|
+
* designed for 100K-agent fleet operations where per-request SVD computation
|
|
8
|
+
* is impractical. Verifies agents in priority order (T7 first — highest
|
|
9
|
+
* blast radius if compromised) with configurable batch size and concurrency.
|
|
10
|
+
*
|
|
11
|
+
* Key design choices:
|
|
12
|
+
* - Priority queue: T5-T7 first, then T3-T4, then T0-T2
|
|
13
|
+
* - I(θ) result cache with configurable TTL (default: 24h)
|
|
14
|
+
* - Bounded concurrency via semaphore pattern
|
|
15
|
+
* - Event emission for monitoring and alerting pipelines
|
|
16
|
+
* - Metrics: verified/sec, avg SVD latency, cache hit rate
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
*/
|
|
20
|
+
import { EventEmitter } from 'node:events';
|
|
21
|
+
const DEFAULT_CONFIG = {
|
|
22
|
+
verificationInterval: 86_400_000,
|
|
23
|
+
batchSize: 100,
|
|
24
|
+
maxConcurrency: 4,
|
|
25
|
+
priorityTiers: [7, 6, 5, 4, 3, 2, 1, 0],
|
|
26
|
+
cacheTtlMs: 86_400_000,
|
|
27
|
+
alertThreshold: 0.7,
|
|
28
|
+
};
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Scheduled ParameSphere Verifier
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
export class ScheduledParameSphereVerifier extends EventEmitter {
|
|
33
|
+
config;
|
|
34
|
+
verifyFn;
|
|
35
|
+
// ── Agent registry ──────────────────────────────────────────────────
|
|
36
|
+
agents = new Map();
|
|
37
|
+
// ── I(θ) cache ──────────────────────────────────────────────────────
|
|
38
|
+
cache = new Map();
|
|
39
|
+
// ── Scheduling state ────────────────────────────────────────────────
|
|
40
|
+
schedulerTimer = null;
|
|
41
|
+
running = false;
|
|
42
|
+
lastRun = null;
|
|
43
|
+
nextRun = null;
|
|
44
|
+
// ── Metrics ─────────────────────────────────────────────────────────
|
|
45
|
+
totalVerifications = 0;
|
|
46
|
+
totalCacheHits = 0;
|
|
47
|
+
totalCacheMisses = 0;
|
|
48
|
+
latencyAccumulatorMs = 0;
|
|
49
|
+
verificationStartTime = 0;
|
|
50
|
+
lastCycleDurationMs = 0;
|
|
51
|
+
constructor(verifyFn, config) {
|
|
52
|
+
super();
|
|
53
|
+
this.verifyFn = verifyFn;
|
|
54
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
55
|
+
}
|
|
56
|
+
// -----------------------------------------------------------------------
|
|
57
|
+
// Agent registration
|
|
58
|
+
// -----------------------------------------------------------------------
|
|
59
|
+
/** Register an agent for scheduled verification. */
|
|
60
|
+
registerAgent(agent) {
|
|
61
|
+
this.agents.set(agent.agentId, agent);
|
|
62
|
+
}
|
|
63
|
+
/** Remove an agent from scheduled verification. */
|
|
64
|
+
unregisterAgent(agentId) {
|
|
65
|
+
this.agents.delete(agentId);
|
|
66
|
+
this.cache.delete(agentId);
|
|
67
|
+
}
|
|
68
|
+
/** Get all registered agent IDs. */
|
|
69
|
+
getRegisteredAgents() {
|
|
70
|
+
return Array.from(this.agents.keys());
|
|
71
|
+
}
|
|
72
|
+
// -----------------------------------------------------------------------
|
|
73
|
+
// Lifecycle
|
|
74
|
+
// -----------------------------------------------------------------------
|
|
75
|
+
/** Start the scheduled verification loop. */
|
|
76
|
+
start() {
|
|
77
|
+
if (this.running)
|
|
78
|
+
return;
|
|
79
|
+
this.running = true;
|
|
80
|
+
this.nextRun = new Date(Date.now() + this.config.verificationInterval);
|
|
81
|
+
this.schedulerTimer = setInterval(() => {
|
|
82
|
+
this.runFullCycle().catch((err) => {
|
|
83
|
+
this.emit('error', err);
|
|
84
|
+
});
|
|
85
|
+
}, this.config.verificationInterval);
|
|
86
|
+
// Run immediately on start
|
|
87
|
+
this.runFullCycle().catch((err) => {
|
|
88
|
+
this.emit('error', err);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** Stop the verifier gracefully. */
|
|
92
|
+
stop() {
|
|
93
|
+
this.running = false;
|
|
94
|
+
if (this.schedulerTimer) {
|
|
95
|
+
clearInterval(this.schedulerTimer);
|
|
96
|
+
this.schedulerTimer = null;
|
|
97
|
+
}
|
|
98
|
+
this.nextRun = null;
|
|
99
|
+
}
|
|
100
|
+
/** Check if the verifier is running. */
|
|
101
|
+
isRunning() {
|
|
102
|
+
return this.running;
|
|
103
|
+
}
|
|
104
|
+
// -----------------------------------------------------------------------
|
|
105
|
+
// Verification
|
|
106
|
+
// -----------------------------------------------------------------------
|
|
107
|
+
/**
|
|
108
|
+
* Run a full verification cycle across all agents, ordered by priority tier.
|
|
109
|
+
*/
|
|
110
|
+
async runFullCycle() {
|
|
111
|
+
this.verificationStartTime = Date.now();
|
|
112
|
+
this.emit('verification_started', {
|
|
113
|
+
totalAgents: this.agents.size,
|
|
114
|
+
timestamp: new Date(),
|
|
115
|
+
});
|
|
116
|
+
const ordered = this.getPriorityOrderedAgents();
|
|
117
|
+
const allResults = [];
|
|
118
|
+
// Process in batches
|
|
119
|
+
for (let i = 0; i < ordered.length; i += this.config.batchSize) {
|
|
120
|
+
const batch = ordered.slice(i, i + this.config.batchSize);
|
|
121
|
+
const batchIds = batch.map((a) => a.agentId);
|
|
122
|
+
const batchResults = await this.verifyBatch(batchIds);
|
|
123
|
+
allResults.push(...batchResults);
|
|
124
|
+
this.emit('batch_completed', {
|
|
125
|
+
batchIndex: Math.floor(i / this.config.batchSize),
|
|
126
|
+
batchSize: batch.length,
|
|
127
|
+
resultsCount: batchResults.length,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
this.lastRun = new Date();
|
|
131
|
+
this.lastCycleDurationMs = Date.now() - this.verificationStartTime;
|
|
132
|
+
this.nextRun = this.running
|
|
133
|
+
? new Date(Date.now() + this.config.verificationInterval)
|
|
134
|
+
: null;
|
|
135
|
+
this.emit('verification_completed', {
|
|
136
|
+
agentsVerified: allResults.length,
|
|
137
|
+
durationMs: this.lastCycleDurationMs,
|
|
138
|
+
timestamp: this.lastRun,
|
|
139
|
+
});
|
|
140
|
+
return allResults;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Verify a specific batch of agents by ID.
|
|
144
|
+
* Uses bounded concurrency (semaphore pattern).
|
|
145
|
+
*/
|
|
146
|
+
async verifyBatch(agentIds) {
|
|
147
|
+
const results = [];
|
|
148
|
+
const now = Date.now();
|
|
149
|
+
// Filter to only agents that need verification (cache miss or expired)
|
|
150
|
+
const needsVerification = [];
|
|
151
|
+
for (const id of agentIds) {
|
|
152
|
+
const cached = this.cache.get(id);
|
|
153
|
+
if (cached && now - cached.cachedAt < this.config.cacheTtlMs) {
|
|
154
|
+
// Cache hit
|
|
155
|
+
this.totalCacheHits++;
|
|
156
|
+
results.push(cached);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
this.totalCacheMisses++;
|
|
160
|
+
needsVerification.push(id);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Verify uncached agents with bounded concurrency
|
|
164
|
+
const pending = [];
|
|
165
|
+
let activeCount = 0;
|
|
166
|
+
let resolveSlot = null;
|
|
167
|
+
const acquireSlot = () => {
|
|
168
|
+
if (activeCount < this.config.maxConcurrency) {
|
|
169
|
+
activeCount++;
|
|
170
|
+
return Promise.resolve();
|
|
171
|
+
}
|
|
172
|
+
return new Promise((resolve) => {
|
|
173
|
+
resolveSlot = resolve;
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
const releaseSlot = () => {
|
|
177
|
+
activeCount--;
|
|
178
|
+
if (resolveSlot) {
|
|
179
|
+
const resolve = resolveSlot;
|
|
180
|
+
resolveSlot = null;
|
|
181
|
+
activeCount++;
|
|
182
|
+
resolve();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
// Process with concurrency limit
|
|
186
|
+
const tasks = needsVerification.map(async (agentId) => {
|
|
187
|
+
await acquireSlot();
|
|
188
|
+
try {
|
|
189
|
+
return await this.verifySingleAgent(agentId);
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
releaseSlot();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
const taskResults = await Promise.all(tasks);
|
|
196
|
+
for (const result of taskResults) {
|
|
197
|
+
if (result) {
|
|
198
|
+
results.push(result);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return results;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get the current verification status.
|
|
205
|
+
*/
|
|
206
|
+
getVerificationStatus() {
|
|
207
|
+
const verified = this.totalVerifications;
|
|
208
|
+
const pending = this.agents.size - this.cache.size;
|
|
209
|
+
return {
|
|
210
|
+
lastRun: this.lastRun,
|
|
211
|
+
nextRun: this.nextRun,
|
|
212
|
+
agentsVerified: verified,
|
|
213
|
+
agentsPending: Math.max(0, pending),
|
|
214
|
+
avgLatencyMs: this.totalVerifications > 0
|
|
215
|
+
? this.latencyAccumulatorMs / this.totalVerifications
|
|
216
|
+
: 0,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get metrics snapshot.
|
|
221
|
+
*/
|
|
222
|
+
getMetrics() {
|
|
223
|
+
const totalRequests = this.totalCacheHits + this.totalCacheMisses;
|
|
224
|
+
const cycleDurationSec = this.lastCycleDurationMs / 1_000;
|
|
225
|
+
return {
|
|
226
|
+
agentsVerifiedPerSec: cycleDurationSec > 0
|
|
227
|
+
? this.totalVerifications / cycleDurationSec
|
|
228
|
+
: 0,
|
|
229
|
+
avgSvdLatencyMs: this.totalVerifications > 0
|
|
230
|
+
? this.latencyAccumulatorMs / this.totalVerifications
|
|
231
|
+
: 0,
|
|
232
|
+
cacheHitRate: totalRequests > 0 ? this.totalCacheHits / totalRequests : 0,
|
|
233
|
+
totalVerifications: this.totalVerifications,
|
|
234
|
+
totalCacheHits: this.totalCacheHits,
|
|
235
|
+
totalCacheMisses: this.totalCacheMisses,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get a cached I(θ) result for an agent (if available and not expired).
|
|
240
|
+
*/
|
|
241
|
+
getCachedResult(agentId) {
|
|
242
|
+
const cached = this.cache.get(agentId);
|
|
243
|
+
if (!cached)
|
|
244
|
+
return null;
|
|
245
|
+
const now = Date.now();
|
|
246
|
+
if (now - cached.cachedAt >= this.config.cacheTtlMs) {
|
|
247
|
+
this.cache.delete(agentId);
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
return cached;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Invalidate a cached result (forces re-verification on next cycle).
|
|
254
|
+
*/
|
|
255
|
+
invalidateCache(agentId) {
|
|
256
|
+
this.cache.delete(agentId);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Clear the entire cache.
|
|
260
|
+
*/
|
|
261
|
+
clearCache() {
|
|
262
|
+
this.cache.clear();
|
|
263
|
+
}
|
|
264
|
+
// -----------------------------------------------------------------------
|
|
265
|
+
// Internal
|
|
266
|
+
// -----------------------------------------------------------------------
|
|
267
|
+
getPriorityOrderedAgents() {
|
|
268
|
+
const agentsByTier = new Map();
|
|
269
|
+
for (const agent of this.agents.values()) {
|
|
270
|
+
const existing = agentsByTier.get(agent.tier) ?? [];
|
|
271
|
+
existing.push(agent);
|
|
272
|
+
agentsByTier.set(agent.tier, existing);
|
|
273
|
+
}
|
|
274
|
+
const ordered = [];
|
|
275
|
+
for (const tier of this.config.priorityTiers) {
|
|
276
|
+
const agents = agentsByTier.get(tier);
|
|
277
|
+
if (agents) {
|
|
278
|
+
ordered.push(...agents);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Include any agents whose tier isn't in the priority list
|
|
282
|
+
for (const agent of this.agents.values()) {
|
|
283
|
+
if (!this.config.priorityTiers.includes(agent.tier)) {
|
|
284
|
+
ordered.push(agent);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return ordered;
|
|
288
|
+
}
|
|
289
|
+
async verifySingleAgent(agentId) {
|
|
290
|
+
const agent = this.agents.get(agentId);
|
|
291
|
+
if (!agent)
|
|
292
|
+
return null;
|
|
293
|
+
const startMs = Date.now();
|
|
294
|
+
try {
|
|
295
|
+
const weights = agent.getWeights ? await agent.getWeights() : undefined;
|
|
296
|
+
const integrity = await this.verifyFn(agentId, weights);
|
|
297
|
+
const latencyMs = Date.now() - startMs;
|
|
298
|
+
this.totalVerifications++;
|
|
299
|
+
this.latencyAccumulatorMs += latencyMs;
|
|
300
|
+
const result = {
|
|
301
|
+
agentId,
|
|
302
|
+
integrity,
|
|
303
|
+
cachedAt: Date.now(),
|
|
304
|
+
latencyMs,
|
|
305
|
+
};
|
|
306
|
+
this.cache.set(agentId, result);
|
|
307
|
+
// Emit integrity alert if below threshold
|
|
308
|
+
if (integrity.composite < this.config.alertThreshold) {
|
|
309
|
+
this.emit('integrity_alert', {
|
|
310
|
+
agentId,
|
|
311
|
+
integrity: integrity.composite,
|
|
312
|
+
threshold: this.config.alertThreshold,
|
|
313
|
+
tier: agent.tier,
|
|
314
|
+
timestamp: new Date(),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
this.emit('error', {
|
|
321
|
+
agentId,
|
|
322
|
+
error: err instanceof Error ? err.message : String(err),
|
|
323
|
+
timestamp: new Date(),
|
|
324
|
+
});
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// ---------------------------------------------------------------------------
|
|
330
|
+
// Factory
|
|
331
|
+
// ---------------------------------------------------------------------------
|
|
332
|
+
/**
|
|
333
|
+
* Create a scheduled ParameSphere batch verifier.
|
|
334
|
+
*/
|
|
335
|
+
export function createScheduledParameSphereVerifier(verifyFn, config) {
|
|
336
|
+
return new ScheduledParameSphereVerifier(verifyFn, config);
|
|
337
|
+
}
|
|
338
|
+
//# sourceMappingURL=scheduled-verifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduled-verifier.js","sourceRoot":"","sources":["../../src/paramesphere/scheduled-verifier.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAiC3C,MAAM,cAAc,GAAkD;IACpE,oBAAoB,EAAE,UAAU;IAChC,SAAS,EAAE,GAAG;IACd,cAAc,EAAE,CAAC;IACjB,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACvC,UAAU,EAAE,UAAU;IACtB,cAAc,EAAE,GAAG;CACpB,CAAC;AA2CF,8EAA8E;AAC9E,kCAAkC;AAClC,8EAA8E;AAE9E,MAAM,OAAO,6BAA8B,SAAQ,YAAY;IAC5C,MAAM,CAAsC;IAC5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OAAO;gBACP,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;gBACvD,SAAS,EAAE,IAAI,IAAI,EAAE;aACtB,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;GAEG;AACH,MAAM,UAAU,mCAAmC,CACjD,QAAuB,EACvB,MAAqD;IAErD,OAAO,IAAI,6BAA6B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface SvdWorkerPoolConfig {
|
|
2
|
+
/** Number of worker threads (default: cpus - 1, min 1) */
|
|
3
|
+
poolSize?: number;
|
|
4
|
+
/** Max pending tasks before rejecting (default: 1000) */
|
|
5
|
+
maxQueueDepth?: number;
|
|
6
|
+
/** Timeout per SVD computation in ms (default: 5000) */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class SvdWorkerPool {
|
|
10
|
+
private readonly workers;
|
|
11
|
+
private readonly idle;
|
|
12
|
+
private readonly queue;
|
|
13
|
+
private readonly pending;
|
|
14
|
+
private readonly poolSize;
|
|
15
|
+
private readonly maxQueueDepth;
|
|
16
|
+
private readonly timeoutMs;
|
|
17
|
+
private _completed;
|
|
18
|
+
private _errors;
|
|
19
|
+
private _shutdown;
|
|
20
|
+
constructor(config?: SvdWorkerPoolConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Compute top-K singular values off the main thread.
|
|
23
|
+
*/
|
|
24
|
+
computeTopK(matrix: number[][], k: number, maxIterations?: number): Promise<number[]>;
|
|
25
|
+
/** Pool statistics */
|
|
26
|
+
get stats(): {
|
|
27
|
+
active: number;
|
|
28
|
+
queued: number;
|
|
29
|
+
completed: number;
|
|
30
|
+
errors: number;
|
|
31
|
+
};
|
|
32
|
+
/** Shutdown all workers */
|
|
33
|
+
shutdown(): Promise<void>;
|
|
34
|
+
private dispatch;
|
|
35
|
+
private handleResult;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=svd-worker-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svd-worker-pool.d.ts","sourceRoot":"","sources":["../../src/paramesphere/svd-worker-pool.ts"],"names":[],"mappings":"AA2BA,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAsBD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,GAAE,mBAAwB;IAsB5C;;OAEG;IACG,WAAW,CACf,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,CAAC,EAAE,MAAM,EACT,aAAa,GAAE,MAAY,GAC1B,OAAO,CAAC,MAAM,EAAE,CAAC;IA6BpB,sBAAsB;IACtB,IAAI,KAAK;;;;;MAOR;IAED,2BAA2B;IACrB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB/B,OAAO,CAAC,QAAQ;IAUhB,OAAO,CAAC,YAAY;CA0BrB"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2024-2026 Vorion LLC
|
|
3
|
+
/**
|
|
4
|
+
* SVD Worker Thread Pool
|
|
5
|
+
*
|
|
6
|
+
* Moves ParameSphere SVD computation off the Node.js event loop.
|
|
7
|
+
* At 21ms per fingerprint, 100+ T5-T7 agents would block the main
|
|
8
|
+
* thread for seconds. Worker threads eliminate this bottleneck.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* const pool = new SvdWorkerPool({ poolSize: 4 });
|
|
12
|
+
* const values = await pool.computeTopK(matrix, 8);
|
|
13
|
+
* await pool.shutdown();
|
|
14
|
+
*
|
|
15
|
+
* @module @vorionsys/atsf-core/paramesphere
|
|
16
|
+
*/
|
|
17
|
+
import { Worker } from 'worker_threads';
|
|
18
|
+
import { fileURLToPath } from 'url';
|
|
19
|
+
import { dirname, join } from 'path';
|
|
20
|
+
import { availableParallelism } from 'os';
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Worker Pool
|
|
23
|
+
// =============================================================================
|
|
24
|
+
let taskCounter = 0;
|
|
25
|
+
export class SvdWorkerPool {
|
|
26
|
+
workers = [];
|
|
27
|
+
idle = [];
|
|
28
|
+
queue = [];
|
|
29
|
+
pending = new Map();
|
|
30
|
+
poolSize;
|
|
31
|
+
maxQueueDepth;
|
|
32
|
+
timeoutMs;
|
|
33
|
+
_completed = 0;
|
|
34
|
+
_errors = 0;
|
|
35
|
+
_shutdown = false;
|
|
36
|
+
constructor(config = {}) {
|
|
37
|
+
this.poolSize = config.poolSize ?? Math.max(1, availableParallelism() - 1);
|
|
38
|
+
this.maxQueueDepth = config.maxQueueDepth ?? 1000;
|
|
39
|
+
this.timeoutMs = config.timeoutMs ?? 5000;
|
|
40
|
+
// Resolve worker script path relative to this file
|
|
41
|
+
const workerPath = join(dirname(fileURLToPath(import.meta.url)), 'svd-worker.js');
|
|
42
|
+
for (let i = 0; i < this.poolSize; i++) {
|
|
43
|
+
const worker = new Worker(workerPath);
|
|
44
|
+
worker.on('message', (msg) => {
|
|
45
|
+
this.handleResult(msg);
|
|
46
|
+
});
|
|
47
|
+
worker.on('error', (err) => {
|
|
48
|
+
console.error('[SvdWorkerPool] Worker error:', err);
|
|
49
|
+
this._errors++;
|
|
50
|
+
});
|
|
51
|
+
this.workers.push(worker);
|
|
52
|
+
this.idle.push(worker);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Compute top-K singular values off the main thread.
|
|
57
|
+
*/
|
|
58
|
+
async computeTopK(matrix, k, maxIterations = 300) {
|
|
59
|
+
if (this._shutdown) {
|
|
60
|
+
throw new Error('SvdWorkerPool is shut down');
|
|
61
|
+
}
|
|
62
|
+
if (this.queue.length >= this.maxQueueDepth) {
|
|
63
|
+
throw new Error(`SvdWorkerPool queue full (${this.maxQueueDepth})`);
|
|
64
|
+
}
|
|
65
|
+
const taskId = `svd-${++taskCounter}`;
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const timer = setTimeout(() => {
|
|
68
|
+
this.pending.delete(taskId);
|
|
69
|
+
this._errors++;
|
|
70
|
+
reject(new Error(`SVD computation timed out after ${this.timeoutMs}ms`));
|
|
71
|
+
}, this.timeoutMs);
|
|
72
|
+
const task = { taskId, matrix, k, maxIterations, resolve, reject, timer };
|
|
73
|
+
const worker = this.idle.pop();
|
|
74
|
+
if (worker) {
|
|
75
|
+
this.dispatch(worker, task);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.queue.push(task);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Pool statistics */
|
|
83
|
+
get stats() {
|
|
84
|
+
return {
|
|
85
|
+
active: this.poolSize - this.idle.length,
|
|
86
|
+
queued: this.queue.length,
|
|
87
|
+
completed: this._completed,
|
|
88
|
+
errors: this._errors,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** Shutdown all workers */
|
|
92
|
+
async shutdown() {
|
|
93
|
+
this._shutdown = true;
|
|
94
|
+
// Reject all queued tasks
|
|
95
|
+
for (const task of this.queue) {
|
|
96
|
+
clearTimeout(task.timer);
|
|
97
|
+
task.reject(new Error('SvdWorkerPool shutting down'));
|
|
98
|
+
}
|
|
99
|
+
this.queue.length = 0;
|
|
100
|
+
// Terminate all workers
|
|
101
|
+
await Promise.all(this.workers.map(w => w.terminate()));
|
|
102
|
+
this.workers.length = 0;
|
|
103
|
+
this.idle.length = 0;
|
|
104
|
+
}
|
|
105
|
+
// =========================================================================
|
|
106
|
+
// Internal
|
|
107
|
+
// =========================================================================
|
|
108
|
+
dispatch(worker, task) {
|
|
109
|
+
this.pending.set(task.taskId, task);
|
|
110
|
+
worker.postMessage({
|
|
111
|
+
taskId: task.taskId,
|
|
112
|
+
matrix: task.matrix,
|
|
113
|
+
k: task.k,
|
|
114
|
+
maxIterations: task.maxIterations,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
handleResult(msg) {
|
|
118
|
+
const task = this.pending.get(msg.taskId);
|
|
119
|
+
if (!task)
|
|
120
|
+
return; // Timed out already
|
|
121
|
+
this.pending.delete(msg.taskId);
|
|
122
|
+
clearTimeout(task.timer);
|
|
123
|
+
if (msg.error) {
|
|
124
|
+
this._errors++;
|
|
125
|
+
task.reject(new Error(msg.error));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this._completed++;
|
|
129
|
+
task.resolve(msg.result);
|
|
130
|
+
}
|
|
131
|
+
// Dispatch next queued task or return worker to idle
|
|
132
|
+
const worker = this.workers.find(w => !this.idle.includes(w));
|
|
133
|
+
if (worker) {
|
|
134
|
+
const next = this.queue.shift();
|
|
135
|
+
if (next) {
|
|
136
|
+
this.dispatch(worker, next);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.idle.push(worker);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|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C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,IAAI,EAAE,CAAC;gBACT,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svd-worker.d.ts","sourceRoot":"","sources":["../../src/paramesphere/svd-worker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2024-2026 Vorion LLC
|
|
3
|
+
/**
|
|
4
|
+
* SVD Worker Thread — runs power iteration off the main event loop.
|
|
5
|
+
*
|
|
6
|
+
* Receives: { matrix: number[][], k: number, maxIterations: number, taskId: string }
|
|
7
|
+
* Posts: { taskId: string, result: number[] } or { taskId: string, error: string }
|
|
8
|
+
*/
|
|
9
|
+
import { parentPort } from 'worker_threads';
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// SVD Power Iteration (duplicated from paramesphere-engine for isolation)
|
|
12
|
+
// =============================================================================
|
|
13
|
+
function matVecMul(matrix, vec) {
|
|
14
|
+
const rows = matrix.length;
|
|
15
|
+
const result = new Array(rows).fill(0);
|
|
16
|
+
for (let i = 0; i < rows; i++) {
|
|
17
|
+
const row = matrix[i];
|
|
18
|
+
let sum = 0;
|
|
19
|
+
for (let j = 0; j < vec.length; j++) {
|
|
20
|
+
sum += row[j] * vec[j];
|
|
21
|
+
}
|
|
22
|
+
result[i] = sum;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
function matTransVecMul(matrix, vec) {
|
|
27
|
+
const cols = matrix[0].length;
|
|
28
|
+
const result = new Array(cols).fill(0);
|
|
29
|
+
for (let i = 0; i < matrix.length; i++) {
|
|
30
|
+
const row = matrix[i];
|
|
31
|
+
const vi = vec[i];
|
|
32
|
+
for (let j = 0; j < cols; j++) {
|
|
33
|
+
result[j] += row[j] * vi;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
function vecNorm(vec) {
|
|
39
|
+
let sum = 0;
|
|
40
|
+
for (const v of vec)
|
|
41
|
+
sum += v * v;
|
|
42
|
+
return Math.sqrt(sum);
|
|
43
|
+
}
|
|
44
|
+
function normalize(vec) {
|
|
45
|
+
const norm = vecNorm(vec);
|
|
46
|
+
if (norm === 0)
|
|
47
|
+
return vec;
|
|
48
|
+
return vec.map(v => v / norm);
|
|
49
|
+
}
|
|
50
|
+
function topKSingularValues(matrix, k, maxIterations = 300, tolerance = 1e-10) {
|
|
51
|
+
const rows = matrix.length;
|
|
52
|
+
const cols = matrix[0]?.length ?? 0;
|
|
53
|
+
if (rows === 0 || cols === 0)
|
|
54
|
+
return [];
|
|
55
|
+
const actualK = Math.min(k, rows, cols);
|
|
56
|
+
const singularValues = [];
|
|
57
|
+
// Work on a copy to allow deflation
|
|
58
|
+
const work = matrix.map(row => [...row]);
|
|
59
|
+
for (let sv = 0; sv < actualK; sv++) {
|
|
60
|
+
// Random starting vector
|
|
61
|
+
let v = new Array(cols);
|
|
62
|
+
for (let i = 0; i < cols; i++)
|
|
63
|
+
v[i] = Math.random();
|
|
64
|
+
v = normalize(v);
|
|
65
|
+
let sigma = 0;
|
|
66
|
+
for (let iter = 0; iter < maxIterations; iter++) {
|
|
67
|
+
const u = normalize(matVecMul(work, v));
|
|
68
|
+
const vNew = normalize(matTransVecMul(work, u));
|
|
69
|
+
const newSigma = vecNorm(matVecMul(work, vNew));
|
|
70
|
+
if (Math.abs(newSigma - sigma) < tolerance) {
|
|
71
|
+
sigma = newSigma;
|
|
72
|
+
v = vNew;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
sigma = newSigma;
|
|
76
|
+
v = vNew;
|
|
77
|
+
}
|
|
78
|
+
singularValues.push(sigma);
|
|
79
|
+
// Deflate: remove this singular value's contribution
|
|
80
|
+
const u = normalize(matVecMul(work, v));
|
|
81
|
+
for (let i = 0; i < rows; i++) {
|
|
82
|
+
for (let j = 0; j < cols; j++) {
|
|
83
|
+
work[i][j] -= sigma * u[i] * v[j];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return singularValues;
|
|
88
|
+
}
|
|
89
|
+
// =============================================================================
|
|
90
|
+
// Message Handler
|
|
91
|
+
// =============================================================================
|
|
92
|
+
if (parentPort) {
|
|
93
|
+
parentPort.on('message', (msg) => {
|
|
94
|
+
try {
|
|
95
|
+
const result = topKSingularValues(msg.matrix, msg.k, msg.maxIterations);
|
|
96
|
+
parentPort.postMessage({ taskId: msg.taskId, result });
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
parentPort.postMessage({ taskId: msg.taskId, error: String(err) });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=svd-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svd-worker.js","sourceRoot":"","sources":["../../src/paramesphere/svd-worker.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,gFAAgF;AAChF,0EAA0E;AAC1E,gFAAgF;AAEhF,SAAS,SAAS,CAAC,MAAkB,EAAE,GAAa;IAClD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3B,MAAM,MAAM,GAAG,I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