Skip to content

fix: reduce log noise and debug exposure#416

Merged
liujuanjuan1984 merged 2 commits intomainfrom
eval/415-log-level-audit
Apr 10, 2026
Merged

fix: reduce log noise and debug exposure#416
liujuanjuan1984 merged 2 commits intomainfrom
eval/415-log-level-audit

Conversation

@liujuanjuan1984
Copy link
Copy Markdown
Collaborator

@liujuanjuan1984 liujuanjuan1984 commented Apr 10, 2026

关联 issue

Closes #415

变更说明

执行链路

  • 将 unary OpenCode HTTP status 错误从默认 ERROR 堆栈调整为 WARNING,并仅在 DEBUG 级别附带堆栈信息。
  • 将 unary OpenCode timeout 错误从默认 ERROR 堆栈调整为 WARNING,并仅在 DEBUG 级别附带堆栈信息。
  • 将 upstream concurrency backpressure 的本地预算命中日志下调为 DEBUG,避免限流期间按请求刷默认 WARNING
  • 将 OpenCode response debug 日志中的响应正文替换为 text_len
  • 保留未知异常路径的 exception 记录,避免隐藏真正的运行时故障。

流式输出

  • 将可恢复的 OpenCode event stream retry 日志下调为 DEBUG,避免默认 WARNING 运行时输出重试堆栈噪音。
  • 将非前缀 snapshot rewrite 抑制日志下调为 DEBUG,保留调试可见性但不污染默认日志。
  • 将 stream chunk debug 日志中的内容文本替换为 content_len

服务请求处理

  • 将客户端断开连接导致的 producer task 取消日志从 WARNING 下调为 DEBUG,按正常控制流处理。
  • 将 executor request debug 日志中的用户输入正文替换为 text_len

文档与测试

  • 更新英文文档,明确 lightweight metric log records 需要 A2A_LOG_LEVEL=DEBUG
  • 补充日志级别相关测试,覆盖 stream retry、OpenCode HTTP status 错误、concurrency backpressure 以及 debug 日志不直接输出用户输入/响应正文。

验证

  • uv run pytest --no-cov tests/execution/test_metrics.py::test_streaming_retry_metric_increments_once_per_retry tests/execution/test_agent_errors.py::test_streaming_execute_http_error_emits_status_update_with_metadata tests/server/test_app_behaviors.py::test_normalize_log_level_configure_logging_and_main tests/server/test_transport_contract.py::test_normalize_log_level_falls_back_to_warning_for_invalid_value
  • uv run pytest --no-cov tests/execution/test_streaming_output_contract_logging.py::test_execute_debug_log_records_text_length_without_raw_user_text tests/execution/test_agent_errors.py::test_streaming_execute_upstream_backpressure_emits_status_update_with_metadata tests/upstream/test_opencode_upstream_client_params.py::test_send_message_raises_concurrency_limit_error_when_request_budget_exhausted
  • uv run ruff check src/opencode_a2a/execution/executor.py src/opencode_a2a/execution/coordinator.py src/opencode_a2a/execution/stream_runtime.py src/opencode_a2a/opencode_upstream_client.py tests/execution/test_streaming_output_contract_logging.py tests/execution/test_agent_errors.py tests/upstream/test_opencode_upstream_client_params.py
  • uv run ruff format --check src/opencode_a2a/execution/executor.py src/opencode_a2a/execution/coordinator.py src/opencode_a2a/execution/stream_runtime.py src/opencode_a2a/opencode_upstream_client.py tests/execution/test_streaming_output_contract_logging.py tests/execution/test_agent_errors.py tests/upstream/test_opencode_upstream_client_params.py
  • ./scripts/doctor.sh,571 项测试通过,覆盖率 91.65%。

@liujuanjuan1984
Copy link
Copy Markdown
Collaborator Author

PR 变更审查

审查范围:基于 origin/main...HEAD 审查 PR #416 引入的 1 个 commit:71fdfc5 fix: reduce default log noise

代码变动审查

未发现阻塞问题。

  • src/opencode_a2a/execution/coordinator.py:将已被映射为 A2A 任务错误的 OpenCode HTTP status / timeout 路径从默认 ERROR stack trace 收敛为 WARNING,并通过 logger.isEnabledFor(logging.DEBUG) 保留 debug-only 堆栈。这个分层合理:默认运行时仍能看到 upstream 失败摘要,调试时仍能拿到 traceback,未知异常路径仍保留 exception
  • src/opencode_a2a/execution/stream_runtime.py:stream retry 属于可恢复路径,下调到 DEBUG 后仍保留 retry metric;非前缀 snapshot rewrite 是兼容/防御性抑制路径,下调到 DEBUG 与降噪目标一致。
  • src/opencode_a2a/server/application.py:客户端断开导致 producer task cancel 属于正常控制流,下调到 DEBUG 合理,避免默认 WARNING 下误报。
  • tests/execution/test_agent_errors.pytests/execution/test_metrics.py:新增断言覆盖关键日志级别行为,能防止后续回退到默认高噪音输出。
  • docs/guide.md:文档补充 metric logs 需要 A2A_LOG_LEVEL=DEBUG,与现有 emit_metric 使用 logger.debug 的实现一致。

