Skip to content

feat(tool): configurable timeout protection for tool and task execution#20103

Open
ESRE-dev wants to merge 1 commit intoanomalyco:devfrom
ESRE-dev:pr/tool-timeout
Open

feat(tool): configurable timeout protection for tool and task execution#20103
ESRE-dev wants to merge 1 commit intoanomalyco:devfrom
ESRE-dev:pr/tool-timeout

Conversation

@ESRE-dev
Copy link
Copy Markdown

@ESRE-dev ESRE-dev commented Mar 30, 2026

Issue for this PR

Closes #15080

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds configurable timeout protection for both normal tool execution and subagent task execution to prevent indefinite hangs.

Key changes:

  1. Shared abort utility

    • Adds a raceSignal(...) helper that cleanly races async work against an abort signal.
  2. Global non-task tool timeout

    • Adds a default timeout for non-task tools in the tool execution wrapper.
    • Supports config override via experimental.tool_timeout.
    • Keeps task excluded from this outer timeout so it can manage its own deadline.
  3. Task tool deadline management

    • Adds task-level timeout behavior (default deadline + optional override).
    • Supports config via experimental.task_timeout.
    • On timeout, cancels child session execution and returns structured output with task_id.
    • Preserves partial-output recovery behavior where available.
  4. Config schema updates

    • Adds timeout fields used by the above behavior.

Related overlap (not duplicates):

How did you verify your code works?

  • Added and ran packages/opencode/test/tool/timeout.test.ts.
  • Ran targeted tool/session tests to confirm timeout behavior and cancellation flow.
  • Verified that task timeout behavior remains isolated from non-task global tool timeout.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

- Add raceSignal() utility for clean abort-signal racing
- Wrap non-task tool execution with configurable timeout (default 15min)
- Add task-level deadline management with timeout recovery
- Support experimental.tool_timeout and experimental.task_timeout config
- Task tool manages its own deadline, skips outer timeout wrapper
avion23 pushed a commit to avion23/opencode that referenced this pull request Apr 2, 2026
…nomalyco#20104, anomalyco#20103)

- SessionActivity tracker for per-session activity timestamps
- Watchdog tick (60s) with leaf-filtering to force-error stuck tools
- Idle detection (default 5min) cancels unresponsive subagent sessions
- Orphan cleanup on startup for crash recovery
- raceSignal() for abort-aware tool execution with configurable timeouts
- Non-task tools: 15min global timeout (configurable)
- Task tools: 4hr default timeout with partial output recovery
- Fixed pre-existing typecheck error in app.tsx (removed externalOutputMode)
avion23 pushed a commit to avion23/opencode that referenced this pull request Apr 3, 2026
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.

[FEATURE]: Add configurable timeout parameter to the Task tool

1 participant