Skip to content

Commit df7317d

Browse files
committed
refactor(sdk)!: make wait_ready succeed only on Ready
wait_ready previously also returned Ok for a sandbox that reached Completed. A caller waiting for a sandbox almost always needs a live one, and the name suggests that, so a sandbox that completes before becoming ready is now an error that fails fast, like Stopped, Error and the suspended phases. This applies to the Rust SDK's OpenShellClient and WorkspaceScopedClient and to the TypeScript SDK's waitReady, so the SDKs agree. The Go SDK has moved to ai-openshell/sdk-go and gets the same change there. BREAKING CHANGE: Rust wait_ready and TypeScript waitReady return an error instead of the sandbox when it reaches the Completed phase. Callers that need to wait for a finished workload should poll the sandbox. Signed-off-by: Evan Lezar <[email protected]>
1 parent b0871a9 commit df7317d

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎sdk/typescript/src/client.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ describe('sandbox templates', () => {
13251325
});
13261326

13271327
describe('waits', () => {
1328-
it('waitReady accepts successful main-process completion', async () => {
1328+
it('waitReady rejects main-process completion without waiting for timeout', async () => {
13291329
const sandbox = client({
13301330
getSandbox: () => ({
13311331
sandbox: {
@@ -1334,7 +1334,10 @@ describe('waits', () => {
13341334
},
13351335
}),
13361336
});
1337-
await expect(sandbox.waitReady('sb', 1)).resolves.toMatchObject({ phase: 'completed', exitCode: 0 });
1337+
await expect(sandbox.waitReady('sb', 30)).rejects.toMatchObject({
1338+
code: 'connect',
1339+
message: expect.stringContaining('completed before becoming ready'),
1340+
});
13381341
});
13391342

13401343
it('waitReady rejects stopped main-process results without waiting for timeout', async () => {

‎sdk/typescript/src/client.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,8 @@ export class SandboxClient {
13411341
}
13421342
}
13431343

1344-
// Poll until the sandbox is ready. The timeout bounds the returned promise,
1344+
// Poll until the sandbox is ready; a sandbox that completes, stops, errors or
1345+
// is suspended first is an error. The timeout bounds the returned promise,
13451346
// not just the sleep loop: each poll RPC carries the remaining deadline (and
13461347
// any caller signal), so a stalled get() is aborted rather than hanging.
13471348
async waitReady(name: string, timeoutSecs: number, options?: WaitOptions | null): Promise<SandboxRef> {
@@ -1361,7 +1362,10 @@ export class SandboxClient {
13611362
} catch (e) {
13621363
throw mapWaitError(e, name, deadline, signal, pollOptions.signal);
13631364
}
1364-
if (ref.phase === 'ready' || ref.phase === 'completed') return ref;
1365+
if (ref.phase === 'ready') return ref;
1366+
if (ref.phase === 'completed') {
1367+
throw new SdkError('connect', `sandbox '${name}' completed before becoming ready`);
1368+
}
13651369
if (ref.phase === 'stopped') throw new SdkError('connect', `sandbox '${name}' stopped before becoming ready`);
13661370
if (ref.phase === 'error') throw new SdkError('connect', `sandbox '${name}' entered error phase`);
13671371
if (ref.phase === 'suspending' || ref.phase === 'suspended') {

0 commit comments

Comments
 (0)