fix(background-agent): coalesce parent wake races

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-18 15:38:52 +09:00
parent c712b71d9a
commit af1ad4d04b
2 changed files with 156 additions and 1 deletions
@@ -194,6 +194,12 @@ export class ParentWakeNotifier {
if (promptResult.status === "failed") {
throw promptResult.error
}
if (promptResult.status === "reserved" && promptResult.reservedBy === "background-agent-parent-wake") {
log("[background-agent] Ignored duplicate parent wake flush already reserved by promptAsync gate:", {
sessionID,
})
return
}
if (promptResult.status !== "dispatched") {
this.requeueWake(sessionID, latestWake)
this.schedulePendingParentWakeFlush(sessionID)
@@ -451,7 +457,7 @@ export class ParentWakeNotifier {
if (createdAt === undefined) {
return false
}
return Date.now() - createdAt < this.options.userMessageInProgressWindowMs
return Date.now() - createdAt <= this.options.userMessageInProgressWindowMs
}
if (role === "assistant" || role === "tool") {
// An assistant/tool message is more recent than the last user message,