Skip to content

fix(core): stabilize connection lifecycle and presence for v1.3.0 - #6

Merged
nayandas69 merged 1 commit into
mainfrom
dev
Oct 25, 2026
Merged

nayandas69 merged 1 commit into
mainfrom
dev

Conversation

@nayandas69

Copy link
Copy Markdown
Contributor

StatusCode v1.3.0 — Stability Release

Stabilization release targeting every defect found in v1.2.0's connection lifecycle, idle handling, and presence payload. The headline fix: reconnecting after Discord quits, restarts, or a manual "Reconnect" never actually worked in v1.2.0 — it was structurally impossible.

🔴 Critical

Reconnect was permanently broken after the first disconnect

Reading the vendored discord-rpc 4.0.1 source confirmed the root cause: the library memoizes its internal connect promise and never resets it after the transport closes (RPCClient.connect() returns the settled _connectPromise forever, and destroy() only closes the socket).

The consequences in v1.2.0, all fixed:

  • After Discord quit or restarted, every later login on the same client threw connection closed immediately — reconnect could never succeed.
  • Worse, after a graceful close the stale promise was resolved, so a re-login "succeeded" instantly without connecting: the extension reported connected while holding a dead socket, then looped forever between fake successes and setActivity failures. This is why presence never came back after Discord restarted.

Fix: DiscordClient now creates a fresh RPC client instance for every connection attempt (with its event handlers attached per instance, so late events from a discarded client cannot corrupt the next attempt's state), destroys the previous one safely, and serializes concurrent logins — simultaneous connect calls (startup retry, status-bar click, config change) now share one in-flight attempt instead of opening competing IPC connections.

🟡 Reliability & correctness

  • Stale disconnect events after manual reconnect — the discarded client's late disconnected event no longer flips the status bar to "Disconnected" and schedules a reconnect against a healthy connection. Intentional disconnects suppress the callback entirely, so the status bar stays "Disabled" after a disable.
  • Half-open clients after failed logins — a failed login() now destroys the half-connected client before rethrowing, so its transport can't linger into the next attempt.
  • Status bar stuck on "Connecting…" — while the background retry loop works, the status now shows "Retrying…" instead of holding "Connecting…" indefinitely.
  • statuscode.reconnectInterval changes were ignored while running — the retry loop restarts on config change so a new interval takes effect immediately.

🟢 Presence accuracy

  • Idle state ignored file switching — switching files while idle updated the presence but did not reset the idle timer, so idle overwrote it seconds later. Editor switches now count as user activity (recordActivity(true)).
  • Diagnostics could wake the idle state — lint/diagnostic updates (not user activity) no longer overwrite the "Idle" presence, and a queued update can no longer race it.
  • Discord rejected long presence text — details, state, and image hover texts are truncated to Discord's 128-character limit (long file or workspace names caused rejected-payload errors).
  • .git suffix shown in presence — owner/repo.git remotes now display as owner/repo.
  • Non-HTTPS repository button URLs — git:// and http:// remotes are normalized to https:// and trailing slashes stripped, so the clickable "View Repository" button always opens.

Files changed

File Change
src/discord-client.ts Fresh client per connection, serialized logins, safe teardown, stale-event suppression, payload truncation
src/activity-manager.ts Idle-aware activity recording; diagnostics/idle race removed
src/util.ts extractRepoName/toGitHubHttpsUrl parsing fixes; truncateDiscordText + DISCORD_TEXT_LIMIT
src/extension.ts "Retrying…" status; retry loop restart on interval change
src/test/util.test.ts 8 new tests (repo URL parsing, truncation)
package.json Version 1.2.0 → 1.3.0

@nayandas69
nayandas69 merged commit 76a8110 into main Oct 25, 2026
1 check passed
@nayandas69
nayandas69 deleted the dev branch October 25, 2026 19:57
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