[FEATURE]: Pass signal argument to custom tools so they can be aborted and not hang on esc esc #2185

Closed
opened 2026-02-16 17:34:34 -05:00 by yindo · 4 comments
Owner

Originally created by @remorses on GitHub (Oct 20, 2025).

Originally assigned to: @rekram1-node on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Currenlty custom tools do not have a way to abort and hang when pressing esc esc to abort

Originally created by @remorses on GitHub (Oct 20, 2025). Originally assigned to: @rekram1-node on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request Currenlty custom tools do not have a way to abort and hang when pressing esc esc to abort
yindo closed this issue 2026-02-16 17:34:34 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 20, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #684: interrupt sometimes has no effect - reports that calling the interrupt API sometimes has no effect and has delays
  • #1179: ESC often doesn't work - describes ESC not interrupting the flow and sessions becoming unresponsive
  • #1734: Esc not working on agent hangs - when agent hangs with 'working...' state, ESC interruption doesn't work
  • #3255: Urgent but very general issue, ESC stop working or how to get out of auto commit type action model? - ESC stops working and can't interrupt long tasks
  • #652: App becomes unresponsive when executing commands requiring sudo password - describes processes hanging when requiring input that can't be provided

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 20, 2025): This issue might be a duplicate of existing issues. Please check: - #684: interrupt sometimes has no effect - reports that calling the interrupt API sometimes has no effect and has delays - #1179: ESC often doesn't work - describes ESC not interrupting the flow and sessions becoming unresponsive - #1734: Esc not working on agent hangs - when agent hangs with 'working...' state, ESC interruption doesn't work - #3255: Urgent but very general issue, ESC stop working or how to get out of auto commit type action model? - ESC stops working and can't interrupt long tasks - #652: App becomes unresponsive when executing commands requiring sudo password - describes processes hanging when requiring input that can't be provided Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Oct 20, 2025):

will fix

@rekram1-node commented on GitHub (Oct 20, 2025): will fix
Author
Owner

@rekram1-node commented on GitHub (Oct 20, 2025):

We do pass the signal, so this works:

import { type Plugin, tool } from "@opencode-ai/plugin"

export const CustomToolsPlugin: Plugin = async (pluginCtx) => {
  return {
    tool: {
      mytool: tool({
        description: "This is a custom tool",
        args: {
          foo: tool.schema.string(),
        },
        async execute(args, ctx) {
          await new Promise((resolve, reject) => {
            const timeout = setTimeout(resolve, 60000)
            ctx.abort.addEventListener(
              "abort",
              () => {
                clearTimeout(timeout)
                reject(new DOMException("Aborted", "AbortError"))
              },
              { once: true },
            )
          })
          return `Hello ${args.foo}!`
        },
      }),
    },
  }
}

But if you aren't referencing the signal then tools will appear to ignore the abort

@rekram1-node commented on GitHub (Oct 20, 2025): We do pass the signal, so this works: ``` import { type Plugin, tool } from "@opencode-ai/plugin" export const CustomToolsPlugin: Plugin = async (pluginCtx) => { return { tool: { mytool: tool({ description: "This is a custom tool", args: { foo: tool.schema.string(), }, async execute(args, ctx) { await new Promise((resolve, reject) => { const timeout = setTimeout(resolve, 60000) ctx.abort.addEventListener( "abort", () => { clearTimeout(timeout) reject(new DOMException("Aborted", "AbortError")) }, { once: true }, ) }) return `Hello ${args.foo}!` }, }), }, } } ``` But if you aren't referencing the signal then tools will appear to ignore the abort
Author
Owner

@remorses commented on GitHub (Oct 20, 2025):

Didn't know about ctx

@remorses commented on GitHub (Oct 20, 2025): Didn't know about ctx
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2185