Skip to content

fix: reconnect race in bus-publisher + safe JSON.stringify in onWarn #45 - #46

Merged
four-bytes-robby merged 1 commit into
mainfrom
fix/45-bus-publisher-reconnect-json
Jun 17, 2026
Merged

fix: reconnect race in bus-publisher + safe JSON.stringify in onWarn #45#46
four-bytes-robby merged 1 commit into
mainfrom
fix/45-bus-publisher-reconnect-json

Conversation

@four-bytes-robby

@four-bytes-robby four-bytes-robby commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

Fixes two bugs found by PR review bots on PR #44:

Bug 1: bus-publisher.ts — reconnecting flag race condition

File: src/bus-publisher.ts

this.reconnecting was set to false before await this.init() completed. If init failed, reconnect was permanently disabled. Fix: only set the flag to false after init succeeds (or retry if bus is still null).

Bug 2: four-opencode-token-budget-guard.ts — unsafe JSON.stringify

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

JSON.stringify was called without a try/catch on the onWarn args. Circular references would throw and crash the logger. Fix: wrap in try/catch, return "[unserializable]" on failure.

Checklist


Summary by cubic

Fixes a reconnect race in the bus publisher to ensure it reliably restores the connection, and hardens onWarn logging to avoid crashes on circular data. Addresses #45.

  • Bug Fixes
    • Bus reconnect: only unset reconnecting after init succeeds; if bus is still null, retry again in 5s.
    • Logging: wrap JSON.stringify in try/catch for onWarn; non-objects use String, fallback to "[unserializable]".

Written for commit 082abd0. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced system resilience with improved automatic reconnection retry logic for message bus connections, ensuring better recovery during temporary connection failures.
    • Improved reliability of event warning logs through more robust error data serialization handling, preventing potential display failures on complex or non-serializable error objects.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

Recent review info
Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dfc78072-bdc6-4a42-8b74-b889d347ac4a

Commits

Reviewing files that changed from the base of the PR and between d8296b7 and 082abd0.

Files selected for processing (2)
  • src/bus-publisher.ts
  • src/four-opencode-token-budget-guard.ts

Walkthrough

Walkthrough

BusPublisher.publish replaces a one-shot setTimeout reconnect with a self-scheduling reconnect function that retries every 5 seconds until the bus is restored. Separately, the warning logger in FourTokenBudgetGuardPlugin wraps JSON.stringify in a try/catch and falls back to "[unserializable]" for non-serializable objects.

Changes

Bus Robustness Improvements

Layer / File(s) Summary
Self-retrying reconnect loop src/bus-publisher.ts A named reconnect async function replaces the one-shot inline setTimeout. After calling init, if this.bus is still null it reschedules itself after 5s; once the bus is available it clears this.reconnecting. Duplicate retry loops are suppressed by the existing this.reconnecting guard.
Defensive warn payload serialization src/four-opencode-token-budget-guard.ts The onWarn handler now wraps JSON.stringify in a try/catch for non-null object arguments, emitting "[unserializable]" on failure, and falls back to .toString() for non-object values.

Estimated code review effort

3 (Moderate) | ~15 minutes

Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes both main changes: fixing a reconnect race condition in bus-publisher and adding safe JSON.stringify handling in onWarn, directly matching the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Tip: You can configure your own custom pre-merge checks in the settings.

Finishing Touches
Generate docstrings
  • Create stacked PR
  • Commit on current branch
Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/45-bus-publisher-reconnect-json
Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/45-bus-publisher-reconnect-json

Comment @coderabbitai help to get the list of available commands and usage tips.

@four-bytes-robby
four-bytes-robby merged commit 1be68d2 into main Jun 17, 2026
4 of 5 checks passed
@four-bytes-robby
four-bytes-robby deleted the fix/45-bus-publisher-reconnect-json branch June 17, 2026 10:51
@four-bytes-robby
four-bytes-robby restored the fix/45-bus-publisher-reconnect-json branch June 17, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant