Skip to content

mocactl sbx: a stale .sbx/sandbox.json control plane overrides the one just logged in to #889

Closed

Description

@pdettori

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

  1. In a repo whose .sbx/sandbox.json was written by sbx up against control plane A.
  2. mocactl sbx login --control-plane-url B succeeds ("logged in to the sandbox service as ...").
  3. mocactl sbx ls works (uses B, remembered).
  4. mocactl sbx up fails:
    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, ...
    
  5. Only mocactl sbx up --control-plane-url B works: 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 login succeeds, treat the logged-in control plane as the active one: for up, 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_URL already covers this per shell; worth documenting next to sbx login in the help, and deciding whether sbx login --control-plane-url should 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

  1. added
    bug
    on Nov 18, 2026
  2. assigned and unassigned on Nov 18, 2026
  3. esnible commented on Nov 18, 2026

    @esnible
    Member

    A related inconsistency: sbx create and sbx up resolve the control plane differently. In the same repository they can hit two different control planes.

    In packages/mocactl/src/sbx/cli.ts:

    • sbx up reads .sbx/sandbox.json (around line 1180) and feeds the binding's controlPlaneUrl in as if it were the flag (line 1379):
      const flagUrl = values['control-plane-url'] || (env.MOCACTL_SBX_URL ? undefined : boundUrl);
      Order: flag, MOCACTL_SBX_URL, binding, remembered at login (config.json), the login's own (sbx-auth.json).
    • sbx create is in neither IN_REPO nor TAKES_SANDBOX_FLAG (lines 599–615), so it never reads the binding. boundUrl stays 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 login to B), sbx create goes to B and sbx up goes 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 up used) holds for push/pull/run/mcp against an existing sandbox. It doesn't really apply once up is going to create a new sandbox, and create doesn't follow it at all.

    Suggestion: up should 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), up should fall back to the same resolution create uses 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 in openSbx.

    Assisted-By: Claude Code

  4. self-assigned this
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions