feat(timeout): add agent timeout handling #141

Merged
shoko merged 1 commits from feat/agent-timeout into main 2026-04-05 06:59:05 +02:00
Owner

Overview

Implements #137 - Agent timeout handling.

Changes

Configuration

TASK_TIMEOUT_HOURS="${TASK_TIMEOUT_HOURS:-1}"  # Default: 1 hour

Queue Item Enhancement

Queue items now track additional fields:

{
  "id": "q_xxx",
  "issue_ref": "github.com/user/repo#123",
  "message": "task description",
  "state": "notified",
  "pending_since": "...",
  "notified_at": "2026-04-05T10:00:00Z",
  "completed_at": null,
  "error": null,
  "opencode_session_id": "ses_xyz",
  "pid": 12345
}

Timeout Behavior

  1. When a queue item is set to notified, the daemon records the PID and session ID
  2. In each daemon loop iteration, check_task_timeouts() runs
  3. If notified_at is older than TASK_TIMEOUT_HOURS:
    • The process is killed (by PID if available, or by session/worktree)
    • Queue item is marked as error
    • Session file is updated with state: "timeout"

Integration

  • check_task_timeouts() is called in the queue daemon loop
  • Timeout checking runs on every daemon poll interval

Closes #137

## Overview Implements #137 - Agent timeout handling. ## Changes ### Configuration ```bash TASK_TIMEOUT_HOURS="${TASK_TIMEOUT_HOURS:-1}" # Default: 1 hour ``` ### Queue Item Enhancement Queue items now track additional fields: ```json { "id": "q_xxx", "issue_ref": "github.com/user/repo#123", "message": "task description", "state": "notified", "pending_since": "...", "notified_at": "2026-04-05T10:00:00Z", "completed_at": null, "error": null, "opencode_session_id": "ses_xyz", "pid": 12345 } ``` ### Timeout Behavior 1. When a queue item is set to `notified`, the daemon records the PID and session ID 2. In each daemon loop iteration, `check_task_timeouts()` runs 3. If `notified_at` is older than `TASK_TIMEOUT_HOURS`: - The process is killed (by PID if available, or by session/worktree) - Queue item is marked as `error` - Session file is updated with `state: "timeout"` ### Integration - `check_task_timeouts()` is called in the queue daemon loop - Timeout checking runs on every daemon poll interval ## Related Issues Closes #137
shoko added 1 commit 2026-04-05 06:53:46 +02:00
Implements #137 - Agent timeout handling.

Changes:
- Add TASK_TIMEOUT_HOURS config (default: 1 hour)
- Update queue item to track opencode_session_id and pid
- Add check_task_timeouts() function that:
  - Checks notified tasks against timeout threshold
  - Kills process if exceeded
  - Marks session as 'timeout' state
- Integrate timeout check into queue daemon loop

Timeout behavior:
- Task is marked 'notified' when PM receives it
- If not completed within TASK_TIMEOUT_HOURS, task is killed
- Queue item marked 'error', session marked 'timeout'
han approved these changes 2026-04-05 06:58:42 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko merged commit 2212fabf22 into main 2026-04-05 06:59:05 +02:00
Sign in to join this conversation.