fix(serial-assistant): daemon 重启自动重开口 + 自动重连 + 日志缺口标记(#75) #76
Reference in New Issue
Block a user
Delete Branch "improve-serial-assistant-8e959e85113d"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is by an automated agent, not a human.
问题摘要(Gitea issue #75)
serial-assistant 采集层的 daemon 一旦崩溃/被杀/读错丢口,旧行为是「新实例起得来但口不开、serial.log 静默追加无边界、wait-idle 计满还良性返回 no_data」——采集静默停摆,且读日志方无法区分「板子安静」与「采集器死」。用户批示「按照你的建议进行修复测试」,本 PR 按工单登记的 R1–R5 实施,不扩面。
改动对照 R1–R5
.dsh/skills/serial-assistant/scripts/serial_tool.py)meta.json的port字段升格为「开口意图」现场(_save_meta写_open_identity(),缺口期不清空;显式close//stop清除)。run()先读旧 meta 再覆写(旧实现覆写在前、现场即被抹成 null = 根因);重开在串口线程内执行(串口对象唯一持有者不变量),首次 = 出生 +1.5s。restart特判:cmd_start(force)在POST /stop前抓/status现场、新 daemon 就绪后POST /open开回来(stop语义不变,结果进返回 JSON 的reopen键)_port_error后退避重试:1.5s 起步、倍增、30s 封顶,直到成功或显式 close;逐次失败原文进 daemon.log(dlog=stderr),不刷 serial.log[SYS]行四种:daemon started v… pid=… prev_pid=… auto-reopen pending …(启动边界)/GAP-START(丢口与崩溃恢复两种,后者声明窗口起点下限)/GAP-END reopened … after Ss, N attempt(s); bytes … unrecoverable(缺口止)/GAP-RETRY(退避期仅首次 + 之后每分钟 ≤1 条,口径定死写入设计说明 §6.1)status新增auto_reopen={enabled,pending,attempts,last_error,next_retry_in_ms};port新增desired(意图)与ready(实际)并列,缺口期 name/baud 显示待重开参数;wait-idle入口加无口门:口未开秒回ok:false+ auto-reopen 现场,不再计满返回良性no_dataVERSION=1.2.0-skill;selftest 新增 T10–T15(重开意图判定含 close 后不重开/崩溃现场重开、退避倍增封顶、缺口行格式、无口门、auto_reopen 三态、restart 捕获),合计 45 项;SKILL.md(4713B)、使用指南(行为+新字段示例)、设计说明(§6.1 机理单一详述处 + §13 版本记录)同步兼容性:JSON 只增字段、退出码形状不变(0/1/2/3)。
run_boot_test.py正常路径(open→clear→wait-idle)不受影响;其 wait-idle 撞无口时按采集错误 exit 2 归因而非「板子静默」——正是工单要的区分。验证证据
selftest45/45 PASS(.venvPython 3.14.7,exit 0);文件无 BOM、LF、无 U+FFFD。open→taskkill /F→10s 后任意 CLI 自动拉起→port.ready=true、desired=true;serial.log 依次出现daemon started … prev_pid=<旧pid> auto-reopen pending COM3@115200+GAP-START after daemon restart …+GAP-END reopened COM3@115200 (gen=1) after 1.5s, 1 attempt(s);期间板上[PROF]流真实恢复。close→restart→不自动重开(ready=false、desired=false、auto_reopen.enabled=false、返回 JSON 无reopen键)。ok:false、0.1s 秒回(非no_data),error 带 auto-reopen 现场。restart返回reopen.requested.port=COM3且reopen.result.ok=true,重启后口就绪。--no-verify。遗留风险
[SYS]行为英文(serial.log 行内文本与既有 error/opened 行同口径,避免混编码);机理/口径全文在docs/测试说明/测试工具/串口助手设计说明.md§6.1。close即停)。[PROF]流),测试只做开关口/杀 daemon,未烧录未碰板。Fixes #75
This is by an automated agent, not a human.
CI 归因:远程「静态门禁 (pre-commit)」与「主机侧单测 (MSVC)」两个 push 任务在本 PR head
dfd1528上为 failure,但同样在 master 当前尖f8c9296(#74 合并提交)上 failure——属 runner 环境既有问题,与本 PR 的 4 个文件(serial-assistant skill + 两份文档 + SKILL.md,无固件)无关;pull_request 形态的「主机侧单测 (MSVC)」在本 head 上为 success。提交期本地门禁 49 根全部 Passed(含 gitlint / doc-links / skill-size / no-mojibake)。