@shumkov/orchestra 0.10.12 → 0.10.13

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.
@@ -1838,6 +1838,7 @@ class ProcessManager {
1838
1838
  */
1839
1839
  _wireCallbacks(proc) {
1840
1840
  const capturedGeneration = proc.generationId ?? null;
1841
+ let abnormalTerminationReported = false;
1841
1842
  const hasCapturedGeneration = () => (
1842
1843
  capturedGeneration == null
1843
1844
  || proc.generationId === capturedGeneration
@@ -1847,6 +1848,39 @@ class ProcessManager {
1847
1848
  && !this._retiring.has(proc)
1848
1849
  && hasCapturedGeneration()
1849
1850
  );
1851
+ const reportAbnormalTermination = (event, exitCode = null) => {
1852
+ const verifiedSafeCodexStartupRelease = (
1853
+ event === 'close'
1854
+ && this._isCodex(proc)
1855
+ && this._starting.has(proc.sessionKey)
1856
+ && proc.startupReleaseSafe === true
1857
+ && proc.closed === true
1858
+ && proc.state === 'Closed'
1859
+ );
1860
+ if (
1861
+ abnormalTerminationReported
1862
+ || verifiedSafeCodexStartupRelease
1863
+ || this._shuttingDown
1864
+ || this._retiring.has(proc)
1865
+ || (this._retirementIntents.get(proc.sessionKey) ?? 0) > 0
1866
+ || !isCurrentGeneration()
1867
+ ) return;
1868
+ abnormalTerminationReported = true;
1869
+ const callback = this.callbacks.onAbnormalTermination;
1870
+ if (typeof callback !== 'function') return;
1871
+ const evidence = Object.freeze({
1872
+ event,
1873
+ backend: proc.backend,
1874
+ generationId: capturedGeneration,
1875
+ exitCode: Number.isSafeInteger(exitCode) ? exitCode : null,
1876
+ });
1877
+ try { callback(proc.sessionKey, evidence, proc); }
1878
+ catch (error) {
1879
+ this.logger.error?.(
1880
+ `[pm:${proc.label}] onAbnormalTermination threw: ${error.message}`,
1881
+ );
1882
+ }
1883
+ };
1850
1884
  for (const [cbName, eventName] of Object.entries(CALLBACK_TO_EVENT)) {
1851
1885
  const fn = this.callbacks[cbName];
1852
1886
  if (typeof fn !== 'function') continue;
@@ -1914,6 +1948,7 @@ class ProcessManager {
1914
1948
  // 'close': process closed itself (iteration loop exited or
1915
1949
  // _closeQuery returned). Remove from the Map + signal LRU.
1916
1950
  proc.on('close', (...args) => {
1951
+ reportAbnormalTermination('close', args[0]);
1917
1952
  if (!this._isCodex(proc)) {
1918
1953
  if (
1919
1954
  !this._retiring.has(proc)
@@ -1980,6 +2015,7 @@ class ProcessManager {
1980
2015
  // We don't re-spawn proactively: an idle disconnected session shouldn't
1981
2016
  // burn LRU budget. Lazy respawn on next message is the right shape.
1982
2017
  proc.on('bridge-disconnected', () => {
2018
+ reportAbnormalTermination('bridge-disconnected');
1983
2019
  this.logger.warn?.(`[pm:${proc.label}] channels bridge disconnected — killing dead instance for lazy respawn`);
1984
2020
  // Serialize with start/replacement/kill. Re-check object identity after
1985
2021
  // the gate so a late disconnect from an old generation cannot kill its
@@ -248,6 +248,7 @@ class SdkProcess extends Process {
248
248
  }
249
249
 
250
250
  async _runIteration() {
251
+ let closeEmitted = false;
251
252
  try {
252
253
  for await (const msg of this.query) {
253
254
  await this._handleEvent(msg);
@@ -256,9 +257,12 @@ class SdkProcess extends Process {
256
257
  } catch (err) {
257
258
  this._failAllPendings(err);
258
259
  this.emit('close', err.code === 'AbortError' ? 0 : 1);
260
+ closeEmitted = true;
259
261
  } finally {
262
+ const alreadyClosed = this.closed;
260
263
  this.closed = true;
261
264
  this.inFlight = false;
265
+ if (!closeEmitted && !alreadyClosed) this.emit('close', 0);
262
266
  this.emit('idle');
263
267
  }
264
268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shumkov/orchestra",
3
- "version": "0.10.12",
3
+ "version": "0.10.13",
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",