[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

Aperta
#1,059 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

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

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
196
Fork
78
Merge medio
9h 24m
PR unite (30g)
44

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bmad-code-org/bmad-loop

Tutte le issue di bmad-code-org/bmad-loop

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.