@opengeni/worker-bundle 2.3.1-canary.37062299158001 → 2.3.1

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.
Files changed (62) hide show
  1. package/dist/activities/agent-turn/claude-usage-observer.d.ts +6 -30
  2. package/dist/activities/agent-turn/credential-leases.d.ts +32 -5
  3. package/dist/activities/agent-turn/errors.d.ts +0 -3
  4. package/dist/activities/agent-turn/finalization-monitor.d.ts +1 -1
  5. package/dist/activities/agent-turn/finalization.d.ts +0 -2
  6. package/dist/activities/agent-turn/quiescence.d.ts +4 -3
  7. package/dist/activities/agent-turn/turn-context.d.ts +1 -1
  8. package/dist/activities/session-state.d.ts +2 -2
  9. package/dist/activities/types.d.ts +0 -7
  10. package/dist/{activities-control-TTGQGLCJ.js → activities-control-3HAH4FMG.js} +32 -83
  11. package/dist/activities-control-3HAH4FMG.js.map +1 -0
  12. package/dist/activities-control.d.ts +4 -4
  13. package/dist/{activities-turn-TTNAVGKN.js → activities-turn-KU25J3VQ.js} +308 -263
  14. package/dist/activities-turn-KU25J3VQ.js.map +1 -0
  15. package/dist/activities.d.ts +4 -4
  16. package/dist/{chunk-PA7Z55P4.js → chunk-3K3ULWEE.js} +17 -242
  17. package/dist/chunk-3K3ULWEE.js.map +1 -0
  18. package/dist/{chunk-YOI3Z3GF.js → chunk-YG27NEMX.js} +1 -9
  19. package/dist/chunk-YG27NEMX.js.map +1 -0
  20. package/dist/http.d.ts +1 -1
  21. package/dist/index.d.ts +2 -5
  22. package/dist/index.js +16 -82
  23. package/dist/index.js.map +1 -1
  24. package/dist/observability-metrics.d.ts +1 -6
  25. package/dist/sandbox-resume.d.ts +0 -3
  26. package/dist/worker-service-lifecycle.d.ts +0 -12
  27. package/dist/workflow-bundle.js +2 -2
  28. package/package.json +21 -21
  29. package/src/activities/agent-turn/claim.ts +0 -13
  30. package/src/activities/agent-turn/claude-usage-observer.ts +8 -99
  31. package/src/activities/agent-turn/credential-leases.ts +213 -86
  32. package/src/activities/agent-turn/errors.ts +1 -61
  33. package/src/activities/agent-turn/failure-settlement.ts +5 -59
  34. package/src/activities/agent-turn/finalization-monitor.ts +4 -3
  35. package/src/activities/agent-turn/finalization.ts +3 -8
  36. package/src/activities/agent-turn/quiescence.ts +4 -3
  37. package/src/activities/agent-turn/run.ts +20 -24
  38. package/src/activities/agent-turn/sandbox-establish.ts +0 -2
  39. package/src/activities/agent-turn/sandbox-runtime.ts +1 -5
  40. package/src/activities/agent-turn/skill-selection.ts +0 -2
  41. package/src/activities/agent-turn/turn-context.ts +4 -1
  42. package/src/activities/codex-rotation.ts +12 -2
  43. package/src/activities/sandbox-lease.ts +8 -59
  44. package/src/activities/session-state.ts +4 -29
  45. package/src/activities/types.ts +0 -7
  46. package/src/activities-turn.ts +0 -5
  47. package/src/activities.ts +0 -6
  48. package/src/http.ts +2 -4
  49. package/src/index.ts +9 -39
  50. package/src/observability-metrics.ts +0 -27
  51. package/src/sandbox-resume.ts +0 -9
  52. package/src/sandbox-routing.ts +0 -77
  53. package/src/worker-service-lifecycle.ts +0 -53
  54. package/src/workflows/session.ts +1 -6
  55. package/dist/activities/agent-turn/subscription-lease.d.ts +0 -38
  56. package/dist/activities-control-TTGQGLCJ.js.map +0 -1
  57. package/dist/activities-turn-TTNAVGKN.js.map +0 -1
  58. package/dist/chunk-PA7Z55P4.js.map +0 -1
  59. package/dist/chunk-YOI3Z3GF.js.map +0 -1
  60. package/dist/session-event-fanout.d.ts +0 -6
  61. package/src/activities/agent-turn/subscription-lease.ts +0 -115
  62. package/src/session-event-fanout.ts +0 -23
