Skip to content

fix: Replace console.error with structured logging in emitEventToSinks #140

Closed

Description

@minorcell

问题描述

session_runtime_helpers.ts:120-128 中的 emitEventToSinks 函数在生产代码中使用 console.error:

export async function emitEventToSinks(event: HistoryEvent, sinks: HistorySink[]) {
    for (const sink of sinks) {
        try {
            await sink.append(event)
        } catch (err) {
            console.error(`Failed to write history event: ${(err as Error).message}`)
        }
    }
}

问题:

  1. 生产环境错误日志:在关键路径(历史事件写入)失败时只记录到 console,可能导致重要数据丢失不被注意
  2. 错误信息泄露:console.error 可能输出敏感信息到日志
  3. 缺乏重试机制:写入失败后没有重试逻辑

建议修复

  1. 使用结构化日志系统(如 pino)
  2. 添加错误回调或通知机制
  3. 考虑实现重试逻辑
  4. 在关键错误时提供更详细的上下文

Activity

  1. minorcell commented on Feb 11, 2026

    @minorcell
    OwnerAuthor

    Fixed in commit f7e4056.

    Changes:

    • Replaced console.error in emitEventToSinks with structured JSON logging to stderr.
    • Added structured fields: level, event, sink, and message.
    • Added a unit test that simulates sink write failure and validates the emitted JSON log payload.

    Validation:

    • pnpm test packages/core/src/runtime/session_runtime_helpers.test.ts
  2. minorcell commented on Feb 11, 2026

    @minorcell
    OwnerAuthor

    Closing as fixed by f7e4056.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolsBuilt-in tools and tool runtimeneeds-triageIssue needs initial triage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions