fix(todo-continuation): gate idle prompts

This commit is contained in:
YeonGyu-Kim
2026-05-15 11:30:20 +09:00
parent b0b61182b4
commit a524754eca
@@ -21,7 +21,7 @@ import {
getAgentConfigKey,
normalizeAgentForPromptKey,
} from "../../shared/agent-display-names"
import { isSessionActive } from "../shared/session-idle-settle"
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
import {
CONTINUATION_PROMPT,
@@ -166,11 +166,6 @@ ${todoList}`
return
}
if (await isSessionActive(ctx.client, sessionID)) {
log(`[${HOOK_NAME}] Skipped injection: session is active before prompt`, { sessionID })
return
}
if (injectionState) {
injectionState.inFlight = true
}
@@ -190,17 +185,33 @@ ${todoList}`
: undefined
const launchVariant = model?.variant
await ctx.client.session.promptAsync({
path: { id: sessionID },
body: {
agent: launchAgent ?? promptAgent,
...(launchModel ? { model: launchModel } : {}),
...(launchVariant ? { variant: launchVariant } : {}),
...(inheritedTools ? { tools: inheritedTools } : {}),
parts: [createInternalAgentContinuationTextPart(prompt)],
const promptResult = await promptAsyncAfterSessionIdle({
client: ctx.client,
sessionID,
source: HOOK_NAME,
settleMs: 0,
input: {
path: { id: sessionID },
body: {
agent: launchAgent ?? promptAgent,
...(launchModel ? { model: launchModel } : {}),
...(launchVariant ? { variant: launchVariant } : {}),
...(inheritedTools ? { tools: inheritedTools } : {}),
parts: [createInternalAgentContinuationTextPart(prompt)],
},
query: { directory: ctx.directory },
},
query: { directory: ctx.directory },
})
if (promptResult.status === "failed") {
throw promptResult.error
}
if (promptResult.status !== "dispatched") {
log(`[${HOOK_NAME}] Injection skipped by promptAsync gate`, { sessionID, status: promptResult.status })
if (injectionState) {
injectionState.inFlight = false
}
return
}
log(`[${HOOK_NAME}] Injection successful`, { sessionID })
if (injectionState) {