diff --git a/auto-kol/agent-memory-viewer/backend/src/index.ts b/auto-kol/agent-memory-viewer/backend/src/index.ts index 015ca70..738e509 100644 --- a/auto-kol/agent-memory-viewer/backend/src/index.ts +++ b/auto-kol/agent-memory-viewer/backend/src/index.ts @@ -25,27 +25,29 @@ process.on('unhandledRejection', async (reason, promise) => { async function main() { try { await initialize(); - await resurrection(); + resurrection(); const memoryWatcher = watchMemoryHashUpdates(async (agent, cid) => { - try { - logger.info('New memory hash detected', { agent, cid }); - const memory = await downloadMemory(cid); - if (memory) { - const savedMemory = await saveMemoryRecord(cid, memory, memory?.previousCid); - logger.info('Memory processed successfully', { + logger.info('New memory hash detected', { agent, cid }); + + downloadMemory(cid) + .then(async memory => { + if (memory) { + const savedMemory = await saveMemoryRecord(cid, memory, memory?.previousCid); + logger.info('Memory processed successfully', { + cid, + isNew: savedMemory.created_at === savedMemory.created_at + }); + } + }) + .catch(error => { + logger.error('Error processing memory update', { + error, + agent, cid, - isNew: savedMemory.created_at === savedMemory.created_at + errorType: error instanceof Error ? error.constructor.name : typeof error }); - } - } catch (error) { - logger.error('Error processing memory update', { - error, - agent, - cid, - errorType: error instanceof Error ? error.constructor.name : typeof error }); - } }); createWebSocketServer(); diff --git a/auto-kol/agent-memory-viewer/backend/src/utils/dsn.ts b/auto-kol/agent-memory-viewer/backend/src/utils/dsn.ts index 2da1bda..d4455a9 100644 --- a/auto-kol/agent-memory-viewer/backend/src/utils/dsn.ts +++ b/auto-kol/agent-memory-viewer/backend/src/utils/dsn.ts @@ -5,7 +5,7 @@ import { createLogger } from './logger.js'; const logger = createLogger('dsn'); -const MAX_RETRIES = 10; +const MAX_RETRIES = 15; const INITIAL_RETRY_DELAY = 10000; async function delay(ms: number) { @@ -70,4 +70,4 @@ export async function downloadMemory(cid: string, retryCount = 0): Promise }); throw error; } -} \ No newline at end of file +} diff --git a/auto-kol/agent-memory-viewer/backend/src/utils/resurrection.ts b/auto-kol/agent-memory-viewer/backend/src/utils/resurrection.ts index cfeb451..3471b22 100644 --- a/auto-kol/agent-memory-viewer/backend/src/utils/resurrection.ts +++ b/auto-kol/agent-memory-viewer/backend/src/utils/resurrection.ts @@ -8,7 +8,15 @@ const logger = createLogger('resurrection'); export async function resurrection() { logger.info('Starting resurrection'); let hash = await getLastMemoryHash(); + + processResurrection(hash).catch(error => { + logger.error('Error during resurrection:', error); + }); +} + +async function processResurrection(startHash: string) { const memories: { hash: string; data: any }[] = []; + let hash = startHash; while (true) { const existingMemory = await getMemoryByCid(hash); @@ -17,19 +25,34 @@ export async function resurrection() { break; } - const memory = await downloadMemory(hash); - if (!memory) break; - - memories.push({ hash, data: memory }); - hash = memory?.previousCid; - - if (!hash) break; + try { + const memory = await downloadMemory(hash); + if (!memory) break; + + memories.push({ hash, data: memory }); + hash = memory?.previousCid; + + if (!hash) break; + } catch (error) { + logger.error('Failed to download memory during resurrection', { + cid: hash, + error + }); + break; + } } for (let i = memories.length - 1; i >= 0; i--) { const { hash, data } = memories[i]; - await saveMemoryRecord(hash, data, data?.previousCid); - logger.info('Saved memory during resurrection', { cid: hash }); + try { + await saveMemoryRecord(hash, data, data?.previousCid); + logger.info('Saved memory during resurrection', { cid: hash }); + } catch (error) { + logger.error('Failed to save memory during resurrection', { + cid: hash, + error + }); + } } logger.info('Resurrection complete', { memoriesProcessed: memories.length });