@sealant/sdk-next 0.40.0-next.964 → 0.40.0-next.966
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effect/read-retry.d.ts +13 -1
- package/dist/effect/read-retry.js +38 -5
- package/dist/facade/workspace.js +19 -2
- package/package.json +3 -3
|
@@ -6,7 +6,9 @@ export declare const READ_RETRY_BUDGET_MS = 60000;
|
|
|
6
6
|
* How long to wait before reading again after `error` on retry number `attempt` (from 0), or
|
|
7
7
|
* `undefined` when the failure is not one a second read can fix.
|
|
8
8
|
*/
|
|
9
|
-
export declare const readRetryDelayMs: (error: unknown, attempt: number, now?: number
|
|
9
|
+
export declare const readRetryDelayMs: (error: unknown, attempt: number, now?: number, options?: {
|
|
10
|
+
readonly retryBudgetExceeded?: boolean;
|
|
11
|
+
}) => number | undefined;
|
|
10
12
|
/**
|
|
11
13
|
* Runs `read`, reading again on a failure {@link readRetryDelayMs} admits, until the total wait
|
|
12
14
|
* would pass {@link READ_RETRY_BUDGET_MS} or `deadline`. The failure it ends with names the run.
|
|
@@ -16,3 +18,13 @@ export declare const retryRead: <A, E, R>(read: Effect.Effect<A, E, R>, options:
|
|
|
16
18
|
readonly what: string;
|
|
17
19
|
readonly deadline: number;
|
|
18
20
|
}) => Effect.Effect<A, SealantApiError, R>;
|
|
21
|
+
/**
|
|
22
|
+
* Retries an idempotent workspace status read on transient transport errors and 5xx responses,
|
|
23
|
+
* within {@link READ_RETRY_BUDGET_MS} and `deadline`. Non-retryable failures — including 429
|
|
24
|
+
* budget refusals, which callers translate into `workspace_readiness_refused` /
|
|
25
|
+
* `workspace_stop_observation_refused` — fail immediately unchanged.
|
|
26
|
+
*/
|
|
27
|
+
export declare const retryWorkspaceRead: <A, E, R>(read: Effect.Effect<A, E, R>, options: {
|
|
28
|
+
readonly workspaceId: string;
|
|
29
|
+
readonly deadline: number;
|
|
30
|
+
}) => Effect.Effect<A, E | SealantApiError, R>;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* backoff, within a bounded total wait. Anything else (a 404, a 400, a body that does not decode)
|
|
6
6
|
* fails at once. Either way the failure names the run, so a caller can still read its result.
|
|
7
7
|
*/
|
|
8
|
-
import { BudgetExceededError, RunInternalServerError } from "@sealant/api-contracts";
|
|
8
|
+
import { BudgetExceededError, RunInternalServerError, WorkspaceInternalServerError, } from "@sealant/api-contracts";
|
|
9
9
|
import { Duration, Effect, Result } from "effect";
|
|
10
10
|
import { HttpClientError } from "effect/http";
|
|
11
11
|
import { SealantApiError } from "../errors.js";
|
|
@@ -29,8 +29,9 @@ const retryAfterMs = (value, now) => {
|
|
|
29
29
|
const statusOf = (error) => {
|
|
30
30
|
if (error instanceof BudgetExceededError)
|
|
31
31
|
return 429;
|
|
32
|
-
if (error instanceof RunInternalServerError)
|
|
32
|
+
if (error instanceof RunInternalServerError || error instanceof WorkspaceInternalServerError) {
|
|
33
33
|
return 500;
|
|
34
|
+
}
|
|
34
35
|
if (HttpClientError.isHttpClientError(error) && "response" in error.reason) {
|
|
35
36
|
return error.reason.response.status;
|
|
36
37
|
}
|
|
@@ -40,13 +41,15 @@ const statusOf = (error) => {
|
|
|
40
41
|
* How long to wait before reading again after `error` on retry number `attempt` (from 0), or
|
|
41
42
|
* `undefined` when the failure is not one a second read can fix.
|
|
42
43
|
*/
|
|
43
|
-
export const readRetryDelayMs = (error, attempt, now = Date.now()) => {
|
|
44
|
+
export const readRetryDelayMs = (error, attempt, now = Date.now(), options) => {
|
|
45
|
+
const retryBudget = options?.retryBudgetExceeded ?? true;
|
|
44
46
|
const backoff = Math.min(READ_RETRY_FIRST_MS * 2 ** attempt, READ_RETRY_MAX_BACKOFF_MS);
|
|
45
47
|
if (error instanceof BudgetExceededError) {
|
|
46
|
-
return Math.max(error.retryAfterSeconds * 1_000, backoff);
|
|
48
|
+
return retryBudget ? Math.max(error.retryAfterSeconds * 1_000, backoff) : undefined;
|
|
47
49
|
}
|
|
48
|
-
if (error instanceof RunInternalServerError)
|
|
50
|
+
if (error instanceof RunInternalServerError || error instanceof WorkspaceInternalServerError) {
|
|
49
51
|
return backoff;
|
|
52
|
+
}
|
|
50
53
|
if (!HttpClientError.isHttpClientError(error))
|
|
51
54
|
return undefined;
|
|
52
55
|
const { reason } = error;
|
|
@@ -55,6 +58,8 @@ export const readRetryDelayMs = (error, attempt, now = Date.now()) => {
|
|
|
55
58
|
if (!("response" in reason))
|
|
56
59
|
return undefined;
|
|
57
60
|
const status = reason.response.status;
|
|
61
|
+
if (status === 429 && !retryBudget)
|
|
62
|
+
return undefined;
|
|
58
63
|
if (status !== 429 && status < 500)
|
|
59
64
|
return undefined;
|
|
60
65
|
const after = retryAfterMs(reason.response.headers["retry-after"], now);
|
|
@@ -84,3 +89,31 @@ export const retryRead = (read, options) => Effect.gen(function* () {
|
|
|
84
89
|
waited += delay;
|
|
85
90
|
}
|
|
86
91
|
});
|
|
92
|
+
/**
|
|
93
|
+
* Retries an idempotent workspace status read on transient transport errors and 5xx responses,
|
|
94
|
+
* within {@link READ_RETRY_BUDGET_MS} and `deadline`. Non-retryable failures — including 429
|
|
95
|
+
* budget refusals, which callers translate into `workspace_readiness_refused` /
|
|
96
|
+
* `workspace_stop_observation_refused` — fail immediately unchanged.
|
|
97
|
+
*/
|
|
98
|
+
export const retryWorkspaceRead = (read, options) => Effect.gen(function* () {
|
|
99
|
+
let waited = 0;
|
|
100
|
+
for (let attempt = 0;; attempt += 1) {
|
|
101
|
+
const result = yield* Effect.result(read);
|
|
102
|
+
if (Result.isSuccess(result))
|
|
103
|
+
return result.success;
|
|
104
|
+
const error = result.failure;
|
|
105
|
+
const delay = readRetryDelayMs(error, attempt, Date.now(), { retryBudgetExceeded: false });
|
|
106
|
+
if (delay === undefined) {
|
|
107
|
+
return yield* Effect.fail(error);
|
|
108
|
+
}
|
|
109
|
+
const room = Math.min(READ_RETRY_BUDGET_MS - waited, options.deadline - elapsed());
|
|
110
|
+
if (delay > room) {
|
|
111
|
+
const mapped = toSealantError(error);
|
|
112
|
+
const status = statusOf(error);
|
|
113
|
+
const tries = attempt === 0 ? "" : ` (read ${String(attempt + 1)} times)`;
|
|
114
|
+
return yield* Effect.fail(new SealantApiError(`Reading workspace ${options.workspaceId} failed${tries}: ${mapped.message}`, { code: mapped.code, ...(status === undefined ? {} : { status }), cause: error }));
|
|
115
|
+
}
|
|
116
|
+
yield* Effect.sleep(Duration.millis(delay));
|
|
117
|
+
waited += delay;
|
|
118
|
+
}
|
|
119
|
+
});
|
package/dist/facade/workspace.js
CHANGED
|
@@ -2,6 +2,7 @@ import { sessionArgvIssue, WORKSPACE_GATEWAY_UNAVAILABLE_CODE } from "@sealant/a
|
|
|
2
2
|
import { applyDotfiles } from "../effect/apply-dotfiles.js";
|
|
3
3
|
import { execWorkspace } from "../effect/exec-workspace.js";
|
|
4
4
|
import { applyWorkspaceNetworkPolicyOp, bindWorkspaceOp, getWorkspaceNetworkPolicyOp, revokeWorkspaceAccessOp, flushWorkspaceCaptureOp, getWorkspaceCaptureStatusOp, createSessionAsUserOp, createSessionOp, expireWorkspaceOp, clearWorkspaceSshUserOp, getSessionOp, getWorkspaceOp, listSessionsOp, replanWorkspaceCaptureOp, recoverWorkspaceOp, restartWorkspaceOp, listWorkspaceCredentialsOp, putWorkspaceCredentialsOp, pruneWorkspaceCredentialsOp, releaseWorkspaceCredentialsOp, stopWorkspaceOp, } from "../effect/operations.js";
|
|
5
|
+
import { READ_RETRY_BUDGET_MS, retryWorkspaceRead } from "../effect/read-retry.js";
|
|
5
6
|
import { withCallerTrace } from "../effect/trace.js";
|
|
6
7
|
import { SealantApiError, SealantBoatError, SealantBudgetExceededError, SealantError, SealantNotImplementedError, } from "../errors.js";
|
|
7
8
|
import { specHarnessId } from "../internal/blueprint.js";
|
|
@@ -520,8 +521,21 @@ export const makeWorkspace = (ctx, init) => {
|
|
|
520
521
|
? " A stop was requested; the workspace has not been observed stopped."
|
|
521
522
|
: " Requesting a stop failed; stop it yourself."}`, { code });
|
|
522
523
|
};
|
|
524
|
+
const readDeadline = () => {
|
|
525
|
+
const now = elapsed();
|
|
526
|
+
if (building) {
|
|
527
|
+
const buildRoom = imageBuildTimeoutMs === undefined
|
|
528
|
+
? READ_RETRY_BUDGET_MS
|
|
529
|
+
: Math.max(0, imageBuildTimeoutMs - (buildMs + (now - lastPollAt)));
|
|
530
|
+
return now + buildRoom;
|
|
531
|
+
}
|
|
532
|
+
return now + Math.max(0, readyTimeoutMs - (now - startedAt - buildMs));
|
|
533
|
+
};
|
|
523
534
|
for (;;) {
|
|
524
|
-
const details = await ctx.runtime.run(getWorkspaceOp(init.id, ctx.config.hostLocal.ownerUserId),
|
|
535
|
+
const details = await ctx.runtime.run(retryWorkspaceRead(getWorkspaceOp(init.id, ctx.config.hostLocal.ownerUserId), {
|
|
536
|
+
workspaceId: init.id,
|
|
537
|
+
deadline: readDeadline(),
|
|
538
|
+
}), trace);
|
|
525
539
|
const now = elapsed();
|
|
526
540
|
// The time since the last look was spent building when the last look saw a build.
|
|
527
541
|
if (building)
|
|
@@ -746,7 +760,10 @@ export const makeWorkspace = (ctx, init) => {
|
|
|
746
760
|
const deadline = elapsed() + STOP_TIMEOUT_MS;
|
|
747
761
|
for (;;) {
|
|
748
762
|
const details = await ctx.runtime
|
|
749
|
-
.run(getWorkspaceOp(init.id, ctx.config.hostLocal.ownerUserId),
|
|
763
|
+
.run(retryWorkspaceRead(getWorkspaceOp(init.id, ctx.config.hostLocal.ownerUserId), {
|
|
764
|
+
workspaceId: init.id,
|
|
765
|
+
deadline,
|
|
766
|
+
}), trace)
|
|
750
767
|
.catch((error) => {
|
|
751
768
|
if (error instanceof SealantBudgetExceededError) {
|
|
752
769
|
throw new SealantError(`A stop for workspace ${init.id} was accepted, but a follow-up request reached its budget. Read the workspace again to observe its status.`, { code: "workspace_stop_observation_refused", cause: error });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealant/sdk-next",
|
|
3
|
-
"version": "0.40.0-next.
|
|
3
|
+
"version": "0.40.0-next.966",
|
|
4
4
|
"description": "The fluent public SDK for Sealant — create a workspace, run a harness, replay the record.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"node": ">=20"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.
|
|
29
|
+
"@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.966"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"effect": "^4.0.5"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "449c6833bd97eba69e54001cb970c10b6821063e",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
}
|