diff --git a/src/bus-publisher.ts b/src/bus-publisher.ts index 588a9e3..1f6c203 100644 --- a/src/bus-publisher.ts +++ b/src/bus-publisher.ts @@ -53,10 +53,15 @@ export class BusPublisher { this.bus = null; if (!this.reconnecting) { this.reconnecting = true; - setTimeout(async () => { - this.reconnecting = false; + const reconnect = async (): Promise => { await this.init({ onWarn: this.onWarn }); - }, 5000); + if (!this.bus) { + setTimeout(reconnect, 5000); + return; + } + this.reconnecting = false; + }; + setTimeout(reconnect, 5000); } } } diff --git a/src/four-opencode-token-budget-guard.ts b/src/four-opencode-token-budget-guard.ts index 9850b57..73c21fa 100644 --- a/src/four-opencode-token-budget-guard.ts +++ b/src/four-opencode-token-budget-guard.ts @@ -37,7 +37,14 @@ export const FourTokenBudgetGuardPlugin: Plugin = async (ctx) => { service: "tbg", level: "warn", message: msg, - extra: { details: args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(" ") } + extra: { details: args.map(a => { + if (typeof a !== 'object' || a === null) return String(a); + try { + return JSON.stringify(a); + } catch { + return "[unserializable]"; + } + }).join(" ") } } }).catch(() => {}); }