fix: make git installs buildable - #10
Conversation
Without a stable Idempotency-Key, request() minted a fresh random UUID
per call, defeating Edge's server-side idempotency store: every retry
of a create -- including a full re-attach after a crash -- looked like
a brand-new request and could create a duplicate sandbox.
ZeishCreateSandboxOptions gains an optional idempotencyKey; createSandbox
passes it through as the request's Idempotency-Key header instead of a
random one. createAndStartSandbox keys it per attempt
(`${idempotencyKey}:attempt-${n}`) so a genuine retry-with-a-fresh-machine
still creates a new sandbox, while a raw transport retry of the same
attempt's HTTP call reuses it.
createSandbox already sets desiredStatus "running" and boots the
machine on its own. createAndStartSandbox called startSandbox() again
right after, unconditionally -- reproduced via raw curl (no SDK, no
other client): calling POST /sandboxes/{id}/start immediately after
POST /sandboxes races Edge's state machine and kills the machine
outright, landing on status "failed" with an empty
"runtime terminal state: " lastError. machined's own StartService.Start
permits starting from the "created" state, so it doesn't reject the
redundant call -- it forwards it into the FSM while create is still
in flight.
Only call start when the freshly created sandbox isn't already on its
way up (desiredStatus / status not already running).
Expose raw_l4 ingress with explicit tcp or udp transport in the public SDK and document exposedPorts as a deprecated TCP compatibility shorthand. Signed-off-by: Aaqa Ishtyaq <aaqaishtyaq@gmail.com>
Expose runtime service metadata in the SDK so URL-based services and native UDP endpoints use distinct client representations. Add transport, host, and port fields without changing the raw_l4 creation contract. Signed-off-by: Aaqa Ishtyaq <aaqaishtyaq@gmail.com>
Require generic protocol-aware ingress in the public SDK and stop emitting the removed exposedPorts compatibility field. Signed-off-by: Aaqa Ishtyaq <aaqaishtyaq@gmail.com>
Bump the provider package version and run the package build from the prepare lifecycle so Git-based consumers receive generated declarations and runtime dist files even though dist remains a publish artifact. Signed-off-by: Aaqa Ishtyaq <aaqaishtyaq@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d9ce8c6d8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| templateId, | ||
| region: options?.region, | ||
| metadata: options?.metadata, | ||
| ...(ingressOptions.ingress ? { ingress: ingressOptions.ingress } : {}), |
There was a problem hiding this comment.
Avoid dereferencing omitted sandbox options
When the provider is configured with defaultTemplateId and the caller invokes sandbox.create() without options, ingressOptions remains undefined because the assertion does not create an object, and reading .ingress throws before the API request. Preserve the previously supported optional-options path by using optional chaining or defaulting this value to an empty object.
Useful? React with 👍 / 👎.
| const idempotencyKey = input.idempotencyKey | ||
| ? `${input.idempotencyKey}:attempt-${attempt}` | ||
| : undefined; |
There was a problem hiding this comment.
Reuse the create key after ambiguous transport failures
When Edge accepts the create request but its response is lost, createdId remains unset, the catch advances to the next loop iteration, and this suffix changes from attempt-1 to attempt-2; Edge therefore cannot deduplicate the retry and a second sandbox is created while the first is orphaned. Keep the same idempotency key until a create response establishes that the attempt produced a known sandbox, and only advance it when intentionally replacing that known sandbox.
Useful? React with 👍 / 👎.
| "proto" | ||
| ], | ||
| "scripts": { | ||
| "prepare": "pnpm build", |
There was a problem hiding this comment.
Run the prepare build without requiring global pnpm
When npm installs this repository as a Git dependency on a machine without a globally installed pnpm, this lifecycle command fails with pnpm: not found, since pnpm is neither a dependency nor otherwise provisioned by this package. npm installs the package's dependencies and devDependencies before running prepare, as documented in its lifecycle-script reference, so invoking the locally available vite build directly would make the Git install package-manager-neutral.
Useful? React with 👍 / 👎.
Avoid reading ingress from omitted sandbox options, keep idempotency keys stable across ambiguous create transport failures, and advance the key only after a sandbox identity is returned. Run the package prepare hook through the locally installed Vite binary so Git installs do not require a global pnpm executable. Signed-off-by: Aaqa Ishtyaq <aaqaishtyaq@gmail.com>
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.