Skip to content

Guard against overlapping and abandoned switches (#8) - #12

Merged
sorenbcoding merged 2 commits into
mainfrom
fix/8-switch-state-guards
Nov 13, 2026
Merged

sorenbcoding merged 2 commits into
mainfrom
fix/8-switch-state-guards

Conversation

@sorenbcoding

Copy link
Copy Markdown
Owner

Closes #8. Found in an external code review.

What changes

  • Overlapping switches: Switcher.start() claims the switch (current) before its first await and refuses a second start() with "A tenant switch is already running". Every exit before the runner starts releases the claim (abort()).
  • Panel: Connect is disabled while any card shows the Checking credentials… prompt, as in the desktop app.
  • Abandoned switches: the new src/switchState.ts isActiveStatus() rule says a running status older than the 5-minute timeout is stale. preflight(), start() and resumePending() share runningStatus(), which discards a stale file with a log line. A timeout also removes its own job's status file.
  • CHANGELOG Unreleased.

Cross-process locking (two Studio windows, or Studio plus the desktop app) is tracked separately in #11.

Testing

  • npm run typecheck, npm run build and the brand check pass.
  • npm test: 48 passed. The new test/switchState.test.ts covers recent, stale, finished, missing and unreadable statuses.
  • Switcher itself has no unit tests (it needs the vscode API). The guard logic is checked by reading it through. A manual check in Studio comes with the 0.4.2 test packages.

🤖 Generated with Claude Code

sorenbcoding and others added 2 commits November 13, 2026 14:18
A second Connect during the credential check could start another
switch that overwrote the first one's job file. start() now claims the
switch before its first await and refuses a second one, and the panel
disables Connect while a card is checking credentials.

A switch that timed out left switch-status.json as running, which
blocked every later switch until Studio reloaded. A running status older
than the timeout now counts as stale and is discarded, and a timeout
removes its own status file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sorenbcoding
sorenbcoding merged commit 27b349b into main Nov 13, 2026
1 check passed
@sorenbcoding
sorenbcoding deleted the fix/8-switch-state-guards branch November 13, 2026 13:19
sorenbcoding added a commit that referenced this pull request Nov 19, 2026
Guard against overlapping and abandoned switches (#8)
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.

Guard against overlapping and abandoned switches

1 participant