Skip to content

fix: restart when Telegram polling stops#254

Merged
0xmrpeter merged 2 commits into
Open-ACP:mainfrom
civonafets:fix/telegram-poller-supervision
May 9, 2026
Merged

fix: restart when Telegram polling stops#254
0xmrpeter merged 2 commits into
Open-ACP:mainfrom
civonafets:fix/telegram-poller-supervision

Conversation

@civonafets
Copy link
Copy Markdown
Contributor

Telegram long polling can stop after the grammY polling promise rejects. The process can stay alive, but no new Telegram messages are consumed.

This change supervises the polling promise. If it rejects during normal runtime, OpenACP requests the normal restart path. During shutdown it does nothing, so stop and restart do not loop. If no restart hook is available, it exits so an external supervisor can start it again.

Also fixes one CLI test mock so the full test suite is isolated from the local daemon state.

Tests:

  • pnpm test
  • tsc --noEmit

@0xmrpeter 0xmrpeter merged commit 269d8d2 into Open-ACP:main May 9, 2026
4 checks passed
@0xmrpeter
Copy link
Copy Markdown
Contributor

Thanks for this fix, @civonafets! This is a real production issue — a silently dead polling loop is exactly the kind of failure that's hard to diagnose, and the supervision approach here is the right call.

Merged and then added a few follow-up improvements on top:

  • Race condition fix: _stopping is now re-checked inside both setImmediate callbacks, so a stop() call that arrives after the .catch() handler fires but before the deferred restart runs will correctly suppress the restart/exit.
  • Removed unused _pollingPromise field: the .catch() chain handles recovery without needing to hold the reference, and the comment was slightly misleading (after .catch(), the promise can no longer reject).
  • Simplified error unwrapping: the nested 3-level ternary for rootCause was hard to read — flattened it to two clean lines.
  • Added two more tests: one for the process.exit(1) fallback path (no restart hook available), and one that verifies the shutdown race condition — polling fails + immediate stop() should not trigger a restart.

Great contribution overall, solid test coverage from the start. 🙌

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.

3 participants