Skip to content

Handle signed-out Cloud runtime connections#4480

Open
KyleAMathews wants to merge 4 commits into
mainfrom
fix/cloud-logged-out-runtime-error-main
Open

Handle signed-out Cloud runtime connections#4480
KyleAMathews wants to merge 4 commits into
mainfrom
fix/cloud-logged-out-runtime-error-main

Conversation

@KyleAMathews
Copy link
Copy Markdown
Contributor

Summary

  • show a clear sign-in-required error before starting local runtime for Electric Cloud servers
  • require an active Cloud session before reusing cached agents tokens
  • avoid injecting cached Cloud agents auth headers after sign-out

Testing

  • pnpm --filter @electric-ax/agents-desktop typecheck (fails in this worktree because node_modules/workspace dependencies are not installed/linked; missing modules include electron, undici, @electric-sql/client, and workspace packages)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Electric Agents Desktop Builds

Build artifacts for commit b64fb04.

Platform Status Artifact
macOS Apple Silicon Passed DMG
macOS Intel Passed DMG
Windows x64 Passed Installer
Linux x64 Passed AppImage / deb

Workflow run

@samwillis
Copy link
Copy Markdown
Contributor

Note to reviewer: we need to also clear the servers on the desktop app that come from cloud when the user explicitly signed out. This fix is more for if the auth fails / expires I think.

Copy link
Copy Markdown
Contributor

@samwillis samwillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interactive review with GPT.

Main issue: sign-out should delete Cloud servers

This fixes the signed-out runtime startup path, but I think explicit Cloud sign-out still leaves the main stale-state problem in place: saved electric-cloud servers remain in desktop settings after sign-out.

Current sign-out only clears the Cloud auth session:

ipcMain.handle(`desktop:cloud-auth-sign-out`, async () => {
  await deps.getCloudAuth().signOut()
})

The CloudAuth subscriber then stops the Cloud agent-server shape streams, but it does not remove the Cloud-derived server configs from settings.servers, disconnect their runtime entries, clear selections/default server, or delete their per-tenant cached agents tokens.

That means a signed-out user can still have Cloud servers in the app. This PR now prevents connecting them while signed out, which is good, but after signing into a different Cloud account the app can still reuse old Cloud server entries and cached cloud-agents-token:<tenantId> values from the previous account.

Why this matters

prepareConnection() now correctly requires an active Cloud session before using a cached agents token:

const token = await this.cloudAuth.getToken()
if (!token) {
  throw new Error(`Not signed in to Electric Cloud`)
}

const cached = this.getAgentsToken(tenantId)
if (cached) return { url, tenantId }

But the cached token is still keyed only by tenantId, not by Cloud user/account. So once any user is signed in, a stale saved Cloud server can reuse an old agents token for that tenant without checking that the current Cloud user should still see that server.

Suggested fix

On explicit Cloud sign-out, delete all servers with source === "electric-cloud" and clean up their related state:

  • disconnect/stop any running runtime entries for those servers
  • delete the saved Cloud server configs from settings.servers
  • clear matching window selections and defaultServerId
  • delete each server’s cached agents token via forgetAgentsToken(tenantId)
  • save settings and refresh desktop state

The existing forgetServer() path already does most of this for one server, so the sign-out IPC could either reuse that behavior for all Cloud servers or add a dedicated “forget all Cloud servers” helper.

Existing good parts in this PR

The new checks do improve the failure mode:

  • auth header injection no longer sends cached Cloud agents auth headers while signed out
  • prepareConnection() no longer reuses cached agents tokens unless there is an active Cloud session
  • startRuntime() now surfaces a clear “Sign in to Electric Cloud” error before health checks / runtime startup

I’d still block on deleting Cloud servers during explicit sign-out, because otherwise the app keeps Cloud account-specific state around after the user has asked to sign out.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 4, 2026

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit b64fb04
🔍 Latest deploy log https://app.netlify.com/projects/electric-next/deploys/6a230334e215050008057897
😎 Deploy Preview https://deploy-preview-4480--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

# Conflicts:
#	packages/agents-desktop/src/cloud/auth-injection.ts
@KyleAMathews KyleAMathews requested a review from samwillis June 5, 2026 18:13
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.

2 participants