instar 0.23.0 → 0.23.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwPH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAy+BD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA0yEtE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwPH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA6gCD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA0yEtE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
@@ -723,6 +723,10 @@ function messageToPipeline(msg, topicName) {
723
723
  };
724
724
  }
725
725
  function wireTelegramRouting(telegram, sessionManager, quotaTracker, topicMemory, userManager, fixCommandHandler) {
726
+ // Guard: tracks which topic IDs have a spawn in progress.
727
+ // Prevents duplicate concurrent spawns for the same topic when messages
728
+ // arrive faster than the async spawn completes.
729
+ const spawningTopics = new Set();
726
730
  telegram.onTopicMessage = (msg) => {
727
731
  const topicId = msg.metadata?.messageThreadId ?? null;
728
732
  if (!topicId)
@@ -830,9 +834,26 @@ function wireTelegramRouting(telegram, sessionManager, quotaTracker, topicMemory
830
834
  }
831
835
  catch { /* classification failed — fall through to respawn */ }
832
836
  if (!isQuotaDeath) {
837
+ // Guard: skip respawn if one is already in progress for this topic.
838
+ // Prevents the infinite respawn loop: dead session + rapid messages → each
839
+ // message triggers a new respawn → multiple concurrent spawns → chaos.
840
+ if (spawningTopics.has(topicId)) {
841
+ console.log(`[telegram→session] Spawn already in progress for topic ${topicId} — skipping duplicate respawn`);
842
+ return;
843
+ }
844
+ spawningTopics.add(topicId);
833
845
  telegram.sendToTopic(topicId, `🔄 Session restarting — message queued.`).catch(() => { });
834
- respawnSessionForTopic(sessionManager, telegram, targetSession, topicId, text, topicMemory, resolvedUser ?? undefined).catch(err => {
846
+ respawnSessionForTopic(sessionManager, telegram, targetSession, topicId, text, topicMemory, resolvedUser ?? undefined)
847
+ .catch(err => {
835
848
  console.error(`[telegram→session] Respawn failed:`, err);
849
+ const errMsg = err instanceof Error ? err.message : String(err);
850
+ const userMsg = errMsg.includes('session limit') || errMsg.includes('limit')
851
+ ? `❌ Session restart failed — session limit reached. Close an existing session or increase maxSessions in your config, then try again.`
852
+ : `❌ Session restart failed. Try sending your message again in a moment.`;
853
+ telegram.sendToTopic(topicId, userMsg).catch(() => { });
854
+ })
855
+ .finally(() => {
856
+ spawningTopics.delete(topicId);
836
857
  });
837
858
  }
838
859
  }
@@ -841,7 +862,14 @@ function wireTelegramRouting(telegram, sessionManager, quotaTracker, topicMemory
841
862
  // No session mapped — auto-spawn with topic history (same as respawn path).
842
863
  // Without history, the agent has no conversational context and gives blind answers.
843
864
  console.log(`[telegram→session] No session for topic ${topicId}, auto-spawning with history...`);
865
+ // Guard: skip spawn if one is already in progress for this topic.
866
+ if (spawningTopics.has(topicId)) {
867
+ telegram.sendToTopic(topicId, `Session is still starting up — please wait a moment.`).catch(() => { });
868
+ console.log(`[telegram→session] Spawn already in progress for topic ${topicId} — skipping duplicate`);
869
+ return;
870
+ }
844
871
  const spawnName = storedTopicName || `topic-${topicId}`;
872
+ spawningTopics.add(topicId);
845
873
  // Use the shared spawn helper that includes topic history + user context
846
874
  spawnSessionForTopic(sessionManager, telegram, spawnName, topicId, text, topicMemory, resolvedUser ?? undefined).then((newSessionName) => {
847
875
  telegram.registerTopicSession(topicId, newSessionName, spawnName);
@@ -849,8 +877,13 @@ function wireTelegramRouting(telegram, sessionManager, quotaTracker, topicMemory
849
877
  console.log(`[telegram→session] Auto-spawned "${newSessionName}" for topic ${topicId}`);
850
878
  }).catch((err) => {
851
879
  console.error(`[telegram→session] Auto-spawn failed:`, err);
852
- console.error(`[telegram] Auto-spawn failed for topic ${topicId}:`, err);
853
- telegram.sendToTopic(topicId, 'Having trouble starting a session right now. Try sending your message again in a moment.').catch(() => { });
880
+ const errMsg = err instanceof Error ? err.message : String(err);
881
+ const userMsg = errMsg.includes('session limit') || errMsg.includes('limit')
882
+ ? `❌ Unable to start session — session limit reached. Close an existing session or increase maxSessions in your config, then try again.`
883
+ : 'Having trouble starting a session right now. Try sending your message again in a moment.';
884
+ telegram.sendToTopic(topicId, userMsg).catch(() => { });
885
+ }).finally(() => {
886
+ spawningTopics.delete(topicId);
854
887
  });
855
888
  }
856
889
  };