Skip to content
Merged
Prev Previous commit
Next Next commit
Revert "Feat(logs) upgrade mothership chat messages to error (#3772)"
This reverts commit 9d1b976.
  • Loading branch information
Theodore Li committed Mar 28, 2026
commit 584ac10fb88b2903679c95ae5a0d78be13f8b189
16 changes: 8 additions & 8 deletions apps/sim/app/api/copilot/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export async function POST(req: NextRequest) {

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

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

logger.error(
logger.info(
appendCopilotLogContext('Non-streaming response from orchestrator', {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
Expand Down Expand Up @@ -617,7 +617,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.error(
logger.info(
appendCopilotLogContext('Starting title generation for non-streaming response', {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
Expand All @@ -633,7 +633,7 @@ export async function POST(req: NextRequest) {
updatedAt: new Date(),
})
.where(eq(copilotChats.id, actualChatId!))
logger.error(
logger.info(
appendCopilotLogContext(`Generated and saved title: ${title}`, {
requestId: tracker.requestId,
messageId: userMessageIdToUse,
Expand Down Expand Up @@ -662,7 +662,7 @@ export async function POST(req: NextRequest) {
.where(eq(copilotChats.id, actualChatId!))
}

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

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

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

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

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

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

if (abortController.signal.aborted) {
logger.error(
logger.info(
appendCopilotLogContext('Stream aborted by explicit stop', { requestId, messageId })
)
await eventWriter.close().catch(() => {})
Expand All @@ -483,7 +483,7 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
'An unexpected error occurred while processing the response.'

if (clientDisconnected) {
logger.error(
logger.info(
appendCopilotLogContext('Stream failed after client disconnect', {
requestId,
messageId,
Expand Down Expand Up @@ -539,7 +539,7 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
}
} catch (error) {
if (abortController.signal.aborted) {
logger.error(
logger.info(
appendCopilotLogContext('Stream aborted by explicit stop', { requestId, messageId })
)
await eventWriter.close().catch(() => {})
Expand All @@ -548,7 +548,7 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
return
}
if (clientDisconnected) {
logger.error(
logger.info(
appendCopilotLogContext('Stream errored after client disconnect', {
requestId,
messageId,
Expand Down
24 changes: 12 additions & 12 deletions apps/sim/lib/copilot/orchestrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export async function orchestrateCopilotStream(
let claimedToolCallIds: string[] = []
let claimedByWorkerId: string | null = null

logger.error(withLogContext('Starting copilot orchestration'), {
logger.info(withLogContext('Starting copilot orchestration'), {
goRoute,
workflowId,
workspaceId,
Expand All @@ -155,7 +155,7 @@ export async function orchestrateCopilotStream(
for (;;) {
context.streamComplete = false

logger.error(withLogContext('Starting orchestration loop iteration'), {
logger.info(withLogContext('Starting orchestration loop iteration'), {
route,
hasPendingAsyncContinuation: Boolean(context.awaitingAsyncContinuation),
claimedToolCallCount: claimedToolCallIds.length,
Expand All @@ -168,7 +168,7 @@ export async function orchestrateCopilotStream(
const d = (event.data ?? {}) as Record<string, unknown>
const response = (d.response ?? {}) as Record<string, unknown>
if (response.async_pause) {
logger.error(withLogContext('Detected async pause from copilot backend'), {
logger.info(withLogContext('Detected async pause from copilot backend'), {
route,
checkpointId:
typeof (response.async_pause as Record<string, unknown>)?.checkpointId ===
Expand Down Expand Up @@ -201,7 +201,7 @@ export async function orchestrateCopilotStream(
loopOptions
)

logger.error(withLogContext('Completed orchestration loop iteration'), {
logger.info(withLogContext('Completed orchestration loop iteration'), {
route,
streamComplete: context.streamComplete,
wasAborted: context.wasAborted,
Expand All @@ -210,7 +210,7 @@ export async function orchestrateCopilotStream(
})

if (claimedToolCallIds.length > 0) {
logger.error(withLogContext('Marking async tool calls as delivered'), {
logger.info(withLogContext('Marking async tool calls as delivered'), {
toolCallIds: claimedToolCallIds,
})
await Promise.all(
Expand All @@ -223,7 +223,7 @@ export async function orchestrateCopilotStream(
}

if (options.abortSignal?.aborted || context.wasAborted) {
logger.error(withLogContext('Stopping orchestration because request was aborted'), {
logger.info(withLogContext('Stopping orchestration because request was aborted'), {
pendingToolCallCount: Array.from(context.toolCalls.values()).filter(
(toolCall) => toolCall.status === 'pending' || toolCall.status === 'executing'
).length,
Expand All @@ -241,13 +241,13 @@ export async function orchestrateCopilotStream(

const continuation = context.awaitingAsyncContinuation
if (!continuation) {
logger.error(withLogContext('No async continuation pending; finishing orchestration'))
logger.info(withLogContext('No async continuation pending; finishing orchestration'))
break
}

let resumeReady = false
let resumeRetries = 0
logger.error(withLogContext('Processing async continuation'), {
logger.info(withLogContext('Processing async continuation'), {
checkpointId: continuation.checkpointId,
runId: continuation.runId,
pendingToolCallIds: continuation.pendingToolCallIds,
Expand Down Expand Up @@ -443,7 +443,7 @@ export async function orchestrateCopilotStream(
}
if (resumeRetries < 3) {
resumeRetries++
logger.error(withLogContext('Retrying async resume after claim contention'), {
logger.info(withLogContext('Retrying async resume after claim contention'), {
checkpointId: continuation.checkpointId,
runId: continuation.runId,
workerId: resumeWorkerId,
Expand Down Expand Up @@ -474,7 +474,7 @@ export async function orchestrateCopilotStream(
]
claimedByWorkerId = claimedToolCallIds.length > 0 ? resumeWorkerId : null

logger.error(withLogContext('Resuming async tool continuation'), {
logger.info(withLogContext('Resuming async tool continuation'), {
checkpointId: continuation.checkpointId,
runId: continuation.runId,
workerId: resumeWorkerId,
Expand Down Expand Up @@ -540,7 +540,7 @@ export async function orchestrateCopilotStream(
checkpointId: continuation.checkpointId,
results,
}
logger.error(withLogContext('Prepared async continuation payload for resume endpoint'), {
logger.info(withLogContext('Prepared async continuation payload for resume endpoint'), {
route,
checkpointId: continuation.checkpointId,
resultCount: results.length,
Expand Down Expand Up @@ -569,7 +569,7 @@ export async function orchestrateCopilotStream(
usage: context.usage,
cost: context.cost,
}
logger.error(withLogContext('Completing copilot orchestration'), {
logger.info(withLogContext('Completing copilot orchestration'), {
success: result.success,
chatId: result.chatId,
hasRequestId: Boolean(result.requestId),
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export const sseHandlers: Record<string, SSEHandler> = {
const rid = typeof event.data === 'string' ? event.data : undefined
if (rid) {
context.requestId = rid
logger.error(
logger.info(
appendCopilotLogContext('Mapped copilot message to Go trace ID', {
messageId: context.messageId,
}),
Expand Down
21 changes: 9 additions & 12 deletions apps/sim/lib/copilot/orchestrator/sse/handlers/tool-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async function maybeWriteOutputToFile(
contentType
)

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

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

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

logger.error(
appendCopilotLogContext('Tool execution started', { messageId: context.messageId }),
{
toolCallId: toolCall.id,
toolName: toolCall.name,
params: toolCall.params,
}
)
logger.info(appendCopilotLogContext('Tool execution started', { messageId: context.messageId }), {
toolCallId: toolCall.id,
toolName: toolCall.name,
params: toolCall.params,
})

try {
let result = await executeToolServerSide(toolCall, execContext)
Expand Down Expand Up @@ -693,7 +690,7 @@ export async function executeToolAndReport(
: raw && typeof raw === 'object'
? JSON.stringify(raw).slice(0, 200)
: undefined
logger.error(
logger.info(
appendCopilotLogContext('Tool execution succeeded', { messageId: context.messageId }),
{
toolCallId: toolCall.id,
Expand Down
Loading