@shumkov/orchestra 0.10.16 → 0.10.17
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.
|
@@ -409,10 +409,29 @@ class ProcessManager {
|
|
|
409
409
|
* @param {object} [opts.callbacks={}] — keys: onInit, onClose, ...
|
|
410
410
|
* @param {number} [opts.lruWaitMs] — how long getOrSpawn parks
|
|
411
411
|
* when all entries are in-flight
|
|
412
|
+
* @param {(input: {
|
|
413
|
+
* sessionKey: string,
|
|
414
|
+
* generationId: string,
|
|
415
|
+
* attemptId: string,
|
|
416
|
+
* providerSessionId: string,
|
|
417
|
+
* providerTurnId: string,
|
|
418
|
+
* sourceMsgId: (string|number),
|
|
419
|
+
* }) => {
|
|
420
|
+
* committed: true,
|
|
421
|
+
* disposition: 'retirement-requested',
|
|
422
|
+
* sessionKey: string,
|
|
423
|
+
* generationId: string,
|
|
424
|
+
* attemptId: string,
|
|
425
|
+
* providerSessionId: string,
|
|
426
|
+
* providerTurnId: string,
|
|
427
|
+
* sourceMsgId: (string|number),
|
|
428
|
+
* }}
|
|
429
|
+
* [opts.codexRetirementPreparer] — synchronous consumer ownership handshake;
|
|
430
|
+
* the acknowledgement echoes every input binding without normalization.
|
|
412
431
|
* @param {(input: object) => Promise<{committed: true}>}
|
|
413
432
|
* [opts.codexRetirementVerifier] — consumer durability handshake.
|
|
414
433
|
* @param {number} [opts.codexRetirementTimeoutMs=30000]
|
|
415
|
-
* — absolute deadline for the optional durability handshake.
|
|
434
|
+
* — absolute deadline for the optional post-stop durability handshake.
|
|
416
435
|
*/
|
|
417
436
|
constructor({
|
|
418
437
|
processFactory,
|
|
@@ -424,6 +443,7 @@ class ProcessManager {
|
|
|
424
443
|
codexRecoveryState,
|
|
425
444
|
codexHostIdentity = null,
|
|
426
445
|
codexBootSessionIdentity = null,
|
|
446
|
+
codexRetirementPreparer = null,
|
|
427
447
|
codexRetirementVerifier = null,
|
|
428
448
|
codexRetirementTimeoutMs = DEFAULT_CODEX_RETIREMENT_TIMEOUT_MS,
|
|
429
449
|
} = {}) {
|
|
@@ -458,6 +478,15 @@ class ProcessManager {
|
|
|
458
478
|
// record, even when that record says no generation was live.
|
|
459
479
|
this.codexHostIdentity = codexHostIdentity;
|
|
460
480
|
this.codexBootSessionIdentity = codexBootSessionIdentity;
|
|
481
|
+
if (
|
|
482
|
+
codexRetirementPreparer != null
|
|
483
|
+
&& typeof codexRetirementPreparer !== 'function'
|
|
484
|
+
) {
|
|
485
|
+
throw new TypeError(
|
|
486
|
+
'ProcessManager: codexRetirementPreparer function required',
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
this.codexRetirementPreparer = codexRetirementPreparer;
|
|
461
490
|
if (
|
|
462
491
|
codexRetirementVerifier != null
|
|
463
492
|
&& typeof codexRetirementVerifier !== 'function'
|
|
@@ -1465,6 +1494,64 @@ class ProcessManager {
|
|
|
1465
1494
|
}
|
|
1466
1495
|
}
|
|
1467
1496
|
|
|
1497
|
+
_prepareCodexRetirement(candidate) {
|
|
1498
|
+
if (!this.codexRetirementPreparer) {
|
|
1499
|
+
throw managerError(
|
|
1500
|
+
'Codex continuation retirement requires durable preparation',
|
|
1501
|
+
'CODEX_RETIREMENT_PREPARATION_FAILED',
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
const input = Object.freeze({
|
|
1505
|
+
sessionKey: candidate.sessionKey,
|
|
1506
|
+
generationId: candidate.generationId,
|
|
1507
|
+
attemptId: candidate.attemptId,
|
|
1508
|
+
providerSessionId: candidate.providerSessionId,
|
|
1509
|
+
providerTurnId: candidate.providerTurnId,
|
|
1510
|
+
sourceMsgId: candidate.sourceMsgId,
|
|
1511
|
+
});
|
|
1512
|
+
let preparation;
|
|
1513
|
+
try {
|
|
1514
|
+
preparation = this.codexRetirementPreparer(input);
|
|
1515
|
+
} catch (cause) {
|
|
1516
|
+
throw managerError(
|
|
1517
|
+
'Codex continuation retirement preparation failed',
|
|
1518
|
+
'CODEX_RETIREMENT_PREPARATION_FAILED',
|
|
1519
|
+
{ cause },
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
const expectedKeys = [
|
|
1523
|
+
'committed',
|
|
1524
|
+
'disposition',
|
|
1525
|
+
'sessionKey',
|
|
1526
|
+
'generationId',
|
|
1527
|
+
'attemptId',
|
|
1528
|
+
'providerSessionId',
|
|
1529
|
+
'providerTurnId',
|
|
1530
|
+
'sourceMsgId',
|
|
1531
|
+
];
|
|
1532
|
+
const keys = preparation && typeof preparation === 'object'
|
|
1533
|
+
? Reflect.ownKeys(preparation)
|
|
1534
|
+
: [];
|
|
1535
|
+
if (
|
|
1536
|
+
typeof preparation?.then === 'function'
|
|
1537
|
+
|| keys.length !== expectedKeys.length
|
|
1538
|
+
|| expectedKeys.some((key) => !Object.hasOwn(preparation, key))
|
|
1539
|
+
|| preparation.committed !== true
|
|
1540
|
+
|| preparation.disposition !== 'retirement-requested'
|
|
1541
|
+
|| preparation.sessionKey !== input.sessionKey
|
|
1542
|
+
|| preparation.generationId !== input.generationId
|
|
1543
|
+
|| preparation.attemptId !== input.attemptId
|
|
1544
|
+
|| preparation.providerSessionId !== input.providerSessionId
|
|
1545
|
+
|| preparation.providerTurnId !== input.providerTurnId
|
|
1546
|
+
|| preparation.sourceMsgId !== input.sourceMsgId
|
|
1547
|
+
) {
|
|
1548
|
+
throw managerError(
|
|
1549
|
+
'Codex continuation retirement preparation was not exact',
|
|
1550
|
+
'CODEX_RETIREMENT_PREPARATION_FAILED',
|
|
1551
|
+
);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1468
1555
|
_evictLRU() {
|
|
1469
1556
|
let oldest = null;
|
|
1470
1557
|
let oldestKey = null;
|
|
@@ -1722,12 +1809,18 @@ class ProcessManager {
|
|
|
1722
1809
|
async retireForCleanRestart({
|
|
1723
1810
|
getDeliveryEvidence,
|
|
1724
1811
|
qualificationExpectation,
|
|
1812
|
+
continuationAuthorized = false,
|
|
1725
1813
|
} = {}) {
|
|
1726
1814
|
if (typeof getDeliveryEvidence !== 'function') {
|
|
1727
1815
|
throw new TypeError(
|
|
1728
1816
|
'ProcessManager.retireForCleanRestart: getDeliveryEvidence function required',
|
|
1729
1817
|
);
|
|
1730
1818
|
}
|
|
1819
|
+
if (typeof continuationAuthorized !== 'boolean') {
|
|
1820
|
+
throw new TypeError(
|
|
1821
|
+
'ProcessManager.retireForCleanRestart: continuationAuthorized boolean required',
|
|
1822
|
+
);
|
|
1823
|
+
}
|
|
1731
1824
|
this._shuttingDown = true;
|
|
1732
1825
|
this._lifecycleAdmissionClosed = true;
|
|
1733
1826
|
for (const w of this._lruWaiters) {
|
|
@@ -1817,6 +1910,9 @@ class ProcessManager {
|
|
|
1817
1910
|
);
|
|
1818
1911
|
}
|
|
1819
1912
|
}
|
|
1913
|
+
if (continuationAuthorized && candidate) {
|
|
1914
|
+
this._prepareCodexRetirement(candidate);
|
|
1915
|
+
}
|
|
1820
1916
|
const retirementPromise = this._strictRetire(proc, 'clean-restart');
|
|
1821
1917
|
retirementPromise.catch(() => {});
|
|
1822
1918
|
let deliveryEvidence = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shumkov/orchestra",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.17",
|
|
4
4
|
"description": "Transport-agnostic session engine for Claude Code and the native Codex app-server: spawn, steer, supervise, observe turns, and recover.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|