@vtxmacro/cli 2026.8.45 → 2026.8.46
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/bin/vtx.js +266 -174
- package/package.json +1 -1
package/bin/vtx.js
CHANGED
|
@@ -38,7 +38,7 @@ var init_agent_cli_release = __esm({
|
|
|
38
38
|
"agent-cli-release.json"() {
|
|
39
39
|
agent_cli_release_default = {
|
|
40
40
|
package_name: "@vtxmacro/cli",
|
|
41
|
-
package_version: "2026.8.
|
|
41
|
+
package_version: "2026.8.46",
|
|
42
42
|
codex_package_name: "@openai/codex",
|
|
43
43
|
codex_version: "0.147.0",
|
|
44
44
|
copilot_sdk_package_name: "@github/copilot-sdk",
|
|
@@ -30744,6 +30744,9 @@ var init_runner = __esm({
|
|
|
30744
30744
|
let completed = 0;
|
|
30745
30745
|
let failed = 0;
|
|
30746
30746
|
let acceptAttemptUpdates = true;
|
|
30747
|
+
let stopHostHeartbeatLoop = () => {
|
|
30748
|
+
};
|
|
30749
|
+
let hostHeartbeatLoop = Promise.resolve();
|
|
30747
30750
|
let wakeDrain;
|
|
30748
30751
|
const drainSignal = new Promise((resolve6) => {
|
|
30749
30752
|
wakeDrain = resolve6;
|
|
@@ -30759,6 +30762,7 @@ var init_runner = __esm({
|
|
|
30759
30762
|
if (drainRequested && priority(reason) <= priority(drainReason)) return;
|
|
30760
30763
|
drainRequested = true;
|
|
30761
30764
|
drainReason = reason;
|
|
30765
|
+
stopHostHeartbeatLoop();
|
|
30762
30766
|
wakeDrain();
|
|
30763
30767
|
};
|
|
30764
30768
|
try {
|
|
@@ -30890,6 +30894,18 @@ var init_runner = __esm({
|
|
|
30890
30894
|
updated_at: isoAt(now())
|
|
30891
30895
|
};
|
|
30892
30896
|
await this.persistReceipt(receipt, now);
|
|
30897
|
+
let receiptMutationChain = Promise.resolve();
|
|
30898
|
+
const mutateReceipt = async (mutation) => {
|
|
30899
|
+
let result2;
|
|
30900
|
+
const operation = receiptMutationChain.then(async () => {
|
|
30901
|
+
result2 = mutation(receipt);
|
|
30902
|
+
receipt = result2;
|
|
30903
|
+
await this.persistReceipt(receipt, now);
|
|
30904
|
+
});
|
|
30905
|
+
receiptMutationChain = operation;
|
|
30906
|
+
await operation;
|
|
30907
|
+
return result2;
|
|
30908
|
+
};
|
|
30893
30909
|
const envelopePublicKey = await this.dependencies.envelopePublicKey(credential);
|
|
30894
30910
|
const retryExact = async (operation, boundary = {}) => {
|
|
30895
30911
|
let lastError;
|
|
@@ -30932,40 +30948,48 @@ var init_runner = __esm({
|
|
|
30932
30948
|
const publishAdvertisement = async (health, forceAdvance, retryRemote = true, allowDefinitiveReseed = true) => {
|
|
30933
30949
|
let advertisement = receipt.pending_advertisement;
|
|
30934
30950
|
if (!advertisement) {
|
|
30935
|
-
const
|
|
30936
|
-
|
|
30937
|
-
|
|
30938
|
-
|
|
30939
|
-
|
|
30940
|
-
|
|
30941
|
-
|
|
30942
|
-
|
|
30943
|
-
|
|
30944
|
-
|
|
30945
|
-
|
|
30946
|
-
|
|
30947
|
-
|
|
30948
|
-
|
|
30949
|
-
|
|
30950
|
-
|
|
30951
|
-
|
|
30952
|
-
|
|
30953
|
-
|
|
30954
|
-
|
|
30955
|
-
|
|
30956
|
-
|
|
30957
|
-
|
|
30958
|
-
|
|
30959
|
-
|
|
30960
|
-
|
|
30961
|
-
|
|
30951
|
+
const updated = await mutateReceipt((current) => {
|
|
30952
|
+
if (current.pending_advertisement) return current;
|
|
30953
|
+
const generation = current.registered && forceAdvance ? current.advertisement_generation + 1 : current.advertisement_generation;
|
|
30954
|
+
const advertisedAt = now();
|
|
30955
|
+
const pendingAdvertisement = hostAdvertisementSchema.parse({
|
|
30956
|
+
schema_version: EXTERNAL_INFERENCE_ADVERTISEMENT_SCHEMA_VERSION,
|
|
30957
|
+
contract_version: EXTERNAL_INFERENCE_CONTRACT_VERSION,
|
|
30958
|
+
operation_id: stableOperationId("advertise", [
|
|
30959
|
+
localState.host_id,
|
|
30960
|
+
localState.host_generation,
|
|
30961
|
+
generation,
|
|
30962
|
+
localState.key_generation,
|
|
30963
|
+
advertisedAt
|
|
30964
|
+
]),
|
|
30965
|
+
host_id: localState.host_id,
|
|
30966
|
+
host_generation: localState.host_generation,
|
|
30967
|
+
advertisement_generation: generation,
|
|
30968
|
+
key_generation: localState.key_generation,
|
|
30969
|
+
adapter: settings.adapterId,
|
|
30970
|
+
display_name: this.options.displayName.trim(),
|
|
30971
|
+
...this.options.authenticatedAccountIdentity ? { authenticated_account_identity: this.options.authenticatedAccountIdentity } : {},
|
|
30972
|
+
authenticated_account_email: this.options.authenticatedAccountEmail ?? null,
|
|
30973
|
+
authenticated_account_plan: this.options.authenticatedAccountPlan ?? null,
|
|
30974
|
+
protocol_version: this.options.protocolVersion,
|
|
30975
|
+
envelope_public_key: envelopePublicKey,
|
|
30976
|
+
health,
|
|
30977
|
+
advertised_at: isoAt(advertisedAt),
|
|
30978
|
+
expires_at: isoAt(advertisedAt + settings.advertisementTtlMs),
|
|
30979
|
+
models: settings.advertisedModels
|
|
30980
|
+
});
|
|
30981
|
+
return {
|
|
30982
|
+
...current,
|
|
30983
|
+
pending_advertisement: pendingAdvertisement,
|
|
30984
|
+
updated_at: isoAt(now())
|
|
30985
|
+
};
|
|
30962
30986
|
});
|
|
30963
|
-
|
|
30964
|
-
|
|
30965
|
-
|
|
30966
|
-
|
|
30967
|
-
|
|
30968
|
-
|
|
30987
|
+
advertisement = updated.pending_advertisement;
|
|
30988
|
+
}
|
|
30989
|
+
if (!advertisement) {
|
|
30990
|
+
throw new InferenceHostRecoveryRequiredError(
|
|
30991
|
+
"The durable host advertisement receipt is unavailable."
|
|
30992
|
+
);
|
|
30969
30993
|
}
|
|
30970
30994
|
const tool = receipt.registered ? "inference.host.advertise" : "inference.host.register";
|
|
30971
30995
|
let result2;
|
|
@@ -30980,26 +31004,24 @@ var init_runner = __esm({
|
|
|
30980
31004
|
const definitivelyNotApplied = error48 instanceof ExternalInferenceMcpError ? error48.definitivelyNotApplied : Boolean(error48 && typeof error48 === "object" && error48.definitivelyNotApplied === true);
|
|
30981
31005
|
const expectedGeneration = receipt.registered ? receipt.advertisement_generation + 1 : receipt.advertisement_generation;
|
|
30982
31006
|
if (definitivelyNotApplied && advertisement.advertisement_generation === expectedGeneration && allowDefinitiveReseed) {
|
|
30983
|
-
|
|
30984
|
-
...
|
|
30985
|
-
pending_advertisement: null,
|
|
31007
|
+
await mutateReceipt((current) => ({
|
|
31008
|
+
...current,
|
|
31009
|
+
pending_advertisement: current.pending_advertisement?.operation_id === advertisement.operation_id ? null : current.pending_advertisement,
|
|
30986
31010
|
updated_at: isoAt(now())
|
|
30987
|
-
};
|
|
30988
|
-
await this.persistReceipt(receipt, now);
|
|
31011
|
+
}));
|
|
30989
31012
|
return await publishAdvertisement(health, forceAdvance, retryRemote, false);
|
|
30990
31013
|
}
|
|
30991
31014
|
throw error48;
|
|
30992
31015
|
}
|
|
30993
31016
|
assertAdvertisementResult(advertisement, result2);
|
|
30994
|
-
|
|
30995
|
-
...
|
|
31017
|
+
await mutateReceipt((current) => ({
|
|
31018
|
+
...current,
|
|
30996
31019
|
registered: true,
|
|
30997
31020
|
advertisement_generation: result2.host.advertisement_generation,
|
|
30998
31021
|
advertisement_expires_at: advertisement.expires_at,
|
|
30999
|
-
pending_advertisement: null,
|
|
31022
|
+
pending_advertisement: current.pending_advertisement?.operation_id === advertisement.operation_id ? null : current.pending_advertisement,
|
|
31000
31023
|
updated_at: isoAt(now())
|
|
31001
|
-
};
|
|
31002
|
-
await this.persistReceipt(receipt, now);
|
|
31024
|
+
}));
|
|
31003
31025
|
};
|
|
31004
31026
|
const wasRegistered = receipt.registered;
|
|
31005
31027
|
await publishAdvertisement("healthy", wasRegistered);
|
|
@@ -31012,32 +31034,34 @@ var init_runner = __esm({
|
|
|
31012
31034
|
let providerRateLimitsObservedAtMs = now();
|
|
31013
31035
|
const hostHeartbeat = async (status, requestOptions = {
|
|
31014
31036
|
signal: this.options.signal
|
|
31015
|
-
}, retryRemote = true, allowOfflineProjection = false, definitiveReseedAttempt = 0) => {
|
|
31016
|
-
|
|
31017
|
-
|
|
31018
|
-
|
|
31019
|
-
|
|
31020
|
-
|
|
31021
|
-
|
|
31022
|
-
|
|
31023
|
-
|
|
31024
|
-
|
|
31025
|
-
|
|
31026
|
-
|
|
31027
|
-
|
|
31028
|
-
|
|
31029
|
-
|
|
31030
|
-
|
|
31031
|
-
|
|
31032
|
-
|
|
31033
|
-
|
|
31034
|
-
|
|
31035
|
-
|
|
31036
|
-
|
|
31037
|
-
|
|
31038
|
-
|
|
31039
|
-
|
|
31040
|
-
|
|
31037
|
+
}, retryRemote = true, allowOfflineProjection = false, definitiveReseedAttempt = 0, advertisementGeneration = receipt.advertisement_generation) => {
|
|
31038
|
+
let request;
|
|
31039
|
+
await mutateReceipt((current) => {
|
|
31040
|
+
const sequence = current.host_heartbeat_sequence + 1;
|
|
31041
|
+
request = {
|
|
31042
|
+
schema_version: "external_inference_host_heartbeat_v1",
|
|
31043
|
+
contract_version: EXTERNAL_INFERENCE_CONTRACT_VERSION,
|
|
31044
|
+
host_id: localState.host_id,
|
|
31045
|
+
host_generation: localState.host_generation,
|
|
31046
|
+
advertisement_generation: advertisementGeneration,
|
|
31047
|
+
key_generation: localState.key_generation,
|
|
31048
|
+
sequence,
|
|
31049
|
+
status,
|
|
31050
|
+
active_attempts: active.size,
|
|
31051
|
+
available_slots: settings.maxConcurrency === null ? UNBOUNDED_AVAILABLE_SLOTS - active.size : Math.max(0, settings.maxConcurrency - active.size),
|
|
31052
|
+
provider_weekly_quota: providerWeeklyQuotaFromRateLimits(
|
|
31053
|
+
providerRateLimits,
|
|
31054
|
+
providerRateLimitsObservedAtMs,
|
|
31055
|
+
now()
|
|
31056
|
+
),
|
|
31057
|
+
observed_at: isoAt(now())
|
|
31058
|
+
};
|
|
31059
|
+
return {
|
|
31060
|
+
...current,
|
|
31061
|
+
host_heartbeat_sequence: sequence,
|
|
31062
|
+
updated_at: isoAt(now())
|
|
31063
|
+
};
|
|
31064
|
+
});
|
|
31041
31065
|
const heartbeatOperation = () => mcp.callTool(
|
|
31042
31066
|
"inference.host.heartbeat",
|
|
31043
31067
|
request,
|
|
@@ -31054,7 +31078,8 @@ var init_runner = __esm({
|
|
|
31054
31078
|
requestOptions,
|
|
31055
31079
|
retryRemote,
|
|
31056
31080
|
allowOfflineProjection,
|
|
31057
|
-
definitiveReseedAttempt + 1
|
|
31081
|
+
definitiveReseedAttempt + 1,
|
|
31082
|
+
advertisementGeneration
|
|
31058
31083
|
);
|
|
31059
31084
|
}
|
|
31060
31085
|
throw error48;
|
|
@@ -31089,12 +31114,109 @@ var init_runner = __esm({
|
|
|
31089
31114
|
}
|
|
31090
31115
|
return gapMs;
|
|
31091
31116
|
};
|
|
31092
|
-
let nextHostHeartbeatAt = now() + settings.hostHeartbeatMs;
|
|
31093
31117
|
let nextAdvertisementAttemptAt = 0;
|
|
31094
31118
|
let nextProviderRateLimitRefreshAt = now() + settings.providerRateLimitRefreshMs;
|
|
31095
31119
|
let nextClaimAt = Math.max(now(), providerRetryAtMs ?? 0);
|
|
31096
31120
|
let pendingClaimPromotions = 0;
|
|
31097
31121
|
let onceClaimed = false;
|
|
31122
|
+
const hostHeartbeatAbort = new AbortController();
|
|
31123
|
+
stopHostHeartbeatLoop = () => hostHeartbeatAbort.abort();
|
|
31124
|
+
let nextHostHeartbeatAt = now() + settings.hostHeartbeatMs;
|
|
31125
|
+
hostHeartbeatLoop = (async () => {
|
|
31126
|
+
while (!drainRequested && !hostHeartbeatAbort.signal.aborted) {
|
|
31127
|
+
try {
|
|
31128
|
+
await sleep4(
|
|
31129
|
+
Math.max(MIN_SLEEP_MS, nextHostHeartbeatAt - now()),
|
|
31130
|
+
hostHeartbeatAbort.signal
|
|
31131
|
+
);
|
|
31132
|
+
} catch (error48) {
|
|
31133
|
+
if (hostHeartbeatAbort.signal.aborted || drainRequested) return;
|
|
31134
|
+
throw error48;
|
|
31135
|
+
}
|
|
31136
|
+
if (drainRequested || hostHeartbeatAbort.signal.aborted) return;
|
|
31137
|
+
const heartbeatStartedAt = now();
|
|
31138
|
+
observeHostHeartbeatGap(heartbeatStartedAt);
|
|
31139
|
+
const attemptedAdvertisementGeneration = receipt.advertisement_generation;
|
|
31140
|
+
try {
|
|
31141
|
+
const expiresAt = receipt.advertisement_expires_at ? Date.parse(receipt.advertisement_expires_at) : 0;
|
|
31142
|
+
const refreshPendingAcrossExpiry = receipt.pending_advertisement !== null && expiresAt <= heartbeatStartedAt;
|
|
31143
|
+
await hostHeartbeat(
|
|
31144
|
+
"healthy",
|
|
31145
|
+
{ signal: hostHeartbeatAbort.signal },
|
|
31146
|
+
false,
|
|
31147
|
+
refreshPendingAcrossExpiry,
|
|
31148
|
+
0,
|
|
31149
|
+
attemptedAdvertisementGeneration
|
|
31150
|
+
);
|
|
31151
|
+
} catch (error48) {
|
|
31152
|
+
if (hostHeartbeatAbort.signal.aborted || drainRequested) return;
|
|
31153
|
+
const errorCode = error48 && typeof error48 === "object" && "code" in error48 ? String(error48.code) : "";
|
|
31154
|
+
const pendingAdvertisement = receipt.pending_advertisement;
|
|
31155
|
+
const recoveryAdvertisementGeneration = receipt.advertisement_generation > attemptedAdvertisementGeneration ? receipt.advertisement_generation : errorCode === "generation_stale" && pendingAdvertisement && pendingAdvertisement.advertisement_generation === attemptedAdvertisementGeneration + 1 ? pendingAdvertisement.advertisement_generation : null;
|
|
31156
|
+
if (errorCode === "generation_stale" && recoveryAdvertisementGeneration !== null) {
|
|
31157
|
+
try {
|
|
31158
|
+
await hostHeartbeat(
|
|
31159
|
+
"healthy",
|
|
31160
|
+
{ signal: hostHeartbeatAbort.signal },
|
|
31161
|
+
false,
|
|
31162
|
+
false,
|
|
31163
|
+
0,
|
|
31164
|
+
recoveryAdvertisementGeneration
|
|
31165
|
+
);
|
|
31166
|
+
if (receipt.advertisement_generation < recoveryAdvertisementGeneration) {
|
|
31167
|
+
await mutateReceipt((current) => current.advertisement_generation >= recoveryAdvertisementGeneration ? current : {
|
|
31168
|
+
...current,
|
|
31169
|
+
advertisement_generation: recoveryAdvertisementGeneration,
|
|
31170
|
+
advertisement_expires_at: pendingAdvertisement?.expires_at ?? current.advertisement_expires_at,
|
|
31171
|
+
updated_at: isoAt(now())
|
|
31172
|
+
});
|
|
31173
|
+
}
|
|
31174
|
+
} catch (recoveryError) {
|
|
31175
|
+
if (hostHeartbeatAbort.signal.aborted || drainRequested) return;
|
|
31176
|
+
if (controlPlaneFatal(recoveryError)) {
|
|
31177
|
+
requestDrain("authority_lost");
|
|
31178
|
+
return;
|
|
31179
|
+
}
|
|
31180
|
+
if (!retryableRemoteError(recoveryError)) {
|
|
31181
|
+
requestDrain("host_heartbeat_failed");
|
|
31182
|
+
return;
|
|
31183
|
+
}
|
|
31184
|
+
nextHostHeartbeatAt = now() + remoteRetryAfterMs(recoveryError, settings.hostHeartbeatMs);
|
|
31185
|
+
continue;
|
|
31186
|
+
}
|
|
31187
|
+
} else if (controlPlaneFatal(error48)) {
|
|
31188
|
+
requestDrain("authority_lost");
|
|
31189
|
+
return;
|
|
31190
|
+
} else if (!retryableRemoteError(error48)) {
|
|
31191
|
+
requestDrain("host_heartbeat_failed");
|
|
31192
|
+
return;
|
|
31193
|
+
} else {
|
|
31194
|
+
nextHostHeartbeatAt = now() + remoteRetryAfterMs(error48, settings.hostHeartbeatMs);
|
|
31195
|
+
continue;
|
|
31196
|
+
}
|
|
31197
|
+
}
|
|
31198
|
+
const heartbeatSucceededAt = now();
|
|
31199
|
+
const gapMs = observeHostHeartbeatGap(heartbeatSucceededAt);
|
|
31200
|
+
if (hostHeartbeatGapOpen) {
|
|
31201
|
+
emitDiagnostic("host_heartbeat_gap_recovered", {
|
|
31202
|
+
gap_ms: gapMs,
|
|
31203
|
+
configured_interval_ms: settings.hostHeartbeatMs,
|
|
31204
|
+
diagnostic_threshold_ms: hostHeartbeatGapThresholdMs,
|
|
31205
|
+
active_attempts: active.size,
|
|
31206
|
+
host_heartbeat_sequence: receipt.host_heartbeat_sequence
|
|
31207
|
+
});
|
|
31208
|
+
hostHeartbeatGapOpen = false;
|
|
31209
|
+
}
|
|
31210
|
+
lastHostHeartbeatSucceededAt = heartbeatSucceededAt;
|
|
31211
|
+
nextHostHeartbeatAt = Math.max(
|
|
31212
|
+
nextHostHeartbeatAt + settings.hostHeartbeatMs,
|
|
31213
|
+
heartbeatSucceededAt + MIN_SLEEP_MS
|
|
31214
|
+
);
|
|
31215
|
+
}
|
|
31216
|
+
})().catch((error48) => {
|
|
31217
|
+
if (hostHeartbeatAbort.signal.aborted || drainRequested) return;
|
|
31218
|
+
requestDrain(controlPlaneFatal(error48) ? "authority_lost" : "host_heartbeat_failed");
|
|
31219
|
+
});
|
|
31098
31220
|
const recoveryQueue = [];
|
|
31099
31221
|
const attemptStartRetryCounts = /* @__PURE__ */ new Map();
|
|
31100
31222
|
const launchClaim = (claim, recovery, claimRequest) => {
|
|
@@ -31130,15 +31252,14 @@ var init_runner = __esm({
|
|
|
31130
31252
|
credential,
|
|
31131
31253
|
mcp,
|
|
31132
31254
|
receipt: () => receipt,
|
|
31133
|
-
updateReceipt: async (
|
|
31255
|
+
updateReceipt: async (mutation) => {
|
|
31134
31256
|
if (!acceptAttemptUpdates) {
|
|
31135
31257
|
throw new InferenceHostRunnerError(
|
|
31136
31258
|
"runtime_closed",
|
|
31137
31259
|
"The drained inference runtime no longer accepts attempt updates."
|
|
31138
31260
|
);
|
|
31139
31261
|
}
|
|
31140
|
-
|
|
31141
|
-
await this.persistReceipt(receipt, now);
|
|
31262
|
+
await mutateReceipt(mutation);
|
|
31142
31263
|
},
|
|
31143
31264
|
retryExact,
|
|
31144
31265
|
signal: controller.signal,
|
|
@@ -31236,10 +31357,11 @@ var init_runner = __esm({
|
|
|
31236
31357
|
return attemptId;
|
|
31237
31358
|
};
|
|
31238
31359
|
const removeRecoveredAttempt = async (attemptId) => {
|
|
31239
|
-
|
|
31240
|
-
|
|
31241
|
-
|
|
31242
|
-
|
|
31360
|
+
await mutateReceipt((current) => {
|
|
31361
|
+
const attempts = { ...current.attempts };
|
|
31362
|
+
delete attempts[attemptId];
|
|
31363
|
+
return { ...current, attempts, updated_at: isoAt(now()) };
|
|
31364
|
+
});
|
|
31243
31365
|
};
|
|
31244
31366
|
for (const recovery of Object.values({ ...receipt.attempts })) {
|
|
31245
31367
|
if (recovery.phase === "terminal_pending") {
|
|
@@ -31354,73 +31476,37 @@ var init_runner = __esm({
|
|
|
31354
31476
|
nextClaimAt = Math.max(nextClaimAt, nextAdvertisementAttemptAt);
|
|
31355
31477
|
}
|
|
31356
31478
|
}
|
|
31357
|
-
if (currentTime >= nextHostHeartbeatAt) {
|
|
31358
|
-
observeHostHeartbeatGap(currentTime);
|
|
31359
|
-
try {
|
|
31360
|
-
const refreshPendingAcrossExpiry = receipt.pending_advertisement !== null && expiresAt <= currentTime && nextAdvertisementAttemptAt > currentTime;
|
|
31361
|
-
await hostHeartbeat(
|
|
31362
|
-
"healthy",
|
|
31363
|
-
{ signal: this.options.signal },
|
|
31364
|
-
false,
|
|
31365
|
-
refreshPendingAcrossExpiry
|
|
31366
|
-
);
|
|
31367
|
-
const heartbeatSucceededAt = now();
|
|
31368
|
-
const gapMs = observeHostHeartbeatGap(heartbeatSucceededAt);
|
|
31369
|
-
if (hostHeartbeatGapOpen) {
|
|
31370
|
-
emitDiagnostic("host_heartbeat_gap_recovered", {
|
|
31371
|
-
gap_ms: gapMs,
|
|
31372
|
-
configured_interval_ms: settings.hostHeartbeatMs,
|
|
31373
|
-
diagnostic_threshold_ms: hostHeartbeatGapThresholdMs,
|
|
31374
|
-
active_attempts: active.size,
|
|
31375
|
-
host_heartbeat_sequence: receipt.host_heartbeat_sequence
|
|
31376
|
-
});
|
|
31377
|
-
hostHeartbeatGapOpen = false;
|
|
31378
|
-
}
|
|
31379
|
-
lastHostHeartbeatSucceededAt = heartbeatSucceededAt;
|
|
31380
|
-
} catch (error48) {
|
|
31381
|
-
if (controlPlaneFatal(error48)) {
|
|
31382
|
-
requestDrain("authority_lost");
|
|
31383
|
-
break;
|
|
31384
|
-
}
|
|
31385
|
-
if (!retryableRemoteError(error48)) {
|
|
31386
|
-
requestDrain("host_heartbeat_failed");
|
|
31387
|
-
break;
|
|
31388
|
-
}
|
|
31389
|
-
nextHostHeartbeatAt = now() + remoteRetryAfterMs(error48, settings.hostHeartbeatMs);
|
|
31390
|
-
}
|
|
31391
|
-
if (!drainRequested && currentTime >= nextHostHeartbeatAt) {
|
|
31392
|
-
nextHostHeartbeatAt = now() + settings.hostHeartbeatMs;
|
|
31393
|
-
}
|
|
31394
|
-
}
|
|
31395
31479
|
while (recoveryQueue.length > 0 && (settings.maxConcurrency === null || active.size < settings.maxConcurrency)) {
|
|
31396
31480
|
const recovery = recoveryQueue.shift();
|
|
31397
31481
|
launchClaim(recovery.claim, recovery);
|
|
31398
31482
|
}
|
|
31399
31483
|
while (!drainRequested && recoveryQueue.length === 0 && (!this.options.once || !onceClaimed) && (settings.maxConcurrency === null || active.size < settings.maxConcurrency) && pendingClaimPromotions === 0 && now() >= nextClaimAt) {
|
|
31400
31484
|
if (!receipt.pending_claim_request) {
|
|
31401
|
-
|
|
31402
|
-
|
|
31403
|
-
|
|
31404
|
-
|
|
31405
|
-
|
|
31406
|
-
|
|
31407
|
-
|
|
31408
|
-
|
|
31409
|
-
|
|
31410
|
-
localState.
|
|
31411
|
-
|
|
31412
|
-
|
|
31413
|
-
|
|
31414
|
-
|
|
31415
|
-
|
|
31416
|
-
|
|
31417
|
-
|
|
31418
|
-
|
|
31419
|
-
|
|
31420
|
-
|
|
31421
|
-
|
|
31422
|
-
|
|
31423
|
-
|
|
31485
|
+
await mutateReceipt((current) => {
|
|
31486
|
+
if (current.pending_claim_request) return current;
|
|
31487
|
+
const claimSequence = current.claim_sequence + 1;
|
|
31488
|
+
const pendingClaimRequest = {
|
|
31489
|
+
schema_version: "external_inference_job_claim_v1",
|
|
31490
|
+
contract_version: EXTERNAL_INFERENCE_CONTRACT_VERSION,
|
|
31491
|
+
host_id: localState.host_id,
|
|
31492
|
+
host_generation: localState.host_generation,
|
|
31493
|
+
advertisement_generation: current.advertisement_generation,
|
|
31494
|
+
key_generation: localState.key_generation,
|
|
31495
|
+
claim_request_id: stableOperationId("claim", [
|
|
31496
|
+
localState.host_id,
|
|
31497
|
+
localState.host_generation,
|
|
31498
|
+
current.advertisement_generation,
|
|
31499
|
+
claimSequence
|
|
31500
|
+
]),
|
|
31501
|
+
requested_at: isoAt(now())
|
|
31502
|
+
};
|
|
31503
|
+
return {
|
|
31504
|
+
...current,
|
|
31505
|
+
claim_sequence: claimSequence,
|
|
31506
|
+
pending_claim_request: pendingClaimRequest,
|
|
31507
|
+
updated_at: isoAt(now())
|
|
31508
|
+
};
|
|
31509
|
+
});
|
|
31424
31510
|
}
|
|
31425
31511
|
const request = receipt.pending_claim_request;
|
|
31426
31512
|
let claim;
|
|
@@ -31436,12 +31522,11 @@ var init_runner = __esm({
|
|
|
31436
31522
|
requestDrain("authority_lost");
|
|
31437
31523
|
} else if (!this.options.signal?.aborted && error48 instanceof ExternalInferenceMcpError && error48.definitivelyNotApplied) {
|
|
31438
31524
|
if (request.advertisement_generation < receipt.advertisement_generation) {
|
|
31439
|
-
|
|
31440
|
-
...
|
|
31441
|
-
pending_claim_request: null,
|
|
31525
|
+
await mutateReceipt((current) => ({
|
|
31526
|
+
...current,
|
|
31527
|
+
pending_claim_request: current.pending_claim_request?.claim_request_id === request.claim_request_id ? null : current.pending_claim_request,
|
|
31442
31528
|
updated_at: isoAt(now())
|
|
31443
|
-
};
|
|
31444
|
-
await this.persistReceipt(receipt, now);
|
|
31529
|
+
}));
|
|
31445
31530
|
nextClaimAt = now();
|
|
31446
31531
|
} else {
|
|
31447
31532
|
requestDrain("claim_failed");
|
|
@@ -31454,23 +31539,21 @@ var init_runner = __esm({
|
|
|
31454
31539
|
break;
|
|
31455
31540
|
}
|
|
31456
31541
|
if (claim.claim_state === "empty") {
|
|
31457
|
-
|
|
31458
|
-
...
|
|
31459
|
-
pending_claim_request: null,
|
|
31542
|
+
await mutateReceipt((current) => ({
|
|
31543
|
+
...current,
|
|
31544
|
+
pending_claim_request: current.pending_claim_request?.claim_request_id === request.claim_request_id ? null : current.pending_claim_request,
|
|
31460
31545
|
updated_at: isoAt(now())
|
|
31461
|
-
};
|
|
31462
|
-
await this.persistReceipt(receipt, now);
|
|
31546
|
+
}));
|
|
31463
31547
|
nextClaimAt = now() + Math.max(MIN_SLEEP_MS, claim.retry_after_ms);
|
|
31464
31548
|
if (this.options.once) requestDrain("once_empty");
|
|
31465
31549
|
break;
|
|
31466
31550
|
}
|
|
31467
31551
|
if (Date.parse(claim.lease_expires_at) <= now() + MIN_CLAIM_START_WINDOW_MS || Date.parse(claim.deadline_at) <= now() + MIN_CLAIM_START_WINDOW_MS) {
|
|
31468
|
-
|
|
31469
|
-
...
|
|
31470
|
-
pending_claim_request: null,
|
|
31552
|
+
await mutateReceipt((current) => ({
|
|
31553
|
+
...current,
|
|
31554
|
+
pending_claim_request: current.pending_claim_request?.claim_request_id === request.claim_request_id ? null : current.pending_claim_request,
|
|
31471
31555
|
updated_at: isoAt(now())
|
|
31472
|
-
};
|
|
31473
|
-
await this.persistReceipt(receipt, now);
|
|
31556
|
+
}));
|
|
31474
31557
|
nextClaimAt = now();
|
|
31475
31558
|
break;
|
|
31476
31559
|
}
|
|
@@ -31481,7 +31564,8 @@ var init_runner = __esm({
|
|
|
31481
31564
|
const advertisementDueAt = nextAdvertisementAttemptAt > now() ? nextAdvertisementAttemptAt : receipt.advertisement_expires_at ? Date.parse(receipt.advertisement_expires_at) - settings.advertisementRefreshLeadMs : now() + MIN_SLEEP_MS;
|
|
31482
31565
|
const wakeAt = Math.min(
|
|
31483
31566
|
nextClaimAt,
|
|
31484
|
-
|
|
31567
|
+
nextProviderRateLimitRefreshAt,
|
|
31568
|
+
now() + settings.hostHeartbeatMs,
|
|
31485
31569
|
Math.max(now() + MIN_SLEEP_MS, advertisementDueAt)
|
|
31486
31570
|
);
|
|
31487
31571
|
await Promise.race([
|
|
@@ -31490,6 +31574,8 @@ var init_runner = __esm({
|
|
|
31490
31574
|
...active.values()
|
|
31491
31575
|
]);
|
|
31492
31576
|
}
|
|
31577
|
+
stopHostHeartbeatLoop();
|
|
31578
|
+
await hostHeartbeatLoop;
|
|
31493
31579
|
try {
|
|
31494
31580
|
await hostHeartbeat("draining", {
|
|
31495
31581
|
deadlineAtMs: now() + settings.drainTimeoutMs,
|
|
@@ -31524,6 +31610,8 @@ var init_runner = __esm({
|
|
|
31524
31610
|
});
|
|
31525
31611
|
return { claimed, completed, failed, drain_reason: drainReason };
|
|
31526
31612
|
} finally {
|
|
31613
|
+
stopHostHeartbeatLoop();
|
|
31614
|
+
await hostHeartbeatLoop;
|
|
31527
31615
|
removeAbortListener();
|
|
31528
31616
|
unregisterSignals();
|
|
31529
31617
|
try {
|
|
@@ -31595,35 +31683,39 @@ var init_runner = __esm({
|
|
|
31595
31683
|
);
|
|
31596
31684
|
}
|
|
31597
31685
|
if (!options.resumeReceipt) {
|
|
31598
|
-
|
|
31599
|
-
|
|
31600
|
-
|
|
31601
|
-
|
|
31602
|
-
|
|
31603
|
-
|
|
31604
|
-
|
|
31686
|
+
await options.updateReceipt((current) => {
|
|
31687
|
+
const pendingClaimRequest = options.claimRequest && current.pending_claim_request?.claim_request_id === options.claimRequest.claim_request_id ? null : current.pending_claim_request ?? null;
|
|
31688
|
+
return {
|
|
31689
|
+
...current,
|
|
31690
|
+
pending_claim_request: pendingClaimRequest,
|
|
31691
|
+
attempts: { ...current.attempts, [attemptId]: attemptReceipt },
|
|
31692
|
+
updated_at: isoAt(now())
|
|
31693
|
+
};
|
|
31605
31694
|
});
|
|
31606
31695
|
options.onClaimPersisted?.();
|
|
31607
31696
|
}
|
|
31608
31697
|
const updateAttempt = async (changes) => {
|
|
31609
|
-
|
|
31698
|
+
const nextAttemptReceipt = validateAttemptReceipt({
|
|
31610
31699
|
...attemptReceipt,
|
|
31611
31700
|
...changes,
|
|
31612
31701
|
updated_at: isoAt(now())
|
|
31613
31702
|
});
|
|
31614
|
-
|
|
31615
|
-
|
|
31616
|
-
|
|
31703
|
+
attemptReceipt = nextAttemptReceipt;
|
|
31704
|
+
await options.updateReceipt((current) => ({
|
|
31705
|
+
...current,
|
|
31706
|
+
attempts: { ...current.attempts, [attemptId]: nextAttemptReceipt },
|
|
31617
31707
|
updated_at: isoAt(now())
|
|
31618
|
-
});
|
|
31708
|
+
}));
|
|
31619
31709
|
};
|
|
31620
31710
|
const removeAttempt = async () => {
|
|
31621
|
-
|
|
31622
|
-
|
|
31623
|
-
|
|
31624
|
-
|
|
31625
|
-
|
|
31626
|
-
|
|
31711
|
+
await options.updateReceipt((current) => {
|
|
31712
|
+
const attempts = { ...current.attempts };
|
|
31713
|
+
delete attempts[attemptId];
|
|
31714
|
+
return {
|
|
31715
|
+
...current,
|
|
31716
|
+
attempts,
|
|
31717
|
+
updated_at: isoAt(now())
|
|
31718
|
+
};
|
|
31627
31719
|
});
|
|
31628
31720
|
};
|
|
31629
31721
|
if (attemptReceipt.phase === "claimed") {
|