Skip to content

[BUG] bus-publisher reconnect race + unsafe JSON.stringify in onWarn #45

Description

@four-bytes-robby

Bug 1: bus-publisher.ts — reconnecting flag set BEFORE init completes

File: src/bus-publisher.ts lines 55–59

Problem: this.reconnecting = false is set before await this.init() completes. If init fails, reconnect is permanently disabled because the flag is already false.

Current code:

} catch {
  this.bus = null;
  if (!this.reconnecting) {
    this.reconnecting = true;
    setTimeout(async () => {
      this.reconnecting = false;   // BUG: set to false BEFORE init
      await this.init({ onWarn: this.onWarn });  // if init fails, reconnect is permanently disabled
    }, 5000);
  }
}

Fix: Only set this.reconnecting = false AFTER init succeeds.


Bug 2: four-opencode-token-budget-guard.ts — JSON.stringify without try/catch

File: src/four-opencode-token-budget-guard.ts line 38

Problem: JSON.stringify is called without a try/catch, so circular references will throw and crash the logger.

Current code:

extra: { details: args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(" ") }

Fix: Wrap JSON.stringify in try/catch and return "[unserializable]" on failure.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions