@shumkov/orchestra 0.10.17 → 0.10.18

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.
@@ -740,3 +740,162 @@ prepared/write-attempted/response-observed ledger, Codex-owned retry rule,
740
740
  unknown-effect non-replay rule, immutable model/effort thread policy, exact
741
741
  profile provenance, one-live daemon lease, and accepted quarantine contract.
742
742
  No Orchestra backend or Claude behavior has been changed by U1.
743
+
744
+ ## Credential-free hook notification probe passed
745
+
746
+ Codex 0.145.0 emits `hook/started` and `hook/completed` whenever the active
747
+ configuration enables hooks. `lib/codex/protocol-schema.json` lists both as
748
+ dropped server notifications and `lib/codex/app-server-client.js` enforces that
749
+ drop. The characterization allowlist in `scripts/spikes/codex-app-server-rpc.mjs`
750
+ admits the same two methods without retaining them. Every other `hook/*` method
751
+ remains an exact-match fail-closed protocol fault; that is proved
752
+ deterministically by "Codex U1a faults a well-formed but unlisted hook
753
+ notification" in `tests/codex-app-server-spike.test.js` rather than by a live
754
+ peer.
755
+
756
+ `scripts/spikes/codex-app-server-hook-probe.mjs` is the reproducible gate:
757
+
758
+ ```sh
759
+ node scripts/spikes/codex-app-server-hook-probe.mjs \
760
+ --binary /absolute/versioned/path/to/codex \
761
+ --probe-root /absolute/non-temporary/probe-root
762
+ ```
763
+
764
+ It exits 0 only when every gate check passes, and deliberately exits 1
765
+ otherwise, including on a thrown failure.
766
+
767
+ Containment holds on the complete successful envelope, not only on failure, and
768
+ it is a closed-key projection rather than denylist filtering. Every emitted
769
+ object is built key by key from an approved name list with an approved scalar
770
+ type; no evidence-derived object is ever spread. An unapproved key is therefore
771
+ dropped and cannot be emitted whatever it contains, including benign plain text
772
+ no regex would catch. An approved slot holding a wrong type or an
773
+ off-enum value collapses the whole result to a content-free `STOP` with a
774
+ category. Raw turn ids are stripped from both lanes. The trailing
775
+ content-free assertion is retained as defense in depth, not as the mechanism.
776
+
777
+ Nothing raw is persisted. The hook handler parses stdin in place and writes only
778
+ closed fields — event name, whether a `turn_id` was supplied, and its SHA-256 —
779
+ so the user prompt, cwd, and transcript path never reach disk, and no raw turn
780
+ id is stored. The raw JSON-RPC lane routes each response directly to its pending
781
+ request and keeps no session-wide result cache; a result exists only as a local
782
+ value for the duration of that request, and callers digest or project what they
783
+ need and discard the rest. Only bounded closed-field summaries survive the
784
+ request.
785
+
786
+ ### What the authoritative lane is
787
+
788
+ The hooks-on and hooks-off lanes drive the production `CodexAppServerClient`
789
+ with the real `attestPinnedCodexBinary` target-pin attestation, an isolated
790
+ mode-0700 owned `codexHome`, the exact `expectedConfigSha256`, and the
791
+ production delivery-checkpoint ledger. Each lane awaits an actual delivered
792
+ `turn/completed` rather than sleeping. The gate therefore fails if the
793
+ production schema-backed boundary breaks, even when a raw stdio session would
794
+ still have completed.
795
+
796
+ The hooks-off control lane is held to the same predicates as hooks-on —
797
+ completed status, an assistant item, no fault, and the same three-way
798
+ start/started/completed identity equality — and additionally must see no hook
799
+ traffic at all.
800
+
801
+ A raw stdio session remains only as a secondary characterization of the payloads
802
+ the production client intentionally drops. Its outcome can never satisfy
803
+ authoritative completion: the gate requires
804
+ `authoritative.source === 'production-client'`.
805
+
806
+ That session enforces the same exact envelope key sets the production client
807
+ accepts — `{id, result}` / `{id, error}` for responses and
808
+ `{method, params, emittedAtMs}` for notifications. Ambiguous response and
809
+ notification shapes, arbitrary extra top-level members, unlisted notification
810
+ methods, and unexpected response ids all fail closed. It bounds stdout lines,
811
+ undelimited partials, aggregate bytes, message count and stderr bytes; on stream
812
+ end it flushes the decoder and fails on a trailing partial or on EOF with
813
+ requests still pending. Its terminal failure is re-checked **after** child
814
+ teardown and stream drain, so malformed bytes that arrive while the child is
815
+ being killed cannot be reported as success. Cleanup signals the owned process
816
+ group, and proves the group is empty by enumerating it with
817
+ `/bin/ps -axo pid=,pgid=` — the same mechanism the U1b effect proxy uses —
818
+ rather than trusting leader exit alone; an exit or a non-empty group that cannot
819
+ be proved is a `cleanup` failure.
820
+
821
+ Close-time faults count. The production lane reads its settled fault outcome
822
+ **after** `client.close()`, so a fault the client delivers during close cannot
823
+ be lost, and a close failure is reported rather than swallowed. Loopback
824
+ provider shutdown force-closes idle and active connections under a bound; a
825
+ provider close rejection or timeout yields a content-free `cleanup` STOP even
826
+ when the lanes themselves passed. Probe-root creation and provider acquisition
827
+ both sit inside nested guards so scratch removal always runs.
828
+
829
+ The turn completes against a loopback Responses provider declaring
830
+ `requires_openai_auth = false`, inside homes that contain no `auth.json`.
831
+ Credential-free is a property of that construction, gated on those two concrete
832
+ conditions, not an observation of file reads. No product credential is read,
833
+ copied, or required, and no existing Codex home is touched.
834
+
835
+ ### Observed
836
+
837
+ - both lanes reached delivered `turn/completed` status `completed` with an
838
+ assistant item and no fault;
839
+ - the `turn/start` response id, the single delivered `turn/started.params.turn.id`,
840
+ and the completed turn id were equal;
841
+ - no `hook/*` method reached the production delivered notification sink in
842
+ either lane;
843
+ - the exact configured event multiset (`sessionStart`, `userPromptSubmit`)
844
+ appeared, each with exactly one `hook/started` (`running`) followed by one
845
+ `hook/completed` (`completed`), all timestamps 10-digit epoch seconds;
846
+ - exactly one hook stdin capture existed per configured event, counted from
847
+ per-invocation capture files rather than a last-writer-wins name, so a
848
+ repeated invocation fails the gate;
849
+ - the owned `config.toml` digest was byte-identical across each lane run;
850
+ - removing only the two schema drop entries flipped the gate to `STOP` with
851
+ `authoritative.faultCategory` `protocol` and exit 1, while the hooks-off
852
+ control stayed fault-free;
853
+ - no probe directory or child process survived either a passing or a failing
854
+ run.
855
+
856
+ ### Two distinct turn identities
857
+
858
+ App-server notification `params.turnId` and hook stdin `turn_id` are different
859
+ surfaces and must not be conflated.
860
+
861
+ - `params.turnId` rides on the `hook/started` and `hook/completed`
862
+ notifications, which the production client drops. It is characterized only in
863
+ the secondary raw lane, which runs its own separate turn: the probe emits
864
+ `notificationTurnIdMatchesRawTurn`, a boolean comparing the digest of each
865
+ hook notification's `params.turnId` against the digest of *that lane's* own
866
+ `turn/start` turn id. It is deliberately not compared against the
867
+ authoritative lane's turn, which belongs to a different turn entirely.
868
+ - Hook stdin `turn_id` is supplied to the hook process itself. The probe proves
869
+ from the authoritative lane's own captures that `userPromptSubmit` stdin
870
+ `turn_id` equals the authoritative turn id. It is **absent** for
871
+ `sessionStart`, whose stdin carries `cwd`, `hook_event_name`, `model`,
872
+ `permission_mode`, `session_id`, `source`, and `transcript_path` but no
873
+ `turn_id`. Hook stdin identifies the thread as `session_id`, not `thread_id`.
874
+
875
+ The probe requires the `sessionStart` capture to exist while omitting
876
+ `turn_id`; a missing capture fails. It records that event as
877
+ `present-without-turn-id`, never as a satisfied equality. Any receipt design
878
+ keyed on hook stdin `turn_id` must select an event that supplies one; a
879
+ `sessionStart` hook cannot discharge that correlation.
880
+
881
+ ### What the config digest does and does not attest
882
+
883
+ The probe drives the full drift sequence and gates every step: hooks are
884
+ discovered `untrusted`, rendered `trusted`, then the hook handler is mutated.
885
+ After mutation `hooks/list` reports a new `currentHash` and `trustStatus:
886
+ modified` **while `config.toml` and its digest are unchanged**. Only after the
887
+ new trusted hash is re-rendered does the owned-config digest change and the hook
888
+ return to `trusted`/enabled.
889
+
890
+ Digest-only attestation therefore does not detect an un-rendered hook-file
891
+ mutation; the `trustStatus` returned by `hooks/list` is the signal that does.
892
+
893
+ Scope limits. This is a protocol-boundary and correlation result, not a hosted
894
+ product result: the completed turn is served by a loopback provider, not by the
895
+ real model backend. `CodexProcess` is not exercised; `CodexAppServerClient` is
896
+ the smallest production boundary for this two-method change. The named-profile
897
+ checker (`scripts/spikes/codex-app-server-real.mjs`) still rejects any
898
+ configuration where `effective.hooks != null`, so the reviewed hook-free
899
+ validation profile above is unchanged and was not re-run with hooks. A
900
+ hook-enabled authenticated run against the hosted backend, and the
901
+ wrapper/absolute-binary-path rejection, remain unproved here.
@@ -157,6 +157,8 @@
157
157
  "item/reasoning/summaryTextDelta",
