Skip to content

fix: handle queue.Empty in task mode to prevent crash on LLM timeout#291

Open
Jeason00011 wants to merge 1 commit intolsdefine:mainfrom
Jeason00011:fix/task-mode-queue-empty
Open

fix: handle queue.Empty in task mode to prevent crash on LLM timeout#291
Jeason00011 wants to merge 1 commit intolsdefine:mainfrom
Jeason00011:fix/task-mode-queue-empty

Conversation

@Jeason00011
Copy link
Copy Markdown

@Jeason00011 Jeason00011 commented May 7, 2026

Problem

--task mode crashes with unhandled queue.Empty when LLM response has no chunk output for 300s.

# agentmain.py:211 (before fix)
while 'done' not in (item := dq.get(timeout=300)):   # raises queue.Empty → crash

Trigger: stream=False + slow model (queuing/rate-limited), or network stall where TCP hasn't timed out yet.

Evidence: reflect mode already handles this

# agentmain.py:240-245 (reflect mode)
try:
    while 'done' not in (item := dq.get(timeout=120)): pass
    result = item['done']
except Exception as e:
    if getattr(mod, 'ONCE', False): raise
    print(f'[Reflect] drain error: {e}'); result = f'[ERROR] {e}'

Same pattern, same timeout mechanism, but wrapped in try/except. Task mode was missed.

Fix

Add try/except around the task mode drain loop. On timeout, write error to output file and break gracefully (consistent with reflect mode behavior).

Discovery

Found by systematic code health scan — checking symmetric code paths for inconsistent error handling (hint from repo maintainer to inspect the dual-mode pattern).

@Jeason00011 Jeason00011 closed this May 7, 2026
@Jeason00011 Jeason00011 reopened this May 7, 2026
@Jeason00011 Jeason00011 marked this pull request as draft May 7, 2026 13:30
The reflect mode already catches this exception, but task mode did not,
causing an unhandled crash when LLM response exceeds 120s between chunks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Jeason00011 Jeason00011 force-pushed the fix/task-mode-queue-empty branch from 63312a1 to ae81626 Compare May 7, 2026 13:34
@Jeason00011 Jeason00011 marked this pull request as ready for review May 7, 2026 13:35
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