fix(hooks): settle idle prompt continuations

This commit is contained in:
YeonGyu-Kim
2026-05-10 12:55:36 +09:00
parent 806842981f
commit 1ea4dfe215
8 changed files with 118 additions and 1 deletions
@@ -63,6 +63,41 @@ describe("unstable-agent-babysitter hook", () => {
_resetForTesting()
})
test("settles idle before injecting a reminder", async () => {
// #given
setMainSession("main-1")
const promptCalls: Array<{ input: unknown }> = []
const ctx = createMockPluginInput({
messagesBySession: {
"main-1": [
{ info: { agent: "sisyphus", model: { providerID: "openai", modelID: "gpt-4" } } },
],
"bg-1": [
{ info: { role: "assistant" }, parts: [{ type: "thinking", thinking: "deep thought" }] },
],
},
promptCalls,
})
const backgroundManager = createBackgroundManager([createTask()])
const hook = createUnstableAgentBabysitterHook(ctx, {
backgroundManager,
config: { timeout_ms: 120000 },
idleSettleMs: 50,
})
// #when
const startedAt = Date.now()
const eventPromise = hook.event({ event: { type: "session.idle", properties: { sessionID: "main-1" } } })
await Promise.resolve()
// #then
expect(promptCalls.length).toBe(0)
await eventPromise
expect(Date.now() - startedAt).toBeGreaterThanOrEqual(45)
expect(promptCalls.length).toBe(1)
})
test("fires reminder for hung gemini task", async () => {
// #given
setMainSession("main-1")
@@ -11,6 +11,7 @@ import {
isUnstableTask,
THINKING_SUMMARY_MAX_CHARS,
} from "./task-message-analyzer"
import { settleAfterSessionIdle } from "../shared/session-idle-settle"
const HOOK_NAME = "unstable-agent-babysitter"
const DEFAULT_TIMEOUT_MS = 120000
@@ -54,6 +55,7 @@ type BabysitterContext = {
type BabysitterOptions = {
backgroundManager: Pick<BackgroundManager, "getTasksByParentSession">
config?: BabysittingConfig
idleSettleMs?: number
}
@@ -212,6 +214,7 @@ export function createUnstableAgentBabysitterHook(ctx: BabysitterContext, option
? { providerID: model.providerID, modelID: model.modelID }
: undefined
const launchVariant = model?.variant
await settleAfterSessionIdle(options.idleSettleMs)
await ctx.client.session.promptAsync({
path: { id: mainSessionID },