@shumkov/orchestra 0.11.0 → 0.11.1

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.
@@ -2334,7 +2334,7 @@ class CliProcess extends Process {
2334
2334
  }
2335
2335
 
2336
2336
  if (result?.ok && msg.name === 'reply') {
2337
- this._recordConsumedReplyDelivery(args.consumed_turn_ids, args.text);
2337
+ this._recordConsumedReplyDelivery(args.consumed_turn_ids, args.text, args.interim === true);
2338
2338
  }
2339
2339
 
2340
2340
  // Review #16 + C9: only record the reply for pending-turn resolution when
@@ -2718,32 +2718,30 @@ class CliProcess extends Process {
2718
2718
  this._ledgerTransition(id, 'resolved');
2719
2719
  this._logEvent('cli-input-acked', { turn_id: id, source: e.source });
2720
2720
  }
2721
- // UMI 2026-06-11 19:49 false ⏱ timeout: when claude answers a
2722
- // primary+fold in ONE reply but echoes the FOLD's turn_id, the reply
2723
- // routes via late-reply correlation and the PRIMARY pending absorbs
2724
- // nothing — yet this ack names the primary. Mark it consumed so the
2725
- // finalizer rungs treat it as replied (resolve already-delivered)
2726
- // instead of rejecting it at a ceiling AFTER the user got the answer.
2721
+ // Consumption prevents drop recovery even when a sibling turn owns the
2722
+ // reply. Successful final-answer delivery is recorded separately because
2723
+ // an interim status or an unsuccessful send can also acknowledge input.
2727
2724
  const pending = this.pendingTurns.get(id);
2728
2725
  if (pending) {
2729
2726
  pending._consumedAcked = true;
2730
- // The ack itself flips rung-2 eligibility on — arm now. (The turn's
2731
- // last _noteActivity ran BEFORE this flag was set, so without this
2732
- // a quiet tail would never re-arm and the turn would sit until a
2733
- // ceiling.)
2727
+ // The consuming answer may already have delivered; recheck eligibility.
2734
2728
  this._armActivityQuiet(id, pending);
2735
2729
  }
2736
2730
  }
2737
2731
  }
2738
2732
 
2739
2733
  /** Record text only after the dispatcher confirms that the consuming reply arrived. */
