From ad6e1cd3a0764759b397c0dba7d22447a7efa4a4 Mon Sep 17 00:00:00 2001 From: RayWoo Date: Mon, 27 Apr 2026 14:33:09 +0000 Subject: [PATCH] fix(memory-core): raise NARRATIVE_TIMEOUT_MS from 15s to 60s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #72837. The 15s narrative-subagent timeout was empirically too tight for warm-gateway runs across light, REM, and deep phases — gpt-5.4-mini latency through OpenAI alone routinely brushes 12s+, so the first sweep after a restart deterministically times out across all three phases. 60s gives realistic LLM-call headroom while still capping the worst case at one minute, preserving the original comment's "don't leave parent cron running for minutes" constraint. Test: updates the matching toMatchObject assertion in dreaming-narrative.test.ts from 15_000 to 60_000. --- extensions/memory-core/src/dreaming-narrative.test.ts | 2 +- extensions/memory-core/src/dreaming-narrative.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/extensions/memory-core/src/dreaming-narrative.test.ts b/extensions/memory-core/src/dreaming-narrative.test.ts index 6bdfc70645c..3bd36793dc6 100644 --- a/extensions/memory-core/src/dreaming-narrative.test.ts +++ b/extensions/memory-core/src/dreaming-narrative.test.ts @@ -675,7 +675,7 @@ describe("generateAndAppendDreamNarrative", () => { }); expect(subagent.waitForRun).toHaveBeenCalledOnce(); - expect(subagent.waitForRun.mock.calls[0][0]).toMatchObject({ timeoutMs: 15_000 }); + expect(subagent.waitForRun.mock.calls[0][0]).toMatchObject({ timeoutMs: 60_000 }); expect(logger.warn).toHaveBeenCalledWith( expect.stringContaining("narrative session cleanup failed for rem phase"), ); diff --git a/extensions/memory-core/src/dreaming-narrative.ts b/extensions/memory-core/src/dreaming-narrative.ts index 347af57c2aa..f67e7e65472 100644 --- a/extensions/memory-core/src/dreaming-narrative.ts +++ b/extensions/memory-core/src/dreaming-narrative.ts @@ -87,10 +87,15 @@ const NARRATIVE_SYSTEM_PROMPT = [ "- Output ONLY the diary entry. No preamble, no sign-off, no commentary.", ].join("\n"); -// Narrative generation is best-effort. Keep the timeout short so a stalled +// Narrative generation is best-effort. Keep the timeout bounded so a stalled // diary subagent does not leave the parent dreaming cron job "running" for -// minutes after the reports have already been written. -const NARRATIVE_TIMEOUT_MS = 15_000; +// many minutes after the reports have already been written. The previous 15 s +// limit was empirically too tight for warm-gateway runs across light, REM, and +// deep phases — even unblocked LLM calls hit it on the first sweep after a +// restart. 60 s gives realistic latency headroom while still capping the +// worst case at one minute, well below the multi-minute stall the original +// comment warned against. +const NARRATIVE_TIMEOUT_MS = 60_000; const DREAMING_SESSION_KEY_PREFIX = "dreaming-narrative-"; const DREAMING_TRANSCRIPT_RUN_MARKER = '"runId":"dreaming-narrative-'; const DREAMING_ORPHAN_MIN_AGE_MS = 300_000;