replicas-engine 0.1.1240 → 0.1.1241

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.
@@ -8,12 +8,12 @@ import {
8
8
  listRunningCodexModels,
9
9
  restartCodexAspHost,
10
10
  restartCodexAspHostIfRunning
11
- } from "./chunk-OEGVEGYP.js";
12
- import "./chunk-2XSQNRTM.js";
13
- import "./chunk-DM4L753M.js";
14
- import "./chunk-YESWD6QV.js";
11
+ } from "./chunk-A23O2Z7T.js";
12
+ import "./chunk-4UMPF6MZ.js";
13
+ import "./chunk-3DZUIWNK.js";
14
+ import "./chunk-MMIG2PXJ.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
- import "./chunk-TOKC7PCQ.js";
16
+ import "./chunk-MSM5OSLN.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
  export {
19
19
  CODEX_ULTRAFAST_SERVICE_TIER,
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  execFileAsync
6
- } from "./chunk-YESWD6QV.js";
6
+ } from "./chunk-MMIG2PXJ.js";
7
7
  import {
8
8
  isVersionBelow
9
- } from "./chunk-TOKC7PCQ.js";
9
+ } from "./chunk-MSM5OSLN.js";
10
10
 
11
11
  // src/utils/codex-agent-env.ts
12
12
  function buildCodexAgentEnv(source = process.env) {
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
240
240
  if (method === "foundry") return "azure";
241
241
  return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
242
242
  }
243
- var ENGINE_PACKAGE_VERSION = "0.1.1240";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1241";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  SUBPROCESS_MAX_BUFFER,
6
6
  execFileAsync
7
- } from "./chunk-YESWD6QV.js";
7
+ } from "./chunk-MMIG2PXJ.js";
8
8
  import {
9
9
  isRecord as isRecord2
10
10
  } from "./chunk-UZSNFLDQ.js";
@@ -18,7 +18,7 @@ import {
18
18
  isValidAgentProvider,
19
19
  parsePosixEnvFile,
20
20
  readReplicasRuntimeEnv
21
- } from "./chunk-TOKC7PCQ.js";
21
+ } from "./chunk-MSM5OSLN.js";
22
22
 
23
23
  // src/runtime-env-loader.ts
24
24
  import { readFileSync } from "fs";
@@ -10,15 +10,15 @@ import {
10
10
  resolveDiffBase,
11
11
  runGitCommand,
12
12
  setAgentCredentialSnapshot
13
- } from "./chunk-2XSQNRTM.js";
13
+ } from "./chunk-4UMPF6MZ.js";
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-DM4L753M.js";
17
+ } from "./chunk-3DZUIWNK.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
21
- } from "./chunk-YESWD6QV.js";
21
+ } from "./chunk-MMIG2PXJ.js";
22
22
  import {
23
23
  isRecord
24
24
  } from "./chunk-UZSNFLDQ.js";
@@ -55,7 +55,7 @@ import {
55
55
  resolveOpenAICompatibleModelsUrl,
56
56
  splitMothershipInstructions,
57
57
  withTimeout
58
- } from "./chunk-TOKC7PCQ.js";
58
+ } from "./chunk-MSM5OSLN.js";
59
59
 
60
60
  // src/managers/codex-token-manager.ts
61
61
  import { promises as fs } from "fs";
@@ -291,7 +291,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
291
291
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
292
292
  await this.applyCredentialsResponse(data);
293
293
  setAgentCredentialSnapshot("codex", data);
294
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-QQPAD2E4.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-35RQ4C35.js");
295
295
  await restartCodexAspHostIfRunning2();
296
296
  });
297
297
  await this.start(true);
@@ -313,7 +313,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
313
313
  const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
314
314
  await this.applyCredentialsResponse(data);
315
315
  if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
316
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-QQPAD2E4.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-35RQ4C35.js");
317
317
  await restartCodexAspHostIfRunning2();
318
318
  }
319
319
  setAgentCredentialSnapshot("codex", data);
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  AspClient
6
- } from "./chunk-DM4L753M.js";
6
+ } from "./chunk-3DZUIWNK.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -13,7 +13,7 @@ import {
13
13
  isRecord,
14
14
  readOllamaAuthEnv,
15
15
  readOpenAICompatibleAuthEnv
16
- } from "./chunk-TOKC7PCQ.js";
16
+ } from "./chunk-MSM5OSLN.js";
17
17
 
18
18
  // src/managers/codex-asp/notification-dispatch.ts
19
19
  var TURN_STARTED_METHOD = "turn/started";
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-TOKC7PCQ.js";
8
+ } from "./chunk-MSM5OSLN.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  HOOK_EXEC_MAX_BUFFER_BYTES
6
- } from "./chunk-TOKC7PCQ.js";
6
+ } from "./chunk-MSM5OSLN.js";
7
7
 
8
8
  // src/utils/exec.ts
9
9
  import { exec, execFile } from "child_process";
@@ -1419,6 +1419,7 @@ var CODEX_ASP_TRANSCRIPT_UPDATED_EVENT_TYPE = "codex-asp-transcript-updated";
1419
1419
  var CODEX_ITEM_EVENT_TYPE = "codex-item";
1420
1420
  var CODEX_ITEM_PARTIAL_EVENT_TYPE = "codex-item-partial";
1421
1421
  var CODEX_TURN_EVENT_TYPE = "codex-turn";
1422
+ var CODEX_TURN_RETRY_EVENT_TYPE = "codex-turn-retry";
1422
1423
  var CODEX_HISTORY_FORMAT_EVENT_TYPE = "codex-history-format";
1423
1424
  function getEventStreamId(event) {
1424
1425
  if (event.type === CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE) {
@@ -1496,6 +1497,10 @@ function coerceChatGoalPayload(payload) {
1496
1497
  updatedAt
1497
1498
  };
1498
1499
  }
1500
+ function parseCodexTurnRetryPayload(payload) {
1501
+ const { attempt, maxAttempts, [CODEX_ASP_ITEM_ID_PAYLOAD_KEY]: turnId } = payload;
1502
+ return typeof attempt === "number" && typeof maxAttempts === "number" && typeof turnId === "string" ? { attempt, maxAttempts, [CODEX_ASP_ITEM_ID_PAYLOAD_KEY]: turnId } : void 0;
1503
+ }
1499
1504
  var CONTEXT_USAGE_EVENT_TYPE = "context-usage";
1500
1505
 
1501
1506
  // ../shared/src/engine/v1.ts
@@ -5673,6 +5678,7 @@ ${operation.diff}` : ""}`).join("\n\n");
5673
5678
  }
5674
5679
  if (message2.type === "harness_switch") return { kind: "error", title: describeHarnessSwitch(message2), summary: "", content: "" };
5675
5680
  if (message2.type === "interruption") return { kind: "error", title: "Agent stopped", summary: "", content: "" };
5681
+ if (message2.type === "capacity_retry") return { kind: "task", title: "Model at capacity", summary: `Retry ${message2.attempt} of ${message2.maxAttempts}`, content: "" };
5676
5682
  if (message2.type === "multitask_event") return { kind: "task", title: "Subagent update", summary: message2.events.map((event) => `${event.agentName}: ${event.summary}`).join(" \xB7 "), content: "" };
5677
5683
  return { kind: "error", title: "Agent error", summary: "", content: message2.message };
5678
5684
  }