需求匹配审查

PR 与 issue #415 的目标一致:保持默认 A2A_LOG_LEVEL=WARNING,审查并下调开发期/可恢复路径的日志噪音,没有扩大 payload logging 暴露面,也没有移除必要的失败信号。

PR 标题与描述审查

  • 标题 fix: reduce default log noise 符合英文 commit message 风格,并与 commit 71fdfc5 对齐。
  • 描述已按模块用中文拆分执行链路、流式输出、服务请求处理、文档与测试。
  • Closes #415 关系准确:该 PR 直接完成 issue 审查并收敛默认日志输出噪音 #415 的日志默认噪音治理需求,不只是 related。

剩余风险

未发现当前实现的明显行为偏差。剩余风险主要是运维侧可能曾依赖客户端断开或 stream retry 的默认 WARNING 可见性;但这些事件属于正常/可恢复路径,且 DEBUG 仍保留诊断能力,符合本次降噪目标。

验证

  • uv run pytest --no-cov tests/execution/test_metrics.py::test_streaming_retry_metric_increments_once_per_retry tests/execution/test_agent_errors.py::test_streaming_execute_http_error_emits_status_update_with_metadata tests/server/test_app_behaviors.py::test_normalize_log_level_configure_logging_and_main tests/server/test_transport_contract.py::test_normalize_log_level_falls_back_to_warning_for_invalid_value 通过。
  • ./scripts/doctor.sh 通过,570 项测试通过,覆盖率 91.65%。

@liujuanjuan1984 liujuanjuan1984 changed the title fix: reduce default log noise fix: reduce log noise and debug exposure Apr 10, 2026
@liujuanjuan1984
Copy link
Copy Markdown
Collaborator Author

第二轮日志审查更新

基于当前分支继续审查剩余日志后,追加提交:

  • 7da5588 fix: tighten debug log exposure

本轮结论

未发现需要继续下调的默认可见 WARNING / exception 路径。保留项主要是 upstream contract mismatch、未知异常、task store 失败、取消 abort 失败、请求体过大、数据库 terminal persistence 冲突和持久化能力降级;这些都属于真实失败、配置降级、安全/一致性信号,默认可见是合理的。

本轮调整

  • 将 concurrency backpressure 的本地预算命中日志从 WARNING 下调为 DEBUG,避免限流期间按请求刷默认日志;错误响应和 metadata 仍保留 UPSTREAM_BACKPRESSURE
  • 将 executor request debug 日志中的原始 user_text 替换为 text_len
  • 将 OpenCode response debug 日志中的响应正文替换为 text_len
  • 将 stream chunk debug 日志中的内容文本替换为 content_len
  • 补充测试确认 debug 日志不直接输出用户输入/响应正文,并确认 backpressure 日志级别为 DEBUG

保留说明

  • A2A_LOG_PAYLOADS 控制的 payload debug 日志保持 opt-in 语义。
  • OpenCode stream event debug payload 日志保持现有文档语义,并继续依赖现有 redaction/truncation 机制;本轮只收敛非 payload-log 路径的正文暴露。

验证

  • uv run pytest --no-cov tests/execution/test_streaming_output_contract_logging.py::test_execute_debug_log_records_text_length_without_raw_user_text tests/execution/test_agent_errors.py::test_streaming_execute_upstream_backpressure_emits_status_update_with_metadata tests/upstream/test_opencode_upstream_client_params.py::test_send_message_raises_concurrency_limit_error_when_request_budget_exhausted 通过。
  • uv run ruff check ... 通过。
  • uv run ruff format --check ... 通过。
  • ./scripts/doctor.sh 通过,571 项测试通过,覆盖率 91.65%。

@liujuanjuan1984 liujuanjuan1984 marked this pull request as ready for review April 10, 2026 09:21
@liujuanjuan1984 liujuanjuan1984 merged commit be19c73 into main Apr 10, 2026
3 checks passed
@liujuanjuan1984 liujuanjuan1984 deleted the eval/415-log-level-audit branch April 10, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

审查并收敛默认日志输出噪音

1 participant