Repository navigation
fix(mocactl): sbx token --json carries sandboxExpiresAt - #850
Conversation
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]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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."
mocactl sbx token --jsonnow prints the sandbox'ssandboxExpiresAtbeside the token'sexpiresAt.What changed and why
POST /v1/sandboxes/{id}/tokenreturnssandboxExpiresAt: 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 ownexpiresAt: it tells a client how long re-minting can keep the sandbox alive. mocactl's connection and MCP server already follow it, butsbx token --jsonprinted onlytokenandexpiresAt, 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 addssandboxExpiresAtexactly as the control plane sent it (same name, epoch seconds), on every line, including each--renew-everyline.grantOfinexec.ts) already does.docs/sbx/user-guide.md(section 9) lists the--jsonfields, anddocs/api/sandbox-v1-direct-client.mdsays the command printssandboxExpiresAt.Tests
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'sexpiresAt+ 2700). On main it fails: the received object has nosandboxExpiresAt(- "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 nosandboxExpiresAtkey. 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 --noEmitis clean.scripts/check-doc-links.py: 0 broken links. Prettier is clean.Out of scope
sbx create,sbx getandsbx ls --jsonalready print the whole sandbox record,expiresAtincluded, so they needed no change.Every commit is signed off (DCO).
Assisted-By: Claude Code