158
158
  "item/reasoning/summaryPartAdded",
159
159
  "item/reasoning/textDelta",
160
+ "hook/started",
161
+ "hook/completed",
160
162
  "warning",
161
163
  "deprecationNotice",
162
164
  "configWarning",
@@ -1059,9 +1059,10 @@ class CodexProcess extends Process {
1059
1059
  turnId: null,
1060
1060
  responseSeen: false,
1061
1061
  startedSeen: false,
1062
- startDeliveryState: 'preparing',
1062
+ startDeliveryState: 'queued',
1063
1063
  startResponseOutcome: null,
1064
1064
  startCancellationRequested: false,
1065
+ startPreparationDisposition: makeDeferred(),
1065
1066
  startDisposition: makeDeferred(),
1066
1067
  terminal: null,
1067
1068
  terminalDeferred: makeDeferred(),
@@ -1134,6 +1135,7 @@ class CodexProcess extends Process {
1134
1135
  }
1135
1136
  this.current = pending;
1136
1137
  this.inFlight = true;
1138
+ pending.startDeliveryState = 'attesting';
1137
1139
  pending.startedAt = Date.now();
1138
1140
  pending.deadlineAt = pending.startedAt + pending.maxTurnMs;
1139
1141
  this.state = 'StartingTurn';
@@ -1192,6 +1194,8 @@ class CodexProcess extends Process {
1192
1194
  }
1193
1195
  this._assertLifecycle(lifecycle);
1194
1196
  };
