Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/functions/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions test/capture-review-fixes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading