Skip to content

refactor(tool-timeout): extract createTimeoutController, deduplicate timer logic - #2

Merged
FahadBinHussain merged 1 commit into
FahadBinHussain:tool-execution-timeoutfrom
zxkjack123:fix/tool-timeout-type-safety
Jul 21, 2026
Merged

refactor(tool-timeout): extract createTimeoutController, deduplicate timer logic#2
FahadBinHussain merged 1 commit into
FahadBinHussain:tool-execution-timeoutfrom
zxkjack123:fix/tool-timeout-type-safety

Conversation

@zxkjack123

Copy link
Copy Markdown

Stacked on PR to anomalyco/opencode anomalyco#36869 (tool-execution-timeout by @FahadBinHussain). This extracts the repeated AbortController + setTimeout + composeSignals + clearTimeout pattern into a single ToolTimeout.createTimeoutController() helper and adds timer-lifecycle tests.

What

  • tool-timeout.ts: Add createTimeoutController({ tool, timeoutMs, userSignal }) — one-stop helper that creates the AbortController, arms the timer, composes signals, and returns { signal, dispose } for guaranteed cleanup
  • tools.ts: Replace two duplicated blocks (built-in tools + MCP plugin tools) with createTimeoutController calls, reducing ~30 lines of duplicated low-level timer management
  • tool-timeout.test.ts: Add 5 integration tests

New tests

Test What it verifies
fires ToolTimeoutError after timeout Timer actually fires with the correct error type
aborted signal has correct tool and timeoutMs Error carries the right metadata
composes user signal with timeout signal User abort (Esc) + timer abort combine into one signal
dispose clears the timer so no abort fires finally { dispose() } prevents leak — timer is cleared before it fires
non-aborted signal when idle Signal starts non-aborted, as expected

Verification

bun test test/session/tool-timeout.test.ts
  ✓ 15 pass / 0 fail

bun run typecheck (packages/opencode)
  ✓ tsgo --noEmit (clean)

The 3 pre-existing failures in task.test.ts (subagent description, variant, permission shape) are unchanged from upstream/dev — they depend on local .opencode/ agent config, not on this change.

…r logic

- Extract composeSignals + AbortController + setTimeout/clearTimeout
  pattern into ToolTimeout.createTimeoutController()
- Replace two duplicated AbortController/setTimeout blocks in
  tools.ts (built-in tools + MCP plugin tools) with a single call
- Add 5 integration tests covering timeout firing, signal composition,
  dispose cleanup, and idle signal verification
- All 15 tool-timeout tests pass; 3 pre-existing task.test.ts
  failures unchanged from upstream/dev
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1af47a38-ee02-4820-895c-2ac613aa17fb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@FahadBinHussain
FahadBinHussain merged commit cafcc31 into FahadBinHussain:tool-execution-timeout Jul 21, 2026
1 check passed
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.

2 participants