Skip to content

fix(scheduler): handle delivery timeout and fix BaseException catch#3563

Open
Kewe63 wants to merge 2 commits intoNousResearch:mainfrom
Kewe63:fix/scheduler-delivery-error-handling
Open

fix(scheduler): handle delivery timeout and fix BaseException catch#3563
Kewe63 wants to merge 2 commits intoNousResearch:mainfrom
Kewe63:fix/scheduler-delivery-error-handling

Conversation

@Kewe63
Copy link
Copy Markdown
Contributor

@Kewe63 Kewe63 commented Mar 28, 2026

🐛 Bug Fixes

# File Bug Type Severity Fix Summary
1 cron/scheduler.py Unhandled TimeoutError HIGH ThreadPoolExecutor fallback in _deliver_result() had no timeout error handling — a 30s
timeout would crash the delivery path silently; added except concurrent.futures.TimeoutError
2 cron/scheduler.py Invalid exception clause MEDIUM except (Exception, KeyboardInterrupt) is redundant — KeyboardInterrupt derives from
BaseException not Exception, so it was never caught; replaced with except BaseException

🧪 Test Results

  • Total tests run: 116
  • Passed: 116 | Failed: 0 | Skipped: 4
  • Test environment: Python 3.11.9 / pytest + pytest-xdist

📋 Change Summary

  • Files affected: 1 (cron/scheduler.py)
  • Lines changed: +12 / -5

✅ Checklist

  • All tests passing
  • No breaking changes introduced
  • Documentation updated (if applicable)

Kewe63 added 2 commits March 28, 2026 21:57
- Fix incorrect type annotations: last_prompt_tokens and model
  parameters in update_session() were annotated as int/str with
  None defaults; corrected to Optional[int] and Optional[str]
- Add OSError handling in append_to_transcript() JSONL write path;
  previously an unhandled IOError would propagate and break the
  caller's flow
- Make rewrite_transcript() JSONL write atomic using tempfile +
  os.fsync + os.replace to prevent data loss if the write fails
  mid-way (file was previously truncated before new content landed)
- Wrap ThreadPoolExecutor fallback in try/except to catch
  concurrent.futures.TimeoutError (30s timeout) which previously
  propagated unhandled and crashed the delivery path
- Replace invalid `except (Exception, KeyboardInterrupt)` with
  `except BaseException` in session cleanup finally block;
  KeyboardInterrupt derives from BaseException not Exception,
  so the previous clause never caught it
@Kewe63
Copy link
Copy Markdown
Contributor Author

Kewe63 commented Mar 28, 2026

BaseException is used intentionally here in a finally cleanup block catching KeyboardInterrupt ensures the SQLite session is properly closed even on Ctrl+C, preventing potential data corruption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant