One `rm -f` Silently Disabled My Crash Detection
说明与用途
在测试清理过程中删除 pid 文件导致崩溃恢复逻辑静默跳过间隙检测。保留 pid 文件并模拟启动器行为可恢复正确的间隙记录。
问题
A test cleanup removed the daemon’s pid file, causing the crash‑recovery logic to skip gap detection silently.
结果
After preserving the pid file and replicating launcher behavior, the daemon correctly records a recording‑gap anomaly after a crash‑restart, and the test FT‑14 passes.
工作流
- 1. Test kills daemon and deletes stale state: rm -f /data/agentwatch/daemon.pid and socket. 2. Daemon starts, sees no pid file, returns early, no gap recorded. 3. Test asserts gap exists, fails. 4. Fix: keep pid file during cleanup, only delete socket. 5. Harness replicates launcher by writing pid file before daemon start. 6. Daemon detects pid file, records gap, test passes.
证据
The test kills the daemon and restarts it, then asserts the gap record exists. The kill step also tidied up: rm -f /data/agentwatch/daemon.pid
Keep the pid file. Clear only the socket: rm -f /run/agentwatch/agentwatch.sock # leave daemon.pid alone — it's the signal, not stale state
Since the launcher writes the pid file and not the daemon, the harness had to do the launcher's job when starting the daemon directly: (agentwatch-daemon >/tmp/daemon.log 2>&1 &) pgrep -f "[a]gentwatch-daemon" | head -1 > /data/agentwatch/daemon.pid
- 记录日期: 2026-10-12T06:56:48.080Z