fix(todo-continuation-enforcer): check isContinuationStopped in injectContinuation to close race window

When /stop-continuation is invoked during the 2s countdown, the stop flag
was never checked inside injectContinuation, so the injection would still
fire after the countdown elapsed.

Propagate isContinuationStopped from handleSessionIdle through startCountdown
into injectContinuation, where it is now re-checked before any API call.
This commit is contained in:
YeonGyu-Kim
2026-02-19 14:07:52 +09:00
parent 31dc6e206d
commit 9fa9dace2c
3 changed files with 11 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ export async function injectContinuation(args: {
skipAgents?: string[]
resolvedInfo?: ResolvedMessageInfo
sessionStateStore: SessionStateStore
isContinuationStopped?: (sessionID: string) => boolean
}): Promise<void> {
const {
ctx,
@@ -45,6 +46,7 @@ export async function injectContinuation(args: {
skipAgents = DEFAULT_SKIP_AGENTS,
resolvedInfo,
sessionStateStore,
isContinuationStopped,
} = args
const state = sessionStateStore.getExistingState(sessionID)
@@ -53,6 +55,11 @@ export async function injectContinuation(args: {
return
}
if (isContinuationStopped?.(sessionID)) {
log(`[${HOOK_NAME}] Skipped injection: continuation stopped for session`, { sessionID })
return
}
const hasRunningBgTasks = backgroundManager
? backgroundManager.getTasksByParentSession(sessionID).some((task: { status: string }) => task.status === "running")
: false

View File

@@ -38,6 +38,7 @@ export function startCountdown(args: {
backgroundManager?: BackgroundManager
skipAgents: string[]
sessionStateStore: SessionStateStore
isContinuationStopped?: (sessionID: string) => boolean
}): void {
const {
ctx,
@@ -47,6 +48,7 @@ export function startCountdown(args: {
backgroundManager,
skipAgents,
sessionStateStore,
isContinuationStopped,
} = args
const state = sessionStateStore.getState(sessionID)
@@ -72,6 +74,7 @@ export function startCountdown(args: {
skipAgents,
resolvedInfo,
sessionStateStore,
isContinuationStopped,
})
}, COUNTDOWN_SECONDS * 1000)

View File

@@ -187,5 +187,6 @@ export async function handleSessionIdle(args: {
backgroundManager,
skipAgents,
sessionStateStore,
isContinuationStopped,
})
}