ductor icon indicating copy to clipboard operation
ductor copied to clipboard

Long-running stream timeout and restart/reboot can strand active work (missing warnings + auto-recovery)

Open jhste102lab opened this issue 9 months ago • 1 comments

Problem Statement

Long-running Codex streams can terminate at timeout boundaries without sufficient warning or recovery guidance. In addition, service restart/reboot events can leave active work stranded until the user manually re-prompts.

This is causing user-visible reliability failures in real workflows where tasks legitimately run for extended periods.

User Impact

  • Lost momentum during long-running tasks (stream stops unexpectedly).
  • Unclear timeout state (looks like a silent stall/failure from the user side).
  • Interrupted work after restart/reboot does not consistently recover automatically.
  • Increased manual retries and repeated prompts.

Environment

  • Runtime: ductor running as a Linux systemd --user service
  • Provider: Codex
  • Streaming: enabled
  • Timeout baseline: finite (default runtime timeout)

Reproduction

Scenario A: Timeout without recovery context

  1. Start a long-running Codex stream (complex multi-step task).
  2. Let the stream approach timeout boundary.
  3. Observe stream termination.

Actual:

  • No progressive pre-timeout warnings.
  • User receives limited recovery context and must manually re-drive the task.

Expected:

  • Pre-timeout warnings (e.g., T-60s, T-10s).
  • Actionable timeout outcome.
  • Bounded auto-extension path for legitimate long tasks.

Scenario B: Restart/reboot during active work

  1. Start a foreground turn or named session task.
  2. Restart the ductor service (or reboot host).
  3. Wait for service startup.

Actual:

  • Active work is often not resumed automatically.
  • User must manually prompt again.

Expected:

  • Startup notification clarifying state (started / restarted / reboot detected).
  • Best-effort automatic replay/resume of interrupted foreground and named-session work.

Root Cause Analysis

  1. Timeout handling was fixed-window only, with no user-facing warning stages.
  2. Streaming path lacked bounded auto-extension semantics for valid long-running operations.
  3. Startup path did not fully replay interrupted foreground in-flight turns.
  4. Named sessions did not persist enough recovery context (last_prompt) to auto-resume safely.
  5. Message ingress path lacked a robust exception boundary for transient Telegram API/network failures.
  6. Service lifecycle status was not surfaced to users/operators after startup.

Proposed Resolution

  • Add dynamic timeout cap via env (DUCTOR_DYNAMIC_TIMEOUT_MAX_SECONDS).
  • Emit pre-timeout stream events (timeout_warn_60, timeout_warn_10) and timeout_extended status.
  • Improve timeout completion messaging with explicit next-step guidance.
  • Persist foreground in-flight turn state and auto-replay on startup.
  • Persist named-session recovery state and auto-resume sessions that were running pre-restart.
  • Add startup/restart/reboot status broadcast.
  • Add defensive exception handling in _on_message for TelegramAPIError and unexpected exceptions.

Acceptance Criteria

  • [ ] User sees warning signals at ~60s and ~10s before timeout in stream mode.
  • [ ] Long-running streams can extend within configured bounds.
  • [ ] Timeout messages are actionable and non-ambiguous.
  • [ ] Foreground interrupted work is auto-replayed on startup (best effort, bounded).
  • [ ] Named sessions interrupted by restart are auto-resumed on startup (best effort, bounded).
  • [ ] Users receive startup/restart/reboot notification.
  • [ ] Telegram transient errors do not destabilize the bot process.

Verification Performed

  • python3 -m py_compile for modified runtime files.
  • Runtime log validation for:
    • startup state detection,
    • interrupted turn detection,
    • auto-resume trigger path,
    • timeout warning/extension events.

Notes

  • Full pytest suite was not executed in this environment because pytest was unavailable at runtime.
  • Recovery is intentionally best-effort and bounded to prevent replay loops.

jhste102lab avatar Mar 02 '26 03:03 jhste102lab

Resolved in v0.11.0 — timeout warnings, activity-based extension, and startup auto-recovery are all live. Thanks @jhste102lab for raising this and the follow-up PR #20!

PleasePrompto avatar Mar 02 '26 16:03 PleasePrompto