Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Upgrade info logs to error for message route
  • Loading branch information
Theodore Li committed Mar 25, 2026
commit ba56e4c42343169295f79d01d7b02fdb9a2db54f
24 changes: 8 additions & 16 deletions apps/sim/app/api/copilot/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ export async function POST(req: NextRequest) {

const userMessageIdToUse = userMessageId || crypto.randomUUID()
try {
logger.info(
appendCopilotLogContext('Received chat POST', {
logger.error(appendCopilotLogContext('Received chat POST', {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
}),
Expand Down Expand Up @@ -250,8 +249,7 @@ export async function POST(req: NextRequest) {
actualChatId
)
agentContexts = processed
logger.info(
appendCopilotLogContext('Contexts processed for request', {
logger.error(appendCopilotLogContext('Contexts processed for request', {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
}),
Expand Down Expand Up @@ -357,8 +355,7 @@ export async function POST(req: NextRequest) {
)

try {
logger.info(
appendCopilotLogContext('About to call Sim Agent', {
logger.error(appendCopilotLogContext('About to call Sim Agent', {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
}),
Expand Down Expand Up @@ -555,8 +552,7 @@ export async function POST(req: NextRequest) {
provider: typeof requestPayload?.provider === 'string' ? requestPayload.provider : undefined,
}

logger.info(
appendCopilotLogContext('Non-streaming response from orchestrator', {
logger.error(appendCopilotLogContext('Non-streaming response from orchestrator', {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
}),
Expand Down Expand Up @@ -600,8 +596,7 @@ export async function POST(req: NextRequest) {

// Start title generation in parallel if this is first message (non-streaming)
if (actualChatId && !currentChat.title && conversationHistory.length === 0) {
logger.info(
appendCopilotLogContext('Starting title generation for non-streaming response', {
logger.error(appendCopilotLogContext('Starting title generation for non-streaming response', {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
})
Expand All @@ -616,8 +611,7 @@ export async function POST(req: NextRequest) {
updatedAt: new Date(),
})
.where(eq(copilotChats.id, actualChatId!))
logger.info(
appendCopilotLogContext(`Generated and saved title: ${title}`, {
logger.error(appendCopilotLogContext(`Generated and saved title: ${title}`, {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
})
Expand Down Expand Up @@ -645,8 +639,7 @@ export async function POST(req: NextRequest) {
.where(eq(copilotChats.id, actualChatId!))
}

logger.info(
appendCopilotLogContext('Returning non-streaming response', {
logger.error(appendCopilotLogContext('Returning non-streaming response', {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
}),
Expand Down Expand Up @@ -778,8 +771,7 @@ export async function GET(req: NextRequest) {
...(streamSnapshot ? { streamSnapshot } : {}),
}

logger.info(
appendCopilotLogContext(`Retrieved chat ${chatId}`, {
logger.error(appendCopilotLogContext(`Retrieved chat ${chatId}`, {
messageId: chat.conversationId || undefined,
})
)
Expand Down
10 changes: 4 additions & 6 deletions apps/sim/app/api/copilot/chat/stream/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export async function GET(request: NextRequest) {
const toParam = url.searchParams.get('to')
const toEventId = toParam ? Number(toParam) : undefined

logger.info(
appendCopilotLogContext('[Resume] Received resume request', {
logger.error(appendCopilotLogContext('[Resume] Received resume request', {
messageId: streamId || undefined,
}),
{
Expand All @@ -53,7 +52,7 @@ export async function GET(request: NextRequest) {
}

const meta = (await getStreamMeta(streamId)) as StreamMeta | null
logger.info(appendCopilotLogContext('[Resume] Stream lookup', { messageId: streamId }), {
logger.error(appendCopilotLogContext('[Resume] Stream lookup', { messageId: streamId }), {
streamId,
fromEventId,
toEventId,
Expand All @@ -72,7 +71,7 @@ export async function GET(request: NextRequest) {
if (batchMode) {
const events = await readStreamEvents(streamId, fromEventId)
const filteredEvents = toEventId ? events.filter((e) => e.eventId <= toEventId) : events
logger.info(appendCopilotLogContext('[Resume] Batch response', { messageId: streamId }), {
logger.error(appendCopilotLogContext('[Resume] Batch response', { messageId: streamId }), {
streamId,
fromEventId,
toEventId,
Expand Down Expand Up @@ -124,8 +123,7 @@ export async function GET(request: NextRequest) {
const flushEvents = async () => {
const events = await readStreamEvents(streamId, lastEventId)
if (events.length > 0) {
logger.info(
appendCopilotLogContext('[Resume] Flushing events', { messageId: streamId }),
logger.error(appendCopilotLogContext('[Resume] Flushing events', { messageId: streamId }),
{
streamId,
fromEventId: lastEventId,
Expand Down
3 changes: 1 addition & 2 deletions apps/sim/app/api/mothership/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ export async function POST(req: NextRequest) {
const userMessageId = providedMessageId || crypto.randomUUID()
userMessageIdForLogs = userMessageId

logger.info(
appendCopilotLogContext('Received mothership chat start request', {
logger.error(appendCopilotLogContext('Received mothership chat start request', {
requestId: tracker.requestId,
messageId: userMessageId,
}),
Expand Down
3 changes: 1 addition & 2 deletions apps/sim/app/api/v1/copilot/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ export async function POST(req: NextRequest) {
const chatId = parsed.chatId || crypto.randomUUID()

messageId = crypto.randomUUID()
logger.info(
appendCopilotLogContext('Received headless copilot chat start request', { messageId }),
logger.error(appendCopilotLogContext('Received headless copilot chat start request', { messageId }),
{
workflowId: resolved.workflowId,
workflowName: parsed.workflowName,
Expand Down
3 changes: 1 addition & 2 deletions apps/sim/lib/copilot/chat-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ export async function buildCopilotRequestPayload(
})
}
if (mcpTools.length > 0) {
logger.info(
appendCopilotLogContext('Added MCP tools to copilot payload', {
logger.error(appendCopilotLogContext('Added MCP tools to copilot payload', {
messageId: userMessageId,
}),
{ count: mcpTools.length }
Expand Down
12 changes: 4 additions & 8 deletions apps/sim/lib/copilot/chat-streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
})

if (abortController.signal.aborted) {
logger.info(
appendCopilotLogContext('Stream aborted by explicit stop', { requestId, messageId })
logger.error(appendCopilotLogContext('Stream aborted by explicit stop', { requestId, messageId })
)
Comment on lines +443 to 445
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 User-initiated abort logged as error

'Stream aborted by explicit stop' is triggered when a user intentionally cancels a request — it is expected, non-erroneous behavior. Logging it as error will create false positive alerts every time a user presses a stop button. The same applies to 'Stopping orchestration because request was aborted' in orchestrator/index.ts line 225.

Suggested change
logger.error(
appendCopilotLogContext('Stream aborted by explicit stop', { requestId, messageId })
)
logger.info(
appendCopilotLogContext('Stream aborted by explicit stop', { requestId, messageId })
)

await eventWriter.close().catch(() => {})
await setStreamMeta(streamId, { status: 'cancelled', userId, executionId, runId })
Expand All @@ -456,8 +455,7 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
'An unexpected error occurred while processing the response.'

if (clientDisconnected) {
logger.info(
appendCopilotLogContext('Stream failed after client disconnect', {
logger.error(appendCopilotLogContext('Stream failed after client disconnect', {
requestId,
messageId,
}),
Expand Down Expand Up @@ -500,17 +498,15 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
await updateRunStatus(runId, 'complete', { completedAt: new Date() }).catch(() => {})
} catch (error) {
if (abortController.signal.aborted) {
logger.info(
appendCopilotLogContext('Stream aborted by explicit stop', { requestId, messageId })
logger.error(appendCopilotLogContext('Stream aborted by explicit stop', { requestId, messageId })
)
await eventWriter.close().catch(() => {})
await setStreamMeta(streamId, { status: 'cancelled', userId, executionId, runId })
await updateRunStatus(runId, 'cancelled', { completedAt: new Date() }).catch(() => {})
return
}
if (clientDisconnected) {
logger.info(
appendCopilotLogContext('Stream errored after client disconnect', {
logger.error(appendCopilotLogContext('Stream errored after client disconnect', {
requestId,
messageId,
}),
Expand Down
3 changes: 1 addition & 2 deletions apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ export const sseHandlers: Record<string, SSEHandler> = {
const rid = typeof event.data === 'string' ? event.data : undefined
if (rid) {
context.requestId = rid
logger.info(
appendCopilotLogContext('Mapped copilot message to Go trace ID', {
logger.error(appendCopilotLogContext('Mapped copilot message to Go trace ID', {
messageId: context.messageId,
}),
{
Expand Down
14 changes: 5 additions & 9 deletions apps/sim/lib/copilot/orchestrator/sse/handlers/tool-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ async function maybeWriteOutputToFile(
contentType
)

logger.info(
appendCopilotLogContext('Tool output written to file', { messageId: context.messageId }),
logger.error(appendCopilotLogContext('Tool output written to file', { messageId: context.messageId }),
{
toolName,
fileName,
Expand Down Expand Up @@ -397,8 +396,7 @@ async function maybeWriteOutputToTable(
}
})

logger.info(
appendCopilotLogContext('Tool output written to table', { messageId: context.messageId }),
logger.error(appendCopilotLogContext('Tool output written to table', { messageId: context.messageId }),
{
toolName,
tableId: outputTable,
Expand Down Expand Up @@ -524,8 +522,7 @@ async function maybeWriteReadCsvToTable(
}
})

logger.info(
appendCopilotLogContext('Read output written to table', { messageId: context.messageId }),
logger.error(appendCopilotLogContext('Read output written to table', { messageId: context.messageId }),
{
toolName,
tableId: outputTable,
Expand Down Expand Up @@ -595,7 +592,7 @@ export async function executeToolAndReport(
toolCall.status = 'executing'
await markAsyncToolRunning(toolCall.id, 'sim-stream').catch(() => {})

logger.info(appendCopilotLogContext('Tool execution started', { messageId: context.messageId }), {
logger.error(appendCopilotLogContext('Tool execution started', { messageId: context.messageId }), {
toolCallId: toolCall.id,
toolName: toolCall.name,
params: toolCall.params,
Expand Down Expand Up @@ -686,8 +683,7 @@ export async function executeToolAndReport(
: raw && typeof raw === 'object'
? JSON.stringify(raw).slice(0, 200)
: undefined
logger.info(
appendCopilotLogContext('Tool execution succeeded', { messageId: context.messageId }),
logger.error(appendCopilotLogContext('Tool execution succeeded', { messageId: context.messageId }),
{
toolCallId: toolCall.id,
toolName: toolCall.name,
Expand Down