fix(continuation): auto-continue GPT permission-seeking replies
Resume GPT sessions when the last assistant reply ends in a permission-seeking tail, while honoring stop-continuation and avoiding duplicate continuation across todo and atlas flows. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -17,6 +17,7 @@ export function createTodoContinuationHandler(args: {
|
||||
backgroundManager?: BackgroundManager
|
||||
skipAgents?: string[]
|
||||
isContinuationStopped?: (sessionID: string) => boolean
|
||||
shouldSkipContinuation?: (sessionID: string) => boolean
|
||||
}): (input: { event: { type: string; properties?: unknown } }) => Promise<void> {
|
||||
const {
|
||||
ctx,
|
||||
@@ -24,6 +25,7 @@ export function createTodoContinuationHandler(args: {
|
||||
backgroundManager,
|
||||
skipAgents = DEFAULT_SKIP_AGENTS,
|
||||
isContinuationStopped,
|
||||
shouldSkipContinuation,
|
||||
} = args
|
||||
|
||||
return async ({ event }: { event: { type: string; properties?: unknown } }): Promise<void> => {
|
||||
@@ -56,6 +58,7 @@ export function createTodoContinuationHandler(args: {
|
||||
backgroundManager,
|
||||
skipAgents,
|
||||
isContinuationStopped,
|
||||
shouldSkipContinuation,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export async function handleSessionIdle(args: {
|
||||
backgroundManager?: BackgroundManager
|
||||
skipAgents?: string[]
|
||||
isContinuationStopped?: (sessionID: string) => boolean
|
||||
shouldSkipContinuation?: (sessionID: string) => boolean
|
||||
}): Promise<void> {
|
||||
const {
|
||||
ctx,
|
||||
@@ -37,6 +38,7 @@ export async function handleSessionIdle(args: {
|
||||
backgroundManager,
|
||||
skipAgents = DEFAULT_SKIP_AGENTS,
|
||||
isContinuationStopped,
|
||||
shouldSkipContinuation,
|
||||
} = args
|
||||
|
||||
log(`[${HOOK_NAME}] session.idle`, { sessionID })
|
||||
@@ -186,6 +188,11 @@ export async function handleSessionIdle(args: {
|
||||
return
|
||||
}
|
||||
|
||||
if (shouldSkipContinuation?.(sessionID)) {
|
||||
log(`[${HOOK_NAME}] Skipped: another continuation hook already injected`, { sessionID })
|
||||
return
|
||||
}
|
||||
|
||||
const progressUpdate = sessionStateStore.trackContinuationProgress(sessionID, incompleteCount, todos)
|
||||
if (shouldStopForStagnation({ sessionID, incompleteCount, progressUpdate })) {
|
||||
return
|
||||
|
||||
@@ -17,6 +17,7 @@ export function createTodoContinuationEnforcer(
|
||||
backgroundManager,
|
||||
skipAgents = DEFAULT_SKIP_AGENTS,
|
||||
isContinuationStopped,
|
||||
shouldSkipContinuation,
|
||||
} = options
|
||||
|
||||
const sessionStateStore = createSessionStateStore()
|
||||
@@ -42,6 +43,7 @@ export function createTodoContinuationEnforcer(
|
||||
backgroundManager,
|
||||
skipAgents,
|
||||
isContinuationStopped,
|
||||
shouldSkipContinuation,
|
||||
})
|
||||
|
||||
const cancelAllCountdowns = (): void => {
|
||||
|
||||
@@ -1706,6 +1706,27 @@ describe("todo-continuation-enforcer", () => {
|
||||
expect(promptCalls).toHaveLength(0)
|
||||
})
|
||||
|
||||
test("should not inject when shouldSkipContinuation returns true", async () => {
|
||||
// given - session already handled by another continuation hook
|
||||
const sessionID = "main-skip-other-continuation"
|
||||
setMainSession(sessionID)
|
||||
|
||||
const hook = createTodoContinuationEnforcer(createMockPluginInput(), {
|
||||
shouldSkipContinuation: (id) => id === sessionID,
|
||||
})
|
||||
|
||||
// when - session goes idle
|
||||
await hook.handler({
|
||||
event: { type: "session.idle", properties: { sessionID } },
|
||||
})
|
||||
|
||||
await fakeTimers.advanceBy(3000)
|
||||
|
||||
// then - no countdown toast or continuation injection
|
||||
expect(toastCalls).toHaveLength(0)
|
||||
expect(promptCalls).toHaveLength(0)
|
||||
})
|
||||
|
||||
test("should not inject when isContinuationStopped becomes true during countdown", async () => {
|
||||
// given - session where continuation is not stopped at idle time but stops during countdown
|
||||
const sessionID = "main-race-condition"
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface TodoContinuationEnforcerOptions {
|
||||
backgroundManager?: BackgroundManager
|
||||
skipAgents?: string[]
|
||||
isContinuationStopped?: (sessionID: string) => boolean
|
||||
shouldSkipContinuation?: (sessionID: string) => boolean
|
||||
}
|
||||
|
||||
export interface TodoContinuationEnforcer {
|
||||
|
||||
Reference in New Issue
Block a user