fix(wiki-export): 启动期以进度与统计取代逐条 blob 日志刷屏; - #1119
Merged
Merged
Conversation
启动期 Wiki 内容同步(cli.sh → sync-wiki-content.sh → export_wiki_content.py) 实测输出 412 行,其中 403 行为 blob_download_completed,把仅有的汇总行淹没。 根因为两层,只修一层无效: 1. postgres_client 对每次 blob 读取打 INFO——这是 per-IO trace 而非业务事件; 2. export_wiki_content.py 从未调用 configure_logging,也不经 engine.bootstrap, structlog 停留在出厂默认(不过滤 DEBUG + stock 渲染器,故 _name 键泄漏、 格式与后端不一致),NE_LOG_LEVEL 对该脚本完全失效——仅降级日志不会少一行。 变更: - postgres_client: blob_download_completed / blob_download_range_completed 降为 debug(读是 trace);upload / delete 保持 info(写是审计事件),error 分支不动; - 新增 scripts/_logging.py::configure_script_logging(),把 settings.log_* 映射到 项目唯一日志入口,不 import 重型 engine 包;export_wiki_content.py 在重型 import 之前调用(顺序即正确性),并将末尾 print 汇总改为结构化事件; - wiki_export_service: 补 started / publication / progress 日志,进度按 step=max(1, total//10) 节流,每 publication 恒定约 10 行,输出量与语料规模解耦; - 修正 wiki_export_done 的 publications 口径:len(pubs) 漏计注入的 docs pack, 致同一次运行日志报 1 而 CLI 汇总报 2,改用 len(result.publications)。 验证:实跑 sync-wiki-content.sh,日志 412 → 18 行、blob 行 403 → 0、_name 泄漏 0; NE_LOG_LEVEL=DEBUG 下 403 行明细可完整取回(未删除,仅门控);产物零回归—— 547 文件 / 403 assets 与改前逐字节一致,diff 仅 index.json 的 generated_at 不同; 新增回归用例(capture_logs 断言进度有界 + publications 计数),改前失败改后通过; knowledge 单测与 storage 集成测试 1086 passed。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
…为静默失败; 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
cli.sh→sync-wiki-content.sh→export_wiki_content.py)实测输出 412 行,其中 403 行是blob_download_completed,把仅有的汇总行彻底淹没,用户只想看到「执行进度 + 统计结果」。postgres_client对每次 blob 读取打 INFO —— 这是 per-IO trace 而非业务事件;export_wiki_content.py从未调用configure_logging,也不经engine.bootstrap(全仓唯一在 import 期配置日志之处),structlog 停留在出厂默认:make_filtering_bound_logger(NOTSET)不过滤 DEBUG + stockConsoleRenderer。故NE_LOG_LEVEL对该脚本此前完全失效,仅降级日志一行都不会少。_name=negentropy.storage.postgres键泄漏(项目的add_logger_name处理器本会 pop 掉它),以及logging.level: INFO配置下仍打印的[debug] disposer_registered。logging/core.py(configure_logging唯一入口)、engine/bootstrap.py(唯一既有调用点)。核心变更
postgres_client.py的blob_download_completed与blob_download_range_completed由 info 改 debug(后者是 PDF 阅读器每次 Range 请求刷一行,为后端运行期最高频同类噪音)。语义分界:读是 trace,写是审计事件 ——blob_upload_completed/blob_delete_completed与全部 error 分支保持不变。scripts/_logging.py::configure_script_logging(),把settings.log_*映射到项目唯一日志入口,不 import 重型 engine 包(避免拉起 ADK/LiteLLM 副作用)。export_wiki_content.py在重型 import 之前调用(顺序即正确性:db_session等在 import 期即打disposer_registered),并将末尾print汇总改为结构化事件(configure_logging会以StreamToLogger接管sys.stdout,顺应该设计而非与之对抗)。wiki_export_service增加wiki_export_started/wiki_export_publication/wiki_export_progress,进度按step = max(1, total // 10)节流并强制在末条发一次 —— 每 publication 恒定约 10 行,输出量与语料规模解耦。原continue改写为else分支以保证进度不被跳过(语义等价)。wiki_export_done原用len(pubs),漏计注入的合成 docs publication,导致同一次运行日志报publications=1而 CLI 汇总报2;改用len(result.publications),与to_dict()对齐。风险与回滚
NE_LOG_LEVEL=DEBUG可完整取回;且全仓核实这两个事件零测试、零文档、零看板引用(各仅 1 处定义)。configure_logging会重置 root logger、拦截三方 logger 并接管 stdout/stderr —— 短命 CLI 中均为预期行为;run_script的print("Error: ...", file=sys.stderr)会变成日志行,仍可见,且cli.sh依赖的是退出码而非该文本,行为不变。scripts/*.py未改动,_logging.py仅为其留好接入口。git revert即可完整回退;无 DB 迁移、无配置变更、无接口契约变更。验证证据
test_progress_bounded_and_summary_counts_docs_pack,复用既有免 DB 夹具 +structlog.testing.capture_logs,断言 ①进度日志有界(50 entry → 10 条)②末条覆盖最后一个 entry ③publications == 2。已实测改前失败(assert 1 == 2)、改后通过。tests/unit_tests/knowledge+tests/integration_tests/storage全量 1086 passed;pre-commit(ruff lint + format 等)全绿。bash scripts/sync-wiki-content.sh—— 日志 412 → 18 行、blob_download_completed403 → 0、_name=泄漏 0,格式已与后端一致:NE_LOG_LEVEL=DEBUG下 403 行明细完整取回 —— 同时证明该环境变量对此脚本终于生效。diff -r—— 547 文件 / 403 assets 逐字节一致,唯一差异是index.json的generated_at时间戳。影响范围
storage/postgres_client.py(2 行日志级别)、knowledge/lifecycle/wiki_export_service.py(进度日志 + 统计口径)。PDF 预览 Range 端点的逐请求 INFO 一并降噪。wiki-content-export.yml走bake_assets=false的 URL 重写分支,本就无 blob 日志,仅受益于格式统一;publish-wiki-pages.sh/build-wiki-local.sh调用同一脚本,一处改动覆盖三条噪音路径,无需另改。Next Best Action
apps/negentropy/scripts/*.py仍是「出厂默认 structlog」状态(同样NE_LOG_LEVEL失效、_name=泄漏),_logging.py已留好接入口,可另开 PR 统一接入。docs/.agents/,避免后续新增存储后端时重蹈逐条 IO 打 INFO。🤖 Generated with Claude Code