refactor(prompt-async-gate): remove deprecated dispatch wrappers

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-17 17:15:54 +09:00
parent 1bbe065c60
commit 12bd658079
2 changed files with 73 additions and 97 deletions
+73 -63
View File
@@ -3,8 +3,6 @@ import { afterEach, describe, expect, test } from "bun:test"
import { import {
_setPromptGateMessagesFetchTimeoutMsForTesting, _setPromptGateMessagesFetchTimeoutMsForTesting,
dispatchInternalPrompt, dispatchInternalPrompt,
promptAfterSessionIdle,
promptAsyncAfterSessionIdle,
releaseAllPromptAsyncReservationsForTesting, releaseAllPromptAsyncReservationsForTesting,
releasePromptAsyncReservation, releasePromptAsyncReservation,
} from "./prompt-async-gate" } from "./prompt-async-gate"
@@ -125,7 +123,7 @@ describe("dispatchInternalPrompt", () => {
}) })
}) })
describe("promptAsyncAfterSessionIdle", () => { describe("dispatchInternalPrompt shared gate behavior", () => {
afterEach(() => { afterEach(() => {
// then // then
releaseAllPromptAsyncReservationsForTesting() releaseAllPromptAsyncReservationsForTesting()
@@ -149,7 +147,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = promptAsyncAfterSessionIdle({ const first = dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_race", sessionID: "ses_race",
input: { path: { id: "ses_race" }, body: { parts: [] } }, input: { path: { id: "ses_race" }, body: { parts: [] } },
@@ -158,7 +157,8 @@ describe("promptAsyncAfterSessionIdle", () => {
postDispatchHoldMs: 0, postDispatchHoldMs: 0,
}) })
await Promise.resolve() await Promise.resolve()
const second = await promptAsyncAfterSessionIdle({ const second = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_race", sessionID: "ses_race",
input: { path: { id: "ses_race" }, body: { parts: [] } }, input: { path: { id: "ses_race" }, body: { parts: [] } },
@@ -187,7 +187,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = promptAsyncAfterSessionIdle({ const first = dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_hold_after_dispatch", sessionID: "ses_hold_after_dispatch",
input: { path: { id: "ses_hold_after_dispatch" }, body: { parts: [] } }, input: { path: { id: "ses_hold_after_dispatch" }, body: { parts: [] } },
@@ -195,7 +196,8 @@ describe("promptAsyncAfterSessionIdle", () => {
settleMs: 0, settleMs: 0,
}) })
const firstResult = await first const firstResult = await first
const second = await promptAsyncAfterSessionIdle({ const second = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_hold_after_dispatch", sessionID: "ses_hold_after_dispatch",
input: { path: { id: "ses_hold_after_dispatch" }, body: { parts: [] } }, input: { path: { id: "ses_hold_after_dispatch" }, body: { parts: [] } },
@@ -223,7 +225,8 @@ describe("promptAsyncAfterSessionIdle", () => {
const client = { session } const client = { session }
// when // when
const result = await promptAsyncAfterSessionIdle({ const result = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_bound_prompt_async", sessionID: "ses_bound_prompt_async",
input: { path: { id: "ses_bound_prompt_async" }, body: { parts: [] } }, input: { path: { id: "ses_bound_prompt_async" }, body: { parts: [] } },
@@ -252,7 +255,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const result = await promptAsyncAfterSessionIdle({ const result = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_busy", sessionID: "ses_busy",
input: { path: { id: "ses_busy" }, body: { parts: [] } }, input: { path: { id: "ses_busy" }, body: { parts: [] } },
@@ -291,7 +295,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const result = await promptAsyncAfterSessionIdle({ const result = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_waiting_tools", sessionID: "ses_waiting_tools",
input: { path: { id: "ses_waiting_tools" }, body: { parts: [] } }, input: { path: { id: "ses_waiting_tools" }, body: { parts: [] } },
@@ -324,7 +329,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const result = await promptAsyncAfterSessionIdle({ const result = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_recovery_tools", sessionID: "ses_recovery_tools",
input: { path: { id: "ses_recovery_tools" }, body: { parts: [] } }, input: { path: { id: "ses_recovery_tools" }, body: { parts: [] } },
@@ -354,7 +360,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const result = await promptAsyncAfterSessionIdle({ const result = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_messages_hang", sessionID: "ses_messages_hang",
input: { path: { id: "ses_messages_hang" }, body: { parts: [] } }, input: { path: { id: "ses_messages_hang" }, body: { parts: [] } },
@@ -385,7 +392,8 @@ describe("promptAsyncAfterSessionIdle", () => {
try { try {
// when // when
const first = await promptAsyncAfterSessionIdle({ const first = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_expired_hold", sessionID: "ses_expired_hold",
input: { path: { id: "ses_expired_hold" }, body: { parts: [] } }, input: { path: { id: "ses_expired_hold" }, body: { parts: [] } },
@@ -394,7 +402,8 @@ describe("promptAsyncAfterSessionIdle", () => {
postDispatchHoldMs: 1, postDispatchHoldMs: 1,
}) })
currentNow += 2 currentNow += 2
const second = await promptAsyncAfterSessionIdle({ const second = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_expired_hold", sessionID: "ses_expired_hold",
input: { path: { id: "ses_expired_hold" }, body: { parts: [] } }, input: { path: { id: "ses_expired_hold" }, body: { parts: [] } },
@@ -424,7 +433,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = await promptAsyncAfterSessionIdle({ const first = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_release_scope", sessionID: "ses_release_scope",
input: { input: {
@@ -437,7 +447,8 @@ describe("promptAsyncAfterSessionIdle", () => {
settleMs: 0, settleMs: 0,
}) })
releasePromptAsyncReservation("ses_release_scope", "ralph-loop:activity") releasePromptAsyncReservation("ses_release_scope", "ralph-loop:activity")
const second = await promptAsyncAfterSessionIdle({ const second = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_release_scope", sessionID: "ses_release_scope",
input: { input: {
@@ -467,7 +478,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = await promptAsyncAfterSessionIdle({ const first = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_release_family_scope", sessionID: "ses_release_family_scope",
input: { input: {
@@ -482,7 +494,8 @@ describe("promptAsyncAfterSessionIdle", () => {
"model-fallback-abort:session.error", "model-fallback-abort:session.error",
{ reservedByPrefix: "model-fallback:" }, { reservedByPrefix: "model-fallback:" },
) )
const second = await promptAsyncAfterSessionIdle({ const second = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_release_family_scope", sessionID: "ses_release_family_scope",
input: { input: {
@@ -514,7 +527,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = await promptAsyncAfterSessionIdle({ const first = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_dispatch_timeout", sessionID: "ses_dispatch_timeout",
input: { path: { id: "ses_dispatch_timeout" }, body: { parts: [] } }, input: { path: { id: "ses_dispatch_timeout" }, body: { parts: [] } },
@@ -523,7 +537,8 @@ describe("promptAsyncAfterSessionIdle", () => {
dispatchTimeoutMs: 1, dispatchTimeoutMs: 1,
postDispatchHoldMs: 0, postDispatchHoldMs: 0,
}) })
const second = await promptAsyncAfterSessionIdle({ const second = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_dispatch_timeout", sessionID: "ses_dispatch_timeout",
input: { path: { id: "ses_dispatch_timeout" }, body: { parts: [] } }, input: { path: { id: "ses_dispatch_timeout" }, body: { parts: [] } },
@@ -552,14 +567,16 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = await promptAsyncAfterSessionIdle({ const first = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_post_dispatch_reject", sessionID: "ses_post_dispatch_reject",
input: { path: { id: "ses_post_dispatch_reject" }, body: { parts: [] } }, input: { path: { id: "ses_post_dispatch_reject" }, body: { parts: [] } },
source: "test:reject:first", source: "test:reject:first",
settleMs: 0, settleMs: 0,
}) })
const second = await promptAsyncAfterSessionIdle({ const second = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_post_dispatch_reject", sessionID: "ses_post_dispatch_reject",
input: { path: { id: "ses_post_dispatch_reject" }, body: { parts: [] } }, input: { path: { id: "ses_post_dispatch_reject" }, body: { parts: [] } },
@@ -585,7 +602,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = await promptAsyncAfterSessionIdle({ const first = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_prefix_sibling", sessionID: "ses_prefix_sibling",
input: { input: {
@@ -600,7 +618,8 @@ describe("promptAsyncAfterSessionIdle", () => {
"model-fallback-abort:session.error", "model-fallback-abort:session.error",
{ reservedByPrefix: "model-fallback:" }, { reservedByPrefix: "model-fallback:" },
) )
const second = await promptAsyncAfterSessionIdle({ const second = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_prefix_sibling", sessionID: "ses_prefix_sibling",
input: { input: {
@@ -637,23 +656,19 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = promptAfterSessionIdle({ const first = dispatchInternalPrompt({ mode: "sync", client,
client, sessionID: "ses_prompt_race",
sessionID: "ses_prompt_race", input: { path: { id: "ses_prompt_race" }, body: { parts: [] } },
input: { path: { id: "ses_prompt_race" }, body: { parts: [] } }, source: "test:prompt:first",
source: "test:prompt:first", settleMs: 0,
settleMs: 0, postDispatchHoldMs: 0, })
postDispatchHoldMs: 0,
})
await Promise.resolve() await Promise.resolve()
const second = await promptAfterSessionIdle({ const second = await dispatchInternalPrompt({ mode: "sync", client,
client, sessionID: "ses_prompt_race",
sessionID: "ses_prompt_race", input: { path: { id: "ses_prompt_race" }, body: { parts: [] } },
input: { path: { id: "ses_prompt_race" }, body: { parts: [] } }, source: "test:prompt:second",
source: "test:prompt:second", settleMs: 0,
settleMs: 0, postDispatchHoldMs: 0, })
postDispatchHoldMs: 0,
})
releasePrompt?.() releasePrompt?.()
const firstResult = await first const firstResult = await first
@@ -675,21 +690,17 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const first = promptAfterSessionIdle({ const first = dispatchInternalPrompt({ mode: "sync", client,
client, sessionID: "ses_prompt_hold_after_dispatch",
sessionID: "ses_prompt_hold_after_dispatch", input: { path: { id: "ses_prompt_hold_after_dispatch" }, body: { parts: [] } },
input: { path: { id: "ses_prompt_hold_after_dispatch" }, body: { parts: [] } }, source: "test:prompt-hold:first",
source: "test:prompt-hold:first", settleMs: 0, })
settleMs: 0,
})
const firstResult = await first const firstResult = await first
const second = await promptAfterSessionIdle({ const second = await dispatchInternalPrompt({ mode: "sync", client,
client, sessionID: "ses_prompt_hold_after_dispatch",
sessionID: "ses_prompt_hold_after_dispatch", input: { path: { id: "ses_prompt_hold_after_dispatch" }, body: { parts: [] } },
input: { path: { id: "ses_prompt_hold_after_dispatch" }, body: { parts: [] } }, source: "test:prompt-hold:second",
source: "test:prompt-hold:second", settleMs: 0, })
settleMs: 0,
})
// then // then
expect(firstResult.status).toBe("dispatched") expect(firstResult.status).toBe("dispatched")
@@ -710,7 +721,8 @@ describe("promptAsyncAfterSessionIdle", () => {
} }
// when // when
const result = await promptAsyncAfterSessionIdle({ const result = await dispatchInternalPrompt({
mode: "async",
client, client,
sessionID: "ses_status_hang", sessionID: "ses_status_hang",
input: { path: { id: "ses_status_hang" }, body: { parts: [] } }, input: { path: { id: "ses_status_hang" }, body: { parts: [] } },
@@ -739,14 +751,12 @@ describe("promptAsyncAfterSessionIdle", () => {
const client = { session } const client = { session }
// when // when
const result = await promptAfterSessionIdle({ const result = await dispatchInternalPrompt({ mode: "sync", client,
client, sessionID: "ses_bound_prompt",
sessionID: "ses_bound_prompt", input: { path: { id: "ses_bound_prompt" }, body: { parts: [] } },
input: { path: { id: "ses_bound_prompt" }, body: { parts: [] } }, source: "test:bound-prompt",
source: "test:bound-prompt", settleMs: 0,
settleMs: 0, postDispatchHoldMs: 0, })
postDispatchHoldMs: 0,
})
// then // then
expect(result).toEqual({ expect(result).toEqual({
-34
View File
@@ -431,40 +431,6 @@ export async function dispatchInternalPrompt<TInput = PromptAsyncInput>(
}) })
} }
export async function promptAsyncAfterSessionIdle<TInput = PromptAsyncInput>(args: {
client: PromptAsyncClient<TInput>
sessionID: string
input: TInput
source: string
settleMs?: number
postDispatchHoldMs?: number
dispatchTimeoutMs?: number
checkStatus?: boolean
checkToolState?: boolean
}): Promise<PromptAsyncGateResult> {
return dispatchInternalPrompt({
...args,
mode: "async",
})
}
export async function promptAfterSessionIdle<TInput = PromptAsyncInput>(args: {
client: PromptClient<TInput>
sessionID: string
input: TInput
source: string
settleMs?: number
postDispatchHoldMs?: number
dispatchTimeoutMs?: number
checkStatus?: boolean
checkToolState?: boolean
}): Promise<PromptAsyncGateResult> {
return dispatchInternalPrompt({
...args,
mode: "sync",
})
}
export function releaseAllPromptAsyncReservationsForTesting(): void { export function releaseAllPromptAsyncReservationsForTesting(): void {
promptAsyncReservations.clear() promptAsyncReservations.clear()
promptGateMessagesFetchTimeoutMsForTesting = undefined promptGateMessagesFetchTimeoutMsForTesting = undefined