1197
+ assertTurnStartAdmission();
1198
+ pending.startDeliveryState = 'preparing';
1195
1199
  const result = await this._mutation('turn/start', params, {
1196
1200
  source: pending.context?.sourceMsgId ?? null,
1197
1201
  clientUserMessageId: pending.clientUserMessageId,
@@ -1203,6 +1207,9 @@ class CodexProcess extends Process {
1203
1207
  pending.startResponseOutcome = outcome;
1204
1208
  }
1205
1209
  },
1210
+ onPreparationDisposition: (disposition) => {
1211
+ pending.startPreparationDisposition.resolve(disposition);
1212
+ },
1206
1213
  assertCanWrite: assertTurnStartAdmission,
1207
1214
  assertCanCommit: assertTurnStartAdmission,
1208
1215
  });
@@ -1324,15 +1331,50 @@ class CodexProcess extends Process {
1324
1331
  return remaining;
1325
1332
  }
1326
1333
 
1334
+ _resolveStartAsNotStarted(pending) {
1335
+ pending.startDeliveryState = 'definitely-not-sent';
1336
+ pending.startPreparationDisposition.resolve({ kind: 'not-started' });
1337
+ pending.startDisposition.resolve({ kind: 'not-started' });
1338
+ }
1339
+
1327
1340
  _resolveStartDispositionFromError(pending, error) {
1328
1341
  if (pending.startDeliveryState === 'accepted') return;
1329
1342
  const durability = this._durabilityFailure(error);
1343
+ if (
1344
+ pending.startDeliveryState === 'queued'
1345
+ || pending.startDeliveryState === 'attesting'
1346
+ ) {
1347
+ this._resolveStartAsNotStarted(pending);
1348
+ return;
1349
+ }
1350
+ if (pending.startDeliveryState === 'checkpoint-not-committed') {
1351
+ const disposition = {
1352
+ kind: 'checkpoint-not-committed',
1353
+ cause: durability ?? error,
1354
+ };
1355
+ pending.startDisposition.resolve(disposition);
1356
+ return;
1357
+ }
1358
+ if (pending.startDeliveryState === 'checkpoint-unknown') {
1359
+ const disposition = {
1360
+ kind: 'checkpoint-unknown',
1361
+ cause: durability ?? error,
1362
+ };
1363
+ pending.startDisposition.resolve(disposition);
1364
+ return;
1365
+ }
1330
1366
  if (
1331
1367
  error?.code === 'CODEX_RPC_NOT_SENT'
1332
1368
  || durability?.deliveryState === 'not-sent'
1333
1369
  ) {
1334
- pending.startDeliveryState = 'definitely-not-sent';
1335
- pending.startDisposition.resolve({ kind: 'definitely-not-sent' });
1370
+ if (
1371
+ pending.startDeliveryState === 'prepared'
1372
+ || pending.startDeliveryState === 'write-checkpointing'
1373
+ ) {
1374
+ pending.startDisposition.resolve({ kind: 'checkpoint-committed' });
1375
+ return;
1376
+ }
1377
+ this._resolveStartAsNotStarted(pending);
1336
1378
  return;
1337
1379
  }
1338
1380
  if (
@@ -1346,8 +1388,67 @@ class CodexProcess extends Process {
1346
1388
  pending.startDisposition.resolve({ kind: 'outcome-unknown' });
1347
1389
  return;
1348
1390
  }
1349
- pending.startDeliveryState = 'definitely-not-sent';
1350
- pending.startDisposition.resolve({ kind: 'definitely-not-sent' });
1391
+ this._resolveStartAsNotStarted(pending);
1392
+ }
1393
+
1394
+ async _resolveInterruptStartDisposition(
1395
+ pending,
1396
+ controlDeadline,
1397
+ lifecycle,
1398
+ ) {
1399
+ if (
1400
+ pending.startDeliveryState === 'queued'
1401
+ || pending.startDeliveryState === 'attesting'
1402
+ || pending.startDeliveryState === 'definitely-not-sent'
1403
+ ) {
1404
+ return { kind: 'not-started' };
1405
+ }
1406
+ const waitMs = Math.max(
1407
+ 1,
1408
+ Math.min(this.turnStartTimeoutMs, controlDeadline - Date.now()),
1409
+ );
1410
+ if (
1411
+ pending.startDeliveryState === 'preparing'
1412
+ || pending.startDeliveryState === 'checkpoint-not-committed'
1413
+ || pending.startDeliveryState === 'checkpoint-unknown'
1414
+ ) {
1415
+ try {
1416
+ return await timeout(
1417
+ pending.startPreparationDisposition.promise,
1418
+ waitMs,
1419
+ 'Codex turn preparation disposition was not observed before interruption',
1420
+ 'CODEX_TURN_START_TIMEOUT',
1421
+ );
1422
+ } catch (error) {
1423
+ return { kind: 'checkpoint-unknown', cause: error };
1424
+ }
1425
+ }
1426
+ if (pending.startDeliveryState === 'prepared') {
1427
+ return { kind: 'checkpoint-committed' };
1428
+ }
1429
+ if (
1430
+ pending.startDeliveryState === 'write-checkpointing'
1431
+ || pending.startDeliveryState === 'write-attempted'
1432
+ || pending.startDeliveryState === 'response-observed'
1433
+ || pending.startDeliveryState === 'outcome-unknown'
1434
+ ) {
1435
+ try {
1436
+ const disposition = await timeout(
1437
+ pending.startDisposition.promise,
1438
+ waitMs,
1439
+ 'Codex turn start disposition was not observed before interruption',
1440
+ 'CODEX_TURN_START_TIMEOUT',
1441
+ );
1442
+ this._assertLifecycle(lifecycle);
1443
+ return disposition;
1444
+ } catch (error) {
1445
+ return { kind: 'checkpoint-unknown', cause: error };
1446
+ }
1447
+ }
1448
+ if (pending.startDeliveryState === 'accepted') {
1449
+ return { kind: 'accepted', turnId: pending.turnId };
1450
+ }
1451
+ return { kind: pending.startDeliveryState };
1351
1452
  }
1352
1453
 
1353
1454
  async _classifyTurnFailure(error, pending) {
@@ -1374,7 +1475,7 @@ class CodexProcess extends Process {
1374
1475
  && pending.responseSeen
1375
1476
  ) {
1376
1477
  try {
1377
- await this.interrupt();
1478
+ await this.interrupt('timeout');
1378
1479
  } catch (interruptError) {
1379
1480
  if (this.state !== 'ContainmentFailed') {
1380
1481
  await this._enterContainment(
@@ -1666,13 +1767,14 @@ class CodexProcess extends Process {
1666
1767
  }
1667
1768
  }
1668
1769
 
1669
- async interrupt() {
1770
+ async interrupt(reason = 'interrupt') {
1670
1771
  if (this.interruptPromise) return this.interruptPromise;
1671
- this.interruptPromise = this._interrupt();
1772
+ const interruptionReason = boundedOpaqueId(reason, 'interruption reason');
1773
+ this.interruptPromise = this._interrupt(interruptionReason);
1672
1774
  return this.interruptPromise;
1673
1775
  }
1674
1776
 
1675
- async _interrupt(controlDeadlineOverride = null) {
1777
+ async _interrupt(interruptionReason, controlDeadlineOverride = null) {
1676
1778
  if (this.closed) return false;
1677
1779
  if (this.state === 'ContainmentFailed') {
1678
1780
  throw processError(
@@ -1708,9 +1810,12 @@ class CodexProcess extends Process {
1708
1810
  ? this.lastTerminal?.turnId
1709
1811
  : null
1710
1812
  );
1813
+ if (pending && priorState === 'StartingTurn') {
1814
+ pending.startCancellationRequested = true;
1815
+ }
1711
1816
  this.state = 'Quiescing';
1712
1817
  const lifecycle = this._captureLifecycle();
1713
- this._drainWaiting('INTERRUPTED');
1818
+ this._drainWaiting('INTERRUPTED', interruptionReason);
1714
1819
  await this.steerChain;
1715
1820
  this._assertLifecycle(lifecycle);
1716
1821
  await this._flushPendingCancellations();
@@ -1721,50 +1826,31 @@ class CodexProcess extends Process {
1721
1826
  }
1722
1827
  let interruptEventEmitted = false;
1723
1828
  if (pending && priorState === 'StartingTurn') {
1724
- pending.startCancellationRequested = true;
1725
- let disposition;
1726
- if (
1727
- pending.startDeliveryState === 'preparing'
1728
- || pending.startDeliveryState === 'prepared'
1729
- ) {
1730
- disposition = { kind: 'definitely-not-sent' };
1731
- } else if (
1732
- pending.startDeliveryState === 'write-checkpointing'
1733
- ||
1734
- pending.startDeliveryState === 'write-attempted'
1735
- || pending.startDeliveryState === 'response-observed'
1736
- ) {
1737
- try {
1738
- disposition = await timeout(
1739
- pending.startDisposition.promise,
1740
- Math.max(
1741
- 1,
1742
- Math.min(
1743
- this.turnStartTimeoutMs,
1744
- controlDeadline - Date.now(),
1745
- ),
1746
- ),
1747
- 'Codex turn start disposition was not observed before interruption',
1748
- 'CODEX_TURN_START_TIMEOUT',
1749
- );
1750
- this._assertLifecycle(lifecycle);
1751
- } catch (error) {
1752
- disposition = { kind: 'outcome-unknown', cause: error };
1753
- }
1754
- } else if (pending.startDeliveryState === 'accepted') {
1755
- disposition = { kind: 'accepted', turnId: pending.turnId };
1756
- } else {
1757
- disposition = { kind: pending.startDeliveryState };
1758
- }
1829
+ const disposition = await this._resolveInterruptStartDisposition(
1830
+ pending,
1831
+ controlDeadline,
1832
+ lifecycle,
1833
+ );
1759
1834
  if (disposition.kind === 'accepted') {
1760
1835
  turnId = disposition.turnId ?? pending.turnId;
1761
- } else if (disposition.kind === 'definitely-not-sent') {
1836
+ } else if (disposition.kind === 'not-started') {
1837
+ turnId = null;
1838
+ const cancelled = processError(
1839
+ 'Codex turn start was interrupted before preparation',
1840
+ 'INTERRUPTED',
1841
+ );
1842
+ pending.cancelled = true;
1843
+ this._rejectPending(pending, cancelled);
1844
+ this._finishPending(pending);
1845
+ } else if (disposition.kind === 'checkpoint-committed') {
1762
1846
  turnId = null;
1763
1847
  try {
1764
1848
  await this._checkpoint('active-start-cancelled', {
1765
1849
  ...this._turnDetail(pending),
1850
+ method: 'turn/start',
1766
1851
  attemptId: pending.attemptId,
1767
1852
  deliveryState: 'definitely-not-sent',
1853
+ reason: interruptionReason,
1768
1854
  });
1769
1855
  this._assertLifecycle(lifecycle);
1770
1856
  } catch (error) {
@@ -1783,6 +1869,17 @@ class CodexProcess extends Process {
1783
1869
  pending.cancelled = true;
1784
1870
  this._rejectPending(pending, cancelled);
1785
1871
  this._finishPending(pending);
1872
+ } else if (disposition.kind === 'checkpoint-not-committed') {
1873
+ const cause = disposition.cause ?? processError(
1874
+ 'Codex turn preparation was rejected without a committed attempt',
1875
+ 'CODEX_DURABILITY_FAILED',
1876
+ );
1877
+ this._blockDurability(cause, pending);
1878
+ throw processError(
1879
+ 'Codex turn preparation was not durably committed',
1880
+ 'CODEX_DURABILITY_FAILED',
1881
+ { cause },
1882
+ );
1786
1883
  } else {
1787
1884
  const error = disposition.cause ?? processError(
1788
1885
  'Codex turn start delivery outcome is unknown',
@@ -2164,15 +2261,35 @@ class CodexProcess extends Process {
2164
2261
  try {
2165
2262
  await this._checkpoint('request-prepared', prepared);
2166
2263
  } catch (error) {
2264
+ const dispositionAware = (
2265
+ typeof detail.onPreparationDisposition === 'function'
2266
+ );
2267
+ const notCommitted = (
2268
+ dispositionAware
2269
+ && error?.checkpointDisposition === 'not-committed'
2270
+ );
2167
2271
  const durability = processError(
2168
2272
  `Codex ${method} prepared checkpoint failed`,
2169
2273
  'CODEX_DURABILITY_FAILED',
2170
2274
  { cause: error },
2171
2275
  );
2172
- durability.deliveryState = 'not-sent';
2276
+ durability.deliveryState = (
2277
+ dispositionAware && !notCommitted ? 'ambiguous' : 'not-sent'
2278
+ );
2279
+ if (dispositionAware) {
2280
+ const disposition = {
2281
+ kind: notCommitted
2282
+ ? 'checkpoint-not-committed'
2283
+ : 'checkpoint-unknown',
2284
+ cause: durability,
2285
+ };
2286
+ detail.onDeliveryState?.(disposition.kind);
2287
+ detail.onPreparationDisposition(disposition);
2288
+ }
2173
2289
  throw durability;
2174
2290
  }
2175
2291
  detail.onDeliveryState?.('prepared');
2292
+ detail.onPreparationDisposition?.({ kind: 'checkpoint-committed' });
2176
2293
  detail.assertCanWrite?.();
2177
2294
  return this.client.request(method, params, {
2178
2295
  timeoutMs: detail.timeoutMs,
@@ -2301,6 +2418,9 @@ class CodexProcess extends Process {
2301
2418
  { cause: error },
2302
2419
  );
2303
2420
  durability.deliveryState = 'ambiguous';
2421
+ if (error?.checkpointDisposition === 'not-committed') {
2422
+ durability.checkpointDisposition = 'not-committed';
2423
+ }
2304
2424
  throw durability;
2305
2425
  }
2306
2426
  fence?.assertActive?.();
@@ -2807,6 +2927,7 @@ class CodexProcess extends Process {
2807
2927
  ) return;
2808
2928
  if (!this.interruptPromise) {
2809
2929
  this.interruptPromise = this._interrupt(
2930
+ 'timeout',
2810
2931
  Date.now() + this.interruptTimeoutMs + this.cleanupTimeoutMs,
2811
2932
  );
2812
2933
  }
@@ -3132,11 +3253,11 @@ class CodexProcess extends Process {
3132
3253
  this._settlePending(pending, 'reject', error);
3133
3254
  }
3134
3255
 
3135
- _drainWaiting(code) {
3256
+ _drainWaiting(code, reason = 'interrupt') {
3136
3257
  let count = 0;
3137
3258
  for (const pending of [...this.pendingQueue]) {
3138
3259
  if (pending === this.current) continue;
3139
- this._reserveCancellation(pending, code);
3260
+ this._reserveCancellation(pending, code, reason);
3140
3261
  count += 1;
3141
3262
  }
3142
3263
  return count;
@@ -3147,16 +3268,16 @@ class CodexProcess extends Process {
3147
3268
  return this._drainAll(code);
3148
3269
  }
3149
3270
 
3150
- _drainAll(code) {
3271
+ _drainAll(code, reason = 'interrupt') {
3151
3272
  let count = 0;
3152
3273
  for (const pending of [...this.pendingQueue]) {
3153
- this._reserveCancellation(pending, code);
3274
+ this._reserveCancellation(pending, code, reason);
3154
3275
  count += 1;
3155
3276
  }
3156
3277
  return count;
3157
3278
  }
3158
3279
 
3159
- _reserveCancellation(pending, code) {
3280
+ _reserveCancellation(pending, code, reason) {
3160
3281
  const index = this.pendingQueue.indexOf(pending);
3161
3282
  if (index !== -1) this.pendingQueue.splice(index, 1);
3162
3283
  try {
@@ -3168,6 +3289,7 @@ class CodexProcess extends Process {
3168
3289
  this.pendingCancellations.push({
3169
3290
  pending,
3170
3291
  code,
3292
+ reason,
3171
3293
  attemptId: pending?.attemptId
3172
3294
  ?? `${this.generationId}:cancel:${this.cancellationSequence}`,
3173
3295
  });
@@ -3182,12 +3304,14 @@ class CodexProcess extends Process {
3182
3304
  const { pending } = cancellation;
3183
3305
  try {
3184
3306
  await this._checkpoint('queued-send-cancelled', {
3307
+ method: 'queued/send',
3185
3308
  threadId: this.providerSessionId,
3186
3309
  turnId: pending.turnId ?? null,
3187
3310
  source: pending.context?.sourceMsgId ?? null,
3188
3311
  clientUserMessageId: pending.clientUserMessageId ?? null,
3189
3312
  attemptId: cancellation.attemptId,
3190
3313
  cancellationCode: cancellation.code,
3314
+ reason: cancellation.reason,
3191
3315
  });
3192
3316
  } catch (error) {
3193
3317
  const durability = processError(
@@ -3311,7 +3435,7 @@ class CodexProcess extends Process {
3311
3435
  || pending.startDeliveryState !== 'accepted'
3312
3436
  || pending.turnId == null
3313
3437
  || pending.turnId !== this.activeTurnId
3314
- || this.pendingQueue.length !== 1
3438
+ || this.pendingQueue.length < 1
3315
3439
  || this.pendingQueue[0] !== pending
3316
3440
  || this.pendingSteerCount !== 0
3317
3441
  || this.pendingCancellations.length !== 0
@@ -3329,6 +3453,29 @@ class CodexProcess extends Process {
3329
3453
  || typeof this.spawnProfileId !== 'string'
3330
3454
  || this.spawnProfileId.length === 0
3331
3455
  ) return null;
3456
+ const seenClientIds = new Set([pending.clientUserMessageId]);
3457
+ const seenAttemptIds = new Set([pending.attemptId]);
3458
+ for (const follower of this.pendingQueue.slice(1)) {
3459
+ const followerSource = follower?.context?.sourceMsgId ?? null;
3460
+ if (
3461
+ !follower
3462
+ || follower === pending
3463
+ || follower.settled
3464
+ || follower.terminal
3465
+ || follower.turnId != null
3466
+ || follower.startedAt != null
3467
+ || follower.startDeliveryState !== 'queued'
3468
+ || followerSource == null
3469
+ || typeof follower.clientUserMessageId !== 'string'
3470
+ || follower.clientUserMessageId.length === 0
3471
+ || typeof follower.attemptId !== 'string'
3472
+ || follower.attemptId.length === 0
3473
+ || seenClientIds.has(follower.clientUserMessageId)
3474
+ || seenAttemptIds.has(follower.attemptId)
3475
+ ) return null;
3476
+ seenClientIds.add(follower.clientUserMessageId);
3477
+ seenAttemptIds.add(follower.attemptId);
3478
+ }
3332
3479
  return Object.freeze({
3333
3480
  runtime: 'codex',
3334
3481
  namespace: 'codex:app-server',
@@ -3362,7 +3509,8 @@ class CodexProcess extends Process {
3362
3509
 
3363
3510
  kill(reason = 'kill') {
3364
3511
  if (this.killPromise) return this.killPromise;
3365
- this.killPromise = this._kill(reason);
3512
+ const interruptionReason = boundedOpaqueId(reason, 'interruption reason');
3513
+ this.killPromise = this._kill(interruptionReason);
3366
3514
  return this.killPromise;
3367
3515
  }
3368
3516
 
@@ -3388,8 +3536,8 @@ class CodexProcess extends Process {
3388
3536
  return;
3389
3537
  }
3390
3538
 
3391
- this._drainWaiting('KILLED');
3392
- if (!this.current) this._drainAll('KILLED');
3539
+ this._drainWaiting('KILLED', reason);
3540
+ if (!this.current) this._drainAll('KILLED', reason);
3393
3541
  await this._flushPendingCancellations();
3394
3542
  this._assertLifecycle(lifecycle);
3395
3543
 
@@ -3402,13 +3550,13 @@ class CodexProcess extends Process {
3402
3550
  || this.state === 'BackgroundWorking'
3403
3551
  || this.state === 'Settling'
3404
3552
  ) {
3405
- await this.interrupt();
3553
+ await this.interrupt(reason);
3406
3554
  this._assertLifecycle(lifecycle);
3407
3555
  } else if (
3408
3556
  this.state !== 'Stopped'
3409
3557
  && this.state !== 'Idle'
3410
3558
  ) {
3411
- await this.interrupt();
3559
+ await this.interrupt(reason);
3412
3560
  this._assertLifecycle(lifecycle);
3413
3561
  }
3414
3562
 
@@ -1409,7 +1409,7 @@ class ProcessManager {
1409
1409
  'CODEX_DAEMON_GENERATION_BUSY',
1410
1410
  );
1411
1411
  }
1412
- await proc.interrupt();
1412
+ await proc.interrupt(reason);
1413
1413
  if (
1414
1414
  proc.state !== 'Stopped'
1415
1415
  || !this._codexLeaseMatches(proc)
@@ -2077,7 +2077,7 @@ class ProcessManager {
2077
2077
  }
2078
2078
  return this._withRetirementIntent(sessionKey, async () => {
2079
2079
  if (this.procs.get(sessionKey) !== proc || proc.closed) return false;
2080
- const interrupted = await proc.interrupt();
2080
+ const interrupted = await proc.interrupt('interrupt');
2081
2081
  if (!interrupted) return false;
2082
2082
  await this._killLocked(sessionKey, 'interrupt');
2083
2083
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shumkov/orchestra",
3
- "version": "0.10.17",
3
+ "version": "0.10.18",
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",