Skip to content

fix(logging): api 进程显式初始化应用日志,模型调用记录不再丢失 - #90

Merged
May18th merged 2 commits into
mainfrom
fix/app-logging-init-rebased
Oct 30, 2026
Merged

May18th merged 2 commits into
mainfrom
fix/app-logging-init-rebased

Conversation

@May18th

@May18th May18th commented Oct 30, 2026

Copy link
Copy Markdown
Owner

原提交 e77d749(分支 fix/app-logging-init)已 rebase 到 cc78737 后重推,内容未改,仅补了两处过期数据。

问题

uvicorn 的 --log-level 只作用于 uvicorn / uvicorn.error / uvicorn.access,既不设根 logger 级别也不装 handler。service.py 只写了 logging.getLogger("agent_attack_lab"),api 进程里所有 logger.info 被根 logger 默认的 WARNING 丢弃。

实测症状:同一战局 attacker 与 defender 各记 17 条 model_call_completed,api 记 0 条,而 4 轮全是 verificationMode=live、每轮靶标 1.7~2.5 秒——模型确实调用了,只是日志没落盘。根因是 agents/common.py 的 logging.basicConfig 副作用:attacker/defender 导入它时顺带打开了日志,api 没有等价调用。

改动

  • 新增 logging_setup.configure_logging():根 logger 无 handler 时装一个,把 agent_attack_lab 包 logger 调到 INFO,不动根级别(避免 httpx/openai 噪音)
  • service.py 与 agents/common.py 统一调用它,不再依赖导入副作用
  • tests/test_logging_setup.py 覆盖 6 种情形

本次 rebase 顺带校正(第二个 commit)

验证

合并会触发 backend/** 部署。部署后预期:三个服务的 journal 都能看到 model_call_completed / model_text_completed。

userName added 2 commits October 30, 2026 10:57
uvicorn's --log-level only configures its own loggers; it neither sets the root
logger level nor installs a root handler. service.py only fetched
logging.getLogger(agent_attack_lab) without configuring it, so every
logger.info record from the api process was dropped by the root logger default
of WARNING. attacker/defender did emit logs because importing agents.common
triggered logging.basicConfig as a side effect.

The result was a misleading split: for one battle, attacker and defender each
logged 17 model_call_completed lines while api logged none, even though all four
rounds ran with verificationMode=live and each target call took 1.7-2.5s.

Add logging_setup.configure_logging(): install a root handler when missing and
lift the agent_attack_lab package logger to INFO without touching the root
level, so httpx/openai INFO noise stays suppressed. Call it from service.py and
agents.common instead of relying on import side effects.
rebase 到 cc78737 后全量为 338 passed, 5 skipped(原文 332 是 #88 合并前的
过期基线);b585460 已不是当前 release,改成当时在跑的 release 以免误读。
@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
6fd57a3 2026-10-30T02:59:25.081Z View logs ↗

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying agent-attack-lab with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6fd57a3
Status: ✅  Deploy successful!
Preview URL: https://8ea518cb.agent-attack-lab.pages.dev
Branch Preview URL: https://fix-app-logging-init-rebased.agent-attack-lab.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-app-logging-init-rebased-agent-attack-lab.3498414260.workers.dev (commit 6fd57a3)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://7516aca0-agent-attack-lab.3498414260.workers.dev 6fd57a3 2026-10-30T03:00:09.693Z Visit the dashboard ↗

@May18th
May18th merged commit 1d0cf3f into main Oct 30, 2026
6 checks passed
May18th added a commit that referenced this pull request Oct 30, 2026
chore(diagnose): 增加三个服务的模型调用计数 [skip ci]

判断「模型是否被调用」以业务数据为准,这一步只回答「日志有没有落盘」。
logging 补修上线后,api 单元应同时出现 model_call_completed 与
model_text_completed(靶标),可用于直接核对。#90 之前在 api 恒为 0。

Co-authored-by: userName <userEmail>
@May18th
May18th deleted the fix/app-logging-init-rebased branch October 30, 2026 03:23
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