fix(plugin): allow real session.idle after synthetic idle within dedup window

When session.status(idle) is converted to synthetic session.idle and recorded in recentAnyIdles, a real session.idle arriving within 500ms was being dropped by the dedup logic. recentSyntheticIdles was cleared but recentAnyIdles persisted, causing TODO-DIAG to red-alert with 'no todossession.idle event'.

Fix: when real session.idle arrives, also clear recentAnyIdles entry so dedup does not drop it. Test renamed and expected dispatchCalls updated 1 → 2.

Fixes #2667
This commit is contained in:
YeonGyu-Kim
2026-05-10 14:54:01 +09:00
parent 50699e3af1
commit a196d84c2e
2 changed files with 7 additions and 2 deletions
+4 -2
View File
@@ -335,7 +335,7 @@ describe("createEventHandler - idle deduplication", () => {
expect(spawnTmuxPane).toHaveBeenCalledTimes(1)
})
it("dedups real-idle-after-synthetic-idle within 500ms", async () => {
it("does NOT dedup real-idle-after-synthetic-idle within 500ms", async () => {
//#given
const dispatchCalls: EventInput[] = []
const eventHandler = createIdleTrackingEventHandler(dispatchCalls)
@@ -359,9 +359,11 @@ describe("createEventHandler - idle deduplication", () => {
}))
//#then
expect(dispatchCalls).toHaveLength(1)
expect(dispatchCalls).toHaveLength(2)
expect(dispatchCalls[0]?.event.type).toBe("session.idle")
expect((dispatchCalls[0]?.event.properties as { sessionID?: string } | undefined)?.sessionID).toBe(sessionId)
expect(dispatchCalls[1]?.event.type).toBe("session.idle")
expect((dispatchCalls[1]?.event.properties as { sessionID?: string } | undefined)?.sessionID).toBe(sessionId)
})
it("dedups back-to-back real session.idle events for the same sessionID within 500ms", async () => {
+3
View File
@@ -415,6 +415,9 @@ export function createEventHandler(args: {
const emittedAt = recentSyntheticIdles.get(sessionID);
if (emittedAt !== undefined && now - emittedAt < DEDUP_WINDOW_MS) {
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);
}
recentRealIdles.set(sessionID, now);
if (!shouldDispatchIdleEvent(sessionID, now)) {