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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -187,5 +187,6 @@ export async function handleSessionIdle(args: {
|
||||
backgroundManager,
|
||||
skipAgents,
|
||||
sessionStateStore,
|
||||
isContinuationStopped,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user