Repository navigation
Description
Summary
After a successful mocactl sbx login --control-plane-url URL, mocactl sbx up in a repository whose .sbx/sandbox.json names a different control plane still targets the binding's control plane and fails with "not logged in", even though the login just succeeded. It looks as if the URL is only "set" after the first sandbox is created on the new control plane.
What actually happens (verified in the code)
sbx login does remember the URL: with --control-plane-url, cmdLogin saves it as sbxControlPlaneUrl in config.json (packages/mocactl/src/sbx/commands.ts, cmdLogin), and sbx ls right after login works for that reason.
The problem is precedence for sbx up and the commands that default to the bound sandbox. In packages/mocactl/src/sbx/cli.ts the control plane recorded in .sbx/sandbox.json (readBinding(...).controlPlaneUrl) is fed in as if it were --control-plane-url, so it outranks the URL remembered at login. The documented order is: flag, MOCACTL_SBX_URL, the bound sandbox's, the one remembered at login, the login's own.
A binding left over from an earlier sandbox on another control plane therefore wins over the control plane you just logged in to.
Reproduction
- In a repo whose
.sbx/sandbox.jsonwas written bysbx upagainst control plane A. mocactl sbx login --control-plane-url Bsucceeds ("logged in to the sandbox service as ...").mocactl sbx lsworks (uses B, remembered).mocactl sbx upfails:sbx: not logged in to the sandbox service at A (from .sbx/sandbox.json): run `mocactl sbx login --control-plane-url 'A'`; that is not the control plane you logged in to (B): log in there only if you trust it, ...- Only
mocactl sbx up --control-plane-url Bworks: it reports the bound sandbox no longer exists, creates a new one, and rewrites the binding to B.
Expected
A successful login should make that control plane the one used by default, including over a stale binding in the current repository. At minimum, sbx up should not silently pick a control plane the user has no login for when a login for another one was just made.
Options to consider
- When
sbx loginsucceeds, treat the logged-in control plane as the active one: forup, prefer the remembered/logged-in URL over a binding whose control plane has no login on this machine (the binding can't be used without one anyway). - Or keep the binding precedence (it protects against pushing a repo to an unexpected control plane) but make the failure actionable: offer to rebind (
sbx up --control-plane-url B, which already works) instead of only suggesting a login on the old control plane. - Multiple terminals with different control planes:
MOCACTL_SBX_URLalready covers this per shell; worth documenting next tosbx loginin the help, and deciding whethersbx login --control-plane-urlshould overwrite the global remembered URL at all when it is set.
Environment
mocactl sbx on macOS, two control planes (A: https://api.moca-sbx.vpc-int.res.ibm.com, B: https://sbx-api-moca-sbx.apps.epoc001.ete14.res.ibm.com).
Assisted-By: Claude Code
Activity
esnible commentedon Nov 18, 2026
A related inconsistency:
sbx createandsbx upresolve the control plane differently. In the same repository they can hit two different control planes.In
packages/mocactl/src/sbx/cli.ts:sbx upreads.sbx/sandbox.json(around line 1180) and feeds the binding'scontrolPlaneUrlin as if it were the flag (line 1379):MOCACTL_SBX_URL, binding, remembered at login (config.json), the login's own (sbx-auth.json).sbx createis in neitherIN_REPOnorTAKES_SANDBOX_FLAG(lines 599–615), so it never reads the binding.boundUrlstays undefined and it skips that step: flag,MOCACTL_SBX_URL, remembered at login, the login's own.So in this issue's scenario (repository bound to A, last
sbx loginto B),sbx creategoes to B andsbx upgoes to A. This happens even when the bound sandbox no longer exists.cmdUp(sync.ts, around line 276) prints "the bound sandbox … no longer exists; finding or creating another", but it still creates the new one on A, because the URL was fixed before the existence check.R5j's reason for binding precedence (a bound sandbox lives on the control plane
upused) holds forpush/pull/run/mcpagainst an existing sandbox. It doesn't really apply onceupis going to create a new sandbox, andcreatedoesn't follow it at all.Suggestion:
upshould use the binding's URL only while the bound sandbox still exists on it. When the bound sandbox is gone (or there's no login for the binding's control plane),upshould fall back to the same resolutioncreateuses and rewrite the binding. It should also warn when it does use a binding URL that differs from the remembered login URL. Today that warning only appears on the not-logged-in path inopenSbx.Assisted-By: Claude Code