fix(memory-core): raise NARRATIVE_TIMEOUT_MS from 15s to 60s

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.
This commit is contained in:
RayWoo
2026-04-27 14:33:09 +00:00
committed by Peter Steinberger
parent 16322d5cfc
commit ad6e1cd3a0
2 changed files with 9 additions and 4 deletions

View File

@@ -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"),
);

View File

@@ -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;