@@ -4,7 +4,6 @@ import {
4
4
  PostCompactionContinuationEmptyError,
5
5
  SandboxDeadlineRotationError,
6
6
  agentRunFailurePayload,
7
- agentRunRecoveryFailurePayload,
8
7
  armAndReconcileCodexCapacityWait,
9
8
  armTurnQuiescenceWatchdog,
10
9
  assertAgentStreamNotCancelled,
@@ -32,7 +31,6 @@ import {
32
31
  compactionFailureReasonFromError,
33
32
  compactionFailureTurnEventPayload,
34
33
  computeIdleDelayMs,
35
- createClaudeUsageObserver,
36
34
  createFreshSandboxReadinessReplacementBudget,
37
35
  createKnowledgeSourceSyncActivities,
38
36
  createModelHistoryAttachmentProjector,
@@ -97,7 +95,7 @@ import {
97
95
  withFirstPartyTools,
98
96
  wrapLazyTurnBoxWithRouting,
99
97
  wrapTurnBoxWithRouting
100
- } from "./chunk-PA7Z55P4.js";
98
+ } from "./chunk-3K3ULWEE.js";
101
99
  import {
102
100
  StreamTimingMetrics,
103
101
  makeMachineOpObserver,
@@ -129,7 +127,7 @@ import {
129
127
  runtimeMetricsHooksForObservability,
130
128
  sandboxAutomaticRecoveryOutcome,
131
129
  turnLifecycleMetricsFor
132
- } from "./chunk-YOI3Z3GF.js";
130
+ } from "./chunk-YG27NEMX.js";
133
131
  import {
134
132
  __export
135
133
  } from "./chunk-PZ5AY32C.js";
@@ -185,6 +183,82 @@ import {
185
183
  import { codexUpstreamModelSlugs } from "@opengeni/config";
186
184
  import { parseModelProvidersJson } from "@opengeni/config";
187
185
  import { withClaudeUsageObserver } from "@opengeni/runtime";
186
+
187
+ // src/activities/agent-turn/claude-usage-observer.ts
188
+ import {
189
+ emptyClaudeUsage,
190
+ mergeClaudeUsage,
191
+ parseClaudeUsageHeaders
192
+ } from "@opengeni/config";
193
+ async function createClaudeUsageObserver(providers, latest, readCredential) {
194
+ const bindings = await Promise.all(
195
+ providers.filter(
196
+ (provider) => provider.kind === "claude-subscription-workspace" || provider.kind === "claude-subscription-organization"
197
+ ).map(async (provider) => {
198
+ const scope = provider.kind === "claude-subscription-workspace" ? "workspace" : "organization";
199
+ const binding = provider.anthropic?.credentialBinding;
200
+ if (binding && provider.apiKey)
201
+ return [
202
+ provider.id,
203
+ {
204
+ scope,
205
+ token: provider.apiKey,
206
+ expectedConnectionId: binding.connectionId,
207
+ expectedCredentialVersion: binding.credentialVersion
208
+ }
209
+ ];
210
+ const credential = await readCredential(scope).catch(() => null);
211
+ if (!credential || credential.token !== provider.apiKey) return null;
212
+ return [
213
+ provider.id,
214
+ {
215
+ scope,
216
+ token: credential.token,
217
+ expectedConnectionId: credential.connectionId,
218
+ expectedCredentialVersion: credential.credentialVersion
219
+ }
220
+ ];
221
+ })
222
+ );
223
+ const captured = new Map(bindings.filter((binding) => binding !== null));
224
+ const observe2 = (providerId, response) => {
225
+ const binding = captured.get(providerId);
226
+ if (!binding) return;
227
+ const { scope, ...identity } = binding;
228
+ const previous = latest.get(scope);
229
+ let observation = parseClaudeUsageHeaders(response.headers);
230
+ if (observation && previous?.observation) {
231
+ const merged = mergeClaudeUsage(
232
+ mergeClaudeUsage(emptyClaudeUsage(binding.expectedCredentialVersion), previous.observation),
233
+ observation
234
+ );
235
+ observation = {
236
+ windows: merged.windows,
237
+ observedAt: merged.observedAt,
238
+ source: merged.source
239
+ };
240
+ }
241
+ if (observation || response.status === 401)
242
+ latest.set(scope, {
243
+ ...identity,
244
+ ...previous?.observation && !observation ? { observation: previous.observation } : {},
245
+ ...observation ? { observation } : {},
246
+ ...response.status === 401 ? { refresh: { status: "reconnect", checkedAt: (/* @__PURE__ */ new Date()).toISOString() } } : {}
247
+ });
248
+ };
249
+ return Object.assign(observe2, {
250
+ binding(providerId) {
251
+ return captured.get(providerId);
252
+ },
253
+ renew(providerId, credential) {
254
+ const binding = captured.get(providerId);
255
+ if (binding && binding.expectedConnectionId === credential.connectionId && binding.expectedCredentialVersion === credential.credentialVersion)
256
+ captured.set(providerId, { ...binding, token: credential.token });
257
+ }
258
+ });
259
+ }
260
+
261
+ // src/activities/agent-turn/run.ts
188
262
  import {
189
263
  xaiSubscriptionRequestStorage
190
264
  } from "@opengeni/xai-subscription";
@@ -1187,72 +1261,161 @@ import {
1187
1261
  heartbeatXaiCredentialLeaseUntil
1188
1262
  } from "@opengeni/db";
1189
1263
 
1190
- // src/activities/agent-turn/subscription-lease.ts
1191
- var SubscriptionTurnLease = class {
1192
- constructor(leaseDeps) {
1193
- this.leaseDeps = leaseDeps;
1194
- if (!Number.isFinite(leaseDeps.ttlMs) || leaseDeps.ttlMs <= 0)
1195
- throw new Error("Subscription lease TTL must be positive");
1196
- this.now = leaseDeps.now ?? (() => performance.now());
1264
+ // src/activities/agent-turn/codex.ts
1265
+ import {
1266
+ listCodexAccountStatuses,
1267
+ fetchCodexUsageForAccount
1268
+ } from "@opengeni/db";
1269
+ import { createHash as createHash2 } from "crypto";
1270
+ function codexWorkspaceMetricKey(workspaceId) {
1271
+ return createHash2("sha256").update(workspaceId).digest("hex").slice(0, 12);
1272
+ }
1273
+ function acceptsPromptCacheKeyForTurn(resolvedModel) {
1274
+ if (!resolvedModel) {
1275
+ return true;
1276
+ }
1277
+ return resolvedModel.provider.builtin === true || resolvedModel.provider.kind === "codex-subscription" || // Native Claude consumes this internal key as session identity; it never
1278
+ // sends OpenAI's prompt_cache_key field to the Messages endpoint.
1279
+ resolvedModel.provider.api === "anthropic-messages";
1280
+ }
1281
+ async function refreshCappedCodexUsageRows(db, settings, workspaceId, accounts, capacitySignals, acceptedTurnId) {
1282
+ const now = /* @__PURE__ */ new Date();
1283
+ const stale = accounts.filter(
1284
+ (account) => account.status === "active" && codexAccountNeedsLiveCapacityRefresh(account, now)
1285
+ );
1286
+ if (stale.length === 0) {
1287
+ return accounts;
1288
+ }
1289
+ await refreshCodexUsageAndRepairCapacityWaiters(
1290
+ stale.map(
1291
+ (account) => () => fetchCodexUsageForAccount(db, settings, workspaceId, account.id, void 0, acceptedTurnId)
1292
+ ),
1293
+ () => signalPendingCodexCapacityWakeTargets({ db, ...capacitySignals }, workspaceId)
1294
+ );
1295
+ return listCodexAccountStatuses(db, workspaceId, acceptedTurnId).catch(() => accounts);
1296
+ }
1297
+ function codexCredentialLeaseDeadlineExpired(confirmedUntilMs, nowMs = performance.now()) {
1298
+ return confirmedUntilMs === null || !Number.isFinite(confirmedUntilMs) || confirmedUntilMs <= nowMs;
1299
+ }
1300
+
1301
+ // src/activities/agent-turn/credential-leases.ts
1302
+ var CodexCredentialLeaseLostError = class extends Error {
1303
+ constructor(reason) {
1304
+ super("Codex credential lease is not usable for provider dispatch");
1305
+ this.reason = reason;
1306
+ this.name = "CodexCredentialLeaseLostError";
1307
+ }
1308
+ code = "codex_credential_lease_lost";
1309
+ };
1310
+ var CodexTurnLease = class {
1311
+ constructor(deps) {
1312
+ this.deps = deps;
1197
1313
  }
1198
1314
  held = false;
1199
1315
  lost = false;
1200
1316
  lossReason = null;
1201
1317
  holderId = null;
1202
1318
  generation = null;
1319
+ // Monotonic worker deadline, not a comparison between the Postgres and
1320
+ // worker wall clocks. It is advanced only after a database renewal confirms,
1321
+ // from the request START + TTL; slow queries therefore shorten (never extend)
1322
+ // the conservative ownership window.
1203
1323
  confirmedUntilMs = null;
1204
1324
  heartbeatInFlight = false;
1205
1325
  heartbeatTimer;
1206
- now;
1207
- expired = (deadline) => deadline === null || !Number.isFinite(deadline) || this.now() >= deadline;
1208
1326
  markLost = (reason) => {
1209
1327
  if (this.lost) return;
1210
1328
  this.lost = true;
1211
1329
  this.lossReason = reason;
1212
- this.leaseDeps.onLost(reason);
1330
+ this.deps.observability.incrementCounter({
1331
+ name: "opengeni_codex_lease_renewals_total",
1332
+ help: "Codex lease renewal checkpoints by outcome and reason.",
1333
+ labels: { workspace_key: this.deps.codexWorkspaceKey, outcome: "lost", reason }
1334
+ });
1335
+ this.deps.observability.warn("Codex credential lease was lost during an active turn", {
1336
+ workspaceId: this.deps.workspaceId,
1337
+ turnId: this.deps.getTurnId(),
1338
+ reason
1339
+ });
1213
1340
  };
1341
+ /** Fail closed at the last worker-confirmed lease deadline before dispatch. */
1214
1342
  assertUsable = () => {
1215
- if (this.lost) throw this.leaseDeps.lostError(this.lossReason ?? "not_found");
1216
- if (!this.held || this.holderId === null || this.generation === null || this.expired(this.confirmedUntilMs)) {
1343
+ if (this.lost) {
1344
+ throw new CodexCredentialLeaseLostError(this.lossReason ?? "not_found");
1345
+ }
1346
+ if (!this.held || this.holderId === null || this.generation === null || codexCredentialLeaseDeadlineExpired(this.confirmedUntilMs)) {
1217
1347
  this.markLost("deadline");
1218
- throw this.leaseDeps.lostError("deadline");
1348
+ throw new CodexCredentialLeaseLostError("deadline");
1219
1349
  }
1220
1350
  };
1221
- renew = async (reason = "timer") => {
1222
- const turnId = this.leaseDeps.getTurnId();
1223
- if (!turnId || !this.held || !this.holderId || this.generation === null || this.lost) return;
1224
- if (this.expired(this.confirmedUntilMs)) {
1351
+ renew = async (reason) => {
1352
+ const turnId = this.deps.getTurnId();
1353
+ if (!turnId || !this.held || !this.holderId || this.generation === null || this.lost) {
1354
+ return;
1355
+ }
1356
+ if (codexCredentialLeaseDeadlineExpired(this.confirmedUntilMs)) {
1225
1357
  this.markLost("deadline");
1226
1358
  return;
1227
1359
  }
1228
1360
  if (this.heartbeatInFlight) return;
1229
1361
  this.heartbeatInFlight = true;
1230
- const priorDeadline = this.confirmedUntilMs;
1231
- const startedAt = this.now();
1232
- const identity = { turnId, holderId: this.holderId, generation: this.generation };
1362
+ const priorConfirmedUntilMs = this.confirmedUntilMs;
1363
+ const renewalStartedAtMs = performance.now();
1233
1364
  try {
1234
- const renewedUntil = await this.leaseDeps.heartbeat(identity);
1235
- if (!this.held || this.lost || this.leaseDeps.getTurnId() !== identity.turnId || this.holderId !== identity.holderId || this.generation !== identity.generation)
1236
- return;
1237
- if (!renewedUntil) this.markLost("not_found");
1238
- else if (this.expired(priorDeadline) || this.expired(startedAt + this.leaseDeps.ttlMs))
1365
+ const renewedUntil = await heartbeatCodexCredentialLeaseUntil(
1366
+ this.deps.db,
1367
+ this.deps.accountId,
1368
+ this.deps.workspaceId,
1369
+ turnId,
1370
+ this.holderId,
1371
+ this.generation,
1372
+ CODEX_CREDENTIAL_LEASE_TTL_MS
1373
+ );
1374
+ if (!renewedUntil) {
1375
+ this.markLost("not_found");
1376
+ } else if (codexCredentialLeaseDeadlineExpired(priorConfirmedUntilMs) || codexCredentialLeaseDeadlineExpired(renewalStartedAtMs + CODEX_CREDENTIAL_LEASE_TTL_MS)) {
1239
1377
  this.markLost("deadline");
1240
- else {
1241
- this.confirmedUntilMs = startedAt + this.leaseDeps.ttlMs;
1242
- this.leaseDeps.onRenewed?.(reason);
1378
+ } else {
1379
+ this.confirmedUntilMs = renewalStartedAtMs + CODEX_CREDENTIAL_LEASE_TTL_MS;
1380
+ this.deps.observability.incrementCounter({
1381
+ name: "opengeni_codex_lease_renewals_total",
1382
+ help: "Codex lease renewal checkpoints by outcome and reason.",
1383
+ labels: {
1384
+ workspace_key: this.deps.codexWorkspaceKey,
1385
+ outcome: "completed",
1386
+ reason
1387
+ }
1388
+ });
1243
1389
  }
1244
1390
  } catch (error51) {
1245
- if (!this.held || this.lost || this.leaseDeps.getTurnId() !== identity.turnId || this.holderId !== identity.holderId || this.generation !== identity.generation)
1391
+ if (codexCredentialLeaseDeadlineExpired(this.confirmedUntilMs)) {
1392
+ this.markLost("deadline");
1246
1393
  return;
1247
- if (this.expired(this.confirmedUntilMs)) this.markLost("deadline");
1248
- else this.leaseDeps.onError(error51, reason);
1394
+ }
1395
+ this.deps.observability.warn("Codex credential lease heartbeat failed", {
1396
+ workspaceId: this.deps.workspaceId,
1397
+ turnId,
1398
+ reason,
1399
+ ...safeErrorDiagnostic(error51)
1400
+ });
1401
+ this.deps.observability.incrementCounter({
1402
+ name: "opengeni_codex_lease_renewals_total",
1403
+ help: "Codex lease renewal checkpoints by outcome and reason.",
1404
+ labels: {
1405
+ workspace_key: this.deps.codexWorkspaceKey,
1406
+ outcome: "error",
1407
+ reason
1408
+ }
1409
+ });
1249
1410
  } finally {
1250
1411
  this.heartbeatInFlight = false;
1251
1412
  }
1252
1413
  };
1253
1414
  startHeartbeat = () => {
1254
- if (!this.leaseDeps.getTurnId() || this.heartbeatTimer) return;
1255
- this.heartbeatTimer = setInterval(() => void this.renew("timer"), 6e4);
1415
+ if (!this.deps.getTurnId() || this.heartbeatTimer) return;
1416
+ this.heartbeatTimer = setInterval(() => {
1417
+ void this.renew("timer");
1418
+ }, 6e4);
1256
1419
  this.heartbeatTimer.unref?.();
1257
1420
  };
1258
1421
  stopHeartbeat = () => {
@@ -1261,94 +1424,79 @@ var SubscriptionTurnLease = class {
1261
1424
  this.heartbeatTimer = void 0;
1262
1425
  };
1263
1426
  };
1264
-
1265
- // src/activities/agent-turn/credential-leases.ts
1266
- var CodexCredentialLeaseLostError = class extends Error {
1267
- constructor(reason) {
1268
- super("Codex credential lease is not usable for provider dispatch");
1269
- this.reason = reason;
1270
- this.name = "CodexCredentialLeaseLostError";
1271
- }
1272
- code = "codex_credential_lease_lost";
1273
- };
1274
- var CodexTurnLease = class extends SubscriptionTurnLease {
1427
+ var XaiTurnLease = class {
1275
1428
  constructor(deps) {
1276
- super({
1277
- ttlMs: CODEX_CREDENTIAL_LEASE_TTL_MS,
1278
- getTurnId: deps.getTurnId,
1279
- heartbeat: ({ turnId, holderId, generation }) => heartbeatCodexCredentialLeaseUntil(
1280
- deps.db,
1281
- deps.accountId,
1282
- deps.workspaceId,
1283
- turnId,
1284
- holderId,
1285
- generation,
1286
- CODEX_CREDENTIAL_LEASE_TTL_MS
1287
- ),
1288
- lostError: (reason) => new CodexCredentialLeaseLostError(reason),
1289
- onLost: (reason) => {
1290
- deps.observability.incrementCounter({
1291
- name: "opengeni_codex_lease_renewals_total",
1292
- help: "Codex lease renewal checkpoints by outcome and reason.",
1293
- labels: { workspace_key: deps.codexWorkspaceKey, outcome: "lost", reason }
1294
- });
1295
- deps.observability.warn("Codex credential lease was lost during an active turn", {
1296
- workspaceId: deps.workspaceId,
1297
- turnId: deps.getTurnId(),
1298
- reason
1299
- });
1300
- },
1301
- onRenewed: (reason) => deps.observability.incrementCounter({
1302
- name: "opengeni_codex_lease_renewals_total",
1303
- help: "Codex lease renewal checkpoints by outcome and reason.",
1304
- labels: { workspace_key: deps.codexWorkspaceKey, outcome: "completed", reason }
1305
- }),
1306
- onError: (error51, reason) => {
1307
- deps.observability.warn("Codex credential lease heartbeat failed", {
1308
- workspaceId: deps.workspaceId,
1309
- turnId: deps.getTurnId(),
1310
- reason,
1311
- ...safeErrorDiagnostic(error51)
1312
- });
1313
- deps.observability.incrementCounter({
1314
- name: "opengeni_codex_lease_renewals_total",
1315
- help: "Codex lease renewal checkpoints by outcome and reason.",
1316
- labels: { workspace_key: deps.codexWorkspaceKey, outcome: "error", reason }
1317
- });
1318
- }
1319
- });
1429
+ this.deps = deps;
1320
1430
  }
1321
- };
1322
- var XaiTurnLease = class extends SubscriptionTurnLease {
1431
+ held = false;
1432
+ lost = false;
1323
1433
  subjectId = null;
1324
- constructor(deps) {
1325
- super({
1326
- ttlMs: XAI_CREDENTIAL_LEASE_TTL_MS,
1327
- getTurnId: deps.getTurnId,
1328
- heartbeat: ({ turnId, holderId, generation }) => this.subjectId ? heartbeatXaiCredentialLeaseUntil(deps.db, {
1329
- workspaceId: deps.workspaceId,
1434
+ holderId = null;
1435
+ generation = null;
1436
+ confirmedUntilMs = null;
1437
+ heartbeatInFlight = false;
1438
+ heartbeatTimer;
1439
+ markLost = (reason) => {
1440
+ if (this.lost) return;
1441
+ this.lost = true;
1442
+ this.deps.observability.warn("xAI credential lease was lost during an active turn", {
1443
+ workspaceId: this.deps.workspaceId,
1444
+ turnId: this.deps.getTurnId(),
1445
+ reason
1446
+ });
1447
+ };
1448
+ renew = async () => {
1449
+ const turnId = this.deps.getTurnId();
1450
+ if (!turnId || !this.held || !this.subjectId || !this.holderId || this.generation === null || this.lost) {
1451
+ return;
1452
+ }
1453
+ if (codexCredentialLeaseDeadlineExpired(this.confirmedUntilMs)) {
1454
+ this.markLost("deadline");
1455
+ return;
1456
+ }
1457
+ if (this.heartbeatInFlight) return;
1458
+ this.heartbeatInFlight = true;
1459
+ const renewalStartedAtMs = performance.now();
1460
+ try {
1461
+ const renewedUntil = await heartbeatXaiCredentialLeaseUntil(this.deps.db, {
1462
+ workspaceId: this.deps.workspaceId,
1330
1463
  subjectId: this.subjectId,
1331
1464
  turnId,
1332
- holderId,
1333
- generation,
1465
+ holderId: this.holderId,
1466
+ generation: this.generation,
1334
1467
  leaseTtlMs: XAI_CREDENTIAL_LEASE_TTL_MS
1335
- }) : Promise.resolve(null),
1336
- lostError: (reason) => Object.assign(new Error("SuperGrok credential lease is not usable for provider dispatch"), {
1337
- code: "xai_credential_lease_lost",
1338
- reason
1339
- }),
1340
- onLost: (reason) => deps.observability.warn("xAI credential lease was lost during an active turn", {
1341
- workspaceId: deps.workspaceId,
1342
- turnId: deps.getTurnId(),
1343
- reason
1344
- }),
1345
- onError: (error51) => deps.observability.warn("xAI credential lease heartbeat failed", {
1346
- workspaceId: deps.workspaceId,
1347
- turnId: deps.getTurnId(),
1468
+ });
1469
+ if (!renewedUntil) {
1470
+ this.markLost("not_found");
1471
+ } else {
1472
+ this.confirmedUntilMs = renewalStartedAtMs + XAI_CREDENTIAL_LEASE_TTL_MS;
1473
+ }
1474
+ } catch (error51) {
1475
+ if (codexCredentialLeaseDeadlineExpired(this.confirmedUntilMs)) {
1476
+ this.markLost("deadline");
1477
+ return;
1478
+ }
1479
+ this.deps.observability.warn("xAI credential lease heartbeat failed", {
1480
+ workspaceId: this.deps.workspaceId,
1481
+ turnId,
1348
1482
  ...safeErrorDiagnostic(error51)
1349
- })
1350
- });
1351
- }
1483
+ });
1484
+ } finally {
1485
+ this.heartbeatInFlight = false;
1486
+ }
1487
+ };
1488
+ startHeartbeat = () => {
1489
+ if (!this.deps.getTurnId() || this.heartbeatTimer) return;
1490
+ this.heartbeatTimer = setInterval(() => {
1491
+ void this.renew();
1492
+ }, 6e4);
1493
+ this.heartbeatTimer.unref?.();
1494
+ };
1495
+ stopHeartbeat = () => {
1496
+ if (!this.heartbeatTimer) return;
1497
+ clearInterval(this.heartbeatTimer);
1498
+ this.heartbeatTimer = void 0;
1499
+ };
1352
1500
  };
1353
1501
  function createTurnCredentialLeases(deps) {
1354
1502
  const codex = new CodexTurnLease(deps);
@@ -1391,7 +1539,7 @@ import {
1391
1539
  settleGeneratedImageArtifactReady
1392
1540
  } from "@opengeni/db";
1393
1541
  import { retryWhileMissing as retryWhileMissing2 } from "@opengeni/storage";
1394
- import { createHash as createHash3 } from "crypto";
1542
+ import { createHash as createHash4 } from "crypto";
1395
1543
 
1396
1544
  // src/activities/retained-screenshots.ts
1397
1545
  import {
@@ -1415,7 +1563,7 @@ import {
1415
1563
  settleRetainedScreenshotArtifactReady
1416
1564
  } from "@opengeni/db";
1417
1565
  import { retryWhileMissing } from "@opengeni/storage";
1418
- import { createHash as createHash2 } from "crypto";
1566
+ import { createHash as createHash3 } from "crypto";
1419
1567
  var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);
1420
1568
  var PNG_ALLOWED_CRITICAL_CHUNKS = /* @__PURE__ */ new Set(["IHDR", "PLTE", "IDAT", "IEND"]);
1421
1569
  var PNG_MAX_CHUNKS = 16384;
@@ -1699,7 +1847,7 @@ function validateComputerScreenshot(input, limits = {}) {
1699
1847
  bytes: input.bytes,
1700
1848
  mediaType: "image/png",
1701
1849
  sizeBytes: input.bytes.byteLength,
1702
- sha256: createHash2("sha256").update(input.bytes).digest("hex"),
1850
+ sha256: createHash3("sha256").update(input.bytes).digest("hex"),
1703
1851
  width,
1704
1852
  height
1705
1853
  };
@@ -1755,11 +1903,11 @@ function validateRetainableSessionImage(input, limits = {}) {
1755
1903
  bytes: input.bytes,
1756
1904
  ...identity,
1757
1905
  sizeBytes: input.bytes.byteLength,
1758
- sha256: createHash2("sha256").update(input.bytes).digest("hex")
1906
+ sha256: createHash3("sha256").update(input.bytes).digest("hex")
1759
1907
  };
1760
1908
  }
1761
1909
  function retainedScreenshotIdentity(input) {
1762
- const settlementKey = createHash2("sha256").update(
1910
+ const settlementKey = createHash3("sha256").update(
1763
1911
  input.kind === "browser_screenshot" ? "opengeni:browser-screenshot:v1\0" : "opengeni:computer-screenshot:v1\0"
1764
1912
  ).update(input.sessionId).update("\0").update(input.turnId).update("\0").update(input.attemptId).update("\0").update(input.toolCallId).update("\0").update(input.toolOutputId).digest("hex");
1765
1913
  const uuidBytes = Uint8Array.from(Buffer.from(settlementKey.slice(0, 32), "hex"));
@@ -2473,7 +2621,7 @@ function validateGeneratedImage(input) {
2473
2621
  }
2474
2622
  }
2475
2623
  function generatedImageIdentity(input) {
2476
- const hash2 = createHash3("sha256").update("opengeni:generated-image:v2\0").update(input.workspaceId).update("\0").update(input.sourceStrategy).update("\0").update(input.providerId).update("\0").update(input.providerBindingHash).update("\0");
2624
+ const hash2 = createHash4("sha256").update("opengeni:generated-image:v2\0").update(input.workspaceId).update("\0").update(input.sourceStrategy).update("\0").update(input.providerId).update("\0").update(input.providerBindingHash).update("\0");
2477
2625
  if (input.sourceStrategy === "native_hosted") {
2478
2626
  hash2.update(input.providerItemId);
2479
2627
  } else {
@@ -3230,7 +3378,7 @@ function completedToolCallFromSdkEvent(event) {
3230
3378
  }
3231
3379
 
3232
3380
  // src/activities/agent-turn/history-prefix.ts
3233
- import { createHash as createHash4 } from "crypto";
3381
+ import { createHash as createHash5 } from "crypto";
3234
3382
  import { normalizeProtocolJsonValue as normalizeProtocolJsonValue2, sanitizeHistoryItemsForModel as sanitizeHistoryItemsForModel2 } from "@opengeni/runtime";
3235
3383
  var HistoryPrefixGuard = class {
3236
3384
  persisted = [];
@@ -3256,7 +3404,7 @@ var HistoryPrefixGuard = class {
3256
3404
  }
3257
3405
  keys(items, truncationTokens) {
3258
3406
  return sanitizeHistoryItemsForModel2(items, truncationTokens).map(
3259
- (item) => createHash4("sha256").update(JSON.stringify(sorted(normalizeProtocolJsonValue2(item)))).digest("hex")
3407
+ (item) => createHash5("sha256").update(JSON.stringify(sorted(normalizeProtocolJsonValue2(item)))).digest("hex")
3260
3408
  );
3261
3409
  }
3262
3410
  };
@@ -3463,40 +3611,6 @@ function safeObserveHistogram(observability, input) {
3463
3611
  }
3464
3612
  }
3465
3613
 
3466
- // src/activities/agent-turn/codex.ts
3467
- import {
3468
- listCodexAccountStatuses,
3469
- fetchCodexUsageForAccount
3470
- } from "@opengeni/db";
3471
- import { createHash as createHash5 } from "crypto";
3472
- function codexWorkspaceMetricKey(workspaceId) {
3473
- return createHash5("sha256").update(workspaceId).digest("hex").slice(0, 12);
3474
- }
3475
- function acceptsPromptCacheKeyForTurn(resolvedModel) {
3476
- if (!resolvedModel) {
3477
- return true;
3478
- }
3479
- return resolvedModel.provider.builtin === true || resolvedModel.provider.kind === "codex-subscription" || // Native Claude consumes this internal key as session identity; it never
3480
- // sends OpenAI's prompt_cache_key field to the Messages endpoint.
3481
- resolvedModel.provider.api === "anthropic-messages";
3482
- }
3483
- async function refreshCappedCodexUsageRows(db, settings, workspaceId, accounts, capacitySignals, acceptedTurnId) {
3484
- const now = /* @__PURE__ */ new Date();
3485
- const stale = accounts.filter(
3486
- (account) => account.status === "active" && codexAccountNeedsLiveCapacityRefresh(account, now)
3487
- );
3488
- if (stale.length === 0) {
3489
- return accounts;
3490
- }
3491
- await refreshCodexUsageAndRepairCapacityWaiters(
3492
- stale.map(
3493
- (account) => () => fetchCodexUsageForAccount(db, settings, workspaceId, account.id, void 0, acceptedTurnId)
3494
- ),
3495
- () => signalPendingCodexCapacityWakeTargets({ db, ...capacitySignals }, workspaceId)
3496
- );
3497
- return listCodexAccountStatuses(db, workspaceId, acceptedTurnId).catch(() => accounts);
3498
- }
3499
-
3500
3614
  // src/activities/agent-turn/turn-context.ts
3501
3615
  function createTurnContext(input) {
3502
3616
  return {
@@ -3695,7 +3809,7 @@ function startTurnFinalizationMonitor(input) {
3695
3809
  } catch {
3696
3810
  }
3697
3811
  },
3698
- terminateWorker: input.requestWorkerDrain
3812
+ terminateWorker: input.terminateWorker
3699
3813
  });
3700
3814
  slowTimer = setTimeout(
3701
3815
  () => diagnose(() => {
@@ -4557,7 +4671,6 @@ async function finalizeTurnAttempt(deps) {
4557
4671
  deps.eventing.heartbeatTimer = startActivityHeartbeat(deps.activityContext, details);
4558
4672
  const monitor = startTurnFinalizationMonitor({
4559
4673
  observability: deps.observability,
4560
- ...deps.turnFinalizationTimeoutMs === void 0 ? {} : { timeoutMs: deps.turnFinalizationTimeoutMs },
4561
4674
  details,
4562
4675
  heartbeat: (value) => {
4563
4676
  try {
@@ -4565,7 +4678,7 @@ async function finalizeTurnAttempt(deps) {
4565
4678
  } catch {
4566
4679
  }
4567
4680
  },
4568
- requestWorkerDrain: deps.requestWorkerDrain
4681
+ terminateWorker: () => process.exit(1)
4569
4682
  });
4570
4683
  try {
4571
4684
  monitor.enter("tool_writers");
@@ -4799,12 +4912,12 @@ async function finalizeTurnAttemptSteps(deps, monitor) {
4799
4912
  );
4800
4913
  }
4801
4914
  monitor.enter("provider_leases");
4802
- for (const snapshot of providerTurn.latestClaudeUsage.values()) {
4915
+ for (const [scope, snapshot] of providerTurn.latestClaudeUsage) {
4803
4916
  await waitForTurnFinalizerStep(
4804
4917
  recordClaudeSubscriptionUsage(
4805
4918
  db,
4806
4919
  settings,
4807
- { accountId: input.accountId, workspaceId: input.workspaceId, scope: snapshot.scope },
4920
+ { accountId: input.accountId, workspaceId: input.workspaceId, scope },
4808
4921
  snapshot
4809
4922
  ).catch(() => null),
4810
4923
  finalizerSignal
@@ -5158,15 +5271,13 @@ import {
5158
5271
  settleCodexCredentialFailover,
5159
5272
  readLease,
5160
5273
  SandboxLeaseSupersededError,
5161
- isSessionEventPersistenceError as isSessionEventPersistenceError2,
5162
- SANDBOX_SETUP_RECOVERY_LIMIT
5274
+ isSessionEventPersistenceError as isSessionEventPersistenceError2
5163
5275
  } from "@opengeni/db";
5164
5276
  import { publishDurableSessionEvents as publishDurableSessionEvents2 } from "@opengeni/events";
5165
5277
  import {
5166
5278
  maxTurnsExceededRunState,
5167
5279
  isModalTaskExecStartPreDispatchUnavailableError,
5168
- isModalCommandStartOutcomeUnknownError,
5169
- isProviderCommandObservationUnavailableError
5280
+ isModalCommandStartOutcomeUnknownError
5170
5281
  } from "@opengeni/runtime";
5171
5282
  import { ApplicationFailure, CancelledFailure } from "@temporalio/activity";
5172
5283
  import { TurnExecutionPolicyDefinitionMismatchError } from "@opengeni/config";
@@ -6030,8 +6141,7 @@ async function settleTurnFailure(deps) {
6030
6141
  }
6031
6142
  }
6032
6143
  const recoveryTurnId = attempt.turnId;
6033
- const observationUnavailable = isProviderCommandObservationUnavailableError(error51);
6034
- if ((isModalCommandStartOutcomeUnknownError(error51) || observationUnavailable) && recoveryTurnId && attempt.triggerEventId && attempt.executionGeneration > 0) {
6144
+ if (isModalCommandStartOutcomeUnknownError(error51) && recoveryTurnId && attempt.triggerEventId && attempt.executionGeneration > 0) {
6035
6145
  let recovery;
6036
6146
  try {
6037
6147
  if (eventing.turnStartedPublished) {
@@ -6043,10 +6153,10 @@ async function settleTurnFailure(deps) {
6043
6153
  turnId: recoveryTurnId,
6044
6154
  triggerEventId: attempt.triggerEventId,
6045
6155
  attemptId: input.attemptId,
6046
- reason: observationUnavailable ? "sandbox_command_observation_unavailable" : "sandbox_command_start_outcome_unknown",
6156
+ reason: "sandbox_command_start_outcome_unknown",
6047
6157
  sandboxSetupOutcomeUnknown: true,
6048
6158
  detail: {
6049
- code: observationUnavailable ? "sandbox_command_observation_unavailable" : "sandbox_command_start_outcome_unknown",
6159
+ code: "sandbox_command_start_outcome_unknown",
6050
6160
  retryable: false,
6051
6161
  setupOutcome: "unknown",
6052
6162
  replay: "blocked",
@@ -7108,39 +7218,7 @@ async function settleTurnFailure(deps) {
7108
7218
  attemptNumber: nextProviderRecoveryCount,
7109
7219
  retryAfterMs: providerRetryAfterMs(error51)
7110
7220
  });
7111
- const setupRecoveryExhausted = earlyCommandStartUnavailable && recoveryResult.status === "exhausted" && attempt.providerRecoveryCount === SANDBOX_SETUP_RECOVERY_LIMIT;
7112
7221
  try {
7113
- if (setupRecoveryExhausted) {
7114
- const recovery = await requestSessionTurnRecovery(db, input.workspaceId, {
7115
- sessionId: input.sessionId,
7116
- turnId: attempt.turnId,
7117
- triggerEventId: attempt.triggerEventId,
7118
- attemptId: input.attemptId,
7119
- reason: "sandbox_command_start_recovery_exhausted",
7120
- sandboxSetupRecoveryExhausted: true,
7121
- detail: {
7122
- code: failure2.code,
7123
- error: "Automatic sandbox setup recovery exhausted after five retries; the accepted turn remains parked without starting a command.",
7124
- retryable: false,
7125
- setupOutcome: "not_started",
7126
- replay: "blocked",
7127
- recoveryExhausted: true,
7128
- providerRecoveryCount: SANDBOX_SETUP_RECOVERY_LIMIT
7129
- }
7130
- });
7131
- if (recovery.action === "stale") {
7132
- acknowledgeLostAttemptOwnership();
7133
- control.activityStatus = "cancelled";
7134
- control.turnMetricOutcome = "cancelled";
7135
- return claimedResult({ status: "cancelled" });
7136
- }
7137
- acknowledgeRecoveryQuiescence();
7138
- await publishDurableSessionEvents2(bus, input.workspaceId, input.sessionId, recovery.events);
7139
- control.turnMetricOutcome = "recovering";
7140
- control.activityStatus = "recovering";
7141
- control.activityError = error51;
7142
- return claimedResult({ status: "recovering" });
7143
- }
7144
7222
  if (recoveryResult.status === "recovering") {
7145
7223
  if (!earlyRecoverableSetup) {
7146
7224
  await flushRuntimeBatcher();
@@ -7154,7 +7232,7 @@ async function settleTurnFailure(deps) {
7154
7232
  reason: failure2.code ?? "provider_unavailable",
7155
7233
  providerRecoveryCount: nextProviderRecoveryCount,
7156
7234
  detail: {
7157
- ...agentRunRecoveryFailurePayload(error51, failure2),
7235
+ ...failure2,
7158
7236
  continueDelayMs: recoveryResult.continueDelayMs,
7159
7237
  providerRecoveryCount: nextProviderRecoveryCount
7160
7238
  }
@@ -7210,12 +7288,6 @@ async function settleTurnFailure(deps) {
7210
7288
  failureCode: failure2.code ?? "provider_unavailable",
7211
7289
  providerRecoveryCount: nextProviderRecoveryCount
7212
7290
  }
7213
- }) : setupRecoveryExhausted ? postClaimDatabaseRecoveryFailure({
7214
- error: recoveryError,
7215
- turnId: attempt.turnId,
7216
- triggerEventId: attempt.triggerEventId,
7217
- executionGeneration: attempt.executionGeneration,
7218
- sandboxSetupRecoveryExhausted: true
7219
7291
  }) : null;
7220
7292
  if (postClaimRecovery) {
7221
7293
  control.activityStatus = "recovering";
@@ -10007,10 +10079,6 @@ async function runTurnStreamAttempt(deps) {
10007
10079
  }
10008
10080
  }
10009
10081
 
10010
- // src/activities/agent-turn/claim.ts
10011
- import { withDirectModelProviders } from "@opengeni/config";
10012
- import { loadDirectModelProviderConnection } from "@opengeni/db";
10013
-
10014
10082
  // src/activities/agent-turn/recovery-warning.ts
10015
10083
  import { getSandboxRecoveryDiscontinuity } from "@opengeni/db";
10016
10084
  var FILESYSTEM_DISCONTINUITY_PROTOCOL = 3;
@@ -10443,15 +10511,6 @@ async function claimTurnAttempt(deps) {
10443
10511
  workspaceProviderSettings,
10444
10512
  claimedPolicy.kind === "valid" ? claimedPolicy.policy.productModelId : turn.model
10445
10513
  );
10446
- const selectedDirectConnection = await loadDirectModelProviderConnection(
10447
- db,
10448
- capabilitySettings,
10449
- input.workspaceId,
10450
- claimedPolicy.kind === "valid" ? claimedPolicy.policy.productModelId : turn.model ?? ""
10451
- );
10452
- if (selectedDirectConnection) {
10453
- capabilitySettings = withDirectModelProviders(capabilitySettings, [selectedDirectConnection]);
10454
- }
10455
10514
  const codexAppsCredentialId = capabilitySettings.codexConnectedAppsEnabled ? await resolveCodexAppsCredentialIdForRun(db, input.workspaceId) : null;
10456
10515
  const candidatePolicy = claimedPolicy.kind === "valid" ? claimedPolicy.policy : resolveTurnExecutionPolicyV12(capabilitySettings, legacyTurnExecutionPolicyInput(turn));
10457
10516
  const credentialRestriction = claimedPolicy.kind === "absent" ? turn.initiatorContext?.credentialRestriction === "developer_setup" ? "developer_setup" : turnCredentialRestriction(candidatePolicy, session.metadata) : void 0;
@@ -12942,7 +13001,6 @@ import { createProviderCommandRetainer } from "@opengeni/db/retained-provider-co
12942
13001
  import {
12943
13002
  RoutingMutationOutcomeUnknownError,
12944
13003
  ProviderCommandStartOutcomeUnknownError,
12945
- ProviderCommandObservationUnavailableError,
12946
13004
  isModalCommandStartOutcomeUnknownError as isModalCommandStartOutcomeUnknownError2,
12947
13005
  withModalCommandStartSignal,
12948
13006
  resolveModalCheckpointProviderBindingForSession,
@@ -12970,7 +13028,7 @@ function internalMutationUnknownCommand(error51, instanceId) {
12970
13028
  if (!value || typeof value !== "object" || seen.has(value)) continue;
12971
13029
  seen.add(value);
12972
13030
  try {
12973
- if (value instanceof ProviderCommandStartOutcomeUnknownError || value instanceof ProviderCommandObservationUnavailableError) {
13031
+ if (value instanceof ProviderCommandStartOutcomeUnknownError) {
12974
13032
  unknown2 = true;
12975
13033
  let remaining = 64;
12976
13034
  const copyCommandData = (candidate, descriptorDepth = 0) => {
@@ -14103,8 +14161,7 @@ async function establishTurnSandbox(deps) {
14103
14161
  observability,
14104
14162
  freshSandboxReadinessReplacementBudget,
14105
14163
  onSandboxLost: publishSandboxLost,
14106
- objectStorage,
14107
- bus
14164
+ objectStorage
14108
14165
  },
14109
14166
  {
14110
14167
  accountId: input.accountId,
@@ -14179,8 +14236,7 @@ async function establishTurnSandbox(deps) {
14179
14236
  observability,
14180
14237
  freshSandboxReadinessReplacementBudget,
14181
14238
  onSandboxLost: publishSandboxLost,
14182
- objectStorage,
14183
- bus
14239
+ objectStorage
14184
14240
  },
14185
14241
  {
14186
14242
  accountId: input.accountId,
@@ -34235,7 +34291,6 @@ function configuredBundledSkillNames(context) {
34235
34291
  { name: "document-parsing", include: () => true },
34236
34292
  { name: "opengeni-skills", include: () => true },
34237
34293
  { name: "opengeni-projects", include: () => true },
34238
- { name: "opengeni-schedules", include: () => tools.has("scheduled_tasks_create") },
34239
34294
  { name: "opengeni-documents", include: artifacts },
34240
34295
  { name: "opengeni-spreadsheets", include: artifacts },
34241
34296
  { name: "opengeni-presentations", include: artifacts },
@@ -34253,7 +34308,6 @@ function loadConfiguredBundledSkills(context) {
34253
34308
  const names = new Set(configuredBundledSkillNames(context));
34254
34309
  const artifacts = loadNativeToolSkillArtifacts({
34255
34310
  projects: names.has("opengeni-projects"),
34256
- schedules: names.has("opengeni-schedules"),
34257
34311
  editableArtifacts: [
34258
34312
  "opengeni-documents",
34259
34313
  "opengeni-spreadsheets",
@@ -37334,8 +37388,6 @@ function createRunAgentTurnActivity(services) {
37334
37388
  bus,
37335
37389
  runtime,
37336
37390
  summarizeContextForCompaction,
37337
- requestWorkerDrain,
37338
- turnFinalizationTimeoutMs,
37339
37391
  objectStorage,
37340
37392
  observability,
37341
37393
  wakeSessionWorkflow,
@@ -37959,28 +38011,28 @@ function createRunAgentTurnActivity(services) {
37959
38011
  })
37960
38012
  );
37961
38013
  const withClaudeUsage = (fn) => withClaudeUsageObserver(claudeUsageObserver, fn, async (providerId, headers) => {
37962
- return claudeUsageObserver.prepareRequestWithObserver(
37963
- providerId,
37964
- headers,
37965
- async (binding) => {
37966
- const credential = await resolveClaudeSubscriptionCredential(
37967
- db,
37968
- settings,
37969
- {
37970
- accountId: input.accountId,
37971
- workspaceId: input.workspaceId,
37972
- scope: binding.scope
37973
- },
37974
- {
37975
- expectedConnectionId: binding.expectedConnectionId,
37976
- expectedCredentialVersion: binding.expectedCredentialVersion
37977
- }
37978
- );
37979
- if (credential && "reconnectRequired" in credential)
37980
- throw new ClaudeSubscriptionReconnectRequired();
37981
- return credential;
38014
+ const binding = claudeUsageObserver.binding(providerId);
38015
+ if (!binding) return headers;
38016
+ const credential = await resolveClaudeSubscriptionCredential(
38017
+ db,
38018
+ settings,
38019
+ {
38020
+ accountId: input.accountId,
38021
+ workspaceId: input.workspaceId,
38022
+ scope: binding.scope
38023
+ },
38024
+ {
38025
+ expectedConnectionId: binding.expectedConnectionId,
38026
+ expectedCredentialVersion: binding.expectedCredentialVersion
37982
38027
  }
37983
38028
  );
38029
+ if (!credential) return headers;
38030
+ if ("reconnectRequired" in credential)
38031
+ throw new ClaudeSubscriptionReconnectRequired();
38032
+ claudeUsageObserver.renew(providerId, credential);
38033
+ headers.set("authorization", `Bearer ${credential.token}`);
38034
+ headers.delete("x-api-key");
38035
+ return headers;
37984
38036
  });
37985
38037
  const withCodex = (fn) => codexContext ? codexRequestStorage.run(codexContext, fn) : fn();
37986
38038
  const withProviderRequestContext = (fn) => withClaudeUsage(
@@ -38790,8 +38842,6 @@ These are publication receipts for the human's earlier answer. Do not call the r
38790
38842
  });
38791
38843
  } finally {
38792
38844
  await finalizeTurnAttempt({
38793
- turnFinalizationTimeoutMs,
38794
- requestWorkerDrain,
38795
38845
  input,
38796
38846
  settings,
38797
38847
  db,
@@ -39932,17 +39982,12 @@ function createTurnActivityServices(dependencies) {
39932
39982
  let servicesPromise = null;
39933
39983
  return async () => {
39934
39984
  servicesPromise ??= (async () => {
39935
- if (!dependencies.requestWorkerDrain) {
39936
- throw new Error("Turn activities require a host requestWorkerDrain lifecycle edge");
39937
- }
39938
39985
  const services = await shared();
39939
39986
  return {
39940
39987
  ...services,
39941
39988
  runtime: dependencies.runtime ?? createProductionAgentRuntime({
39942
39989
  metrics: runtimeMetricsHooksForObservability(services.observability)
39943
39990
  }),
39944
- requestWorkerDrain: dependencies.requestWorkerDrain,
39945
- turnFinalizationTimeoutMs: dependencies.turnFinalizationTimeoutMs,
39946
39991
  summarizeContextForCompaction: dependencies.summarizeContextForCompaction ?? summarizeForCompaction2
39947
39992
  };
39948
39993
  })();
@@ -39962,4 +40007,4 @@ export {
39962
40007
  createTurnActivities,
39963
40008
  createTurnActivitiesFromServices
39964
40009
  };
39965
- //# sourceMappingURL=activities-turn-TTNAVGKN.js.map
40010
+ //# sourceMappingURL=activities-turn-KU25J3VQ.js.map