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 <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
e8042fa445
commit
5dfe0a34fc
@ -12,6 +12,7 @@ import {
|
|||||||
} from "./fallback-handoff"
|
} from "./fallback-handoff"
|
||||||
|
|
||||||
const processedFallbackMessages = new Set<string>()
|
const processedFallbackMessages = new Set<string>()
|
||||||
|
const MAX_PROCESSED_FALLBACK_MARKERS = 500
|
||||||
|
|
||||||
function getSessionIDFromStatusEvent(input: { event: { properties?: Record<string, unknown> } }): string | undefined {
|
function getSessionIDFromStatusEvent(input: { event: { properties?: Record<string, unknown> } }): string | undefined {
|
||||||
const props = input.event.properties as Record<string, unknown> | undefined
|
const props = input.event.properties as Record<string, unknown> | undefined
|
||||||
@ -97,6 +98,15 @@ export function createAgentSwitchHook(ctx: PluginInput) {
|
|||||||
}
|
}
|
||||||
processedFallbackMessages.add(marker)
|
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 switch_agent already queued a handoff, do not synthesize fallback behavior.
|
||||||
if (getPendingSwitch(sessionID)) {
|
if (getPendingSwitch(sessionID)) {
|
||||||
return
|
return
|
||||||
@ -125,6 +135,7 @@ export function createAgentSwitchHook(ctx: PluginInput) {
|
|||||||
source: "athena-message-fallback",
|
source: "athena-message-fallback",
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
processedFallbackMessages.delete(marker)
|
||||||
log("[agent-switch] Failed to recover fallback handoff from Athena message", {
|
log("[agent-switch] Failed to recover fallback handoff from Athena message", {
|
||||||
sessionID,
|
sessionID,
|
||||||
messageID,
|
messageID,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user