2740
- _recordConsumedReplyDelivery(ids, consumingText) {
2734
+ _recordConsumedReplyDelivery(ids, consumingText, interim = false) {
2741
2735
  if (!Array.isArray(ids) || typeof consumingText !== 'string') return;
2742
2736
  for (const id of new Set(ids)) {
2743
2737
  const pending = this.pendingTurns.get(id);
2744
2738
  if (pending && consumingText.length > (pending._consumedByText?.length || 0)) {
2745
2739
  pending._consumedByText = consumingText;
2746
2740
  }
2741
+ if (pending && !interim && consumingText.trim().length > 0) {
2742
+ pending._consumedFinalReplyDelivered = true;
2743
+ this._armActivityQuiet(id, pending);
2744
+ }
2747
2745
  }
2748
2746
  }
2749
2747
 
@@ -2946,8 +2944,8 @@ class CliProcess extends Process {
2946
2944
  * Is this turn eligible for the rung-2 activity-quiet finalize? Eligible when the
2947
2945
  * answer is already captured where a finalize can deliver it:
2948
2946
  * - a delivered FINAL reply (it went out incrementally), OR
2949
- * - seen + consumed-acked (the answer rode a sibling turn_id — fold-id echo;
2950
- * see _ledgerAckConsumed), OR
2947
+ * - seen + consumed-acked with a successfully delivered final consuming reply
2948
+ * (the answer rode a sibling turn_id), OR
2951
2949
  * - an attributed Stop captured the answer AND no work hook has fired since
2952
2950
  * (_workHookSeq unchanged from the capture) — i.e. claude is genuinely done,
2953
2951
  * not resumed into more work. A reply-less turn's only finalizer is its Stop grace;
@@ -2962,7 +2960,7 @@ class CliProcess extends Process {
2962
2960
  */
2963
2961
  _activityQuietEligible(pending) {
2964
2962
  if (this._turnHasFinalReply(pending)) return true;
2965
- if (pending.seen === true && pending._consumedAcked === true) return true;
2963
+ if (this._turnHasConsumedFinalReply(pending)) return true;
2966
2964
  if (pending._stopHookData
2967
2965
  && (this._workHookSeq || 0) === (pending._stopHookDataSeq || 0)) return true;
2968
2966
  return false;
@@ -3184,6 +3182,12 @@ class CliProcess extends Process {
3184
3182
  return (pending?.replies?.length || 0) > (pending?._interimReplyCount || 0);
3185
3183
  }
3186
3184
 
3185
+ /** Consumption prevents dropped-input recovery; only a delivered answer permits completion. */
3186
+ _turnHasConsumedFinalReply(pending) {
3187
+ return pending.seen === true && pending._consumedAcked === true
3188
+ && pending._consumedFinalReplyDelivered === true;
3189
+ }
3190
+
3187
3191
  /**
3188
3192
  * Compute the {text, alreadyDelivered} a resolving turn delivers, honoring the
3189
3193
  * interim-reply rules. Shared by BOTH resolve paths — `_finalizeTurn` (Stop /
@@ -3486,11 +3490,10 @@ class CliProcess extends Process {
3486
3490
  // would send a scary timeout error AFTER a successful reply (round-2
3487
3491
  // panel finding: the v2 soak gate contradicted the design's own
3488
3492
  // ask-timeout-then-ceiling path). TURN_TIMEOUT rejection is reserved
3489
- // for turns with ZERO delivered replies. Consumed-acked counts as
3490
- // replied: the answer rode a sibling turn_id (fold-id echo — the UMI
3491
- // 2026-06-11 19:49 false ⏱; see _ledgerAckConsumed).
3493
+ // for turns with ZERO delivered replies and no captured answer. A final
3494
+ // consuming reply or a current Stop can also supply the answer.
3492
3495
  if ((pending.replies?.length || 0) > 0
3493
- || (pending.seen === true && pending._consumedAcked === true)) {
3496
+ || this._activityQuietEligible(pending)) {
3494
3497
  // Interim-aware: an interim-only turn delivers its PRODUCED final answer
3495
3498
  // here too (not the status promise) — the same rescue as _finalizeTurn, so
3496
3499
  // the answer isn't dropped when the turn resolves at a ceiling rather than
@@ -3778,12 +3781,12 @@ class CliProcess extends Process {
3778
3781
  pending.absoluteTimer.unref?.();
3779
3782
  return;
3780
3783
  }
3781
- // Turn with a FINAL reply (or consumed-acked): the ceiling RESOLVES it, never
3784
+ // Turn with a FINAL reply (direct or consumed): the ceiling RESOLVES it, never
3782
3785
  // extends. An interim-only turn (status promise, no final reply) is still
3783
3786
  // working — fall through to the busy-aware probe so it extends, not resolves.
3784
3787
  // docs/progress-is-not-turn-end-spec.md
3785
3788
  if (this._turnHasFinalReply(pending)
3786
- || (pending.seen === true && pending._consumedAcked === true)) {
3789
+ || this._turnHasConsumedFinalReply(pending)) {
3787
3790
  pending._fireTimeout('absolute');
3788
3791
  return;
3789
3792
  }
@@ -3793,12 +3796,13 @@ class CliProcess extends Process {
3793
3796
  if (!this.pendingTurns.has(turnId)) return;
3794
3797
  pending = this.pendingTurns.get(turnId);
3795
3798
  // Also bail if the turn entered finalization DURING the probe — a reply
3796
- // landed, or it's in stop-grace, or it consumed-acked. Re-arming or pinging
3797
- // now would resurrect a settling turn (spurious "still working" right as the
3798
- // real answer lands). It will finalize through its own quiet/grace path.
3799
+ // landed, or it's in stop-grace, or a final consuming reply delivered.
3800
+ // Re-arming or pinging now would resurrect a settling turn (spurious "still
3801
+ // working" right as the real answer lands). It will finalize through its own
3802
+ // quiet/grace path.
3799
3803
  if (pending._stopGracePending
3800
3804
  || this._turnHasFinalReply(pending)
3801
- || (pending.seen === true && pending._consumedAcked === true)) return;
3805
+ || this._turnHasConsumedFinalReply(pending)) return;
3802
3806
  const now = Date.now();
3803
3807
  const elapsed = now - pending.startedAt;
3804
3808
  const maxMs = pending._turnHardMaxMs || this.turnHardMaxMs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shumkov/orchestra",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
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",