Skip to content

feat(core): add a Code Mode tool that interrupts a session and everything under it - #65718

Merged
rekram1-node merged 5 commits into
devfrom
session-interrupt-tool
Nov 23, 2026
Merged

rekram1-node merged 5 commits into
devfrom
session-interrupt-tool

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Closes #

Type of change

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

What does this PR do?

Adds opencode.session.interrupt, a Code Mode tool (with full_codemode on) that interrupts any session by ID and stops everything under it:

  • interrupts the session's running turn
  • cancels its background jobs: shell commands, subagents, Code Mode scripts, media generation
  • does the same for its child sessions (subagents), all the way down

Jobs are cancelled the way deleting a session cancels them, without completion notices, so nothing wakes the interrupted sessions again. They're cancelled before the interrupt, so none finishes and wakes the session in between, and again right after it, for any its last step started. A session can't interrupt itself or a session above it, since that would stop the call and the caller's own work. The tool isn't pinned, and asks no permission, like opencode.session.rename.

How did you verify your code works?

A throwaway test with a parent, child and grandchild session and jobs on the parent and grandchild: the tool cancelled both jobs and refused to interrupt the calling session or, from the grandchild, the parent. bun run check passes, and the Code Mode, OpenCode tools and session search tests pass.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

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

Added by the opencode bot (AI-generated).

Related: #36423, #59566

Public API: adds the opencode.session.interrupt Code Mode tool, available with full_codemode only (backwards compatible)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool works as described: I ran it through Code Mode execute on a parent → child → grandchild tree with a job on each session. All the jobs were cancelled, and a session that targets itself is refused. Targeted tests and typecheck:tsc for packages/core pass. I didn't run the TUI, since nothing in it changes.

Public API: adds the opencode.session.interrupt Code Mode tool, available only with full_codemode (backwards compatible). The SDK, HTTP API and config are unchanged.

Concern: the self-interrupt guard only compares session IDs, so a subagent can still interrupt itself by targeting its parent or any session above it (inline comment).

Related: #36423, #59566

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier points are fixed. The tool now refuses the caller and any session above it: I tried a child targeting its parent and a grandchild targeting the root, and both were refused. Jobs are now cancelled both before and after the interrupt, so nothing can wake the session in between. Called from a session outside the tree, it stopped all three sessions' jobs; I checked this with a throwaway test. typecheck:tsc and the existing session search and tool registry tests pass. Nothing new to raise.

Public API: adds the full_codemode-only opencode.session.interrupt Code Mode tool (backwards compatible); nothing else changes.

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