diff --git a/src/functions/status.ts b/src/functions/status.ts index fdf2c2b14c..db843be91d 100644 --- a/src/functions/status.ts +++ b/src/functions/status.ts @@ -525,11 +525,17 @@ function captureProblems(capture: CaptureStatus | null, now: Date, restPort: num const base = captureRestBase(restPort); const inbox = capture.inbox; if (inbox && inbox.dead > 0) { + // Errors returned by mem::observe dead-letter on the first attempt, so the + // message cannot claim the retry budget was used. + const sessionCap = inbox.lastError?.startsWith("Session observation limit reached") ?? false; + const listAndRetry = `List them with curl -s ${CURL_AUTH_HEADER} '${base}/capture?status=dead'. After fixing the cause, retry them with curl -X POST ${base}/capture/retry ${CURL_AUTH_HEADER} -H "Content-Type: application/json" -d '{"all":true}'.`; problems.push({ level: "warn", code: "capture-dead-letters", - message: `${plural(inbox.dead, "captured observation")} could not be stored after ${plural(capture.policy.maxAttempts, "attempt")} and ${inbox.dead === 1 ? "is parked as a dead letter" : "are parked as dead letters"}${inbox.lastError ? `: ${inbox.lastError}` : "."}`, - fix: `List them with curl -s ${CURL_AUTH_HEADER} '${base}/capture?status=dead'. After fixing the cause, retry them with curl -X POST ${base}/capture/retry ${CURL_AUTH_HEADER} -H "Content-Type: application/json" -d '{"all":true}'.`, + message: `${plural(inbox.dead, "captured observation")} could not be stored and ${inbox.dead === 1 ? "is parked as a dead letter" : "are parked as dead letters"}${inbox.lastError ? `: ${inbox.lastError}` : "."}`, + fix: sessionCap + ? `The session reached its MAX_OBS_PER_SESSION cap, so a retry is refused again until the cap is raised. Raise MAX_OBS_PER_SESSION in ~/.agentmemory/.env (0 = no cap) and restart agentmemory. ${listAndRetry}` + : listAndRetry, }); } if (inbox && inbox.retrying + inbox.pending > 0) { diff --git a/test/capture-review-fixes.test.ts b/test/capture-review-fixes.test.ts index 5b64fc27b9..2437c2fcf4 100644 --- a/test/capture-review-fixes.test.ts +++ b/test/capture-review-fixes.test.ts @@ -200,6 +200,24 @@ describe("capture status", () => { expect(drops[0]!.message).toContain("too-large"); }); + it("names MAX_OBS_PER_SESSION when the session cap refused the observations", () => { + const c = capture([], 3); + c.inbox!.lastError = "Session observation limit reached (500)"; + const dead = evaluateStatus(statusInputs(c)).problems.find((p) => p.code === "capture-dead-letters")!; + expect(dead.message).toBe("3 captured observations could not be stored and are parked as dead letters: Session observation limit reached (500)"); + expect(dead.fix).toMatch(/^The session reached its MAX_OBS_PER_SESSION cap/); + expect(dead.fix).toContain("0 = no cap"); + expect(dead.fix?.split(CURL_AUTH_HEADER).length).toBe(3); + }); + + it("does not claim the retry budget was used for other dead letters", () => { + const c = capture([], 1); + c.inbox!.lastError = "disk full"; + const dead = evaluateStatus(statusInputs(c)).problems.find((p) => p.code === "capture-dead-letters")!; + expect(dead.message).not.toMatch(/attempt/); + expect(dead.fix).not.toContain("MAX_OBS_PER_SESSION"); + }); + it("prints recovery commands that send the secret", () => { const report = evaluateStatus(statusInputs(capture([], 2))); const dead = report.problems.find((p) => p.code === "capture-dead-letters");