@@ -6210,13 +6216,42 @@ function parseCodexEvents(events) {
6210
6216
  const pendingCommands = /* @__PURE__ */ new Map();
6211
6217
  const pendingToolCalls = /* @__PURE__ */ new Map();
6212
6218
  const pendingPatches = /* @__PURE__ */ new Map();
6219
+ const retriedTurnIds = /* @__PURE__ */ new Set();
6220
+ let pendingRetry = null;
6213
6221
  events.forEach((event, eventIndex) => {
6214
6222
  const turnId = codexItemFromEvent(event)?.turnId ?? codexTurnFromEvent(event)?.turnId;
6215
6223
  if (turnId !== void 0) {
6216
6224
  if (!turnInsertions.has(turnId)) turnInsertions.set(turnId, messages.length);
6225
+ if (pendingRetry && !retriedTurnIds.has(turnId)) {
6226
+ pendingRetry.status = "completed";
6227
+ pendingRetry = null;
6228
+ }
6229
+ return;
6230
+ }
6231
+ if (event.type === CHAT_INTERRUPTED_EVENT_TYPE) {
6232
+ pendingRetry = null;
6233
+ return;
6234
+ }
6235
+ if (event.type === CODEX_TURN_RETRY_EVENT_TYPE) {
6236
+ const retry = parseCodexTurnRetryPayload(event.payload);
6237
+ if (!retry) return;
6238
+ retriedTurnIds.add(retry[CODEX_ASP_ITEM_ID_PAYLOAD_KEY]);
6239
+ pendingRetry = {
6240
+ id: displayId(event, eventIndex, "capacity-retry"),
6241
+ type: "capacity_retry",
6242
+ attempt: retry.attempt,
6243
+ maxAttempts: retry.maxAttempts,
6244
+ status: "in_progress",
6245
+ timestamp: event.timestamp
6246
+ };
6247
+ messages.push(pendingRetry);
6217
6248
  return;
6218
6249
  }
6219
6250
  if (event.type === "codex-asp-error") {
6251
+ if (pendingRetry) {
6252
+ pendingRetry.status = "completed";
6253
+ pendingRetry = null;
6254
+ }
6220
6255
  const failedTurnId = getPayloadString(event, CODEX_ASP_ITEM_ID_PAYLOAD_KEY);
6221
6256
  if (!(failedTurnId && turns.has(failedTurnId))) {
6222
6257
  messages.push({
@@ -6398,6 +6433,13 @@ function parseCodexEvents(events) {
6398
6433
  if (!turn) continue;
6399
6434
  const kept = [];
6400
6435
  for (const message2 of messagesForCodexTurn(turn)) {
6436
+ if (retriedTurnIds.has(turnId)) {
6437
+ if (message2.type === "error") continue;
6438
+ if (message2.type === "reasoning" && message2.status === "in_progress") {
6439
+ kept.push({ ...message2, status: "failed" });
6440
+ continue;
6441
+ }
6442
+ }
6401
6443
  if (message2.type !== "user") {
6402
6444
  kept.push(message2);
6403
6445
  continue;
@@ -10307,6 +10349,7 @@ export {
10307
10349
  CODEX_ASP_ITEM_ID_PAYLOAD_KEY,
10308
10350
  CODEX_ITEM_EVENT_TYPE,
10309
10351
  CODEX_ITEM_PARTIAL_EVENT_TYPE,
10352
+ CODEX_TURN_RETRY_EVENT_TYPE,
10310
10353
  CODEX_HISTORY_FORMAT_EVENT_TYPE,
10311
10354
  getEventStreamId,
10312
10355
  CODEX_QUOTA_STATUS_EVENT_TYPE,
@@ -5,14 +5,14 @@ import {
5
5
  getOriginDefaultBranch,
6
6
  monolithRequest,
7
7
  runGitCommand
8
- } from "./chunk-2XSQNRTM.js";
8
+ } from "./chunk-4UMPF6MZ.js";
9
9
  import {
10
10
  extractCommandProtectionCommandText,
11
11
  findCommandProtectionGitLookups,
12
12
  findGitCommitSignals,
13
13
  findPrMergeSignals,
14
14
  parseCommandProtectionRequest
15
- } from "./chunk-TOKC7PCQ.js";
15
+ } from "./chunk-MSM5OSLN.js";
16
16
 
17
17
  // src/services/command-protection-service.ts
18
18
  import { readFile, stat } from "fs/promises";
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-I6I2HGF2.js";
7
- import "./chunk-2XSQNRTM.js";
8
- import "./chunk-YESWD6QV.js";
6
+ } from "./chunk-Z2MHQL4K.js";
7
+ import "./chunk-4UMPF6MZ.js";
8
+ import "./chunk-MMIG2PXJ.js";
9
9
  import {
10
10
  isRecord
11
11
  } from "./chunk-UZSNFLDQ.js";
12
- import "./chunk-TOKC7PCQ.js";
12
+ import "./chunk-MSM5OSLN.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/command-protection-hook.ts
@@ -13,12 +13,12 @@ import {
13
13
  recoverCompletedTurn,
14
14
  spawnMuseMsp,
15
15
  startMuseSession
16
- } from "./chunk-UBKI5D7Q.js";
16
+ } from "./chunk-FCIDRN6E.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-DM4L753M.js";
21
- import "./chunk-YESWD6QV.js";
20
+ } from "./chunk-3DZUIWNK.js";
21
+ import "./chunk-MMIG2PXJ.js";
22
22
  import {
23
23
  AGENT,
24
24
  OPENCODE_GO_PROVIDER,
@@ -28,7 +28,7 @@ import {
28
28
  headlessAgentUsagePath,
29
29
  isRecord,
30
30
  withTimeout
31
- } from "./chunk-TOKC7PCQ.js";
31
+ } from "./chunk-MSM5OSLN.js";
32
32
  import "./chunk-VEQXQN22.js";
33
33
 
34
34
  // src/headless-agent.ts
package/dist/src/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  evaluateCommandProtection,
28
28
  extractToolCommand,
29
29
  reportCommandProtectionBlock
30
- } from "./chunk-I6I2HGF2.js";
30
+ } from "./chunk-Z2MHQL4K.js";
31
31
  import {
32
32
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
33
33
  AGENT_MESSAGE_DELTA_METHOD,
@@ -64,10 +64,10 @@ import {
64
64
  spawnMuseMsp,
65
65
  startMuseSession,
66
66
  uuidV7
67
- } from "./chunk-UBKI5D7Q.js";
67
+ } from "./chunk-FCIDRN6E.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
- } from "./chunk-5OU26OYM.js";
70
+ } from "./chunk-K6LHHTEJ.js";
71
71
  import {
72
72
  ACCOUNT_RATE_LIMITS_READ_METHOD,
73
73
  AsyncLock,
@@ -140,7 +140,7 @@ import {
140
140
  timestampFromSeconds,
141
141
  upsertCredentialFileLines,
142
142
  writeSecureCredentialFile
143
- } from "./chunk-OEGVEGYP.js";
143
+ } from "./chunk-A23O2Z7T.js";
144
144
  import {
145
145
  ENGINE_ENV,
146
146
  monolithRequest,
@@ -149,15 +149,15 @@ import {
149
149
  reloadEngineEnv,
150
150
  resolveDiffBase,
151
151
  setAgentCredentialSnapshot
152
- } from "./chunk-2XSQNRTM.js";
152
+ } from "./chunk-4UMPF6MZ.js";
153
153
  import {
154
154
  getCodexModelProvider
155
- } from "./chunk-DM4L753M.js";
155
+ } from "./chunk-3DZUIWNK.js";
156
156
  import {
157
157
  SUBPROCESS_MAX_BUFFER,
158
158
  execAsync,
159
159
  execFileAsync
160
- } from "./chunk-YESWD6QV.js";
160
+ } from "./chunk-MMIG2PXJ.js";
161
161
  import {
162
162
  isRecord as isRecord2
163
163
  } from "./chunk-UZSNFLDQ.js";
@@ -189,6 +189,7 @@ import {
189
189
  CODEX_ITEM_EVENT_TYPE,
190
190
  CODEX_ITEM_PARTIAL_EVENT_TYPE,
191
191
  CODEX_QUOTA_STATUS_EVENT_TYPE,
192
+ CODEX_TURN_RETRY_EVENT_TYPE,
192
193
  CONTEXT_USAGE_EVENT_TYPE,
193
194
  CREDENTIAL_METHOD,
194
195
  CREDENTIAL_SCOPE,
@@ -394,7 +395,7 @@ import {
394
395
  workspaceTokenRequestSchema,
395
396
  workspaceTokenResponseSchema,
396
397
  wrapInTag
397
- } from "./chunk-TOKC7PCQ.js";
398
+ } from "./chunk-MSM5OSLN.js";
398
399
  import {
399
400
  cloneMcpConfig,
400
401
  ensureCompatibilityImports,
@@ -14212,6 +14213,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
14212
14213
  import { existsSync as existsSync6 } from "fs";
14213
14214
  import { mkdir as mkdir8, writeFile as writeFile4 } from "fs/promises";
14214
14215
  import { join as join11 } from "path";
14216
+ import { setTimeout as sleep } from "timers/promises";
14215
14217
 
14216
14218
  // src/managers/codex-asp/item-update-coalescer.ts
14217
14219
  var ITEM_UPDATE_COALESCE_MS = 250;
@@ -14289,6 +14291,17 @@ var CodexQuotaError = class extends Error {
14289
14291
  this.name = "CodexQuotaError";
14290
14292
  }
14291
14293
  };
