Skip to content

An AI-powered search engine with a generative UI

fix: address PR review comments

Yoshiki Miura8a4f76701da8
diff --git a/lib/cache/memory-cache.ts b/lib/cache/memory-cache.ts
index 86d5134d..d586e592 100644
--- a/lib/cache/memory-cache.ts
+++ b/lib/cache/memory-cache.ts
@@ -190,14 +190,16 @@ if (typeof process !== 'undefined' && process.on) {
process.on('SIGINT', () => {
console.log('\nGracefully shutting down cache...')
cleanupCacheInterval()
- process.exit(0)
+ // Let the process exit naturally after cleanup
+ process.exitCode = 0
})
// Graceful shutdown on SIGTERM
process.on('SIGTERM', () => {
console.log('\nGracefully shutting down cache...')
cleanupCacheInterval()
- process.exit(0)
+ // Let the process exit naturally after cleanup
+ process.exitCode = 0
})
// Cleanup before exit
diff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.ts
index 67b4eba5..f34f2803 100644
--- a/lib/streaming/create-chat-stream-response.ts
+++ b/lib/streaming/create-chat-stream-response.ts
@@ -195,15 +195,15 @@ export async function createChatStreamResponse(
// If no tool calls (just answering), skip related questions
if (!hasToolCallsInMessage) {
// Save research message and generate title in parallel
- const savePromises: Promise<any>[] = [
- saveMessage(chatId, validResearchMessage)
+ const saveOperations: (() => Promise<any>)[] = [
+ () => saveMessage(chatId, validResearchMessage)
]
// Generate proper title after conversation starts
if (!initialChat && message) {
const userContent = getTextFromParts(message.parts)
- savePromises.push(
- generateChatTitle({
+ saveOperations.push(
+ () => generateChatTitle({
userMessageContent: userContent,
modelId
}).then(async title => {
@@ -214,14 +214,14 @@ export async function createChatStreamResponse(
}
// Execute saves in background with exponential backoff retry
- Promise.all(savePromises).catch(async error => {
+ Promise.all(saveOperations.map(op => op())).catch(async error => {
console.error('Error saving message or title:', error)
// Retry critical save operations with backoff
try {
- for (const promise of savePromises) {
+ for (const operation of saveOperations) {
await retryDatabaseOperation(
- () => promise,
+ operation,
'save message/title'
)
}
@@ -280,24 +280,24 @@ export async function createChatStreamResponse(
await relatedQuestionsPromise
// Save the complete message after both agents finish
- const savePromises: Promise<any>[] = []
+ const saveOperations: (() => Promise<any>)[] = []
if (validResearchMessage && relatedQuestionsMessage) {
const mergedMessage = mergeUIMessages(
validResearchMessage,
relatedQuestionsMessage
)
- savePromises.push(saveMessage(chatId, mergedMessage))
+ saveOperations.push(() => saveMessage(chatId, mergedMessage))
} else if (validResearchMessage) {
// Save research message only if related questions failed
- savePromises.push(saveMessage(chatId, validResearchMessage))
+ saveOperations.push(() => saveMessage(chatId, validResearchMessage))
}
// Generate proper title after conversation starts
if (!initialChat && message) {
const userContent = getTextFromParts(message.parts)
- savePromises.push(
- generateChatTitle({
+ saveOperations.push(
+ () => generateChatTitle({
userMessageContent: userContent,
modelId
}).then(async title => {
@@ -308,14 +308,14 @@ export async function createChatStreamResponse(
}
// Execute saves in background with exponential backoff retry
- Promise.all(savePromises).catch(async error => {
+ Promise.all(saveOperations.map(op => op())).catch(async error => {
console.error('Error saving message or title:', error)
// Retry critical save operations with backoff
try {
- for (const promise of savePromises) {
+ for (const operation of saveOperations) {
await retryDatabaseOperation(
- () => promise,
+ operation,
'save message/title'
)
}