Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/acp-error-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export function formatUnknownErrorMessage(error: unknown): string {
return String(error);
}

// Matches "session" followed by optional ID (quoted or unquoted) followed by "not found"
// Examples: "Session \"abc\" not found", "Session abc-123 not found"
const SESSION_NOT_FOUND_PATTERN = /session\s+["'\w\-]+\s+not found/i;

function isSessionNotFoundText(value: unknown): boolean {
if (typeof value !== "string") {
return false;
Expand All @@ -100,7 +104,8 @@ function isSessionNotFoundText(value: unknown): boolean {
normalized.includes("resource not found") ||
normalized.includes("session not found") ||
normalized.includes("unknown session") ||
normalized.includes("invalid session identifier")
normalized.includes("invalid session identifier") ||
SESSION_NOT_FOUND_PATTERN.test(value)
);
}

Expand Down
13 changes: 13 additions & 0 deletions test/error-normalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ test("isAcpResourceNotFoundError recognizes session-not-found hints in nested er
true,
);
});

test("isAcpResourceNotFoundError recognizes Cursor session-not-found format", () => {
// Cursor returns: {"code":-32602,"message":"Invalid params","data":{"message":"Session \"xxx\" not found"}}
const cursorError = {
code: -32602,
message: "Invalid params",
data: {
message: 'Session "nonexistent-session-id" not found',
},
};

assert.equal(isAcpResourceNotFoundError(cursorError), true);
});
test("isAcpQueryClosedBeforeResponseError matches typed ACP payload", () => {
const error = {
code: -32603,
Expand Down