sdk: add Renew to the Go and Python SDKs - #225
Merged
Merged
Conversation
POST /v1/sandboxes/{id}/renew had no SDK wrapper, so a client holding a
sandbox past its claim TTL had to hand-roll the request. Renew sends the
sandbox's own token, returns the granted deadline and stores it on the
handle; the e2e test pins the wire mirror against the real server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
POST /v1/sandboxes/{id}/renewshipped in sandboxd without an SDK wrapper, so a client that holds a sandbox longer than its claim TTL had to hand-roll the request (and pick the right bearer). This adds the verb to both SDKs.What
Sandbox.Renew(ctx, ttl) (time.Time, error). Zero TTL asks for the server default; the TTL rounds up to seconds likeWithTimeout. The granted deadline is returned and stored inSandbox.Deadline; a refusal (409 archived, 404) leaves the handle untouched.Sandbox.renew(ttl_seconds=0) -> str, same contract, updatessb.deadline.Lookup/client.lookupcan renew.docs/sdk.mdanddocs/sdk-python.md; the hibernation text now points at renew; READMEs list the verb.No server change. Hot path: none — renew is a control-plane call that claim and data-plane calls never touch.
Tests
sdk/go: table test pins method, path,Authorization: Bearer <sandbox token>(with a different API token configured), the body ({"ttl_seconds":90}/{}), and the returned + recorded deadline; a 409 surfaces as*APIErrorand leavesDeadlineunchanged.e2e:TestRenewEndToEnddrives the real SDK against the real sandboxd handler — an hour's renew lands about an hour out, matches the handle and the node's own record, and a two-minute renew shortens it. This is the drift guard for the wire mirror.sdk/python: parametrized test for the body and bearer, plus the 409 case.Gates:
make go-lint10×0 issues.(5 modules × darwin/linux),asl -forwarder=falseclean on both GOOS forsdk/goande2e,go test -racegreen forsdk/goande2e; Python with CI's pins (ruff 0.15.20, pytest 8.4.2, mypy 1.19.1, Python 3.12): format/check clean, 218 passed, mypy clean.Hardware
Against a production sandboxd 0.1.13 node (released binary), one warm desktop claim with a 2-minute TTL:
The first five lines are the Go SDK (claim, renew, a
Lookuphandle renewing shorter); the rest is the Python SDK on the same sandbox viaclient.lookup, ending with the release.