Skip to content

fix(mocactl): sbx token --json carries sandboxExpiresAt - #850

Merged
webchang merged 1 commit into
rossoctl:mainfrom
webchang:pr/sync-token-json-expires
Nov 17, 2026
Merged

webchang merged 1 commit into
rossoctl:mainfrom
webchang:pr/sync-token-json-expires

Conversation

@webchang

Copy link
Copy Markdown
Member

mocactl sbx token --json now prints the sandbox's sandboxExpiresAt beside the token's expiresAt.

What changed and why

  • Since the idle lifetime (API 1.25.0), POST /v1/sandboxes/{id}/token returns sandboxExpiresAt: the sandbox's deadline after the mint. It slides with activity, and the token is capped at it when minted, so it is at or after the token's own expiresAt: it tells a client how long re-minting can keep the sandbox alive. mocactl's connection and MCP server already follow it, but sbx token --json printed only token and expiresAt, so a client that gets its token from the command line could not tell when the sandbox ends.
  • cmdToken (packages/mocactl/src/sbx/commands.ts) now adds sandboxExpiresAt exactly as the control plane sent it (same name, epoch seconds), on every line, including each --renew-every line.
  • A control plane from before the field sends none, and the line then leaves the key out instead of inventing a value. This is the same pass-through the connection's grant (grantOf in exec.ts) already does.
  • The plain output stays the bare token, for scripts. It never named an expiry, so there was nothing to put the sandbox's beside. The token value is printed nowhere new.
  • Docs: docs/sbx/user-guide.md (section 9) lists the --json fields, and docs/api/sandbox-v1-direct-client.md says the command prints sandboxExpiresAt.

Tests

  • New in packages/mocactl/test/sbx-cli.test.ts:
    • token --json: the token's expiresAt and the sandbox's sandboxExpiresAt, as sent: a scripted token answer as the control plane mints it (a 900 s token on a sandbox with an hour left, sandboxExpiresAt = the token's expiresAt + 2700). On main it fails: the received object has no sandboxExpiresAt (- "sandboxExpiresAt" is missing). With the fix it passes.
    • token --json from a control plane before sandboxExpiresAt: the field is left out: an answer without the field gives {token, expiresAt} and no sandboxExpiresAt key. It passes both before and after the fix.
  • @moca/mocactl, the whole suite (vitest run --minWorkers=1 --maxWorkers=2): 87 files passed, 2 skipped; 2072 tests passed, 4 skipped. tsc --noEmit is clean.
  • scripts/check-doc-links.py: 0 broken links. Prettier is clean.

Out of scope

  • sbx create, sbx get and sbx ls --json already print the whole sandbox record, expiresAt included, so they needed no change.

Every commit is signed off (DCO).

Assisted-By: Claude Code

The control plane's token answer has carried sandboxExpiresAt since the idle
lifetime (API 1.25.0): the sandbox's deadline after the mint, which slides
with activity. The token is capped at it, so it is at or after the token's
own exp, and it tells a client how long re-minting can keep the sandbox
alive. The connection and the MCP server already follow it, but `sbx token
--json` printed only token and expiresAt, so a client that holds its token
from the command line could not learn when the sandbox ends.

The line now adds sandboxExpiresAt as the control plane sent it (same
name, epoch seconds). A control plane from before the field sends none,
and the line then leaves it out rather than inventing a value. The plain
output stays the bare token, for scripts.

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang requested a review from pdettori as a code owner November 17, 2026 14:48
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 17, 2026
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

cmdToken passes the control plane's sandboxExpiresAt through in --json output (every --renew-every line too). It leaves the key out when an older control plane omits it, the same way grantOf in exec.ts does. The plain output is still the bare token. Docs in the user guide §9 and the direct-client guide are updated, and tests cover both the with-field and without-field answers. One nit on a test comment.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1, all signed-off: yes
CI status: all green (17 checks)


it("token --json: the token's expiresAt and the sandbox's sandboxExpiresAt, as sent", async () => {
const { home, env, io } = setup();
// The sandbox ends before its token does: the line must say so, not just the token's exp.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: This comment says the sandbox ends before its token, but the next two lines and the fixture (TOKEN.expiresAt + 2700) say the opposite: the token is capped at the sandbox's deadline, so the sandbox ends at or after it. Drop or reword this line, e.g. "The sandbox outlives its token: the line must say when, not just the token's exp."

@webchang
webchang merged commit d22d10c into rossoctl:main Nov 17, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants