fix(prompt-async-gate): timeout isSessionActive to prevent infinite hang on stale SDK status
- Wrap isSessionActive in withDispatchTimeout (capped at 5s) so a stuck OpenCode SDK status() call cannot block internal prompts forever. - Catch the timeout and treat session as inactive so the prompt can proceed rather than hanging indefinitely. - Add regression test: session.status that never resolves now times out and allows dispatch instead of hanging the test (and production). Refs: AGENTS.md internal-message-injection safety note
This commit is contained in:
@@ -169,7 +169,19 @@ async function dispatchAfterSessionIdle<TInput>(args: {
|
||||
await settleAfterSessionIdle(settleMs)
|
||||
}
|
||||
|
||||
if (canReadStatus && await isSessionActive(client, sessionID)) {
|
||||
let sessionActive = false
|
||||
if (canReadStatus) {
|
||||
try {
|
||||
sessionActive = await withDispatchTimeout(
|
||||
isSessionActive(client, sessionID),
|
||||
Math.min(dispatchTimeoutMs, 5000),
|
||||
`[prompt-async-gate] ${sessionName} isSessionActive`,
|
||||
)
|
||||
} catch {
|
||||
sessionActive = false
|
||||
}
|
||||
}
|
||||
if (sessionActive) {
|
||||
log(`[prompt-async-gate] ${sessionName} skipped because session is active`, { sessionID, source })
|
||||
return { status: "active" }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user