Skip to content

fix(wireClient): bound the offline queue, time out invokes, dedupe reconnect flush - #210

Merged
currentbits merged 1 commit into
mainfrom
coder/wireclient-unbounded-offline-queue-no-in-a22e0e
Aug 17, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/wireclient-unbounded-offline-queue-no-in-a22e0e

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Fixes #130.

Why

While the WebSocket was down, every invoke() was pushed into queued with no size limit, and flushQueue() fired the whole backlog at main in one go on reconnect. The renderer has several interval pollers (devServerStatus every 3-5s, refreshStatus every 60s, summaries every 2s), so a web-server outage meant unbounded memory growth followed by a self-inflicted thundering herd.

Separately, an inflight call was only ever settled by a matching reply. A handler that hung in main left the renderer promise pending forever — the visible symptom being a button stuck in its busy state with no way out.

What changed

src/wireClient.ts:

  • Cap the offline queue at 64 entries, dropping the oldest and rejecting it ("Offline queue full, request dropped"). Rejecting is the point: a silently dropped invoke leaves the same stuck button as an unbounded queue.
  • Per-invoke timeout of 120s, armed when the pending is created rather than when it is sent, so one timer covers both a hung main handler and a call queued through an outage that never gets a reconnect. The timer is cleared on any settle, and a late reply for a timed-out id is ignored.
  • Coalesce the reconnect flush: identical channel + args in the flush batch send a single invoke and share its reply. Repeat poller ticks collapse to one call each instead of one per tick.

Also folded the existing inline unref in scheduleReconnect into a small shared helper, now that two call sites need it.

Tests

Three new cases in test/wireClient.test.ts covering the cap (oldest rejects, 64 survive the flush), the coalescing (three poller ticks -> one invoke, all three promises resolve from the shared reply), and the timeout (rejects with the channel name, late reply is harmless). Full renderer suite: 715 passing. tsc --noEmit clean.

Not done

No staggered flush and no per-channel timeout budgets — the cap plus dedupe already bounds the herd, and one global 120s ceiling is enough until a legitimately slow handler (gh network calls) starts tripping it.

  • PR created by the Claude Code agent

Fixes #130. While disconnected every invoke() piled into `queued`
unbounded, and reconnect fired the whole backlog at main at once. An
invoke was only settled by a matching reply, so a handler that hung in
main left the renderer promise pending forever.

- Cap `queued` at 64, rejecting the oldest.
- Arm a 120s timeout per invoke, covering both a hung handler and a
  queued call that never gets a reconnect.
- Coalesce identical channel+args on flush so repeat poller ticks share
  one invoke instead of stampeding.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 71d101d into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/wireclient-unbounded-offline-queue-no-in-a22e0e branch October 3, 2026 16:07
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.

wireClient: unbounded offline queue, no invoke timeout, reconnect stampede

1 participant