[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

Abierto
#1,059 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
tooling

Línea de trabajo

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

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
196
Forks
78
Merge medio
9 h 24 min
PR fusionados (30 d)
44

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bmad-code-org/bmad-loop

Todos los issues de bmad-code-org/bmad-loop

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.