GeezerVison is showing github.com — fix(core): preserve parent interruption reason in subagents by YMoose · Pull Request #61414 · anomalyco/opencode
Conversation
YMoose
commented
Nov 3, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Fixes #61413
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
When owner teardown interrupts a parent waiting for a foreground subagent, cleanup calls the child's user-stop entry point. The parent can report shutdown while the child reports user, releases its execution claim, and projects an idle marker.
Let that cleanup identify its parent and inherit the active parent's recorded interruption reason, using the same shutdown fallback as the parent's terminal classification. Ordinary user stops still report user. No HTTP API, event schema, or database schema changes.
How did you verify your code works?
- Added regression coverage in
packages/core/test/subagent-lifetime.test.ts for both user and shutdown parent interruptions of a foreground subagent (verifying SessionEvent.Execution.Interrupted reasons, time_suspended execution claims, idle_outcome, and projected idle context messages).
bun run script/test.ts test/subagent-lifetime.test.ts --rerun-each 10 --randomize in packages/core: 50 passed.
- Focused session/subagent suites (79 tests) and full
@opencode/core suite (6,881 passed, 0 failed).
- Root
bun run check: passed (lint and all 35 typecheck tasks).
Visual
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72">
<style>
.flow { animation: flow 2s ease-in-out infinite; }
@keyframes flow { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .flow { animation: none; } }
</style>
<g fill="none" stroke="currentColor" opacity=".6">
<rect x="5" y="10" width="91" height="52" rx="7"/>
<rect x="144" y="10" width="91" height="52" rx="7"/>
<path class="flow" d="M104 36h32m-6-5 6 5-6 5"/>
</g>
<g fill="currentColor" font-family="sans-serif" font-size="11" text-anchor="middle">
<text x="50" y="30">Parent</text><text x="190" y="30">Subagent</text>
<text x="50" y="49">shutdown</text><text x="190" y="49">shutdown</text>
</g>
</svg>
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #36349
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
When owner teardown interrupts a parent waiting for a foreground subagent,
cleanup calls the child's user-stop entry point. The parent can report
`shutdown` while the child reports `user`, releases its execution claim,
and projects an idle marker.
Let that cleanup identify its parent and inherit the active parent's
recorded interruption reason, using the same shutdown fallback as the
parent's terminal classification. Ordinary user stops still report `user`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix works and is well scoped. I reproduced the bug by running the new test against the base: the shutdown case fails there because the child is recorded as a user stop. With this PR, the subagent-lifetime tests and the related coordinator, runner and owned-session suites pass (295 tests), and tsc is clean for packages/core.
I also checked that a user stop still comes through as user. The coordinator stores the parent's reason before it interrupts the parent's fiber, so the subagent's cleanup always sees it. The shutdown fallback only applies when the parent's execution was interrupted with no reason recorded, because a foreground subagent's tool fiber is only interrupted when the parent's step is. Nested subagents also inherit correctly.
Public API: unchanged apart from a new optional parentID field in the options of the internal core Session/SessionExecution interrupt method, which existing callers don't need to change for. The HTTP API, SDK, events and database schema are unchanged.
No blocking concerns.
Related: #36349
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Closing: superseded by the upstream subagent lifetime refactor. #63382 (always run subagents in the background), #63223 and #63392 removed the foreground subagent path this fix hooked into — children now run as background Jobs whose parent teardown no longer interrupts them at all (only an explicit caller cancel does, and the coordinator grew the equivalent interruption(key) API). The scenario this PR fixed can no longer occur.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|