Skip to content

fix(cli): stop waiting when an owned child session without a job ends - #62643

Open
ivopogace wants to merge 1 commit into
anomalyco:devfrom
ivopogace:fix/run-wait-owned-children
Open

ivopogace wants to merge 1 commit into
anomalyco:devfrom
ivopogace:fix/run-wait-owned-children

Conversation

@ivopogace

Copy link
Copy Markdown

Issue for this PR

Closes #62636

Type of change

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

What does this PR do?

opencode run waits for child sessions created with parentID, but only woke up when a job's session finished. Now it also wakes up when such a child finishes, so it exits.

How did you verify your code works?

Added a test that hangs without the fix and passes with it.

Checklist

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

opencode run treats any active session under the root as pending work,
but only woke on a turn ending in a job session. A child created with
parentID (for example by a plugin) kept the run waiting forever after
it finished. Wake on a turn ending in any session the run owns.

@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.

This fixes the hang. I ran the #62636 reproduction from source. On the base, opencode run --session <root> was killed by the 45 s timeout while a parentID child was still busy. With this change it exits 0 as soon as the child finishes. The two control cases (child without parentID, and a child that finished first) still exit 0 right away. noninteractive.test.ts passes, and the new test hangs and fails on the base code. tsc -b passes.

The wait loop takes state.ended.promise before it waits or calls background(). So a child that finishes during or after the active() read still wakes it, even though the ownership check is async. ownsSession already maps lookup failures to false, so there is no unhandled rejection. The extra cost is at most one cached session.get per new session that finishes.

Public API unchanged: this is internal to the run command.

This branch has not been deployed

No deployments
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.

cli: opencode run hangs if a child session is busy when the root finishes

1 participant