14294
+ var CodexModelAtCapacityError = class extends Error {
14295
+ constructor(message, turnId) {
14296
+ super(message);
14297
+ this.turnId = turnId;
14298
+ this.name = "CodexModelAtCapacityError";
14299
+ }
14300
+ turnId;
14301
+ };
14302
+ var MODEL_AT_CAPACITY_RETRIES = 5;
14303
+ var MODEL_AT_CAPACITY_RETRY_BASE_MS = 5e3;
14304
+ var MODEL_AT_CAPACITY_CONTINUE_PROMPT = "Your previous turn stopped because the model was at capacity. Continue from where you left off: first check what is already done, and do not repeat commands, edits, or messages you already completed.";
14292
14305
  var CODEX_SLASH_COMMANDS_CACHE_MS = 3e4;
14293
14306
  var POLICY_REASON_INJECTION_TIMEOUT_MS = 5e3;
14294
14307
  var SUBAGENT_MCP_THREADS_DIR = join11(ENGINE_ENV.HOME_DIR, ".replicas", "codex", "subagent-mcp-threads");
@@ -14643,9 +14656,36 @@ var CodexAspManager = class extends CodingAgentManager {
14643
14656
  }
14644
14657
  await this.executeAspTurn(request, recordUserMessage, signal);
14645
14658
  };
14659
+ const retryAfterCapacityFailure = isCompactCommand(request.message) ? dispatch : () => this.executeAspTurn(request, recordUserMessage, signal, {
14660
+ continuation: true
14661
+ });
14662
+ const dispatchWithCapacityRetries = async () => {
14663
+ try {
14664
+ await dispatch();
14665
+ } catch (error) {
14666
+ let failure = error;
14667
+ for (let attempt = 1; failure instanceof CodexModelAtCapacityError && attempt <= MODEL_AT_CAPACITY_RETRIES; attempt++) {
14668
+ this.onEvent(this.recordCodexHistoryEvent(CODEX_TURN_RETRY_EVENT_TYPE, {
14669
+ attempt,
14670
+ maxAttempts: MODEL_AT_CAPACITY_RETRIES,
14671
+ [CODEX_ASP_ITEM_ID_PAYLOAD_KEY]: failure.turnId
14672
+ }));
14673
+ await sleep(MODEL_AT_CAPACITY_RETRY_BASE_MS * 2 ** (attempt - 1) * (0.5 + Math.random() / 2), void 0, { signal }).catch(() => {
14674
+ });
14675
+ if (signal.aborted) return;
14676
+ try {
14677
+ await retryAfterCapacityFailure();
14678
+ return;
14679
+ } catch (retryError) {
14680
+ failure = retryError;
14681
+ }
14682
+ }
14683
+ throw failure;
14684
+ }
14685
+ };
14646
14686
  let attemptedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex;
