ductor
ductor copied to clipboard
Long-running stream timeout and restart/reboot can strand active work (missing warnings + auto-recovery)
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:
ductorrunning as a Linuxsystemd --userservice - Provider: Codex
- Streaming: enabled
- Timeout baseline: finite (default runtime timeout)
Reproduction
Scenario A: Timeout without recovery context
- Start a long-running Codex stream (complex multi-step task).
- Let the stream approach timeout boundary.
- 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
- Start a foreground turn or named session task.
- Restart the
ductorservice (or reboot host). - 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
- Timeout handling was fixed-window only, with no user-facing warning stages.
- Streaming path lacked bounded auto-extension semantics for valid long-running operations.
- Startup path did not fully replay interrupted foreground in-flight turns.
- Named sessions did not persist enough recovery context (
last_prompt) to auto-resume safely. - Message ingress path lacked a robust exception boundary for transient Telegram API/network failures.
- 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) andtimeout_extendedstatus. - 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_messageforTelegramAPIErrorand 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_compilefor modified runtime files.- Runtime log validation for:
- startup state detection,
- interrupted turn detection,
- auto-resume trigger path,
- timeout warning/extension events.
Notes
- Full
pytestsuite was not executed in this environment becausepytestwas unavailable at runtime. - Recovery is intentionally best-effort and bounded to prevent replay loops.
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!