Skip to content

emrg: daemon start timeout shows emrgd.log tail (real error, not generic message) - #403

Merged
argszero merged 2 commits into
masterfrom
feature/daemon-log-tail
Aug 5, 2026
Merged

emrg: daemon start timeout shows emrgd.log tail (real error, not generic message)#403
argszero merged 2 commits into
masterfrom
feature/daemon-log-tail

Conversation

@argszero

@argszero argszero commented Aug 5, 2026

Copy link
Copy Markdown
Owner

背景

rant 2026-08-05T15:54:28 【关联】部分:config.toml 解析错误(如 vision = trues)导致 daemon 启动失败时,CLI 只显示 failed to start within timeout,吞掉真实报错(daemon 的 stderr 被 DEVNULL 丢弃),用户无法诊断根因。

修复

emrg/client/daemon_manager.py

  • start_daemon() 超时后读取 ~/.emrg/emrgd.log 尾部 15 行,拼接到 RuntimeError 消息
  • 新增 _read_log_tail(path, lines) helper:utf-8 errors=replace,文件缺失/读取失败返回空串(不影响原有行为)
RuntimeError: emrgd failed to start within timeout
  emrgd.log 尾部:
  <真实错误堆栈>

验证

  • 466 passed + import OK + emrg --help OK
  • _read_log_tail 单测:正常尾部截取(line2/line3)、缺失文件返回空串

关联

Windows TUI rant(#401)的独立优化项;daemon 日志本就存在(emrg/server/main.py RotatingFileHandler → ~/.emrg/emrgd.log),CLI 端只是没读它。

…ric message)

rant 2026-08-05T15:54:28 关联:config.toml 解析错误(如 vision = trues)时
daemon 启动失败,但 CLI 只显示 "failed to start within timeout",吞掉真实报错
(stderr 被 DEVNULL 丢弃),用户无法诊断。

修复:start_daemon 超时后读取 ~/.emrg/emrgd.log 尾部 15 行(R124),
拼接到 RuntimeError 消息中。新增 _read_log_tail helper(utf-8 errors=replace,
文件缺失/读取失败返回空串,不影响原有行为)。

验证:466 passed + import OK + --help OK + _read_log_tail 单测
(正常尾部截取 / 缺失文件返回空)。

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle 20260805-1626. 第 1 个 LGTM。修复契合 rant 15:54:28 关联项:daemon stderr 被 DEVNULL 丢弃,超时只显示通用消息。实现最小化:_read_log_tail(utf-8 errors=replace + 缺失返回空)+ 超时路径拼接尾部 15 行。不影响正常启动路径(仅超时分支)。466 passed + import OK + _read_log_tail 单测(尾部截取/缺失空串)通过。

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

技术反馈(测试补充建议):本 PR 与刚关闭的 #404 同源(并发实例各自实现同一 rant 关联项)。#403 实现简洁正确(_read_log_tail 15 行 + 多行格式,best-effort 空串兜底)。建议补充 3 个单元测试以覆盖关键路径(#404 已写好,可参考):

  1. 超时错误包含日志尾部:mock is_running=False + create_subprocess_exec,临时 HOME 写 emrgd.log 含 'vision = trues',断言 RuntimeError 含该文本
  2. 无日志文件:_read_log_tail 返回空串
  3. 只读尾部:30 行日志 max_lines=5,旧行不出现

测试要点:patch 'emrg.client.daemon_manager.Path.home' 指向临时目录(模块级 Path 绑定),asyncio.run 内断言。

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle 20260805-1628. 第 2 个 LGTM。独立验证:① checkout 后 _read_log_tail 行为正确(尾部 5 行、旧行排除、缺失文件返回空串);② 现有 21 个 daemon_manager 测试全过;③ CI test pass 32s;④ 多行格式(emrgd.log 尾部: + 缩进)比单行拼接更可读。测试补充建议已附(可选,非阻塞——无测试的 best-effort 工具函数风险可控,但建议 merge 前或后续补上)。

…ics)

补充技术反馈建议的 3 类测试:
1. tail 截取最后 N 行(30 行 → 取 5)
2. 缺失文件返回空串
3. 文件短于 lines 返回全部 + 非法 UTF-8 用 replacement 字符

25 passed(原 21 + 新增 4)。

@argszero argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle 20260805-1629. 第 3 个 LGTM。技术反馈建议的单元测试已补充(a249e95):TestReadLogTail 4 个用例(尾部截取/缺失空串/短文件全量/非法 UTF-8 replacement)→ 25 passed(原 21+新 4),全量 470 passed。实现保持最小化(_read_log_tail best-effort + 超时拼接)。LGTM 3/3,满足合并条件。

@argszero
argszero merged commit f5c2bfa into master Aug 5, 2026
1 check passed
@argszero
argszero deleted the feature/daemon-log-tail branch August 5, 2026 08:36
argszero added a commit that referenced this pull request Aug 5, 2026
* emrg: bump v0.2.3 — Windows 修复集打版(#399 卸载彻底 + #401 TUI + #403 真实报错)

rant 2026-08-05T17:26:40:master 已合入 6 个 Windows 相关修复但未打 tag,
Windows 用户仍在使用旧安装包。本次 bump 0.2.2 → 0.2.3 并推 tag 触发发布链:
- #399 卸载彻底(kill GUI + whitelist + [UninstallDelete])
- #400 Inno WPARAM/LPARAM → DWORD
- #401 Windows TUI 适配(Win32Console + stdin/resize 线程化)
- #402 Inno 嵌套花括号注释
- #403 daemon start timeout 显示 emrgd.log 尾部真实报错
- #405 README 同步

版本文件 4 处同步:pyproject.toml / __init__.py / make-installer.sh / build-runtime.sh

* emrg: sync uv.lock to 0.2.3

---------

Co-authored-by: EMRG Evolution <emrg@argszero.dev>
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