polygram 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/polygram.js +20 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polygram",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Telegram daemon for Claude Code that preserves the OpenClaw per-chat session model. Migration path for OpenClaw users moving to Claude Code.",
|
|
5
5
|
"main": "lib/ipc-client.js",
|
|
6
6
|
"bin": {
|
package/polygram.js
CHANGED
|
@@ -571,6 +571,17 @@ async function sendToProcess(sessionKey, prompt, context = {}) {
|
|
|
571
571
|
const CONCURRENT_WARN_THRESHOLD = 20;
|
|
572
572
|
const inFlightHandlers = new Map(); // sessionKey → count
|
|
573
573
|
|
|
574
|
+
// Set true by the SIGTERM/SIGINT handler. Module-scoped so the
|
|
575
|
+
// fire-and-forget catch in dispatchHandleMessage can check it: when
|
|
576
|
+
// polygram is going down, in-flight handlers reject with "Process
|
|
577
|
+
// killed" / "Process exited" but those failures aren't "real" — the
|
|
578
|
+
// next boot's replay will re-dispatch them. Suppressing the user-facing
|
|
579
|
+
// "Sorry, I couldn't process" during shutdown removes a misleading
|
|
580
|
+
// post-mortem apology that the user shouldn't have seen in the first
|
|
581
|
+
// place. (The boot replay's own _isReplay flag handles the OTHER half:
|
|
582
|
+
// suppressing the apology if the replay itself fails.)
|
|
583
|
+
let isShuttingDown = false;
|
|
584
|
+
|
|
574
585
|
// Sessions the operator just /stop'd (or natural-language "стоп"). Keyed
|
|
575
586
|
// by sessionKey → timestamp of abort. ANY pending that rejects within
|
|
576
587
|
// ABORT_GRACE_MS of the mark is considered abort-caused — its generic
|
|
@@ -627,11 +638,13 @@ function dispatchHandleMessage(sessionKey, chatId, msg, bot) {
|
|
|
627
638
|
aborted: wasAborted || undefined,
|
|
628
639
|
replay: isReplay || undefined,
|
|
629
640
|
}), 'log handler-error');
|
|
630
|
-
// Suppress the "Sorry, I couldn't process" reply when
|
|
631
|
-
// boot replay
|
|
632
|
-
//
|
|
633
|
-
//
|
|
634
|
-
|
|
641
|
+
// Suppress the "Sorry, I couldn't process" reply when:
|
|
642
|
+
// - boot replay (user typed this minutes ago and moved on)
|
|
643
|
+
// - polygram is shutting down (the failure is "Process killed" /
|
|
644
|
+
// "Process exited" which isn't a real error — boot replay will
|
|
645
|
+
// re-dispatch it on next start)
|
|
646
|
+
// - user just /stop'd (already saw their abort acknowledgement)
|
|
647
|
+
if (!wasAborted && !isReplay && !isShuttingDown) {
|
|
635
648
|
tg(bot, 'sendMessage', {
|
|
636
649
|
chat_id: chatId,
|
|
637
650
|
text: `Sorry, I couldn't process that message. The operator has been notified.`,
|
|
@@ -2157,10 +2170,9 @@ async function main() {
|
|
|
2157
2170
|
// replay picks it up. Prevents "Sorry, I couldn't process that message"
|
|
2158
2171
|
// from showing on every restart.
|
|
2159
2172
|
const SHUTDOWN_DRAIN_MS = 30_000;
|
|
2160
|
-
let shuttingDown = false;
|
|
2161
2173
|
const shutdown = async () => {
|
|
2162
|
-
if (
|
|
2163
|
-
|
|
2174
|
+
if (isShuttingDown) return;
|
|
2175
|
+
isShuttingDown = true;
|
|
2164
2176
|
console.log('\nShutting down...');
|
|
2165
2177
|
// 1. Stop accepting new inbound first so nothing new queues behind the drain.
|
|
2166
2178
|
if (bot && bot._stop) bot._stop();
|