Skip to content

Commit 05f0214

Browse files
committed
fix(acp): handle question.asked event to prevent hanging
When OpenCode runs via ACP, the question tool would hang indefinitely because the question.asked event was not handled in the ACP agent. This change adds a handler for question.asked that: - Converts question options to ACP requestPermission options - Forwards the question to the ACP client via requestPermission - Maps the response back to question answers - Calls the SDK question.reply to unblock the tool Fixes anomalyco#17920
1 parent e14e874 commit 05f0214

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

‎packages/opencode/src/acp/agent.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,66 @@ export namespace ACP {
264264
return
265265
}
266266

267+
case "question.asked": {
268+
const question = event.properties
269+
const session = this.sessionManager.tryGet(question.sessionID)
270+
if (!session) return
271+
272+
const directory = session.cwd
273+
const firstQuestion = question.questions[0]
274+
if (!firstQuestion) return
275+
276+
const options: PermissionOption[] = firstQuestion.options.map((opt) => ({
277+
optionId: opt.label,
278+
name: opt.label,
279+
kind: "allow_once" as const,
280+
}))
281+
282+
const res = await this.connection
283+
.requestPermission({
284+
sessionId: question.sessionID,
285+
toolCall: {
286+
toolCallId: question.tool?.callID ?? question.id,
287+
status: "pending",
288+
title: firstQuestion.question,
289+
rawInput: {
290+
questions: question.questions,
291+
},
292+
kind: "other",
293+
},
294+
options,
295+
})
296+
.catch(async (error) => {
297+
log.error("failed to request permission from ACP for question", {
298+
error,
299+
questionID: question.id,
300+
sessionID: question.sessionID,
301+
})
302+
await this.sdk.question.reject({
303+
requestID: question.id,
304+
directory,
305+
})
306+
return undefined
307+
})
308+
309+
if (!res) return
310+
if (res.outcome.outcome !== "selected") {
311+
await this.sdk.question.reject({
312+
requestID: question.id,
313+
directory,
314+
})
315+
return
316+
}
317+
318+
const answers = [[res.outcome.optionId!]]
319+
await this.sdk.question.reply({
320+
requestID: question.id,
321+
directory,
322+
answers,
323+
})
324+
return
325+
}
326+
267327
case "message.part.updated": {
268328
log.info("message part updated", { event: event.properties })
269329
const props = event.properties

0 commit comments

Comments
 (0)