fix: correct stale session regex and remove duplicate retry logic
The original regex didn't match the actual error ("No conversation
found with session ID: ..."). Added `no conversation found` pattern.
Removed the inline retry — clearing the session and returning 'error'
lets the existing group-queue.ts backoff loop retry with a fresh
session naturally. Simpler, no duplicate error paths.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
47
src/index.ts
47
src/index.ts
@@ -403,57 +403,22 @@ async function runAgent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (output.status === 'error') {
|
if (output.status === 'error') {
|
||||||
// Detect stale/corrupt session: the SDK throws ENOENT when the session
|
// Detect stale/corrupt session — clear it so the next retry starts fresh.
|
||||||
// transcript file (.jsonl) doesn't exist inside the container. This
|
// The session .jsonl can go missing after a crash mid-write, manual
|
||||||
// happens after container restarts since the filesystem is ephemeral.
|
// deletion, or disk-full. The existing backoff in group-queue.ts
|
||||||
// Only clear + retry for this specific signal — transient errors
|
// handles the retry; we just need to remove the broken session ID.
|
||||||
// (network, API) should fall through to the normal backoff path.
|
|
||||||
const isStaleSession =
|
const isStaleSession =
|
||||||
sessionId &&
|
sessionId &&
|
||||||
output.error &&
|
output.error &&
|
||||||
/ENOENT.*\.jsonl|session.*not found/i.test(output.error);
|
/no conversation found|ENOENT.*\.jsonl|session.*not found/i.test(output.error);
|
||||||
|
|
||||||
if (isStaleSession) {
|
if (isStaleSession) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
{ group: group.name, staleSessionId: sessionId, error: output.error },
|
{ group: group.name, staleSessionId: sessionId, error: output.error },
|
||||||
'Stale session detected (ENOENT on session transcript) — clearing and retrying with fresh session',
|
'Stale session detected — clearing for next retry',
|
||||||
);
|
);
|
||||||
delete sessions[group.folder];
|
delete sessions[group.folder];
|
||||||
deleteSession(group.folder);
|
deleteSession(group.folder);
|
||||||
|
|
||||||
const freshOutput = await runContainerAgent(
|
|
||||||
group,
|
|
||||||
{
|
|
||||||
prompt,
|
|
||||||
sessionId: undefined,
|
|
||||||
groupFolder: group.folder,
|
|
||||||
chatJid,
|
|
||||||
isMain,
|
|
||||||
assistantName: ASSISTANT_NAME,
|
|
||||||
},
|
|
||||||
(proc, containerName) =>
|
|
||||||
queue.registerProcess(chatJid, proc, containerName, group.folder),
|
|
||||||
wrappedOnOutput,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (freshOutput.newSessionId) {
|
|
||||||
sessions[group.folder] = freshOutput.newSessionId;
|
|
||||||
setSession(group.folder, freshOutput.newSessionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (freshOutput.status === 'error') {
|
|
||||||
logger.error(
|
|
||||||
{ group: group.name, error: freshOutput.error },
|
|
||||||
'Container agent error on fresh session retry',
|
|
||||||
);
|
|
||||||
return 'error';
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
{ group: group.name, newSessionId: freshOutput.newSessionId },
|
|
||||||
'Fresh session retry succeeded',
|
|
||||||
);
|
|
||||||
return 'success';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|||||||
Reference in New Issue
Block a user