GeezerVison is showing github.com — Merge runner review fixes: wait for background subagents (X31), reope… · rphang/opencode-workflows@67d1032
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: CHANGELOG.md +9Lines changed: 9 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -36,6 +36,15 @@ may contain breaking changes. | 36 | 36 |
| 37 | 37 | ### Fixed | 38 | 38 |
| | 39 | +- **Background subagents** (opencode 2.3, X31). opencode's `subagent` tool now always runs in the | | 40 | + background; an agent that launches one returns the answer it gives after the subagent reports, | | 41 | + not "I launched a subagent". A schema agent no longer spends a retry while its subagent runs, | | 42 | + and a worktree a running job may still use is kept. The wait ends on stop or the agent timeout | | 43 | + (30 min cap with a warning). Background shells are not waited for. | | 44 | +- Steering messages are no longer refused for the rest of an agent's turn when another plugin or a | | 45 | + user prompt keeps the agent working. | | 46 | +- A late structured-output nudge no longer uses up an extra retry; parallel or cross-instance | | 47 | + `workflow_submit` calls no longer lose an attempt or bring back a finished agent's state. | 39 | 48 | - Failed agents report opencode 2.3's actual error instead of "agent session failed (terminal error)". | 40 | 49 | - After an urgent message whose follow-up turn produced no text, the result no longer falls back to | 41 | 50 | the cut-off text of the interrupted step. | |
Collapse file Copy file name to clipboardExpand all lines: README.md +8-6Lines changed: 8 additions & 6 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -113,10 +113,11 @@ run (6 agents, under a minute) is in [`demo/DEMO-OUTPUT.md`](demo/DEMO-OUTPUT.md | 113 | 113 | - **Safe by default.** Workflows start only when you opt in. Scripts run in a sandbox with no | 114 | 114 | filesystem, network or shell. Agents inherit your permission rules and never get more. | 115 | 115 | - **Tested for parity.** 60 behaviors are each tracked against Claude Code in | 116 | | - [`docs/PARITY.md`](docs/PARITY.md), and each has at least one test. The 30 extensions beyond | 117 | | - Claude Code (`X01`–`X30`: steering, the live progress tree, per-agent models, the per-agent | | 116 | + [`docs/PARITY.md`](docs/PARITY.md), and each has at least one test. The 31 extensions beyond | | 117 | + Claude Code (`X01`–`X31`: steering, the live progress tree, per-agent models, the per-agent | 118 | 118 | failure summary and outputs, idle-boundary steering and schema nudges, the freeform | 119 | | - `workflow_script` tool, the TUI agent dialog and sidebar, and the desktop app companion) are specified and tested there the same way. | | 119 | + `workflow_script` tool, the TUI agent dialog and sidebar, waiting for background subagents, and the desktop app | | 120 | + companion) are specified and tested there the same way. | 120 | 121 |
| 121 | 122 | ## Requirements | 122 | 123 |
| @@ -539,7 +540,7 @@ Set them in the environment of the opencode server. They work with every install | 539 | 540 | | `MAX_STRUCTURED_OUTPUT_RETRIES` (or `OPENCODE_WORKFLOW_MAX_STRUCTURED_OUTPUT_RETRIES`) | `5` | Attempts a schema agent gets before `agent()` throws. | | 540 | 541 | | `OPENCODE_WORKFLOW_FREEFORM` | unset (on) | `0`, `false`, `no` or `off` registers no `workflow_script` tool, like the `freeformTool: false` option. | | 541 | 542 | | `OPENCODE_WORKFLOW_RPC_CONTROL` | unset (on) | `0`, `false`, `no` or `off` makes the live tree's RPC read-only, like the `rpcControl: false` option. | | 542 | | -| `OPENCODE_WORKFLOW_IDLE_HOOK` | unset (on) | `0`, `false`, `no` or `off` registers no `experimental.idle` hook (opencode 2.3+). Without it, a steering message that lands as an agent finishes still reaches it through an extra turn, and a schema agent that forgot `workflow_submit` is re-prompted in a new turn instead of nudged in the same one. | | | 543 | +| `OPENCODE_WORKFLOW_IDLE_HOOK` | unset (on) | `0`, `false`, `no` or `off` registers no `experimental.idle` hook (opencode 2.3+). Without it, a steering message that lands as an agent finishes still reaches it through an extra turn, and a schema agent that forgot `workflow_submit` is re-prompted in a new turn instead of nudged in the same one. It also turns off waiting for an agent's background subagents (opencode 2.3 runs them in the background): an agent that launched one is then read as soon as its turn ends. | | 543 | 544 | | `OPENCODE_WORKFLOW_DATA_DIR` | `$XDG_DATA_HOME/opencode/workflows`, else `%LOCALAPPDATA%\opencode\workflows` (Windows) or `~/.local/share/opencode/workflows` | Run transcripts, stored as `<dir>/<sessionID>/<runId>/`. The `dataDir` plugin option wins over it. | | 544 | 545 |
| 545 | 546 | ## How it compares to Claude Code | @@ -555,10 +556,11 @@ that check it: | 555 | 556 | | ADAPTED | 1 | Same purpose, reached another way | | 556 | 557 | | N/A | 1 | Cannot be done as an opencode plugin | | 557 | 558 |
| 558 | | -The same file specifies the 30 extensions (status `EXT`, `X01`–`X30`): steering (including the | | 559 | +The same file specifies the 31 extensions (status `EXT`, `X01`–`X31`): steering (including the | 559 | 560 | opencode 2.3 idle-boundary flush and schema nudges), the live progress tree and its RPC, the | 560 | 561 | per-agent model display, the per-agent failure summary and outputs, the freeform `workflow_script` | 561 | | -tool, the TUI agent dialog and sidebar, and the desktop app companion. | | 562 | +tool, the TUI agent dialog and sidebar, waiting for background subagents, and the desktop app | | 563 | +companion. | 562 | 564 |
| 563 | 565 | Most of the gaps come from one limit of opencode's plugin API: **a plugin cannot create a child | 564 | 566 | session with a `parentID`**. So workflow agents aren't nested under your session in the UI, and | |
Collapse file Copy file name to clipboardExpand all lines: docs/OPENCODE-API-NOTES.md +11-2Lines changed: 11 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -30,7 +30,12 @@ the 2.3.0 packages and `tsc` is clean against their types. | 30 | 30 | posts a `<subagent>` report with its last reply into the parent's inbox (steer) after **every** | 31 | 31 | completed round and wakes the parent (#63209; the opt-out was removed in #63413). The runner | 32 | 32 | therefore keeps creating root sessions (and P63 stays). Upstream's own `subagent` tool is now | 33 | | - always background (#63391). | | 33 | + always background (#63391): the call returns at once with the child's sessionID, the caller's | | 34 | + turn may end, and the job's `<subagent>` report wakes the caller later | | 35 | + (`core/tool/plugin/subagent.ts`). `session.wait()` is `awaitIdle` over executions only | | 36 | + (`core/session/run-coordinator.ts`), so it resolves while the job runs; the job is visible to a | | 37 | + plugin only in the `experimental.idle` event's `background` list. A workflow child that uses the | | 38 | + tool would be read too early: the runner waits for such jobs through the idle hook (X31). | 34 | 39 | - **Failure text:** the `{type:"idle", outcome:"failed"}` context message carries | 35 | 40 | `error: {type, message, status?}` (#53826). An interrupted step keeps its closed text and its | 36 | 41 | assistant message gets `error: {type:"aborted", message:"Step interrupted"}` (#60674). Tokens of an | @@ -196,7 +201,11 @@ at setup (unless `OPENCODE_WORKFLOW_IDLE_HOOK=0`) and keeps a map of its live ch | 196 | 201 | → mailbox, schema, stopping). When a child is about to go idle the hook stops its mailbox | 197 | 202 | (`finishing`), awaits sends in flight, and returns with the window reopened when a sent message is | 198 | 203 | not in `context()` yet: it waits in the inbox, so opencode continues the same execution with it. | 199 | | -A later message is refused `finishing` rather than parked. For a schema agent without an accepted | | 204 | +A later message is refused `finishing` rather than parked; if the execution goes on anyway (another | | 205 | +plugin's idle hook, a user prompt, the cap), the session `context` hook, which runs before every | | 206 | +model request, reopens the window the hook closed. While the child's own subagent or image job | | 207 | +runs, the hook only records it (`workflow-jobs/<sessionID>` in `ctx.storage`) and the runner keeps | | 208 | +waiting after `wait()` until a report lists none (X31). For a schema agent without an accepted | 200 | 209 | submission it then sends the re-prompt text as a `resume:false` steer (a nudge, counted in the P21 | 201 | 210 | budget through the submit registry). The verification and wake above stay as the fallback for | 202 | 211 | 2.0.15, worktree children (their hook runs in the worktree instance, which has no mailbox; it can | |
|