fix(delegation): replace message-count-stability polling with native finish-based completion detection

Sync task completion was fragile — detecting premature stability during
brief idle periods between tool calls. Now mirrors opencode's native
SessionPrompt.loop() logic: checks assistant finish reason is terminal
(not tool-calls/unknown) and assistant.id > user.id.

Also switches sync prompt sender from blocking HTTP (promptSync) to
async fire-and-forget (promptAsync) to avoid JSON parse errors in ACP.
This commit is contained in:
YeonGyu-Kim
2026-02-09 15:37:19 +09:00
parent 20d009964d
commit 11f587194f
6 changed files with 395 additions and 54 deletions
@@ -1,6 +1,6 @@
import type { DelegateTaskArgs, OpencodeClient } from "./types"
import { isPlanFamily } from "./constants"
import { promptSyncWithModelSuggestionRetry } from "../../shared/model-suggestion-retry"
import { promptWithModelSuggestionRetry } from "../../shared/model-suggestion-retry"
import { formatDetailedError } from "./error-formatting"
export async function sendSyncPrompt(
@@ -17,7 +17,7 @@ export async function sendSyncPrompt(
): Promise<string | null> {
try {
const allowTask = isPlanFamily(input.agentToUse)
await promptSyncWithModelSuggestionRetry(client, {
await promptWithModelSuggestionRetry(client, {
path: { id: input.sessionID },
body: {
agent: input.agentToUse,