From 5dfe0a34fc1e8cbd4c6dda9bfc9aba6dc3baaa60 Mon Sep 17 00:00:00 2001 From: ismeth Date: Wed, 18 Feb 2026 20:56:22 +0100 Subject: [PATCH] fix(athena): enable retry and bound growth for agent-switch fallback markers Delete marker from processedFallbackMessages on failure so message can be retried. Add MAX_PROCESSED_FALLBACK_MARKERS=500 with eviction to prevent unbounded Set growth. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- src/hooks/agent-switch/hook.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/hooks/agent-switch/hook.ts b/src/hooks/agent-switch/hook.ts index 61d44023..bc200ce8 100644 --- a/src/hooks/agent-switch/hook.ts +++ b/src/hooks/agent-switch/hook.ts @@ -12,6 +12,7 @@ import { } from "./fallback-handoff" const processedFallbackMessages = new Set() +const MAX_PROCESSED_FALLBACK_MARKERS = 500 function getSessionIDFromStatusEvent(input: { event: { properties?: Record } }): string | undefined { const props = input.event.properties as Record | undefined @@ -97,6 +98,15 @@ export function createAgentSwitchHook(ctx: PluginInput) { } processedFallbackMessages.add(marker) + // Prevent unbounded growth of the Set + if (processedFallbackMessages.size > MAX_PROCESSED_FALLBACK_MARKERS) { + const iterator = processedFallbackMessages.values() + const oldest = iterator.next().value + if (oldest) { + processedFallbackMessages.delete(oldest) + } + } + // If switch_agent already queued a handoff, do not synthesize fallback behavior. if (getPendingSwitch(sessionID)) { return @@ -125,6 +135,7 @@ export function createAgentSwitchHook(ctx: PluginInput) { source: "athena-message-fallback", }) } catch (error) { + processedFallbackMessages.delete(marker) log("[agent-switch] Failed to recover fallback handoff from Athena message", { sessionID, messageID,