fix(sisyphus_task): use promptAsync for sync mode to preserve main session
- session.prompt() changes the active session, causing UI model switch - Switch to promptAsync + polling to avoid main session state change - Matches background-agent pattern for consistency
This commit is contained in:
parent
869efbe9ad
commit
2d3894a860
@ -384,8 +384,9 @@ System notifies on completion. Use \`background_output\` with task_id="${task.id
|
|||||||
metadata: { sessionId: sessionID, category: args.category, sync: true },
|
metadata: { sessionId: sessionID, category: args.category, sync: true },
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
// Use promptAsync to avoid changing main session's active state
|
||||||
await client.session.prompt({
|
let promptError: Error | undefined
|
||||||
|
await client.session.promptAsync({
|
||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
body: {
|
body: {
|
||||||
agent: agentToUse,
|
agent: agentToUse,
|
||||||
@ -397,18 +398,38 @@ System notifies on completion. Use \`background_output\` with task_id="${task.id
|
|||||||
},
|
},
|
||||||
parts: [{ type: "text", text: args.prompt }],
|
parts: [{ type: "text", text: args.prompt }],
|
||||||
},
|
},
|
||||||
|
}).catch((error) => {
|
||||||
|
promptError = error instanceof Error ? error : new Error(String(error))
|
||||||
})
|
})
|
||||||
} catch (promptError) {
|
|
||||||
|
if (promptError) {
|
||||||
if (toastManager && taskId !== undefined) {
|
if (toastManager && taskId !== undefined) {
|
||||||
toastManager.removeTask(taskId)
|
toastManager.removeTask(taskId)
|
||||||
}
|
}
|
||||||
const errorMessage = promptError instanceof Error ? promptError.message : String(promptError)
|
const errorMessage = promptError.message
|
||||||
if (errorMessage.includes("agent.name") || errorMessage.includes("undefined")) {
|
if (errorMessage.includes("agent.name") || errorMessage.includes("undefined")) {
|
||||||
return `❌ Agent "${agentToUse}" not found. Make sure the agent is registered in your opencode.json or provided by a plugin.\n\nSession ID: ${sessionID}`
|
return `❌ Agent "${agentToUse}" not found. Make sure the agent is registered in your opencode.json or provided by a plugin.\n\nSession ID: ${sessionID}`
|
||||||
}
|
}
|
||||||
return `❌ Failed to send prompt: ${errorMessage}\n\nSession ID: ${sessionID}`
|
return `❌ Failed to send prompt: ${errorMessage}\n\nSession ID: ${sessionID}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Poll for session completion
|
||||||
|
const POLL_INTERVAL_MS = 500
|
||||||
|
const MAX_POLL_TIME_MS = 10 * 60 * 1000
|
||||||
|
const pollStart = Date.now()
|
||||||
|
|
||||||
|
while (Date.now() - pollStart < MAX_POLL_TIME_MS) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL_MS))
|
||||||
|
|
||||||
|
const statusResult = await client.session.status()
|
||||||
|
const allStatuses = (statusResult.data ?? {}) as Record<string, { type: string }>
|
||||||
|
const sessionStatus = allStatuses[sessionID]
|
||||||
|
|
||||||
|
if (sessionStatus?.type === "idle") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const messagesResult = await client.session.messages({
|
const messagesResult = await client.session.messages({
|
||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user