Repository navigation
feat(core): add a Code Mode tool that interrupts a session and everything under it - #65718
Conversation
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
Issue for this PR
Closes #
Type of change
What does this PR do?
Adds
opencode.session.interrupt, a Code Mode tool (withfull_codemodeon) that interrupts any session by ID and stops everything under it: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 checkpasses, 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
Added by the opencode bot (AI-generated).
Related: #36423, #59566
Public API: adds the
opencode.session.interruptCode Mode tool, available withfull_codemodeonly (backwards compatible)