@moxt-ai/cli 0.10.0-beta.8 → 0.10.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -8185,11 +8185,11 @@ var init_app_server_client = __esm({
8185
8185
  });
8186
8186
 
8187
8187
  // ../machine-connector/dist/runtime/local-codex-runtime/durable-attempt.js
8188
- function assertCompatibleClaim(persisted, connectionId, claim) {
8188
+ function assertCompatibleClaim(persisted, connectionId, claim, allowRestartFenceRotation) {
8189
8189
  if (persisted.connectionId !== connectionId || persisted.claim.attemptId !== claim.attemptId || persisted.claim.attemptGeneration !== claim.attemptGeneration || persisted.claim.conversationId !== claim.conversationId || persisted.claim.turnId !== claim.turnId || persisted.claim.expectedNativeStoreIdentity !== claim.expectedNativeStoreIdentity) {
8190
8190
  throw new Error(`Local Codex Runtime attempt ${claim.attemptId} conflicts with its durable spool`);
8191
8191
  }
8192
- if (persisted.phase !== LocalCodexAttemptPhase.Claimed && (persisted.claim.leaseToken !== claim.leaseToken || persisted.claim.runToken !== claim.runToken)) {
8192
+ if (persisted.phase !== LocalCodexAttemptPhase.Claimed && !allowRestartFenceRotation && (persisted.claim.leaseToken !== claim.leaseToken || persisted.claim.runToken !== claim.runToken)) {
8193
8193
  throw new Error(`Running Local Codex Runtime attempt ${claim.attemptId} changed its fence`);
8194
8194
  }
8195
8195
  }
@@ -8217,16 +8217,19 @@ var init_durable_attempt = __esm({
8217
8217
  DurableLocalCodexAttempt = class _DurableLocalCodexAttempt {
8218
8218
  store;
8219
8219
  state;
8220
+ recoveryRequired;
8220
8221
  mutationQueue = Promise.resolve();
8221
- constructor(store, state) {
8222
+ constructor(store, state, recoveryRequired = false) {
8222
8223
  this.store = store;
8223
8224
  this.state = state;
8225
+ this.recoveryRequired = recoveryRequired;
8224
8226
  }
8225
8227
  static async create(store, connectionId, connectorInstanceId, claim) {
8226
8228
  const persisted = (await store.readLocalCodexAttempt(claim.attemptId)).value;
8227
8229
  if (persisted !== void 0) {
8228
- assertCompatibleClaim(persisted, connectionId, claim);
8229
- if (persisted.phase === LocalCodexAttemptPhase.Claimed) {
8230
+ const recoveryRequired = persisted.phase === LocalCodexAttemptPhase.TerminalPendingUpload || persisted.phase === LocalCodexAttemptPhase.Running && persisted.connectorInstanceId !== connectorInstanceId;
8231
+ assertCompatibleClaim(persisted, connectionId, claim, recoveryRequired);
8232
+ if (persisted.phase === LocalCodexAttemptPhase.Claimed || recoveryRequired) {
8230
8233
  persisted.claim = claim;
8231
8234
  persisted.connectorInstanceId = connectorInstanceId;
8232
8235
  persisted.acknowledgedSequence = claim.lastAcknowledgedEventSequence;
@@ -8235,7 +8238,7 @@ var init_durable_attempt = __esm({
8235
8238
  persisted.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
8236
8239
  await store.writeLocalCodexAttempt(persisted);
8237
8240
  }
8238
- return new _DurableLocalCodexAttempt(store, persisted);
8241
+ return new _DurableLocalCodexAttempt(store, persisted, recoveryRequired);
8239
8242
  }
8240
8243
  const state = {
8241
8244
  acknowledgedSequence: claim.lastAcknowledgedEventSequence,
@@ -8258,6 +8261,9 @@ var init_durable_attempt = __esm({
8258
8261
  snapshot() {
8259
8262
  return structuredClone(this.state);
8260
8263
  }
8264
+ requiresRecovery() {
8265
+ return this.recoveryRequired;
8266
+ }
8261
8267
  async markRunning(nativeThreadId, nativeTurnId) {
8262
8268
  await this.mutate(async () => {
8263
8269
  this.state.nativeThreadId = nativeThreadId;
@@ -9140,6 +9146,13 @@ async function waitForAbort(signal, milliseconds) {
9140
9146
  signal.addEventListener("abort", complete, { once: true });
9141
9147
  });
9142
9148
  }
9149
+ function createReclaimableClaimWindow() {
9150
+ let close = () => void 0;
9151
+ const completion = new Promise((resolvePromise) => {
9152
+ close = resolvePromise;
9153
+ });
9154
+ return { close, completion };
9155
+ }
9143
9156
  function rejectWhenAborted(signal) {
9144
9157
  return new Promise((_resolve, reject) => {
9145
9158
  const rejectStopped = () => reject(new WorkerStoppedError());
@@ -9523,9 +9536,8 @@ var init_runtime_worker = __esm({
9523
9536
  try {
9524
9537
  await Promise.all([
9525
9538
  this.runHeartbeatLoop(),
9526
- this.runClaimLoop(),
9527
9539
  this.runDiscoveryLoop(),
9528
- this.runRecoveryLoop()
9540
+ this.runAttemptLoops()
9529
9541
  ]);
9530
9542
  } finally {
9531
9543
  for (const active of this.activeAttempts.values()) {
@@ -9535,6 +9547,10 @@ var init_runtime_worker = __esm({
9535
9547
  this.unregisterRoute();
9536
9548
  }
9537
9549
  }
9550
+ async runAttemptLoops() {
9551
+ await this.scanPersistedAttempts();
9552
+ await Promise.all([this.runClaimLoop(), this.runRecoveryLoop()]);
9553
+ }
9538
9554
  async runHeartbeatLoop() {
9539
9555
  while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
9540
9556
  if ([...this.activeAttempts.values()].some((active) => active.interruptedCleanupStarted)) {
@@ -9577,8 +9593,9 @@ var init_runtime_worker = __esm({
9577
9593
  if (response.attempt === void 0) {
9578
9594
  continue;
9579
9595
  }
9580
- this.scheduleExecution(slot, response.attempt);
9596
+ const reclaimableClaimWindow = this.scheduleExecution(slot, response.attempt);
9581
9597
  executionScheduled = true;
9598
+ await reclaimableClaimWindow;
9582
9599
  } catch (error) {
9583
9600
  if (!this.lifetimeAbort.signal.aborted) {
9584
9601
  await this.logger.error(`Local Codex Runtime claim loop failed for connection ${this.connection.connectionId}`, error);
@@ -9596,11 +9613,14 @@ var init_runtime_worker = __esm({
9596
9613
  throw new Error(`Local Codex attempt ${claim.attemptId} is already executing`);
9597
9614
  }
9598
9615
  this.processPool.markExecutionStarted(slot);
9599
- const task = this.executeAttempt(claim).catch(async (error) => await this.logger.error(`Local Codex attempt ${claim.attemptId} execution crashed`, error).catch(() => void 0)).finally(() => {
9616
+ const reclaimableClaimWindow = createReclaimableClaimWindow();
9617
+ const task = this.executeAttempt(claim, reclaimableClaimWindow).catch(async (error) => await this.logger.error(`Local Codex attempt ${claim.attemptId} execution crashed`, error).catch(() => void 0)).finally(() => {
9618
+ reclaimableClaimWindow.close();
9600
9619
  this.executionTasks.delete(claim.attemptId);
9601
9620
  this.processPool.releaseExecutionSlot(slot);
9602
9621
  });
9603
9622
  this.executionTasks.set(claim.attemptId, task);
9623
+ return reclaimableClaimWindow.completion;
9604
9624
  }
9605
9625
  async runDiscoveryLoop() {
9606
9626
  while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
@@ -9701,8 +9721,12 @@ var init_runtime_worker = __esm({
9701
9721
  truncated: eligibleDirectories.length > maximumDiscoveryDirectories
9702
9722
  };
9703
9723
  }
9704
- async executeAttempt(claim) {
9724
+ async executeAttempt(claim, reclaimableClaimWindow) {
9705
9725
  const durable = await DurableLocalCodexAttempt.create(this.store, this.connection.connectionId, this.connectorInstanceId, claim);
9726
+ if (durable.requiresRecovery()) {
9727
+ await this.recoverPersistedAttempt(durable.snapshot());
9728
+ return;
9729
+ }
9706
9730
  const active = createActiveAttempt(claim, durable, this.connection.rootPath);
9707
9731
  if (this.activeAttempts.has(claim.attemptId)) {
9708
9732
  throw new Error(`Local Codex attempt ${claim.attemptId} is already active`);
@@ -9779,6 +9803,7 @@ var init_runtime_worker = __esm({
9779
9803
  nativeTurnId,
9780
9804
  status: LocalCodexTurnStatusWire.Running
9781
9805
  });
9806
+ reclaimableClaimWindow.close();
9782
9807
  await this.interruptActiveTurnIfRequested(active, client);
9783
9808
  const terminal = await Promise.race([
9784
9809
  active.terminal,
@@ -9921,16 +9946,19 @@ var init_runtime_worker = __esm({
9921
9946
  }
9922
9947
  async runRecoveryLoop() {
9923
9948
  while (!this.lifetimeAbort.signal.aborted && !this.relay.isRevoked()) {
9924
- try {
9925
- await this.recoverPersistedAttempts();
9926
- } catch (error) {
9927
- if (!this.lifetimeAbort.signal.aborted) {
9928
- await this.logger.error(`Failed to scan persisted Local Codex attempts for connection ${this.connection.connectionId}`, error);
9929
- }
9930
- }
9949
+ await this.scanPersistedAttempts();
9931
9950
  await waitForAbort(this.lifetimeAbort.signal, recoveryRetryMilliseconds);
9932
9951
  }
9933
9952
  }
9953
+ async scanPersistedAttempts() {
9954
+ try {
9955
+ await this.recoverPersistedAttempts();
9956
+ } catch (error) {
9957
+ if (!this.lifetimeAbort.signal.aborted) {
9958
+ await this.logger.error(`Failed to scan persisted Local Codex attempts for connection ${this.connection.connectionId}`, error);
9959
+ }
9960
+ }
9961
+ }
9934
9962
  async recoverPersistedAttempts() {
9935
9963
  const attempts = await this.store.listLocalCodexAttempts();
9936
9964
  for (const persisted of attempts) {
@@ -14564,7 +14592,7 @@ function getApiKeyOrUndefined() {
14564
14592
 
14565
14593
  // src/utils/http.ts
14566
14594
  function getUserAgent() {
14567
- return `moxt-cli/${"0.10.0-beta.8"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
14595
+ return `moxt-cli/${"0.10.0-beta.9"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
14568
14596
  }
14569
14597
  async function sendRequest(method, path4, init) {
14570
14598
  return await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -28986,7 +29014,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
28986
29014
  var MAX_BATCH_SIZE = 100;
28987
29015
  function commonLabels() {
28988
29016
  return {
28989
- cli_version: "0.10.0-beta.8",
29017
+ cli_version: "0.10.0-beta.9",
28990
29018
  node_version: process.versions.node,
28991
29019
  os: (0, import_node_os11.platform)(),
28992
29020
  arch: (0, import_node_os11.arch)(),
@@ -29032,7 +29060,7 @@ async function flush() {
29032
29060
  }
29033
29061
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
29034
29062
  const payload = {
29035
- release_id: "0.10.0-beta.8",
29063
+ release_id: "0.10.0-beta.9",
29036
29064
  client_type: "cli",
29037
29065
  metric_data_list: batch.map((m) => ({
29038
29066
  profile: "cli",
@@ -29415,9 +29443,9 @@ function commandPath3(command) {
29415
29443
  }
29416
29444
 
29417
29445
  // src/index.ts
29418
- var program2 = createProgram("0.10.0-beta.8");
29419
- installDaemonReconcileHook(program2, "0.10.0-beta.8");
29420
- installUpdateHook(program2, "0.10.0-beta.8");
29446
+ var program2 = createProgram("0.10.0-beta.9");
29447
+ installDaemonReconcileHook(program2, "0.10.0-beta.9");
29448
+ installUpdateHook(program2, "0.10.0-beta.9");
29421
29449
  instrumentProgram(program2);
29422
29450
  installExitHandler();
29423
29451
  program2.parseAsync(process.argv).then(async () => {