fix(plugin): scope synthetic-idle dedup bypass to matching marker

Only clear recentAnyIdles when the stored marker matches the synthetic idle timestamp for the same session, preventing accidental clobbering of newer idle markers. Add a regression test to verify other sessions keep their dedup state during this bypass path.

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-11 08:45:34 +09:00
parent a196d84c2e
commit 2168040ac6
2 changed files with 70 additions and 1 deletions
+66
View File
@@ -366,6 +366,72 @@ describe("createEventHandler - idle deduplication", () => {
expect((dispatchCalls[1]?.event.properties as { sessionID?: string } | undefined)?.sessionID).toBe(sessionId)
})
it("keeps other session dedup state untouched when bypassing synthetic-idle for current session", async () => {
//#given
const originalDateNow = Date.now
let currentNow = 30_000
Date.now = () => currentNow
const dispatchedSessionIds: string[] = []
const eventHandler = createIdleDedupSpyEventHandler({
onEvent: () => {},
sessionNotification: async (input: EventInput) => {
if (input.event.type !== "session.idle") {
return
}
const props = input.event.properties as { sessionID?: string } | undefined
if (props?.sessionID) {
dispatchedSessionIds.push(props.sessionID)
}
},
})
try {
//#when
await eventHandler(asEventHandlerInput({
event: {
type: "session.status",
properties: {
sessionID: "ses_a",
status: { type: "idle" },
},
},
}))
await eventHandler(asEventHandlerInput({
event: {
type: "session.idle",
properties: {
sessionID: "ses_b",
},
},
}))
currentNow += 100
await eventHandler(asEventHandlerInput({
event: {
type: "session.idle",
properties: {
sessionID: "ses_a",
},
},
}))
currentNow += 100
await eventHandler(asEventHandlerInput({
event: {
type: "session.idle",
properties: {
sessionID: "ses_b",
},
},
}))
//#then
expect(dispatchedSessionIds).toEqual(["ses_a", "ses_b", "ses_a"])
} finally {
Date.now = originalDateNow
}
})
it("dedups back-to-back real session.idle events for the same sessionID within 500ms", async () => {
//#given
const originalDateNow = Date.now
+4 -1
View File
@@ -417,7 +417,10 @@ export function createEventHandler(args: {
recentSyntheticIdles.delete(sessionID);
// Let real idle events through even when a synthetic idle fired moments earlier.
// OpenCode diagnostics expect a concrete session.idle event signal.
recentAnyIdles.delete(sessionID);
const lastAnyIdleAt = recentAnyIdles.get(sessionID);
if (lastAnyIdleAt === emittedAt) {
recentAnyIdles.delete(sessionID);
}
}
recentRealIdles.set(sessionID, now);
if (!shouldDispatchIdleEvent(sessionID, now)) {