[superlog] Use warn level for AI tool errors within a request context#498
[superlog] Use warn level for AI tool errors within a request context#498superlog-app[bot] wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
The latest updates on your projects. Learn more about Unkey Deploy
|
Greptile SummaryThis PR fixes false-positive ERROR-level wide events in scheduled insights jobs by changing
Confidence Score: 4/5The core fix is sound and directly addresses the false-positive ERROR logs, but the asymmetric severity between the two code paths in The change is small and targeted. The in-request path now correctly emits WARN for recoverable tool failures, solving the described incident. However, packages/ai/src/ai/tools/utils/logger.ts — specifically the behavioral split between the request-scoped and fallback branches of Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["toolLogger.error(message, context)"] --> B{getActiveAiRequestLogger}
B -- "requestLogger present" --> C["requestLogger.warn(message, ...)"]
B -- "no request context" --> D["log.error({...}) — unchanged"]
C --> E["Wide event stays at INFO/WARN\nJob-level logger.error catches real failures"]
D --> F["Emitted at ERROR level\n(background tasks, non-request paths)"]
style C fill:#ffd966
style D fill:#e06c75
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["toolLogger.error(message, context)"] --> B{getActiveAiRequestLogger}
B -- "requestLogger present" --> C["requestLogger.warn(message, ...)"]
B -- "no request context" --> D["log.error({...}) — unchanged"]
C --> E["Wide event stays at INFO/WARN\nJob-level logger.error catches real failures"]
D --> F["Emitted at ERROR level\n(background tasks, non-request paths)"]
style C fill:#ffd966
style D fill:#e06c75
|
Summary
Scheduled insights jobs were being logged at ERROR severity even when they completed successfully. The false-positive ERROR appeared whenever an AI tool call (e.g. a ClickHouse SQL query, an annotation create) failed inside the agent loop but the agent recovered and generated insights normally —
job_status: "succeeded",run_status: "succeeded",generation_status: "succeeded"all appear in the same log event as"level":"error".Evlog's wide event logger accumulates the highest severity seen within a request scope.
createToolLogger.error()was callingrequestLogger.error(err, {...})on the job's wide eventRequestLogger. Because the AI agent handles tool failures as normal tool-call results (the model receives the error and can try something else), these calls permanently tainted the job-level wide event to ERROR even on full success.The fix changes the
requestLoggercall insidecreateToolLogger.error()fromrequestLogger.error(err)torequestLogger.warn(message). All tool error details remain in thecontextpayload, and the fallbacklog.error()path (used outside any request context) is unchanged. The wide event for a fully successful job will now be emitted at INFO level, while genuinely failed jobs continue to reach ERROR through the job-levellogger.error(err)catch block injobs.ts.An alternative approach would be to add a separate
toolError()method tocreateToolLoggerand update each call site. The single-point fix in the logger is preferable because all AI tool errors share the same recovery semantics.Incident on Superlog
Was this PR helpful? Leave feedback — goes straight to the Superlog team.
Summary by cubic
Use warn level for tool-call failures within a request context so successful jobs no longer emit ERROR wide events. Error details remain in context; error-level logging outside a request context is unchanged.
requestLogger.error(...)torequestLogger.warn(...)increateToolLogger.log.error(...)behavior for non-request contexts.Written for commit 3247b33. Summary will update on new commits.