🧠 refactor: Memory Timeout after Completion and Guarantee Stream Final Event (#8955)

This commit is contained in:
Danny Avila 2025-08-09 00:01:10 -04:00 committed by GitHub
parent 4eeadddfe6
commit 0c9284c8ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 10 deletions

View file

@ -233,6 +233,26 @@ const AgentController = async (req, res, next, initializeClient, addTitle) => {
);
}
}
// Edge case: sendMessage completed but abort happened during sendCompletion
// We need to ensure a final event is sent
else if (!res.headersSent && !res.finished) {
logger.debug(
'[AgentController] Handling edge case: `sendMessage` completed but aborted during `sendCompletion`',
);
const finalResponse = { ...response };
finalResponse.error = true;
sendEvent(res, {
final: true,
conversation,
title: conversation.title,
requestMessage: userMessage,
responseMessage: finalResponse,
error: { message: 'Request was aborted during completion' },
});
res.end();
}
// Save user message if needed
if (!client.skipSaveUserMessage) {