@memberjunction/integration-progress-artifacts 6.2.0-edge.5 → 6.2.0-edge.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.
- package/dist/IntegrationProgressEmitter.d.ts +165 -10
- package/dist/IntegrationProgressEmitter.d.ts.map +1 -1
- package/dist/IntegrationProgressEmitter.js +301 -20
- package/dist/IntegrationProgressEmitter.js.map +1 -1
- package/dist/IntegrationProgressReader.d.ts +93 -9
- package/dist/IntegrationProgressReader.d.ts.map +1 -1
- package/dist/IntegrationProgressReader.js +215 -99
- package/dist/IntegrationProgressReader.js.map +1 -1
- package/dist/IntegrationRunReconciler.d.ts +37 -0
- package/dist/IntegrationRunReconciler.d.ts.map +1 -0
- package/dist/IntegrationRunReconciler.js +97 -0
- package/dist/IntegrationRunReconciler.js.map +1 -0
- package/dist/RunArtifactRoot.d.ts +28 -0
- package/dist/RunArtifactRoot.d.ts.map +1 -0
- package/dist/RunArtifactRoot.js +35 -0
- package/dist/RunArtifactRoot.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +35 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1,65 +1,115 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { CountsContributeToAggregate } from './types.js';
|
|
4
|
+
import { DefaultRunArtifactRoot } from './RunArtifactRoot.js';
|
|
4
5
|
/**
|
|
5
6
|
* Read API for the progress artifacts. Frontend / health-check / resumption code
|
|
6
7
|
* uses this to inspect ongoing or completed runs without touching the emitter.
|
|
7
8
|
*
|
|
8
9
|
* Implementation is purely file-system reads; no shared state with the emitter
|
|
9
10
|
* (an emitter in another process can write while this reader tails).
|
|
11
|
+
*
|
|
12
|
+
* **Read cost is part of the contract.** A run's journal reaches 12–13 k events with multi-KB
|
|
13
|
+
* payloads, and on App Service's SMB filesystem `IntegrationListRuns` with `limit:1` once took 73
|
|
14
|
+
* seconds and then timed out (MJ-RUN-5/21) — because it hydrated EVERY run before applying the
|
|
15
|
+
* limit, and each hydration read the whole journal four times. So:
|
|
16
|
+
*
|
|
17
|
+
* - every filter {@link ListRuns} supports is answered from `manifest.json`/`result.json`, and the
|
|
18
|
+
* limit is applied BEFORE anything opens a journal;
|
|
19
|
+
* - a run that finished carries its own numbers in `result.json`, and they are taken from there
|
|
20
|
+
* rather than re-derived;
|
|
21
|
+
* - when a journal must be read, it is read ONCE and every value comes out of that pass.
|
|
10
22
|
*/
|
|
11
23
|
export class IntegrationProgressReader {
|
|
12
|
-
constructor(rootDir =
|
|
24
|
+
constructor(rootDir = DefaultRunArtifactRoot()) {
|
|
13
25
|
this.rootDir = rootDir;
|
|
14
26
|
}
|
|
15
|
-
/**
|
|
16
|
-
|
|
27
|
+
/** Directory these artifacts live in, so callers can address a run's files directly. */
|
|
28
|
+
get RootDir() {
|
|
29
|
+
return this.rootDir;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* List runs, newest-STARTED first.
|
|
33
|
+
*
|
|
34
|
+
* Ordering is by the manifest's `startedAt`, not by directory mtime. A stranded run stops being
|
|
35
|
+
* written to, so its mtime freezes at the moment it stranded and mtime ordering sank it below
|
|
36
|
+
* every later run — hiding, behind the `limit`, exactly the run an operator is looking for. A
|
|
37
|
+
* start time never moves. (The same reasoning governs retention; see
|
|
38
|
+
* `IntegrationProgressEmitter.pruneOldRuns`.)
|
|
39
|
+
*
|
|
40
|
+
* `offset` exists because the caller authorization-filters AFTER this returns, so a short page
|
|
41
|
+
* does not mean the source is exhausted — it may just mean the caller could not read some of
|
|
42
|
+
* what came back. Without an offset there is no way to ask for the next slice, and both UI
|
|
43
|
+
* surfaces faked paging by re-requesting with a doubled limit.
|
|
44
|
+
*
|
|
45
|
+
* Filters and the limit are applied on the run HEADS — `manifest.json` plus the presence of
|
|
46
|
+
* `result.json` — so only the runs actually being returned are hydrated.
|
|
47
|
+
*/
|
|
48
|
+
async ListRuns(filter = {}, limit = 50, offset = 0) {
|
|
17
49
|
const entries = await this.safeReadDir(this.rootDir);
|
|
18
|
-
const
|
|
50
|
+
const heads = [];
|
|
19
51
|
for (const runID of entries) {
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
continue;
|
|
23
|
-
|
|
52
|
+
const head = await this.readRunHead(runID);
|
|
53
|
+
if (!head)
|
|
54
|
+
continue; // not a run dir (or a manifest still being written)
|
|
55
|
+
const manifest = head.manifest;
|
|
56
|
+
if (filter.runKind && manifest.runKind !== filter.runKind)
|
|
24
57
|
continue;
|
|
25
|
-
if (filter.integrationID &&
|
|
58
|
+
if (filter.integrationID && manifest.integrationID !== filter.integrationID)
|
|
26
59
|
continue;
|
|
27
|
-
if (filter.companyIntegrationID &&
|
|
60
|
+
if (filter.companyIntegrationID && !IntegrationProgressReader.RunCoversCompanyIntegration(manifest, filter.companyIntegrationID))
|
|
28
61
|
continue;
|
|
29
|
-
if (filter.sinceTs &&
|
|
62
|
+
if (filter.sinceTs && manifest.startedAt < filter.sinceTs)
|
|
30
63
|
continue;
|
|
31
|
-
if (filter.inFlightOnly &&
|
|
64
|
+
if (filter.inFlightOnly && head.result)
|
|
32
65
|
continue;
|
|
33
|
-
|
|
34
|
-
|
|
66
|
+
heads.push({ runID, head });
|
|
67
|
+
}
|
|
68
|
+
heads.sort((a, b) => {
|
|
69
|
+
const byStart = IntegrationProgressReader.startMs(b.head.manifest) - IntegrationProgressReader.startMs(a.head.manifest);
|
|
70
|
+
if (byStart !== 0)
|
|
71
|
+
return byStart;
|
|
72
|
+
// Run IDs embed their mint time and a random suffix, so this is a stable, deterministic
|
|
73
|
+
// tiebreak for two runs that started in the same millisecond.
|
|
74
|
+
return a.runID < b.runID ? 1 : a.runID > b.runID ? -1 : 0;
|
|
75
|
+
});
|
|
76
|
+
const start = Math.max(0, offset);
|
|
77
|
+
const kept = heads.slice(start, start + limit);
|
|
78
|
+
const snapshots = [];
|
|
79
|
+
for (const k of kept) {
|
|
80
|
+
snapshots.push(await this.hydrate(k.runID, k.head));
|
|
81
|
+
}
|
|
82
|
+
return snapshots;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The complete set of connections a run touched, normalised across the two manifest shapes.
|
|
86
|
+
*
|
|
87
|
+
* Single-connection runs (every sync, every discovery) carry only `companyIntegrationID`;
|
|
88
|
+
* runs that can span a batch (RSU) carry the full set in `companyIntegrationIDs` and set the
|
|
89
|
+
* singular field only when the set has exactly one member. Callers that make a per-connection
|
|
90
|
+
* decision — listing, and above all AUTHORIZATION — must read the set, not the singular field,
|
|
91
|
+
* or a batch run silently looks connection-less.
|
|
92
|
+
*
|
|
93
|
+
* Returns an empty array for a run with no connection identity at all.
|
|
94
|
+
*/
|
|
95
|
+
static CompanyIntegrationIDsFor(manifest) {
|
|
96
|
+
if (manifest.companyIntegrationIDs && manifest.companyIntegrationIDs.length > 0) {
|
|
97
|
+
return manifest.companyIntegrationIDs;
|
|
35
98
|
}
|
|
36
|
-
|
|
37
|
-
|
|
99
|
+
return manifest.companyIntegrationID ? [manifest.companyIntegrationID] : [];
|
|
100
|
+
}
|
|
101
|
+
/** Whether the given connection is one of the connections a run touched. */
|
|
102
|
+
static RunCoversCompanyIntegration(manifest, companyIntegrationID) {
|
|
103
|
+
return IntegrationProgressReader.CompanyIntegrationIDsFor(manifest).includes(companyIntegrationID);
|
|
38
104
|
}
|
|
39
105
|
/** Read snapshot of a single run. Returns undefined if runID not found. */
|
|
40
106
|
async GetRun(runID) {
|
|
41
107
|
if (!IntegrationProgressReader.isSafeRunID(runID))
|
|
42
108
|
return undefined;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
if (!manifest)
|
|
109
|
+
const head = await this.readRunHead(runID);
|
|
110
|
+
if (!head)
|
|
46
111
|
return undefined;
|
|
47
|
-
|
|
48
|
-
const events = await this.readProgressTail(join(runDir, 'progress.jsonl'), 1);
|
|
49
|
-
const latestEvent = events[events.length - 1];
|
|
50
|
-
const allCounts = await this.aggregateCountsFromTail(join(runDir, 'progress.jsonl'));
|
|
51
|
-
const warnings = await this.aggregateWarningsFromTail(join(runDir, 'progress.jsonl'));
|
|
52
|
-
const eventCount = await this.countLines(join(runDir, 'progress.jsonl'));
|
|
53
|
-
return {
|
|
54
|
-
manifest,
|
|
55
|
-
latestEvent,
|
|
56
|
-
eventCount,
|
|
57
|
-
result,
|
|
58
|
-
isInFlight: !result,
|
|
59
|
-
counts: allCounts,
|
|
60
|
-
warnings: warnings.length > 0 ? warnings : undefined,
|
|
61
|
-
warningCount: warnings.length,
|
|
62
|
-
};
|
|
112
|
+
return this.hydrate(runID, head);
|
|
63
113
|
}
|
|
64
114
|
/** Tail events since a given sequence. */
|
|
65
115
|
async Tail(runID, sinceSeq = 0) {
|
|
@@ -96,6 +146,61 @@ export class IntegrationProgressReader {
|
|
|
96
146
|
return this.ListRuns({ inFlightOnly: true }, 1000);
|
|
97
147
|
}
|
|
98
148
|
// ── Internals ──────────────────────────────────────────────────────
|
|
149
|
+
/** Sortable run start, from the manifest. An unparseable timestamp sorts oldest rather than throwing. */
|
|
150
|
+
static startMs(manifest) {
|
|
151
|
+
const parsed = Date.parse(manifest.startedAt);
|
|
152
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The manifest and (if the run finished) the terminal record. Two small files, no journal.
|
|
156
|
+
*
|
|
157
|
+
* A missing or unparseable manifest means "not a run" — the same rule the emitter's resume path
|
|
158
|
+
* applies — so a stray file under the root is skipped rather than reported as a run.
|
|
159
|
+
*/
|
|
160
|
+
async readRunHead(runID) {
|
|
161
|
+
const runDir = join(this.rootDir, runID);
|
|
162
|
+
const manifest = await this.safeReadJSON(join(runDir, 'manifest.json'));
|
|
163
|
+
if (!manifest)
|
|
164
|
+
return undefined;
|
|
165
|
+
const result = await this.safeReadJSON(join(runDir, 'result.json'));
|
|
166
|
+
return { manifest, result };
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Turns a run head into the full snapshot.
|
|
170
|
+
*
|
|
171
|
+
* A finished run costs ZERO journal reads: the emitter already wrote its aggregate counts,
|
|
172
|
+
* warnings, event count and final event into `result.json` — re-deriving them from the journal is
|
|
173
|
+
* what made a listing read every run's whole event log. A run still in flight, and a run whose
|
|
174
|
+
* `result.json` predates the persisted counters, take exactly one pass.
|
|
175
|
+
*/
|
|
176
|
+
async hydrate(runID, head) {
|
|
177
|
+
const result = head.result;
|
|
178
|
+
if (result && result.eventCount !== undefined) {
|
|
179
|
+
return {
|
|
180
|
+
manifest: head.manifest,
|
|
181
|
+
latestEvent: result.latestEvent,
|
|
182
|
+
eventCount: result.eventCount,
|
|
183
|
+
result,
|
|
184
|
+
isInFlight: false,
|
|
185
|
+
counts: result.aggregateCounts,
|
|
186
|
+
warnings: result.warnings,
|
|
187
|
+
warningCount: result.warningCount ?? result.warnings?.length ?? 0,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const digest = await this.readJournalDigest(join(this.rootDir, runID, 'progress.jsonl'));
|
|
191
|
+
return {
|
|
192
|
+
manifest: head.manifest,
|
|
193
|
+
latestEvent: digest.latestEvent,
|
|
194
|
+
eventCount: digest.eventCount,
|
|
195
|
+
result,
|
|
196
|
+
isInFlight: !result,
|
|
197
|
+
// A terminal record still wins where it has the number: it is the emitter's own account of
|
|
198
|
+
// the run, and for a resumed run it spans both processes.
|
|
199
|
+
counts: result?.aggregateCounts ?? digest.counts,
|
|
200
|
+
warnings: result?.warnings ?? (digest.warnings.length > 0 ? digest.warnings : undefined),
|
|
201
|
+
warningCount: result?.warningCount ?? digest.warnings.length,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
99
204
|
/**
|
|
100
205
|
* SECURITY: run IDs reach {@link GetRun} / {@link Tail} from callers that may pass
|
|
101
206
|
* client-supplied values (e.g. the `IntegrationGetRun` / `IntegrationTailRunEvents` GraphQL
|
|
@@ -140,84 +245,95 @@ export class IntegrationProgressReader {
|
|
|
140
245
|
return undefined;
|
|
141
246
|
}
|
|
142
247
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
248
|
+
/**
|
|
249
|
+
* Per-entity outcome counts for a sync run, recovered from its event stream.
|
|
250
|
+
*
|
|
251
|
+
* The run ROW records only TotalRecords, so history could never show created vs updated vs
|
|
252
|
+
* skipped per table — the field existed on the API type and was never populated, which is what
|
|
253
|
+
* thing.txt saw as an empty breakdown. The engine already emits every number needed on
|
|
254
|
+
* `sync.entity-map.complete`; this reads them back.
|
|
255
|
+
*
|
|
256
|
+
* Honest ceiling: artifacts are pruned by the retention cap and are node-local, so a run old
|
|
257
|
+
* enough to have been pruned yields nothing. The caller must render that as "not recorded"
|
|
258
|
+
* rather than as zeros.
|
|
259
|
+
*/
|
|
260
|
+
async EntityOutcomes(runID) {
|
|
261
|
+
const events = await this.Tail(runID, 0);
|
|
262
|
+
const byEntity = new Map();
|
|
263
|
+
for (const ev of events) {
|
|
264
|
+
// A sync mirrors each entity map's completion as a `stage.complete` whose stage is the
|
|
265
|
+
// object name. `counts` folds created and updated into `succeeded`, so the split rides
|
|
266
|
+
// alongside in `data`.
|
|
267
|
+
if (ev.eventType !== 'stage.complete')
|
|
268
|
+
continue;
|
|
269
|
+
const d = (ev.data ?? {});
|
|
270
|
+
if (d.recordsCreated === undefined && d.recordsUpdated === undefined)
|
|
271
|
+
continue;
|
|
272
|
+
const name = String(d.mjEntity ?? ev.stage ?? '');
|
|
273
|
+
if (!name)
|
|
274
|
+
continue;
|
|
275
|
+
const row = byEntity.get(name) ?? { EntityName: name, InsertCount: 0, UpdateCount: 0, SkipCount: 0, ErrorCount: 0 };
|
|
276
|
+
// A map can appear more than once in a run (resume, or a push pass after a pull), so
|
|
277
|
+
// accumulate rather than overwrite.
|
|
278
|
+
row.InsertCount += Number(d.recordsCreated ?? 0);
|
|
279
|
+
row.UpdateCount += Number(d.recordsUpdated ?? 0);
|
|
280
|
+
row.SkipCount += Number(ev.counts?.skipped ?? 0);
|
|
281
|
+
row.ErrorCount += Number(ev.counts?.failed ?? 0);
|
|
282
|
+
byEntity.set(name, row);
|
|
164
283
|
}
|
|
165
|
-
return
|
|
284
|
+
return [...byEntity.values()];
|
|
166
285
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
286
|
+
/**
|
|
287
|
+
* ONE pass over a journal, yielding every value a snapshot needs from it: the event count, the
|
|
288
|
+
* latest event, the applied-count aggregate and the warnings rollup.
|
|
289
|
+
*
|
|
290
|
+
* This replaces four independent helpers that each read the whole file into a JS string. On a
|
|
291
|
+
* 12–13 k-event journal that was four multi-megabyte strings per run per call — a heap risk as
|
|
292
|
+
* much as an I/O one.
|
|
293
|
+
*/
|
|
294
|
+
async readJournalDigest(path) {
|
|
174
295
|
const raw = await this.safeReadFile(path);
|
|
175
|
-
if (
|
|
176
|
-
return
|
|
296
|
+
if (raw === undefined)
|
|
297
|
+
return { eventCount: 0, warnings: [] };
|
|
177
298
|
const totals = { processed: 0, succeeded: 0, failed: 0, skipped: 0 };
|
|
299
|
+
const warnings = [];
|
|
300
|
+
let eventCount = 0;
|
|
301
|
+
let latestEvent;
|
|
178
302
|
for (const line of raw.split('\n')) {
|
|
179
303
|
if (!line.trim())
|
|
180
304
|
continue;
|
|
305
|
+
eventCount++;
|
|
306
|
+
let ev;
|
|
181
307
|
try {
|
|
182
|
-
|
|
183
|
-
if (!ev.counts)
|
|
184
|
-
continue;
|
|
185
|
-
// Mirror the emitter's rule (CountsContributeToAggregate): only the APPLIED
|
|
186
|
-
// rollup events (`stage.complete`/`run.complete`) feed the total. The FETCHED
|
|
187
|
-
// `processed` on `records.batch.complete` is per-batch progress only and would
|
|
188
|
-
// double-count every record if summed here. Keeping the rule in one place
|
|
189
|
-
// guarantees a re-derived count matches the emitter's running aggregate.
|
|
190
|
-
if (!CountsContributeToAggregate(ev.eventType))
|
|
191
|
-
continue;
|
|
192
|
-
totals.processed += ev.counts.processed ?? 0;
|
|
193
|
-
totals.succeeded += ev.counts.succeeded ?? 0;
|
|
194
|
-
totals.failed += ev.counts.failed ?? 0;
|
|
195
|
-
totals.skipped += ev.counts.skipped ?? 0;
|
|
308
|
+
ev = JSON.parse(line);
|
|
196
309
|
}
|
|
197
|
-
catch {
|
|
198
|
-
}
|
|
199
|
-
return totals;
|
|
200
|
-
}
|
|
201
|
-
async aggregateWarningsFromTail(path) {
|
|
202
|
-
const raw = await this.safeReadFile(path);
|
|
203
|
-
if (!raw)
|
|
204
|
-
return [];
|
|
205
|
-
const warnings = [];
|
|
206
|
-
for (const line of raw.split('\n')) {
|
|
207
|
-
if (!line.trim())
|
|
310
|
+
catch {
|
|
208
311
|
continue;
|
|
209
|
-
try {
|
|
210
|
-
const ev = JSON.parse(line);
|
|
211
|
-
if (ev.eventType !== 'warning')
|
|
212
|
-
continue;
|
|
213
|
-
warnings.push(this.warningFromEvent(ev));
|
|
214
312
|
}
|
|
215
|
-
|
|
313
|
+
// The last PARSEABLE line, not literally the last line: a run killed mid-append leaves a
|
|
314
|
+
// torn fragment, and treating that as "no latest event" is what makes a killed run
|
|
315
|
+
// unrecognisable to the resume path, which matches on the run's last stage.
|
|
316
|
+
latestEvent = ev;
|
|
317
|
+
if (ev.eventType === 'warning')
|
|
318
|
+
warnings.push(IntegrationProgressReader.warningFromEvent(ev));
|
|
319
|
+
if (!ev.counts)
|
|
320
|
+
continue;
|
|
321
|
+
// Mirror the emitter's rule (CountsContributeToAggregate): only the APPLIED
|
|
322
|
+
// rollup events (`stage.complete`/`run.complete`) feed the total. The FETCHED
|
|
323
|
+
// `processed` on `records.batch.complete` is per-batch progress only and would
|
|
324
|
+
// double-count every record if summed here. Keeping the rule in one place
|
|
325
|
+
// guarantees a re-derived count matches the emitter's running aggregate.
|
|
326
|
+
if (!CountsContributeToAggregate(ev.eventType))
|
|
327
|
+
continue;
|
|
328
|
+
totals.processed += ev.counts.processed ?? 0;
|
|
329
|
+
totals.succeeded += ev.counts.succeeded ?? 0;
|
|
330
|
+
totals.failed += ev.counts.failed ?? 0;
|
|
331
|
+
totals.skipped += ev.counts.skipped ?? 0;
|
|
216
332
|
}
|
|
217
|
-
return warnings;
|
|
333
|
+
return { eventCount, latestEvent, counts: totals, warnings };
|
|
218
334
|
}
|
|
219
335
|
/** Reconstruct a {@link SyncWarning} from a persisted `'warning'` event. */
|
|
220
|
-
warningFromEvent(event) {
|
|
336
|
+
static warningFromEvent(event) {
|
|
221
337
|
const { code, ...rest } = event.data ?? {};
|
|
222
338
|
return {
|
|
223
339
|
code: typeof code === 'string' ? code : 'UNKNOWN',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntegrationProgressReader.js","sourceRoot":"","sources":["../src/IntegrationProgressReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"IntegrationProgressReader.js","sourceRoot":"","sources":["../src/IntegrationProgressReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE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E;YAC/E,0EAA0E;YAC1E,yEAAyE;YACzE,IAAI,CAAC,2BAA2B,CAAC,EAAE,CAAC,SAAS,CAAC;gBAAE,SAAS;YACzD,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;YAC7C,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;YAC7C,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;YACvC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACjE,CAAC;IAED,4EAA4E;IACpE,MAAM,CAAC,gBAAgB,CAAC,KAA+B;QAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC3C,OAAO;YACH,IAAI,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACjD,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE;YACxB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE;YAC5B,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;SACxD,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IntegrationRunSnapshot } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Closes out run artifacts that a process death left open.
|
|
4
|
+
*
|
|
5
|
+
* A run is marked terminal by the process that owns it, when it finishes. A process that is KILLED
|
|
6
|
+
* — OOM killer, SIGKILL, host reboot — never gets to do that, so its `result.json` is never written
|
|
7
|
+
* and the run reads as `isInFlight` forever. Nothing distinguishes it from a run still doing work:
|
|
8
|
+
* the wizard spins indefinitely, the active-operations panel shows a live step that will never
|
|
9
|
+
* advance, and no failure is reported anywhere, because the only process that could have reported
|
|
10
|
+
* it is the one that died.
|
|
11
|
+
*
|
|
12
|
+
* Observed 2026-09-14: an RSU run was OOM-killed during CompileTypeScript. Hours later the workspace
|
|
13
|
+
* was healthy and idle, and that run still read as in-flight at step 'CompileTypeScript'.
|
|
14
|
+
*
|
|
15
|
+
* The reconciliation is sound because run artifacts are PROCESS-LOCAL: every run this process can
|
|
16
|
+
* see that is still in flight when this process is starting up necessarily belongs to a process that
|
|
17
|
+
* no longer exists. That is only true at boot, before anything has started a run, which is the one
|
|
18
|
+
* moment this may safely run.
|
|
19
|
+
*
|
|
20
|
+
* `'killed'` is already the artifact vocabulary's term for this exit, so consumers that classify by
|
|
21
|
+
* `exitReason` need no change to understand the result.
|
|
22
|
+
*
|
|
23
|
+
* `skip` names the runs that are NOT dead: ones the starting process is itself the continuation
|
|
24
|
+
* of and will resume (see `RSUPostRestartProgressSession` in MJServer). They are reported in
|
|
25
|
+
* `Skipped`, untouched, so the caller can sweep whichever of them nothing resumed after all.
|
|
26
|
+
*
|
|
27
|
+
* KNOWN LIMIT — assumes ONE process per artifact directory, which is the same single-writer
|
|
28
|
+
* assumption the surrounding services document. If MJAPI is ever scaled past one replica sharing a
|
|
29
|
+
* directory, a starting replica would close out a sibling's live runs. Gate the call, not this
|
|
30
|
+
* function, if that day comes.
|
|
31
|
+
*/
|
|
32
|
+
export declare function SweepInterruptedRuns(rootDir?: string, log?: (message: string) => void, skip?: (snapshot: IntegrationRunSnapshot) => boolean): Promise<{
|
|
33
|
+
Swept: string[];
|
|
34
|
+
Failed: string[];
|
|
35
|
+
Skipped: string[];
|
|
36
|
+
}>;
|
|
37
|
+
//# sourceMappingURL=IntegrationRunReconciler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntegrationRunReconciler.d.ts","sourceRoot":"","sources":["../src/IntegrationRunReconciler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAwB,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,oBAAoB,CACtC,OAAO,CAAC,EAAE,MAAM,EAChB,GAAG,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAe,EACzC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,OAAO,GACrD,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA6DnE"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { IntegrationProgressReader } from './IntegrationProgressReader.js';
|
|
4
|
+
/**
|
|
5
|
+
* Closes out run artifacts that a process death left open.
|
|
6
|
+
*
|
|
7
|
+
* A run is marked terminal by the process that owns it, when it finishes. A process that is KILLED
|
|
8
|
+
* — OOM killer, SIGKILL, host reboot — never gets to do that, so its `result.json` is never written
|
|
9
|
+
* and the run reads as `isInFlight` forever. Nothing distinguishes it from a run still doing work:
|
|
10
|
+
* the wizard spins indefinitely, the active-operations panel shows a live step that will never
|
|
11
|
+
* advance, and no failure is reported anywhere, because the only process that could have reported
|
|
12
|
+
* it is the one that died.
|
|
13
|
+
*
|
|
14
|
+
* Observed 2026-09-14: an RSU run was OOM-killed during CompileTypeScript. Hours later the workspace
|
|
15
|
+
* was healthy and idle, and that run still read as in-flight at step 'CompileTypeScript'.
|
|
16
|
+
*
|
|
17
|
+
* The reconciliation is sound because run artifacts are PROCESS-LOCAL: every run this process can
|
|
18
|
+
* see that is still in flight when this process is starting up necessarily belongs to a process that
|
|
19
|
+
* no longer exists. That is only true at boot, before anything has started a run, which is the one
|
|
20
|
+
* moment this may safely run.
|
|
21
|
+
*
|
|
22
|
+
* `'killed'` is already the artifact vocabulary's term for this exit, so consumers that classify by
|
|
23
|
+
* `exitReason` need no change to understand the result.
|
|
24
|
+
*
|
|
25
|
+
* `skip` names the runs that are NOT dead: ones the starting process is itself the continuation
|
|
26
|
+
* of and will resume (see `RSUPostRestartProgressSession` in MJServer). They are reported in
|
|
27
|
+
* `Skipped`, untouched, so the caller can sweep whichever of them nothing resumed after all.
|
|
28
|
+
*
|
|
29
|
+
* KNOWN LIMIT — assumes ONE process per artifact directory, which is the same single-writer
|
|
30
|
+
* assumption the surrounding services document. If MJAPI is ever scaled past one replica sharing a
|
|
31
|
+
* directory, a starting replica would close out a sibling's live runs. Gate the call, not this
|
|
32
|
+
* function, if that day comes.
|
|
33
|
+
*/
|
|
34
|
+
export async function SweepInterruptedRuns(rootDir, log = () => { }, skip) {
|
|
35
|
+
const reader = rootDir ? new IntegrationProgressReader(rootDir) : new IntegrationProgressReader();
|
|
36
|
+
const swept = [];
|
|
37
|
+
const failed = [];
|
|
38
|
+
const skipped = [];
|
|
39
|
+
let inFlight;
|
|
40
|
+
try {
|
|
41
|
+
inFlight = await reader.FindInFlight();
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
log(`[RunReconciler] could not list in-flight runs: ${e instanceof Error ? e.message : String(e)}`);
|
|
45
|
+
return { Swept: swept, Failed: failed, Skipped: skipped };
|
|
46
|
+
}
|
|
47
|
+
if (inFlight.length === 0)
|
|
48
|
+
return { Swept: swept, Failed: failed, Skipped: skipped };
|
|
49
|
+
for (const snap of inFlight) {
|
|
50
|
+
const runID = snap.manifest.runID;
|
|
51
|
+
// A run the caller intends to pick back up is not dead — it is waiting for its continuation
|
|
52
|
+
// (an RSU run killed inside its own RestartMJAPI step is exactly this). Leave it in flight
|
|
53
|
+
// and name it, so the caller can close out whatever it then fails to re-attach to.
|
|
54
|
+
if (skip?.(snap)) {
|
|
55
|
+
skipped.push(runID);
|
|
56
|
+
log(`[RunReconciler] left ${snap.manifest.runKind} run ${runID} in flight for its continuation to resume`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
// Name the step it died on. That is the single most useful fact for whoever reads this
|
|
60
|
+
// afterwards, and it is the one thing a killed run cannot say for itself.
|
|
61
|
+
const lastStage = snap.latestEvent?.stage;
|
|
62
|
+
const where = lastStage ? ` during '${lastStage}'` : '';
|
|
63
|
+
const startedAt = Date.parse(snap.manifest.startedAt);
|
|
64
|
+
const result = {
|
|
65
|
+
runID,
|
|
66
|
+
completedAt: new Date().toISOString(),
|
|
67
|
+
success: false,
|
|
68
|
+
exitReason: 'killed',
|
|
69
|
+
durationMs: Number.isFinite(startedAt) ? Math.max(0, Date.now() - startedAt) : 0,
|
|
70
|
+
errors: [
|
|
71
|
+
{
|
|
72
|
+
stage: lastStage,
|
|
73
|
+
code: 'RUN_INTERRUPTED',
|
|
74
|
+
message: `The process running this ${snap.manifest.runKind} was terminated${where} ` +
|
|
75
|
+
`before it could finish. Marked terminal at startup by the process that replaced it.`,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
const path = join(reader.RootDir, runID, 'result.json');
|
|
80
|
+
try {
|
|
81
|
+
// 'wx' — never overwrite. A result written between the listing and here is the owning
|
|
82
|
+
// process's own word on the run, and it outranks this inference.
|
|
83
|
+
await fs.writeFile(path, JSON.stringify(result, null, 2), { encoding: 'utf-8', flag: 'wx' });
|
|
84
|
+
swept.push(runID);
|
|
85
|
+
log(`[RunReconciler] closed interrupted ${snap.manifest.runKind} run ${runID}${where}`);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
const code = e?.code;
|
|
89
|
+
if (code === 'EEXIST')
|
|
90
|
+
continue;
|
|
91
|
+
failed.push(runID);
|
|
92
|
+
log(`[RunReconciler] could not close run ${runID}: ${e instanceof Error ? e.message : String(e)}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { Swept: swept, Failed: failed, Skipped: skipped };
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=IntegrationRunReconciler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntegrationRunReconciler.js","sourceRoot":"","sources":["../src/IntegrationRunReconciler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAG3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACtC,OAAgB,EAChB,MAAiC,GAAG,EAAE,GAAE,CAAC,EACzC,IAAoD;IAEpD,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,yBAAyB,EAAE,CAAC;IAClG,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,IAAI,QAAwE,CAAC;IAC7E,IAAI,CAAC;QACD,QAAQ,GAAG,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,GAAG,CAAC,kDAAkD,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACpG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC9D,CAAC;IACD,IAAI,QAAQ,CA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,GAAG;wBAC3E,qFAAqF;iBAC5F;aACJ;SACJ,CAAC;QACF,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;QACxD,IAAI,CAAC;YACD,sFAAsF;YACtF,iEAAiE;YACjE,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7F,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,GAAG,CAAC,sCAAsC,IAAI,CAAC,QAAQ,CAAC,OAAO,QAAQ,KAAK,GAAG,KAAK,EAAE,CAAC,CAAC;QAC5F,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,MAAM,IAAI,GAAI,CAA2B,EAAE,IAAI,CAAC;YAChD,IAAI,IAAI,KAAK,QAAQ;gBAAE,SAAS;YAChC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,GAAG,CAAC,uCAAuC,KAAK,KAAK,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvG,CAAC;IACL,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variable that relocates the run-artifact tree.
|
|
3
|
+
*
|
|
4
|
+
* Why it has to exist: the default root is resolved against `process.cwd()`, and on a
|
|
5
|
+
* symlink-swap deploy the working directory IS the release directory. A deploy points the symlink
|
|
6
|
+
* at a fresh release and prunes the old ones, so every run artifact under the previous release is
|
|
7
|
+
* first orphaned and then deleted — measured live 2026-09-13, where a connector refresh's 652-event
|
|
8
|
+
* journal existed one minute before a deploy and the run listing returned `0 run(s)` immediately
|
|
9
|
+
* after. The artifacts survive the RSU's own pm2 restart (the symlink does not move) but not a
|
|
10
|
+
* deploy, which is exactly backwards from what an operator needs.
|
|
11
|
+
*
|
|
12
|
+
* Point this at a path OUTSIDE the swappable release directory (a sibling of `current`, alongside
|
|
13
|
+
* the environment file a deploy already treats as durable) and the run history outlives the deploy
|
|
14
|
+
* that would otherwise destroy the evidence.
|
|
15
|
+
*/
|
|
16
|
+
export declare const RUN_ARTIFACT_ROOT_ENV_VAR = "MJ_INTEGRATION_RUN_ARTIFACT_ROOT";
|
|
17
|
+
/**
|
|
18
|
+
* The root directory for run artifacts: {@link RUN_ARTIFACT_ROOT_ENV_VAR} when set, otherwise
|
|
19
|
+
* today's `<cwd>/logs/integration-runs`.
|
|
20
|
+
*
|
|
21
|
+
* Read on EVERY call rather than captured at module load. The emitter that writes a run and the
|
|
22
|
+
* reader that resumes or lists it are constructed at different moments in the process's life — and
|
|
23
|
+
* in the RSU's case, in different processes — so a value frozen at import time is a way for one
|
|
24
|
+
* half to read a different directory than the other half wrote. (Contrast `MJ_INTEGRATION_MAX_RUN_DIRS`,
|
|
25
|
+
* which is a number and genuinely can be read once.)
|
|
26
|
+
*/
|
|
27
|
+
export declare function DefaultRunArtifactRoot(): string;
|
|
28
|
+
//# sourceMappingURL=RunArtifactRoot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RunArtifactRoot.d.ts","sourceRoot":"","sources":["../src/RunArtifactRoot.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,yBAAyB,qCAAqC,CAAC;AAE5E;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAK/C"}
|