fix+observability: 修复部署失败 + 日志落盘 + explain 全链路打点#60
Merged
Conversation
TranslateResult.vue 与 tokenize.spec.js 引用了
frontend/src/components/translate/tokenize.js,但该文件未提交,
导致 Rollup 解析失败 → Vite 构建中断 → 部署无产物。
按 docs/superpowers/specs/2026-05-19-translate-deepl-redesign-design.md
§4.3 实现:CJK 逐字 + 英文词(含 don't / well-known)+ 空白/标点
逐字符 token。每个 token 输出 {kind, text, interactive, index},
与 __tests__/tokenize.spec.js 的字段断言对齐(11 测试全过)。
space / punct 显式 interactive=false,便于父容器事件委托快速过滤。
1) 日志落盘(app/logger.py)
- StreamHandler 旁路加 RotatingFileHandler(默认 10MB×5 轮转)
- 通过 LOG_DIR / LOG_FILE / LOG_TO_FILE 等 env 配置
- 目录创建失败时降级为仅 stdout,不阻断启动
- Dockerfile 创建 /app/logs;docker-compose 挂 logs volume 并设 LOG_DIR=/app/logs
- .gitignore 加 logs/,避免 dev 日志污染仓库
2) explain 链路盲区打点(app/services/explain_service.py)
- 入口 / cache HIT|MISS / prompt 拼装大小 / LLM 耗时
/ JSON 解析 / cache 写入 / 总耗时 + LLM 占比
- explain_text 与 stream_sentence_explanation 同步覆盖
- 之前线上看 "tease 解读慢" 完全黑盒,现在能直接定位是 LLM
慢、cache 没命中、还是 prompt 太大(liaison KB 占比)
3) 移除 Fly.io 残留(部署已切到 VPS + docker-compose + Caddy)
- 删除 fly.toml
- .dockerignore / .omc 规划文档 / docs/decisions 同步更新
- 历史决策文档保留 "已迁出" 说明,便于回溯
3 tasks
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.
Summary
围绕「为什么 tease 解读这么慢 + 部署起不来 + 服务器看不到日志」三个问题的一次性修复:
frontend/src/components/translate/tokenize.js(PR2 计划的分词工具,spec 测试与引用早已合入,但实现文件漏推 → Rollup 解析失败 → Vite 构建中断 → 镜像无产物)。11 个 vitest 测试全过、npm run build成功。app/logger.py加RotatingFileHandler(默认 10MB×5 轮转),stdout 不动;LOG_DIR等 env 可配;Dockerfile/docker-compose/.gitignore 同步调整,容器日志挂到/app/logs。app/services/explain_service.py在入口 / cache HIT|MISS / prompt 拼装大小 / LLM 耗时 / JSON 解析 / 总耗时 + LLM 占比 等关键节点加 logger.info/debug。stream_sentence_explanation同步覆盖。fly.toml,.dockerignore与.omc / docs/decisions里的指引同步更新成 VPS + docker-compose + Caddy。改动文件
frontend/src/components/translate/tokenize.jsapp/logger.pyapp/services/explain_service.py_get_user_level/_cache_get/_cache_set/explain_text/stream_sentence_explanation全链路 timing 打点Dockerfile/app/logs/app/datadocker-compose.ymllogs:/javarun/logs→logs:/app/logs,加LOG_DIRenv.gitignorelogs/.dockerignorefly.tomlfly.toml.omc/specs/* .omc/plans/* docs/decisions/*一次解读请求会留下的日志样例
下次再有人反馈「某个词解读慢」,直接
docker compose exec dev-web tail -f /app/logs/app.log就能立刻定位是 LLM 慢、cache 没命中、还是 prompt 太大。Test plan
cd frontend && npx vitest run— tokenize.spec.js 11/11 通过cd frontend && npm run build— Vite + PWA precache 构建成功,无Could not resolvepytest tests/test_v05_explain.py tests/test_v011_explain_refresh.py tests/test_v011_liaison_kb.py tests/test_v08_explain_autosave.py tests/test_v08_explain_stream_autosave.py tests/test_llm_logger.py— 42 通过;2 预先存在的 FakeClient mock 失败(stash 前同样失败,与本 PR 无关)python -c "from main import app"干净启动,104 路由logs/app.log真实写入完整链路日志grep -i fly已无指引性残留(仅保留 3 处「已迁出」历史标注)docker compose exec dev-web ls /app/logs && tail -n 50 /app/logs/app.logGenerated by Claude Code