[BUG] opencode-http (2.x): turn end acted on after `descendant-wait-ended` while the parent was already re-woken by the child's `<subagent>` message

オープン
#1,059 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
tooling

調査の方向性

Start in adapters/opencode_http.py at the if event == "idle": branch of _wait_loop (around line 1760), then read _await_descendants and active_descendants together with the session_busy and execution-event handling. Compare those paths against the descendant-wait-ended and session-end entries in tasks/<task>/session-lifecycle.jsonl from the two sessions to see where the stale idle is acted on. Done looks like the waited turn end is re-validated, by checking whether the parent is busy again or a new session.execution.started arrived, before _result_json(..., wait=True).

索引モデルが issue の本文から書いたものです。

説明

Environment
  • bmad-loop 8224d53 (main, 2026-11-17; --version 0.13.2), installed with uv tool install from git. The descendant wait (#1030) is not in any release yet: v0.13.2 has no _await_descendants.
  • Adapter opencode-http, OpenCode server 2.3.2 (opencode serve)
  • macOS, tmux backend
  • Dev model opencode-go/muse-spark-1.3-contributor, stories mode, bmad-build-auto
Summary

On OpenCode 2.x every subagent call runs in the background (2.3.2 tool description: "Subagents always run in the background … you receive a <subagent> message each time the child goes idle"). The dev skill delegates the review-patch work to a subagent, so the parent ends its turn and _await_descendants (#1030) holds the turn end until the child is idle.

When the child finishes, OpenCode delivers its <subagent> result into the parent's inbox and restarts the parent (session.inbox.enqueued → session.execution.started → session.inbox.delivered). _await_descendants then probes, sees no active descendant, journals descendant-wait-ended and returns True. The wait loop treats the old idle as the turn end and returns completed. But by then the parent is running again: it was about to re-verify, set the spec to done and commit.

The engine then reads the spec at a nonterminal status and decides retry/defer ("spec remained at reconcilable nonterminal status 'in-review'/'in-progress' while harvesting deferrals"). The attempt is rolled back, even though implementation and review were complete.

Evidence (two sessions, same run)

Times are the SSE frame ts; the descendant-wait-* entries come from tasks/<task>/session-lifecycle.jsonl.

15-dev-1

ts (s) event
1795181693.681 parent session.execution.succeeded (turn ended, awaiting the patch subagent)
1795181693.687 descendant-wait-started sessions: [<child>], grace_s: 600
1795181937.635 parent session.inbox.enqueued (<subagent … state="completed">), session.execution.started, session.inbox.delivered
1795181938.620 descendant-wait-ended waited_s: 244.9
1795181938.673 parent session.step.started (the parent is working)
1795181938.715 journal session-end status: completed → dev-decision retry

16-dev-1

ts (s) event
1795183575.596 parent session.execution.succeeded
1795183575.606 descendant-wait-started
1795183743.452 parent inbox.enqueued / execution.started / inbox.delivered
1795183743.471 descendant-wait-ended waited_s: 167.9
1795183743.504 parent session.step.started
1795183743.547 session-end completed → dev-decision retry

In both sessions the parent's transcript ends on the delivered <subagent> message, with no assistant turn after it.

In this case the child was a follow-up to an existing subagent: the call passed sessionID to resume the earlier implementation child, so the child ID was the same one the earlier waits had already seen finish.

Where

adapters/opencode_http.py, the if event == "idle": branch of _wait_loop (around line 1760): when _await_descendants returns True, the loop goes on to _result_json(..., wait=True) with nothing showing that the parent is still settled. _await_descendants only asks active_descendants; it never checks the parent again.

Expected

After a descendant wait that actually waited (descendant-wait-ended), the turn end should be re-validated before it is acted on. For example: if the parent session is busy again (session_busy → True), or a session.execution.started for the parent arrived during the wait, discard the stale idle and keep waiting for the next turn end.

Related
  • #1030: added the OpenCode subagent wait; this is an edge of that wait.
  • #109: the same "yield to await a background subagent" pattern on the Claude adapter.
Side note

With the default dev_stall_grace_s = 600, a long implementation subagent (>10 min) also expires the wait (descendant-wait-timeout) and the parent's stale turn end is acted on in the same way. Raising the grace to 2400 s avoided that, and the next story completed. It does not close the race above.

主要言語
Python
スター
196
フォーク
78
平均マージ
9時間 24分
マージ済み PR(30日)
44

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bmad-code-org/bmad-loop のほかの issue

bmad-code-org/bmad-loop の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。