mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-29 16:54:30 +00:00
* fix(gateway): increase WS handshake timeout from 3s to 10s The 3-second default is too aggressive when the event loop is under load (concurrent sessions, compaction, agent turns), causing spurious 'gateway closed (1000)' errors on CLI commands like `openclaw cron list`. Changes: - Increase DEFAULT_HANDSHAKE_TIMEOUT_MS from 3_000 to 10_000 - Add OPENCLAW_HANDSHAKE_TIMEOUT_MS env var for user override (no VITEST gate) - Keep OPENCLAW_TEST_HANDSHAKE_TIMEOUT_MS as fallback for existing tests Fixes #46892 * fix: restore VITEST guard on test env var, use || for empty-string fallback, fix formatting * fix: cover gateway handshake timeout env override (#49262) (thanks @fuller-stack-dev) --------- Co-authored-by: Wilfred <wilfred@Wilfreds-Mac-mini.local> Co-authored-by: Ayaan Zaidi <hi@obviy.us>
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
// Keep server maxPayload aligned with gateway client maxPayload so high-res canvas snapshots
|
|
// don't get disconnected mid-invoke with "Max payload size exceeded".
|
|
export const MAX_PAYLOAD_BYTES = 25 * 1024 * 1024;
|
|
export const MAX_BUFFERED_BYTES = 50 * 1024 * 1024; // per-connection send buffer limit (2x max payload)
|
|
export const MAX_PREAUTH_PAYLOAD_BYTES = 64 * 1024;
|
|
|
|
const DEFAULT_MAX_CHAT_HISTORY_MESSAGES_BYTES = 6 * 1024 * 1024; // keep history responses comfortably under client WS limits
|
|
let maxChatHistoryMessagesBytes = DEFAULT_MAX_CHAT_HISTORY_MESSAGES_BYTES;
|
|
|
|
export const getMaxChatHistoryMessagesBytes = () => maxChatHistoryMessagesBytes;
|
|
|
|
export const __setMaxChatHistoryMessagesBytesForTest = (value?: number) => {
|
|
if (!process.env.VITEST && process.env.NODE_ENV !== "test") {
|
|
return;
|
|
}
|
|
if (value === undefined) {
|
|
maxChatHistoryMessagesBytes = DEFAULT_MAX_CHAT_HISTORY_MESSAGES_BYTES;
|
|
return;
|
|
}
|
|
if (Number.isFinite(value) && value > 0) {
|
|
maxChatHistoryMessagesBytes = value;
|
|
}
|
|
};
|
|
export const DEFAULT_HANDSHAKE_TIMEOUT_MS = 10_000;
|
|
export const getHandshakeTimeoutMs = () => {
|
|
// User-facing env var (works in all environments); test-only var gated behind VITEST
|
|
const envKey =
|
|
process.env.OPENCLAW_HANDSHAKE_TIMEOUT_MS ||
|
|
(process.env.VITEST && process.env.OPENCLAW_TEST_HANDSHAKE_TIMEOUT_MS);
|
|
if (envKey) {
|
|
const parsed = Number(envKey);
|
|
if (Number.isFinite(parsed) && parsed > 0) {
|
|
return parsed;
|
|
}
|
|
}
|
|
return DEFAULT_HANDSHAKE_TIMEOUT_MS;
|
|
};
|
|
export const TICK_INTERVAL_MS = 30_000;
|
|
export const HEALTH_REFRESH_INTERVAL_MS = 60_000;
|
|
export const DEDUPE_TTL_MS = 5 * 60_000;
|
|
export const DEDUPE_MAX = 1000;
|