@oatscenter/trellis 0.100.0-rc.30 → 0.100.0-rc.31
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/internal_sdk/generated/package.json +1 -1
- package/operations.d.ts +4 -0
- package/package.json +2 -2
- package/service/runtime/core.js +12 -5
- package/service/runtime/internal_jobs/job-manager.d.ts +2 -0
- package/service/runtime/internal_jobs/job-manager.js +45 -16
- package/service/runtime/internal_jobs/runtime-worker.js +5 -0
- package/service/runtime/service.js +17 -0
- package/session/handler_errors.d.ts +7 -1
- package/session/handler_errors.js +13 -1
- package/session.d.ts +1 -1
- package/session.js +3 -3
package/operations.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ export type OperationSnapshot<TProgress = unknown, TOutput = unknown> = {
|
|
|
38
38
|
error?: {
|
|
39
39
|
type: string;
|
|
40
40
|
message: string;
|
|
41
|
+
/** Identifies this failure in the service's log, when the service set one. */
|
|
42
|
+
id?: string;
|
|
43
|
+
/** The trace to follow this failure through, when one was recorded. */
|
|
44
|
+
traceId?: string;
|
|
41
45
|
};
|
|
42
46
|
};
|
|
43
47
|
export type OperationTransferProgress = {
|
package/package.json
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@nats-io/obj": "^3.4.0",
|
|
52
52
|
"@nats-io/transport-node": "^3.4.0",
|
|
53
53
|
"@noble/hashes": "1.8.0",
|
|
54
|
-
"@oatscenter/result": "0.100.0-rc.
|
|
54
|
+
"@oatscenter/result": "0.100.0-rc.31",
|
|
55
55
|
"@opentelemetry/api": "^1.9.1",
|
|
56
56
|
"@opentelemetry/context-async-hooks": "~2.11.0",
|
|
57
57
|
"@opentelemetry/core": "~2.11.0",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"uqr": "0.1.3",
|
|
72
72
|
"zod": "^4.3.6"
|
|
73
73
|
},
|
|
74
|
-
"version": "0.100.0-rc.
|
|
74
|
+
"version": "0.100.0-rc.31",
|
|
75
75
|
"type": "module",
|
|
76
76
|
"license": "Apache-2.0",
|
|
77
77
|
"publishConfig": {
|
package/service/runtime/core.js
CHANGED
|
@@ -17,7 +17,7 @@ import { recordCatalogCounter, recordCatalogDuration, recordCatalogUpDown, route
|
|
|
17
17
|
import { createMapCarrier, extractTraceContext, validateTraceparent, validateTracestate, } from "../../telemetry/carrier.js";
|
|
18
18
|
import { getTrellisTracer } from "../../telemetry/trace.js";
|
|
19
19
|
import { context as otelContext, ROOT_CONTEXT, SpanKind, trace, } from "@opentelemetry/api";
|
|
20
|
-
import { annotateHandlerBoundaryError, buildRuntimeOperationSnapshot, isOperationDeferred, isResultLike, isTerminalRuntimeOperationSnapshot, safeJson, toCatalogAction, Trellis, verifyLocalAuthorization, } from "../../session.js";
|
|
20
|
+
import { annotateHandlerBoundaryError, buildRuntimeOperationSnapshot, callerErrorData, isOperationDeferred, isResultLike, isTerminalRuntimeOperationSnapshot, safeJson, toCatalogAction, Trellis, verifyLocalAuthorization, } from "../../session.js";
|
|
21
21
|
import { LiveAuthorityGuard } from "../../live/authority.js";
|
|
22
22
|
import { fixedTransportProvider, TransportGenerationManager, } from "../../transport/generations.js";
|
|
23
23
|
import { TypedKV } from "../../kv.js";
|
|
@@ -323,7 +323,7 @@ export class TrellisServiceRuntime extends Trellis {
|
|
|
323
323
|
event: { type: "completed" },
|
|
324
324
|
}),
|
|
325
325
|
fail: (operationId, error) => this.#applyOwnedOperationUpdate(operationId, "failed", {
|
|
326
|
-
patch: { error: error
|
|
326
|
+
patch: { error: this.#operationFailureData(operationId, error) },
|
|
327
327
|
event: { type: "failed" },
|
|
328
328
|
}),
|
|
329
329
|
cancel: (operationId) => AsyncResult.from((async () => {
|
|
@@ -1396,7 +1396,7 @@ export class TrellisServiceRuntime extends Trellis {
|
|
|
1396
1396
|
event: { type: "completed" },
|
|
1397
1397
|
}),
|
|
1398
1398
|
fail: (error) => this.#applyControlledOperationUpdate(runtime, fence, ctx, "failed", {
|
|
1399
|
-
patch: { error: error
|
|
1399
|
+
patch: { error: this.#operationFailureData(runtime.id, error) },
|
|
1400
1400
|
event: { type: "failed" },
|
|
1401
1401
|
}),
|
|
1402
1402
|
cancel: () => this.#requestOwnedOperationCancellation(runtime, fence),
|
|
@@ -1420,6 +1420,13 @@ export class TrellisServiceRuntime extends Trellis {
|
|
|
1420
1420
|
defer: () => ({ kind: "deferred" }),
|
|
1421
1421
|
};
|
|
1422
1422
|
}
|
|
1423
|
+
/** Logs a failure's cause under its IDs and returns what its caller may see. */
|
|
1424
|
+
#operationFailureData(target, error) {
|
|
1425
|
+
if (error.getContext().causeMessage !== undefined) {
|
|
1426
|
+
this.#log.error({ operation: target, error: error.toSerializable() }, "Operation failed");
|
|
1427
|
+
}
|
|
1428
|
+
return callerErrorData(error);
|
|
1429
|
+
}
|
|
1423
1430
|
#operationNotFoundError(operationId) {
|
|
1424
1431
|
return new OperationNotFoundError({ operationId });
|
|
1425
1432
|
}
|
|
@@ -1735,7 +1742,7 @@ export class TrellisServiceRuntime extends Trellis {
|
|
|
1735
1742
|
});
|
|
1736
1743
|
void this.respondWithPayload(msg, JSON.stringify({
|
|
1737
1744
|
kind: "error",
|
|
1738
|
-
error: trellisError
|
|
1745
|
+
error: this.#operationFailureData(msg.subject, trellisError),
|
|
1739
1746
|
}), undefined, { responseKind: "success" });
|
|
1740
1747
|
};
|
|
1741
1748
|
// Per-generation control intake: the control subscription is installed on
|
|
@@ -2419,7 +2426,7 @@ export class TrellisServiceRuntime extends Trellis {
|
|
|
2419
2426
|
});
|
|
2420
2427
|
return await this.#applyControlledOperationUpdate(runtime, fence, ctx, "failed", {
|
|
2421
2428
|
patch: {
|
|
2422
|
-
error: annotatedError
|
|
2429
|
+
error: this.#operationFailureData(runtime.id, annotatedError),
|
|
2423
2430
|
completedAt: now(),
|
|
2424
2431
|
},
|
|
2425
2432
|
event: { type: "failed" },
|
|
@@ -24,6 +24,8 @@ type ActiveJobRuntimeMetadata = Partial<ActiveJobMetadata> & {
|
|
|
24
24
|
progressAckIntervalMs?: number;
|
|
25
25
|
latestState?: Job["state"];
|
|
26
26
|
workEventType?: JobEvent["eventType"];
|
|
27
|
+
/** Reads whether the job has finished, once this delivery holds a key slot. */
|
|
28
|
+
isSettled?: () => Promise<boolean>;
|
|
27
29
|
};
|
|
28
30
|
type JobProcessValidation<TPayload, TResult> = {
|
|
29
31
|
validateResult?: (result: TResult, job: Job<TPayload, TResult>) => Promise<void> | void;
|
|
@@ -465,6 +465,12 @@ export class JobManager {
|
|
|
465
465
|
policy: keyedPolicy,
|
|
466
466
|
};
|
|
467
467
|
keyState = acquired.state;
|
|
468
|
+
// The lifecycle read that admitted this delivery may predate another
|
|
469
|
+
// delivery finishing the job and freeing this slot.
|
|
470
|
+
if (await metadata.isSettled?.()) {
|
|
471
|
+
await this.#releaseKeyedSlot(job, lease);
|
|
472
|
+
return { outcome: "deferred", tries, reason: "settled" };
|
|
473
|
+
}
|
|
468
474
|
if (acquired.state.cleanupPending.includes(job.id)) {
|
|
469
475
|
cancellation.cancelForStaleAttempt();
|
|
470
476
|
}
|
|
@@ -602,12 +608,7 @@ export class JobManager {
|
|
|
602
608
|
catch (error) {
|
|
603
609
|
throw JobProcessError.failed(error instanceof Error ? error.message : String(error));
|
|
604
610
|
}
|
|
605
|
-
|
|
606
|
-
if (release === "staleCompletion") {
|
|
607
|
-
await this.#publishStaleCompletionIgnored(job, tries);
|
|
608
|
-
return { outcome: "stale_completion_ignored", tries };
|
|
609
|
-
}
|
|
610
|
-
await this.#publishJobEvent(job.type, job.id, {
|
|
611
|
+
return await this.#settleHoldingSlot(job, lease, tries, {
|
|
611
612
|
jobId: job.id,
|
|
612
613
|
service: job.service,
|
|
613
614
|
jobType: job.type,
|
|
@@ -618,8 +619,7 @@ export class JobManager {
|
|
|
618
619
|
tries,
|
|
619
620
|
result,
|
|
620
621
|
timestamp: this.#meta().nowIso(),
|
|
621
|
-
});
|
|
622
|
-
return { outcome: "completed", tries, result };
|
|
622
|
+
}, { outcome: "completed", tries, result });
|
|
623
623
|
}
|
|
624
624
|
catch (error) {
|
|
625
625
|
if (cancellation.isHostShutdown() || cancellation.isLeaseLost()) {
|
|
@@ -676,12 +676,7 @@ export class JobManager {
|
|
|
676
676
|
operation: job.type,
|
|
677
677
|
phase: "handler_result",
|
|
678
678
|
});
|
|
679
|
-
|
|
680
|
-
if (release === "staleCompletion") {
|
|
681
|
-
await this.#publishStaleCompletionIgnored(job, tries);
|
|
682
|
-
return { outcome: "stale_completion_ignored", tries };
|
|
683
|
-
}
|
|
684
|
-
await this.#publishJobEvent(job.type, job.id, {
|
|
679
|
+
return await this.#settleHoldingSlot(job, lease, tries, {
|
|
685
680
|
jobId: job.id,
|
|
686
681
|
service: job.service,
|
|
687
682
|
jobType: job.type,
|
|
@@ -692,8 +687,7 @@ export class JobManager {
|
|
|
692
687
|
tries,
|
|
693
688
|
error: detail,
|
|
694
689
|
timestamp: this.#meta().nowIso(),
|
|
695
|
-
});
|
|
696
|
-
return { outcome: "failed", tries, error: detail };
|
|
690
|
+
}, { outcome: "failed", tries, error: detail });
|
|
697
691
|
}
|
|
698
692
|
recordTrellisError(error, {
|
|
699
693
|
surface: "job",
|
|
@@ -817,6 +811,41 @@ export class JobManager {
|
|
|
817
811
|
});
|
|
818
812
|
return released.kind === "released" ? "released" : "staleCompletion";
|
|
819
813
|
}
|
|
814
|
+
/**
|
|
815
|
+
* Publishes a terminal event while still holding the key slot, then frees it.
|
|
816
|
+
* A free slot therefore proves a finished job's event is readable, so a
|
|
817
|
+
* redelivered copy that takes the slot can tell the job is done.
|
|
818
|
+
*/
|
|
819
|
+
async #settleHoldingSlot(job, lease, tries, event, settled) {
|
|
820
|
+
if (lease) {
|
|
821
|
+
const renewed = await this.#context.keyCoordinator.renewHeartbeat({
|
|
822
|
+
service: this.#coordinationService(),
|
|
823
|
+
jobType: job.type,
|
|
824
|
+
jobId: job.id,
|
|
825
|
+
lease,
|
|
826
|
+
now: this.#meta().nowIso(),
|
|
827
|
+
});
|
|
828
|
+
if (renewed.kind === "lost") {
|
|
829
|
+
await this.#publishStaleCompletionIgnored(job, tries);
|
|
830
|
+
return { outcome: "stale_completion_ignored", tries };
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
await this.#publishJobEvent(job.type, job.id, event);
|
|
834
|
+
try {
|
|
835
|
+
await this.#releaseKeyedSlot(job, lease);
|
|
836
|
+
}
|
|
837
|
+
catch (error) {
|
|
838
|
+
// The job is finished. Redelivery sees that and clears the slot.
|
|
839
|
+
recordTrellisError(error, {
|
|
840
|
+
surface: "job",
|
|
841
|
+
direction: "worker",
|
|
842
|
+
operation: job.type,
|
|
843
|
+
phase: "slot_release",
|
|
844
|
+
});
|
|
845
|
+
return { outcome: "interrupted", tries };
|
|
846
|
+
}
|
|
847
|
+
return settled;
|
|
848
|
+
}
|
|
820
849
|
async #publishStaleCompletionIgnored(job, tries) {
|
|
821
850
|
await this.#publishJobEvent(job.type, job.id, {
|
|
822
851
|
jobId: job.id,
|
|
@@ -297,6 +297,11 @@ export function startQueueWorkerLoop(options) {
|
|
|
297
297
|
}, {
|
|
298
298
|
latestState: latestLifecycle?.state,
|
|
299
299
|
workEventType: event.eventType,
|
|
300
|
+
...(session.getLatestLifecycleEvent
|
|
301
|
+
? {
|
|
302
|
+
isSettled: async () => lifecycleWorkDecision(await session.getLatestLifecycleEvent?.(job)) === "skip-ack",
|
|
303
|
+
}
|
|
304
|
+
: {}),
|
|
300
305
|
redeliveryCount: msg.info?.redeliveryCount,
|
|
301
306
|
instanceId: options.instanceId,
|
|
302
307
|
progressAckIntervalMs: options.progressAckIntervalMs,
|
|
@@ -1555,6 +1555,23 @@ export function connectTrellisServiceWithRuntimeDeps(args, deps) {
|
|
|
1555
1555
|
};
|
|
1556
1556
|
const connect = () => connectProvisioned(provisioned, "service", {
|
|
1557
1557
|
onPreActivate: async (generation, retainAuthority) => {
|
|
1558
|
+
if (ingress) {
|
|
1559
|
+
// Readmitted with only the right to submit a build, this
|
|
1560
|
+
// build no longer answers for its instance: the deployment
|
|
1561
|
+
// moved past it. It stops rather than linger without
|
|
1562
|
+
// authority; a current build installs itself on connect.
|
|
1563
|
+
const lease = retainAuthority();
|
|
1564
|
+
const metadata = lease.authority.extensions["trellis.nativeParticipant.v1"];
|
|
1565
|
+
lease.release();
|
|
1566
|
+
if (metadata &&
|
|
1567
|
+
typeof metadata === "object" &&
|
|
1568
|
+
!Array.isArray(metadata) &&
|
|
1569
|
+
metadata.participantDigest === "") {
|
|
1570
|
+
const error = new Error("This build is no longer installed for its instance; restart it with the deployment's current build");
|
|
1571
|
+
void connected?.manager.terminate(error);
|
|
1572
|
+
throw error;
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1558
1575
|
await ingress?.install({
|
|
1559
1576
|
id: generation.id,
|
|
1560
1577
|
nc: generation.nc,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseError, Result } from "@oatscenter/result";
|
|
1
|
+
import { BaseError, type BaseErrorSchema, Result } from "@oatscenter/result";
|
|
2
2
|
import { TrellisErrorDataSchema } from "../errors/RemoteError.ts";
|
|
3
3
|
import { UnexpectedError, ValidationError } from "../errors/index.ts";
|
|
4
4
|
import { type TrellisErrorMetricAttributes } from "../telemetry/mod.ts";
|
|
@@ -27,6 +27,12 @@ export type HandlerErrorAnnotationContext = {
|
|
|
27
27
|
};
|
|
28
28
|
export declare function compactHandlerErrorContext(context: HandlerErrorAnnotationContext): Record<string, unknown>;
|
|
29
29
|
export declare function sanitizeHandlerErrorContext(error: BaseError): void;
|
|
30
|
+
/**
|
|
31
|
+
* The form of an error sent to a caller: serialized, without the failure text
|
|
32
|
+
* or stack of its cause. The ID, trace ID and request ID stay, so the caller can
|
|
33
|
+
* quote them to find the full error in the service's log.
|
|
34
|
+
*/
|
|
35
|
+
export declare function callerErrorData(error: BaseError): BaseErrorSchema;
|
|
30
36
|
export declare function annotateHandlerBoundaryError(cause: unknown, context: HandlerErrorAnnotationContext): BaseError;
|
|
31
37
|
export declare function recordRuntimeError(error: unknown, attributes: TrellisErrorMetricAttributes): void;
|
|
32
38
|
export declare function reconstructDeclaredRpcError(errorNames: readonly string[] | undefined, runtimeErrors: readonly RuntimeRpcErrorDesc[] | undefined, data: StaticDecode<typeof TrellisErrorDataSchema>, json: JsonValue): BaseError | ValidationError | UnexpectedError | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseError, Result, isErr } from "@oatscenter/result";
|
|
1
|
+
import { BaseError, Result, isErr, } from "@oatscenter/result";
|
|
2
2
|
import { RemoteError, TrellisErrorDataSchema } from "../errors/RemoteError.js";
|
|
3
3
|
import { UnexpectedError, ValidationError, getBuiltinRpcError, } from "../errors/index.js";
|
|
4
4
|
import { recordTrellisError, } from "../telemetry/mod.js";
|
|
@@ -16,6 +16,18 @@ export function compactHandlerErrorContext(context) {
|
|
|
16
16
|
export function sanitizeHandlerErrorContext(error) {
|
|
17
17
|
delete error.getContext().subject;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* The form of an error sent to a caller: serialized, without the failure text
|
|
21
|
+
* or stack of its cause. The ID, trace ID and request ID stay, so the caller can
|
|
22
|
+
* quote them to find the full error in the service's log.
|
|
23
|
+
*/
|
|
24
|
+
export function callerErrorData(error) {
|
|
25
|
+
const data = error.toSerializable();
|
|
26
|
+
if (data.context === undefined)
|
|
27
|
+
return data;
|
|
28
|
+
const { causeMessage: _message, causeStack: _stack, ...kept } = data.context;
|
|
29
|
+
return { ...data, context: kept };
|
|
30
|
+
}
|
|
19
31
|
export function annotateHandlerBoundaryError(cause, context) {
|
|
20
32
|
const error = cause instanceof BaseError && !(cause instanceof RemoteError)
|
|
21
33
|
? cause
|
package/session.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export { isOperationDeferred, buildRuntimeOperationSnapshot, isTerminalRuntimeOp
|
|
|
27
27
|
export type { OperationRuntimeHandle, OperationDeferred, AcceptedOperation, OperationTransferHandle, OperationHandlerContext, OperationRegistration, OperationTransferContextOf, OperationSurface, RuntimeOperationDesc, RuntimeOperationSignal, RuntimeOperationSignalWaiter, RuntimeOperationTransferProgress, RuntimeOperationState, RuntimeOperationSnapshot, RuntimeOperationRecord, DurableOperationRecord, RuntimeOperationAcceptedEnvelope, RuntimeOperationControlRequest, RuntimeOperationController, } from "./session/operations.ts";
|
|
28
28
|
export { StateConflictError, ResourceUnavailableError, StateHandle, } from "./session/state.ts";
|
|
29
29
|
export type { StateValue, ValueStateStoreClient, StateFacade, StateResourceCalls, StateRegistration, StateWatch, } from "./session/state.ts";
|
|
30
|
-
export { isResultLike, annotateHandlerBoundaryError, } from "./session/handler_errors.ts";
|
|
30
|
+
export { isResultLike, annotateHandlerBoundaryError, callerErrorData, } from "./session/handler_errors.ts";
|
|
31
31
|
export type { HandlerErrorAnnotationContext } from "./session/handler_errors.ts";
|
|
32
32
|
export type { EventListenerContext } from "./session/events.ts";
|
|
33
33
|
export type { ActiveRpcFacade, ActiveEventFacade, ActiveEventPublishFacade, ActiveLiveFacade, ActiveOperationFacade, ActiveRpcHandleFacade, LiveSurface, RpcHandlerContext, HandlerTrellis, HandlerKvFacade, HandlerStoreHandle, HandlerJobQueue, HandlerJobsFacade, HandlerTrellisForContract, HandlerFn, } from "./session/facades.ts";
|
package/session.js
CHANGED
|
@@ -39,12 +39,12 @@ import {} from "./session/operations.js";
|
|
|
39
39
|
import { EMPTY_TRELLIS_API, activeTraceId, causeLogData, causeMessage, ingressRetiredError, isBrowserAuthRequiredError, isRuntimeRpcErrorDesc, payloadByteLength, traceIdFromTraceparent, } from "./session/helpers.js";
|
|
40
40
|
import { toCatalogAction, verifyLocalAuthorization, } from "./session/local_authorization.js";
|
|
41
41
|
import { MAX_PENDING_OPENINGS, base64urlEncode, callerOwnsReply, classifyRequestTransportFailure, createTransportError, encodeRuntimeSchema, mapTransportAcquireFailure, outcomeForFailure, parseRuntimeSchema, requestFailedTransportError, safeJson, } from "./session/wire.js";
|
|
42
|
-
import { annotateHandlerBoundaryError, isResultLike, reconstructDeclaredRpcError, recordRuntimeError, } from "./session/handler_errors.js";
|
|
42
|
+
import { annotateHandlerBoundaryError, callerErrorData, isResultLike, reconstructDeclaredRpcError, recordRuntimeError, } from "./session/handler_errors.js";
|
|
43
43
|
export { verifyLocalAuthorization, toCatalogAction, } from "./session/local_authorization.js";
|
|
44
44
|
export { safeJson, classifyRequestTransportFailure, createActionUnavailableError, base64urlEncode, base64urlDecode, toArrayBuffer, sha256, } from "./session/wire.js";
|
|
45
45
|
export { isOperationDeferred, buildRuntimeOperationSnapshot, isTerminalRuntimeOperationSnapshot, } from "./session/operations.js";
|
|
46
46
|
export { StateConflictError, ResourceUnavailableError, StateHandle, } from "./session/state.js";
|
|
47
|
-
export { isResultLike, annotateHandlerBoundaryError, } from "./session/handler_errors.js";
|
|
47
|
+
export { isResultLike, annotateHandlerBoundaryError, callerErrorData, } from "./session/handler_errors.js";
|
|
48
48
|
/**
|
|
49
49
|
* Creates a Trellis runtime with bootstrap-resolved bindings.
|
|
50
50
|
*
|
|
@@ -1966,7 +1966,7 @@ export class Trellis {
|
|
|
1966
1966
|
responseBytes: context.responseBytes,
|
|
1967
1967
|
error: trellisError.toSerializable(),
|
|
1968
1968
|
}, "RPC error");
|
|
1969
|
-
const errorData = trellisError
|
|
1969
|
+
const errorData = callerErrorData(trellisError);
|
|
1970
1970
|
const hdrs = natsHeaders();
|
|
1971
1971
|
hdrs.set("status", "error");
|
|
1972
1972
|
const serialized = Result.try(() => JSON.stringify(errorData));
|