[Bug]: Auto-continue triggers while waiting for background Shell test results (OpenCode V2)
What happened?
When using @prevalentware/[email protected] with OpenCode v2.1.1, the plugin may prematurely send a Continuation Prompt while the Agent is waiting for a background Shell command to complete.
A typical scenario is running a long-running full test suite (which may take 10–30 minutes or longer).
The Agent starts the test suite using the Shell tool with background: true. OpenCode returns a Shell ID immediately and continues running the tests in the background. Since OpenCode automatically notifies the Agent when the Shell command finishes, the Agent ends its current turn and waits for the completion notification.
However, when OpenCode emits session.execution.succeeded, the Goal plugin considers the Session idle and sends another Continuation Prompt, even though the background Shell is still running and its completion notification has not arrived.
This causes the Agent to resume unnecessarily, potentially responding that it is still waiting, consuming additional tokens and auto-continue turns, or even starting redundant operations.
The core issue is that Session execution completion does not imply that background Shell operations have completed.
The existing defer_while_tasks_active mechanism handles background Task/subagent sessions but does not appear to cover background Shell commands.
This is related to #73, but differs because the parent Session has genuinely finished its current execution. The pending work is an independent background Shell process, not an actively streaming Agent execution.
Expected behavior
When an Agent finishes its current turn while explicitly waiting for a background Shell command (such as a long-running full test suite), the Goal plugin should defer automatic continuation until the relevant Shell completion notification has been delivered and processed.
Expected behavior:
-
Wait for background tasks that require completion:
session.execution.succeededshould not automatically trigger a Continuation Prompt when the Agent is waiting for an unfinished background Shell operation, such as a full regression test suite. -
Respect native Shell completion notifications: The plugin should allow OpenCode's native Shell completion notification mechanism to resume the Agent when the results become available, instead of injecting redundant Continuation Prompts.
-
Avoid unnecessary resource consumption: Waiting for background Shell results should not unnecessarily consume auto-continue turns, waste tokens, or trigger no-progress detection.
-
Continue after results are processed: Once the Shell completion notification has been delivered and processed, the plugin should reevaluate the Goal state and continue only if necessary.
-
Handle intentionally long-running background services: Not all background Shell processes are expected to terminate. Some commands intentionally start persistent services, such as development servers (
npm run dev), web servers, database services, or file watchers (npm run watch). These processes may run indefinitely while the Agent continues performing other tasks. The plugin must not block Goal continuation simply because such a background process is still running. -
Distinguish blocking tasks from persistent services: The plugin should distinguish between:
- Completion-dependent background tasks: Operations such as full test suites, builds, and data processing jobs, where the Agent explicitly needs the final result before proceeding.
- Non-blocking background services: Long-running processes intentionally kept alive to support further work, where the Agent should be allowed to continue without waiting for process termination.
-
Prevent indefinite blocking: The deferral mechanism should support explicit non-blocking or detached process classification, rather than relying solely on process duration or arbitrary timeouts. A legitimate long-running test should not be mistaken for a persistent service merely because it takes a long time, and a persistent service should not prevent the Goal from progressing indefinitely.
Suggested improvement:
Consider introducing a Shell-aware continuation deferral mechanism, similar to defer_while_tasks_active, with the ability to identify whether the Agent is actually waiting for a Shell result.
Ideally, the continuation decision should consider:
- Whether the Session is idle.
- Whether any background Shell operations are still running.
- Whether the Agent is explicitly waiting for their completion.
- Whether a background process is intentionally persistent or detached.
- Whether the relevant Shell completion notifications have already been delivered and processed.
The key principle is:
Session idle ≠ Background work completed.
However, background process running ≠ Goal continuation must be blocked.
Automatic continuation should be deferred only when the Agent is genuinely waiting for a required background result, not simply because a background process exists.
Steps to reproduce
-
Install
@prevalentware/[email protected]on OpenCodev2.1.1. -
Create a Goal that requires running a complete project regression test suite. For example:
/goal Run the full project test suite, wait for the results, fix any failures, and verify that all tests pass. -
Start a long-running full test suite using either of the following methods:
-
Option A — Agent-initiated background execution: Have the Agent execute a Shell command with
background: true. For example:{ "command": "npm run test:full", "background": true } -
Option B — Manual TUI background execution: Have the Agent start the full test suite normally in the foreground. While the Shell command is still running, manually click "Run in Background" in the OpenCode TUI to move the running command into the background.
The test suite should take several minutes to complete.
-
-
The Shell command continues running in the background, and OpenCode manages its execution and eventual completion notification.
-
Let the Agent finish its current turn and wait for OpenCode's automatic Shell completion notification, without starting additional unrelated work or manually polling the test process.
-
OpenCode emits
session.execution.succeeded, indicating that the current Agent execution has finished, even though the background Shell is still running. -
Observe whether the Goal plugin injects a Continuation Prompt before the background Shell completes and its notification is processed.
Actual behavior: The Goal plugin may send a Continuation Prompt while the full test suite is still running, causing unnecessary Agent execution.
Expected behavior: The Goal plugin should defer continuation while the Agent is waiting for the test results, regardless of whether the Shell was started with background: true or manually moved to the background through the TUI. OpenCode's native Shell completion notification should resume the Agent when the background command finishes.
Relevant source code:
- Goal plugin:
src/server.ts—runAutoContinue() - Goal plugin:
TaskTracker.hasBlockingTasks() - OpenCode V2:
packages/core/src/tool/plugin/shell.ts
Related: #73 and PR #4.
Plugin version
@prevalentware/[email protected]
OpenCode version
v2.1.1
Operating system
Windows 11
Model/provider in use
DeepSeek V4.1 Flash 1017
Plugin options
Relevant goal state or logs
Thanks for the detailed reproduction. The V2 Shell result exposes a running shell ID and OpenCode later emits its completion notification, but those signals do not say whether the agent needs the final result or intentionally started a persistent service. Blocking on every running Shell would also block the dev-server case in this issue.
Would an explicit goal tool such as defer_goal_until_shell(shell_id) be an acceptable signal? The agent would call it only when the goal depends on that Shell's final result; unmarked background services would leave Goal continuation enabled. The plugin would clear the deferral after the matching native Shell completion notification is processed. If you expect automatic intent detection instead, what reliable machine-readable signal in OpenCode V2 should distinguish the two cases, including a command moved to the background through the TUI?
2. Thanks for the detailed reproduction. The V2 Shell result exposes a running shell ID and OpenCode later emits its completion notification, but those signals do not say whether the agent needs the final result or intentionally started a persistent service. Blocking on every running Shell would also block the dev-server case in this issue. Would an explicit goal tool such as
defer_goal_until_shell(shell_id)be an acceptable signal? The agent would call it only when the goal depends on that Shell's final result; unmarked background services would leave Goal continuation enabled. The plugin would clear the deferral after the matching native Shell completion notification is processed. If you expect automatic intent detection instead, what reliable machine-readable signal in OpenCode V2 should distinguish the two cases, including a command moved to the background through the TUI?
Thanks, that distinction matches what I meant. Persistent services should remain non-blocking. My concern is unnecessary continuation prompts and token usage while the agent is waiting for a required result, such as a long-running test suite. An explicit defer_goal_until_shell(shell_id) sounds reasonable, provided the agent can use it reliably without requiring me to mark each task manually. I don’t have a verified V2 signal for automatically distinguishing these cases. While deferred, waiting alone should not consume auto-continue turns or trigger no-progress detection. The native Shell completion notification should still reach the agent, and Goal continuation should be reevaluated after that notification has been processed, rather than immediately when the process exits.
Would this also cover commands manually moved to the background through the TUI?
Thanks for the fix! I've tested it, and it works as expected.