[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

Đang mở
#1,059 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

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

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
196
Fork
78
Merge trung bình
9 giờ 24 phút
Pull request đã merge (30 ngày)
44

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bmad-code-org/bmad-loop

Tất cả issue của bmad-code-org/bmad-loop

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.