14647
14687
  try {
14648
- await dispatch();
14688
+ await dispatchWithCapacityRetries();
14649
14689
  } catch (error) {
14650
14690
  let terminalError = error;
14651
14691
  if (terminalError instanceof CodexQuotaError && !quotaFallbackAttempted) {
@@ -14658,7 +14698,7 @@ var CodexAspManager = class extends CodingAgentManager {
14658
14698
  if (fallback.outcome === "switched") {
14659
14699
  if (fallback.model) request = { ...request, model: fallback.model };
14660
14700
  attemptedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex;
14661
- const retryFailure = await this.restartAndRetry(dispatch);
14701
+ const retryFailure = await this.restartAndRetry(dispatchWithCapacityRetries);
14662
14702
  if (!retryFailure) return;
14663
14703
  terminalError = retryFailure.error;
14664
14704
  } else {
@@ -14677,7 +14717,7 @@ var CodexAspManager = class extends CodingAgentManager {
14677
14717
  }
14678
14718
  }
14679
14719
  if (terminalError instanceof CodexAspAuthMethodChangedError) {
14680
- const retryFailure = await this.restartAndRetry(dispatch);
14720
+ const retryFailure = await this.restartAndRetry(dispatchWithCapacityRetries);
14681
14721
  if (!retryFailure) return;
14682
14722
  terminalError = retryFailure.error;
14683
14723
  }
@@ -14689,7 +14729,7 @@ var CodexAspManager = class extends CodingAgentManager {
14689
14729
  attemptedCredential
14690
14730
  );
14691
14731
  if (refreshed.ok) {
14692
- const retryFailure = await this.restartAndRetry(dispatch);
14732
+ const retryFailure = await this.restartAndRetry(dispatchWithCapacityRetries);
14693
14733
  if (!retryFailure) return;
14694
14734
  terminalError = retryFailure.error;
14695
14735
  }
@@ -14755,10 +14795,10 @@ var CodexAspManager = class extends CodingAgentManager {
14755
14795
  const serviceTier = await this.resolveRequestedServiceTier(host, request);
14756
14796
  await this.applyThreadServiceTier(host, threadId, serviceTier);
14757
14797
  if (signal.aborted) {
14758
- await this.keepStoppedRequest(request);
14798
+ if (!options.runTurn && !options.continuation) await this.keepStoppedRequest(request);
14759
14799
  return;
14760
14800
  }
14761
- const runTurn = options.runTurn ?? ((aspHost, aspThreadId) => this.runTurn(aspHost, aspThreadId, request, serviceTier, signal));
14801
+ const runTurn = options.runTurn ?? ((aspHost, aspThreadId) => this.runTurn(aspHost, aspThreadId, request, serviceTier, signal, options.continuation));
14762
14802
  let completedTurn;
14763
14803
  try {
14764
14804
  completedTurn = await runTurn(host, threadId);
@@ -14770,6 +14810,7 @@ var CodexAspManager = class extends CodingAgentManager {
14770
14810
  }
14771
14811
  if (completedTurn.status === "failed") {
14772
14812
  const failure = formatTurnFailure(completedTurn);
14813
+ if (completedTurn.error?.codexErrorInfo === "serverOverloaded") throw new CodexModelAtCapacityError(failure, completedTurn.id);
14773
14814
  throw isQuotaTurnFailure(completedTurn) ? new CodexQuotaError(failure) : new Error(failure);
14774
14815
  }
14775
14816
  this.emitQuotaEvent(this.quotaStatus.recordTurnSuccess());
@@ -14907,17 +14948,29 @@ ${text.slice(-24e3)}`
14907
14948
  console.warn("[CodexAspManager] Failed to apply skill registries:", error);
14908
14949
  }
14909
14950
  }
14910
- async runTurn(host, threadId, request, serviceTier, signal) {
14911
- const { params, tempImagePaths } = await buildTurnStartParams(threadId, request, serviceTier, this.unreadRequests).catch((error) => {
14951
+ async runTurn(host, threadId, request, serviceTier, signal, continuation = false) {
14952
+ const { params, tempImagePaths } = await buildTurnStartParams(
14953
+ threadId,
14954
+ continuation ? { ...request, images: void 0 } : request,
14955
+ serviceTier,
14956
+ continuation ? [] : this.unreadRequests
14957
+ ).catch((error) => {
14912
14958
  this.unreadRequests = this.unreadRequests.map((unread) => ({ ...unread, images: void 0 }));
14913
14959
  throw error;
14914
14960
  });
14915
14961
  return this.observeTurn(host, threadId, request, signal, async () => {
14916
14962
  const turnStartResponse = await host.client.request(
14917
14963
  TURN_START_METHOD,
14918
- params
14964
+ continuation ? {
14965
+ ...params,
14966
+ input: [],
14967
+ additionalContext: {
14968
+ ...params.additionalContext,
14969
+ replicas_capacity_retry: { kind: "application", value: MODEL_AT_CAPACITY_CONTINUE_PROMPT }
14970
+ }
14971
+ } : params
14919
14972
  );
14920
- this.unreadRequests = [];
14973
+ if (!continuation) this.unreadRequests = [];
14921
14974
  return { turn: turnStartResponse.turn, tempImagePaths };
14922
14975
  });
14923
14976
  }
@@ -26451,7 +26504,7 @@ function buildInputRequiredRetryParams(originalParams, responses, requestState)
26451
26504
  function inputRequiredRoundsExceededMessage(method, maxRounds) {
26452
26505
  return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
26453
26506
  }
26454
- function sleep(ms, signal) {
26507
+ function sleep2(ms, signal) {
26455
26508
  return new Promise((resolve7, reject) => {
26456
26509
  if (signal?.aborted) {
26457
26510
  reject(signal.reason instanceof SdkError ? signal.reason : new SdkError(SdkErrorCode.RequestTimeout, String(signal.reason)));
@@ -26514,7 +26567,7 @@ async function runInputRequiredDriver(args) {
26514
26567
  } finally {
26515
26568
  round$1.dispose();
26516
26569
  }
26517
- } else await sleep(REQUEST_STATE_ONLY_LEG_PACING_MS, signal);
26570
+ } else await sleep2(REQUEST_STATE_ONLY_LEG_PACING_MS, signal);
26518
26571
  const legOptions = { ...requestOptions.timeout !== void 0 && { timeout: requestOptions.timeout } };
26519
26572
  if (requestOptions.maxTotalTimeout !== void 0) {
26520
26573
  const totalElapsed = Date.now() - startedAt;
@@ -59718,6 +59771,7 @@ function terminalErrorsFromEvent(event, provider) {
59718
59771
  if (event.type === "codex-asp-error") {
59719
59772
  return [typeof event.payload.message === "string" ? event.payload.message : "Codex run failed"];
59720
59773
  }
59774
+ if (event.type === CODEX_TURN_RETRY_EVENT_TYPE) return null;
59721
59775
  const codexTurn = codexTurnFromEvent(event);
59722
59776
  if (codexTurn) {
59723
59777
  return normalizeCodexAspTranscriptStatus(codexTurn.status) === "failed" ? [codexTurn.error ?? "Codex run failed"] : void 0;
@@ -63756,7 +63810,7 @@ app.post(ENGINE_ACTIVATE_PATH, async (c) => {
63756
63810
  const workspaceId = isRecord(body) && typeof body.workspaceId === "string" ? body.workspaceId : void 0;
63757
63811
  return lifecycleResponse(c, await lifecycle.transition(() => activate(workspaceId === void 0 ? void 0 : { workspaceId })));
63758
63812
  });
63759
- app.post(ENGINE_SLEEP_PATH, async (c) => lifecycleResponse(c, await lifecycle.transition(sleep2)));
63813
+ app.post(ENGINE_SLEEP_PATH, async (c) => lifecycleResponse(c, await lifecycle.transition(sleep3)));
63760
63814
  app.get("/status", async (c) => {
63761
63815
  try {
63762
63816
  const [repos, hasActiveSSHSessions, desktopReady] = await Promise.all([
@@ -64019,7 +64073,7 @@ async function startBackgroundServices(signal) {
64019
64073
  }
64020
64074
  if (!signal.aborted) startStatusBroadcaster();
64021
64075
  }
64022
- async function sleep2() {
64076
+ async function sleep3() {
64023
64077
  if (lifecycle.state === "parked") {
64024
64078
  return createErrorResult({ message: "A parked engine has no workspace to sleep", code: 409 });
64025
64079
  }
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  publishedPullRequestUrls
6
- } from "./chunk-5OU26OYM.js";
6
+ } from "./chunk-K6LHHTEJ.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
10
  import {
11
11
  shouldRefreshPullRequests
12
- } from "./chunk-TOKC7PCQ.js";
12
+ } from "./chunk-MSM5OSLN.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/services/post-tool-pr-notifier.ts
@@ -9,7 +9,7 @@ import {
9
9
  spawnSubagentRequestSchema,
10
10
  subagentResponseSchema,
11
11
  waitSubagentRequestSchema
12
- } from "./chunk-TOKC7PCQ.js";
12
+ } from "./chunk-MSM5OSLN.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/subagent-mcp.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.1240",
3
+ "version": "0.1.1241",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",