opencode-telegram-bot icon indicating copy to clipboard operation
opencode-telegram-bot copied to clipboard

[Bug]: status falsely deletes live daemon state due to second-resolution process start comparison

Open doctor-hlor opened this issue 3 weeks ago • 1 comments

What is broken?

opencode-telegram status can falsely classify a live daemon as stale, delete run/bot-service.json, and report stopped while the process is still alive. After that opencode-telegram stop is a no-op and opencode-telegram start can spawn a second daemon.

Steps to reproduce

  1. Start the daemon with opencode-telegram start --daemon --mode installed.
  2. The state file stores a millisecond timestamp, e.g.: "startedAt": "2026-11-11T03:20:39.620Z".
  3. ps -o lstart= -p <pid> returns the process start rounded to the next second: Wed Nov 11 03:20:40 2026.
  4. Run opencode-telegram status.
  5. Status logs a false stale-daemon warning, removes run/bot-service.json, and reports stopped.
  6. The process is still alive and is still the bot: /usr/bin/node /usr/local/share/npm-global/bin/opencode-telegram start --mode installed.
  7. opencode-telegram stop now reports "not running", while start may create a duplicate daemon.

OS

Linux

Additional context (optional)

Environment:

  • @grinev/opencode-telegram-bot 0.27.0
  • Node.js 24.22.2
  • Linux x86_64
  • Installed globally via npm, started with --daemon --mode installed

Likely regression from PR #190: https://github.com/grinev/opencode-telegram-bot/pull/190

getBotServiceStatus() in src/runtime/service/manager.ts does:

const processCreationTime = await getProcessCreationTime(service.pid);
const storedStartedAtMs = Date.parse(service.startedAt);

if (
  processCreationTime &&
  !Number.isNaN(storedStartedAtMs) &&
  processCreationTime.getTime() > storedStartedAtMs
) {
  // mark stale and delete bot-service.json
}

Observed log:

[2026-11-11T21:42:29.924Z] [WARN] [Manager] Stale daemon state detected: PID=1606 exists but was created at 2026-11-11T03:20:40.000Z (daemon started at 2026-11-11T03:20:39.620Z). The original process died and the PID was reused.
Removed stale daemon state file.
Service status: stopped

doctor-hlor avatar Nov 11 '26 23:11 doctor-hlor

fixed in https://github.com/grinev/opencode-telegram-bot/releases/tag/v0.28.0

grinev avatar Nov 15 '26 12:11 grinev