fix(claude-account): emit accounts_changed once per account add

Merged
SU
3d ago
+95-2

Fixes #5116

Problem

After #5041, one Anthropic /claude-account add produced two accounts_changed events: once from ModelRuntime.login (with the login remedy, which is what invalidates session holds) and once from the unconditional emit at the end of the command's addAccount. RPC clients therefore received duplicate auth_accounts_changed events.

Fix

Remove the command-side emit in account-command.ts (and its now-unused import). The single remaining event is the one from ModelRuntime.login, so the login remedy semantics are preserved. No other login caller is affected: every login path already got its event from login itself.

RED -> GREEN

New regression test test/suite/regressions/5116-account-add-single-event.test.ts drives the registered /claude-account add handler with a stubbed modelRuntime.login that emits exactly like the real one, and counts subscribed events:

  • Before the fix: 2 events, test fails (expected 1).
  • After the fix: exactly 1 event with remedy login, test passes.

Local runs: new regression test 1 passed; existing test/suite/anthropic-subscription-account-command.test.ts 4 passed (5 total across both files); oxlint on both changed files 0 errors. Full bun run check left to CI.

Changelog

Tracker + changelog fragment to follow in changes/unreleased/<this PR>.md once the PR number is known.


Summary by cubic

Fixes #5116: /claude-account add now emits exactly one accounts_changed event instead of two. The command's unconditional emit at the end of addAccount was duplicating the event ModelRuntime.login already sends, so RPC clients received duplicate auth_accounts_changed events. The single event now comes from ModelRuntime.login, preserving the login remedy that invalidates session holds.

Adds a regression test that stubs ModelRuntime.login, counts emitted events, and fails before the fix (2 events) and passes after (1). Adds a changelog fragment for the fix.