echoclaw-relay-agent 0.9.4 → 0.9.6

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.
@@ -37,6 +37,8 @@ const RUN_TTL_MS = 10 * 60 * 1000;
37
37
  const RUN_CLEANUP_INTERVAL_MS = 60 * 1000;
38
38
  /** Max buffered messages when sendBack is null (relay disconnected). */
39
39
  const MAX_BUFFERED_MESSAGES = 50;
40
+ /** Timeout for a single _sendBack call to prevent queue freeze (5 seconds). */
41
+ const SEND_TIMEOUT_MS = 5000;
40
42
  // ── ChatHandler ──────────────────────────────────────────────────
41
43
  export class ChatHandler {
42
44
  constructor(config) {
@@ -590,9 +592,21 @@ export class ChatHandler {
590
592
  }
591
593
  _enqueueSend(msg) {
592
594
  const p = this._sendQueue.then(async () => {
593
- if (this._sendBack) {
594
- await this._sendBack(msg);
595
+ if (!this._sendBack) {
596
+ // sendBack was cleared (relay disconnected) while message was queued.
597
+ // Re-buffer important messages to avoid permanent loss.
598
+ if (msg.type === 'chat_reply' || msg.type === 'chat_delta' || msg.type === 'chat_error') {
599
+ if (this._messageBuffer.length < MAX_BUFFERED_MESSAGES) {
600
+ this._messageBuffer.push(msg);
601
+ }
602
+ }
603
+ return;
595
604
  }
605
+ // Timeout protection: prevent a single hung _sendBack from freezing the entire queue.
606
+ await Promise.race([
607
+ this._sendBack(msg),
608
+ new Promise((_, reject) => setTimeout(() => reject(new Error('send timeout')), SEND_TIMEOUT_MS)),
609
+ ]);
596
610
  }).catch(() => { });
597
611
  this._sendQueue = p;
598
612
  return p;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoclaw-relay-agent",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "description": "EchoClaw Relay Connection — E2E encrypted relay transport, pairing, and session management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",