@cmmd-center/forge 0.13.88 → 0.13.90

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/bin.cjs CHANGED
@@ -66296,7 +66296,7 @@ function normalizeNumberish(value) {
66296
66296
  }
66297
66297
  //#endregion
66298
66298
  //#region package.json
66299
- var version$1 = "0.13.88";
66299
+ var version$1 = "0.13.90";
66300
66300
  //#endregion
66301
66301
  //#region src/sentry.ts
66302
66302
  const SERVER_APP_NAME = "forge-server";
@@ -152788,7 +152788,8 @@ async function issueCmmdRuntimeProviderEgressCredential(input) {
152788
152788
  body: JSON.stringify({
152789
152789
  provider: input.provider,
152790
152790
  ...providerEgressModelBodyFields(input),
152791
- ...input.provider === "openai" && input.providerAccountId ? { provider_account_id: input.providerAccountId } : {}
152791
+ ...input.provider === "openai" && input.providerAccountId ? { provider_account_id: input.providerAccountId } : {},
152792
+ ...input.threadId ? { thread_id: input.threadId } : {}
152792
152793
  })
152793
152794
  });
152794
152795
  if (!response.ok) throw new Error(await describeProviderTokenFailure(response));
@@ -241826,6 +241827,22 @@ function resolveSpriteTaskHoldConfig(env = process.env) {
241826
241827
  function spriteTaskHoldName(namePrefix, turnId) {
241827
241828
  return `${namePrefix}${turnId}`;
241828
241829
  }
241830
+ /**
241831
+ * Thrown by the production transport when the guest API answers a non-2xx
241832
+ * status. Carries the status so a caller can tell a 409 (already held, and
241833
+ * generally benign) apart from a real transport failure.
241834
+ */
241835
+ var SpriteTaskHoldTransportError = class extends Error {
241836
+ status;
241837
+ constructor(status) {
241838
+ super(`sprite task API responded ${status}`);
241839
+ this.name = "SpriteTaskHoldTransportError";
241840
+ this.status = status;
241841
+ }
241842
+ };
241843
+ function transportStatus(cause) {
241844
+ return cause instanceof SpriteTaskHoldTransportError ? cause.status : void 0;
241845
+ }
241829
241846
  const noTimer = () => {};
241830
241847
  /**
241831
241848
  * Resolve with `promise`, but stop waiting after `timeoutMs`. Rejections pass
@@ -241859,12 +241876,25 @@ var SpriteTaskHoldManager = class {
241859
241876
  #transport;
241860
241877
  #timer;
241861
241878
  #onError;
241879
+ #onEvent;
241862
241880
  #holds = /* @__PURE__ */ new Map();
241863
241881
  constructor(options) {
241864
241882
  this.#config = options.config;
241865
241883
  this.#transport = options.transport;
241866
241884
  this.#timer = options.timer ?? DEFAULT_TIMER;
241867
241885
  this.#onError = options.onError ?? (() => {});
241886
+ this.#onEvent = options.onEvent ?? (() => {});
241887
+ }
241888
+ /** Compose and report one acquire/refresh/release outcome, if a caller wants to log it. */
241889
+ #emitEvent(action, holdKey, hold, outcome, status) {
241890
+ this.#onEvent({
241891
+ action,
241892
+ holdKey,
241893
+ holdName: hold.name,
241894
+ threadId: hold.threadId,
241895
+ outcome,
241896
+ ...status !== void 0 ? { status } : {}
241897
+ });
241868
241898
  }
241869
241899
  /** Turn ids that currently hold the sprite awake. Test/diagnostic surface. */
241870
241900
  activeTurnIds() {
@@ -241873,10 +241903,19 @@ var SpriteTaskHoldManager = class {
241873
241903
  /**
241874
241904
  * `maxRefreshes` bounds a hold that has no terminal event of its own, such as a launch
241875
241905
  * whose turn may never start. When the budget is spent the hold releases itself.
241906
+ *
241907
+ * Resolves to whether this hold has ever landed a PUT, never throwing (a
241908
+ * hold problem must not fail a turn). A caller handing off from a
241909
+ * predecessor hold (forge#3589) must not release it on anything less than
241910
+ * "succeeded": a failed initial PUT still installs the refresher below and
241911
+ * keeps retrying every `SPRITE_TASK_HOLD_REFRESH_MS`, so the predecessor is
241912
+ * the only thing covering the sprite until one of those retries lands. A
241913
+ * duplicate call against a live, unreleased hold reports that hold's own
241914
+ * confirmed state rather than a blanket "succeeded", for the same reason.
241876
241915
  */
241877
241916
  async acquire(turnId, threadId = null, options = {}) {
241878
- const existing = this.#holds.get(turnId);
241879
- if (existing !== void 0 && !existing.released) return;
241917
+ const existing = this.#liveHold(turnId);
241918
+ if (existing !== void 0) return existing.confirmed ? "succeeded" : "failed";
241880
241919
  let refreshesLeft = options.maxRefreshes ?? Number.POSITIVE_INFINITY;
241881
241920
  const name = spriteTaskHoldName(this.#config.namePrefix, turnId);
241882
241921
  const hold = {
@@ -241888,24 +241927,54 @@ var SpriteTaskHoldManager = class {
241888
241927
  phase: "idle",
241889
241928
  releaseAttempt: null,
241890
241929
  deletion: null,
241891
- uncertainPut: false
241930
+ uncertainPut: false,
241931
+ confirmed: false
241892
241932
  };
241893
241933
  this.#holds.set(turnId, hold);
241894
241934
  const put = this.#transport.put(name, 300);
241895
241935
  const tracked = put.then(() => "succeeded", () => "failed");
241896
241936
  hold.inFlight.add(tracked);
241937
+ let outcome = "succeeded";
241897
241938
  try {
241898
241939
  await put;
241899
241940
  hold.uncertainPut = false;
241941
+ hold.confirmed = true;
241942
+ this.#emitEvent("acquire", turnId, hold, "success");
241900
241943
  } catch (cause) {
241944
+ outcome = "failed";
241901
241945
  hold.uncertainPut = true;
241902
241946
  hold.inFlight.delete(tracked);
241903
241947
  this.#onError(`failed to acquire sprite task hold for turn ${turnId}`, cause);
241904
- if (hold.released || this.#holds.get(turnId) !== hold) return;
241948
+ this.#emitEvent("acquire", turnId, hold, "failure", transportStatus(cause));
241949
+ if (this.#isStale(turnId, hold)) return outcome;
241905
241950
  }
241906
241951
  hold.inFlight.delete(tracked);
241907
- if (hold.released || this.#holds.get(turnId) !== hold) return;
241908
- hold.refresher = this.#timer.setInterval(() => {
241952
+ if (this.#isStale(turnId, hold)) return outcome;
241953
+ hold.refresher = this.#installRefresher(turnId, hold, name, refreshesLeft);
241954
+ return outcome;
241955
+ }
241956
+ /** The hold registered for `turnId`, if it is still live: not mid-release or concluded. */
241957
+ #liveHold(turnId) {
241958
+ const existing = this.#holds.get(turnId);
241959
+ return existing !== void 0 && !existing.released ? existing : void 0;
241960
+ }
241961
+ /**
241962
+ * Whether `hold` has been superseded since the caller last checked: either
241963
+ * released, or no longer the map's current entry for `turnId` (a fresh
241964
+ * acquire replaced it). Both `acquire`'s post-await fences use this so
241965
+ * neither has to repeat the compound condition inline.
241966
+ */
241967
+ #isStale(turnId, hold) {
241968
+ return hold.released || this.#holds.get(turnId) !== hold;
241969
+ }
241970
+ /**
241971
+ * Install a hold's refresh interval. Extracted out of `acquire` so that
241972
+ * method's own branching stays flat; the ordering and identity-fence rules
241973
+ * around it are unchanged, and this closure owns only the refresh tick.
241974
+ */
241975
+ #installRefresher(turnId, hold, name, initialBudget) {
241976
+ let refreshesLeft = initialBudget;
241977
+ return this.#timer.setInterval(() => {
241909
241978
  if (hold.inFlight.size > 0) return;
241910
241979
  if (refreshesLeft <= 0) {
241911
241980
  if (this.#holds.get(turnId) === hold) this.release(turnId);
@@ -241914,10 +241983,13 @@ var SpriteTaskHoldManager = class {
241914
241983
  refreshesLeft -= 1;
241915
241984
  const refresh = this.#transport.put(name, 300).then(() => {
241916
241985
  hold.uncertainPut = false;
241986
+ hold.confirmed = true;
241987
+ this.#emitEvent("refresh", turnId, hold, "success");
241917
241988
  return "succeeded";
241918
241989
  }, (cause) => {
241919
241990
  hold.uncertainPut = true;
241920
241991
  this.#onError(`failed to refresh sprite task hold for turn ${turnId}`, cause);
241992
+ this.#emitEvent("refresh", turnId, hold, "failure", transportStatus(cause));
241921
241993
  return "failed";
241922
241994
  });
241923
241995
  hold.inFlight.add(refresh);
@@ -241961,6 +242033,7 @@ var SpriteTaskHoldManager = class {
241961
242033
  hold.phase = "joining";
241962
242034
  const attempt = (async () => {
241963
242035
  const outcome = await this.#concludeRelease(hold, turnId, options);
242036
+ this.#emitEvent("release", turnId, hold, outcome);
241964
242037
  if (outcome === "unreleased") {
241965
242038
  hold.phase = "idle";
241966
242039
  this.#removeIfCurrent(turnId, hold);
@@ -242144,7 +242217,7 @@ function makeSpriteTaskHoldTransport(config, fetchImpl = fetch) {
242144
242217
  signal: controller.signal,
242145
242218
  unix: config.socketPath
242146
242219
  });
242147
- if (!response.ok) throw new Error(`sprite task API responded ${response.status}`);
242220
+ if (!response.ok) throw new SpriteTaskHoldTransportError(response.status);
242148
242221
  } finally {
242149
242222
  clearTimeout(deadline);
242150
242223
  }
@@ -242180,13 +242253,14 @@ function makeSpriteTaskHoldTransport(config, fetchImpl = fetch) {
242180
242253
  * Build a manager for this process, or null when the runtime is not a sprite.
242181
242254
  * Callers treat null as "this feature does not apply here".
242182
242255
  */
242183
- function makeSpriteTaskHoldManager(env = process.env, onError) {
242256
+ function makeSpriteTaskHoldManager(env = process.env, onError, onEvent) {
242184
242257
  const config = resolveSpriteTaskHoldConfig(env);
242185
242258
  if (config === null) return null;
242186
242259
  return new SpriteTaskHoldManager({
242187
242260
  config,
242188
242261
  transport: makeSpriteTaskHoldTransport(config),
242189
- ...onError ? { onError } : {}
242262
+ ...onError ? { onError } : {},
242263
+ ...onEvent ? { onEvent } : {}
242190
242264
  });
242191
242265
  }
242192
242266
  //#endregion
@@ -286770,7 +286844,7 @@ const AgentBrowserManagerLive = require_Schema$1.effect(BrowserManager, require_
286770
286844
  const displayPeers = createWebRtcDisplaySessionManager({
286771
286845
  mediaSourceFactory: displayCaptureRuntime.mediaSourceFactory,
286772
286846
  taskHold: displayTaskHoldManager ? {
286773
- acquire: (holdId) => displayTaskHoldManager.acquire(holdId),
286847
+ acquire: (holdId) => displayTaskHoldManager.acquire(holdId).then(() => {}),
286774
286848
  release: (holdId) => displayTaskHoldManager.release(holdId).then(() => {})
286775
286849
  } : void 0
286776
286850
  });
@@ -295145,6 +295219,15 @@ const make$6 = require_Schema$1.gen(function* () {
295145
295219
  const providerService = yield* ProviderService;
295146
295220
  const manager = makeSpriteTaskHoldManager(process.env, (message, cause) => {
295147
295221
  require_Schema$1.runFork(require_Schema$1.logWarning(message, { cause: cause instanceof Error ? cause.message : cause }));
295222
+ }, (event) => {
295223
+ require_Schema$1.runFork(require_Schema$1.logInfo("sprite task hold", {
295224
+ action: event.action,
295225
+ holdKey: event.holdKey,
295226
+ holdName: event.holdName,
295227
+ threadId: event.threadId,
295228
+ outcome: event.outcome,
295229
+ ...event.status !== void 0 ? { status: event.status } : {}
295230
+ }));
295148
295231
  });
295149
295232
  /**
295150
295233
  * Run a manager call, or nothing on runtimes that are not sprites. One
@@ -295160,27 +295243,58 @@ const make$6 = require_Schema$1.gen(function* () {
295160
295243
  deleteTimeoutMs: SPRITE_TASK_HOLD_RELEASE_DELETE_TIMEOUT_MS
295161
295244
  })));
295162
295245
  const launchCallers = /* @__PURE__ */ new Map();
295246
+ const launchGeneration = /* @__PURE__ */ new Map();
295247
+ const turnLaunchGeneration = /* @__PURE__ */ new Map();
295248
+ /**
295249
+ * Belt-and-braces cleanup for a turn reaching a terminal state
295250
+ * (turn.completed or turn.aborted): a launch hold whose hand-off never
295251
+ * confirmed (the turn hold's PUT kept failing) is still up, refreshing on
295252
+ * its own budget, and the turn ending either way means the launch phase is
295253
+ * over. `manager.release(String(turnId))` above can itself wait on the
295254
+ * guest API, so by the time this runs the NEXT stage's own dispatch may
295255
+ * already have acquired a fresh launch hold for the same thread; only
295256
+ * release it here when no such newer launch has started since this turn's
295257
+ * own turn.started was processed (CodeRabbit review, forge#3592). A no-op
295258
+ * when this turn's own generation is stale, or when the hold was already
295259
+ * released.
295260
+ */
295261
+ const releaseLingeringLaunchHold = async (turnId, threadId) => {
295262
+ const capturedGeneration = turnLaunchGeneration.get(turnId);
295263
+ turnLaunchGeneration.delete(turnId);
295264
+ if (manager === null || capturedGeneration === void 0) return;
295265
+ if (launchGeneration.get(threadId) !== capturedGeneration) return;
295266
+ await manager.release(launchHoldId(threadId));
295267
+ };
295163
295268
  const start = require_Schema$1.fn("start")(function* () {
295164
295269
  if (manager === null) return;
295165
295270
  yield* require_Schema$1.forkScoped(require_Path.runForEach(providerService.streamEvents, (event) => {
295166
295271
  if (event.type === "turn.started") {
295167
295272
  const turnId = event.turnId;
295168
295273
  if (turnId === void 0) return require_Schema$1.void_;
295274
+ const threadId = String(event.threadId);
295275
+ const generation = launchGeneration.get(threadId) ?? 0;
295169
295276
  return require_Schema$1.promise(async () => {
295170
- await manager.acquire(String(turnId), String(event.threadId));
295171
- launchCallers.delete(String(event.threadId));
295172
- await manager.release(launchHoldId(String(event.threadId)));
295277
+ const outcome = await manager.acquire(String(turnId), threadId);
295278
+ launchCallers.delete(threadId);
295279
+ turnLaunchGeneration.set(String(turnId), generation);
295280
+ if (outcome === "succeeded") await manager.release(launchHoldId(threadId));
295173
295281
  });
295174
295282
  }
295175
295283
  if (event.type === "turn.completed") {
295176
295284
  const turnId = event.turnId;
295177
295285
  if (turnId === void 0) return require_Schema$1.void_;
295178
- return require_Schema$1.promise(() => manager.release(String(turnId)).then(() => {}));
295286
+ return require_Schema$1.promise(async () => {
295287
+ await manager.release(String(turnId));
295288
+ await releaseLingeringLaunchHold(String(turnId), String(event.threadId));
295289
+ });
295179
295290
  }
295180
295291
  if (event.type === "turn.aborted") {
295181
295292
  const turnId = event.turnId;
295182
295293
  if (turnId === void 0) return require_Schema$1.void_;
295183
- return require_Schema$1.promise(() => manager.release(String(turnId)).then(() => {}));
295294
+ return require_Schema$1.promise(async () => {
295295
+ await manager.release(String(turnId));
295296
+ await releaseLingeringLaunchHold(String(turnId), String(event.threadId));
295297
+ });
295184
295298
  }
295185
295299
  if (event.type === "session.exited") {
295186
295300
  launchCallers.delete(String(event.threadId));
@@ -295192,7 +295306,9 @@ const make$6 = require_Schema$1.gen(function* () {
295192
295306
  /** Takes the launch hold for one more caller. The budget bounds a launch that never starts a turn. */
295193
295307
  const holdLaunch = (threadId) => require_Schema$1.promise(async () => {
295194
295308
  if (manager === null) return;
295195
- launchCallers.set(threadId, (launchCallers.get(threadId) ?? 0) + 1);
295309
+ const callers = launchCallers.get(threadId) ?? 0;
295310
+ launchCallers.set(threadId, callers + 1);
295311
+ if (callers === 0) launchGeneration.set(threadId, (launchGeneration.get(threadId) ?? 0) + 1);
295196
295312
  await manager.acquire(launchHoldId(threadId), threadId, { maxRefreshes: LAUNCH_HOLD_MAX_REFRESHES });
295197
295313
  });
295198
295314
  /** Lets one caller go. The hold itself is released when the last caller has let go. */
@@ -299363,7 +299479,7 @@ function resolveBuildCommitFromEnv(env) {
299363
299479
  * environment descriptor down instead of reporting an honest "unknown".
299364
299480
  */
299365
299481
  function readBakedBuildCommit() {
299366
- return "60b0a6baf90436ed3291c93ac0273567a58cd02e";
299482
+ return "9608e243c924d4030658e7cc80c7be65887b2073";
299367
299483
  }
299368
299484
  async function resolveServerBuildCommit(input) {
299369
299485
  if (isFullCommitSha(input.baked)) return input.baked;
@@ -316821,6 +316937,7 @@ const makePipelineRunCoordinator = require_Schema$1.gen(function* () {
316821
316937
  const policy = yield* PipelineStagePolicy;
316822
316938
  const secretStore = yield* ServerSecretStore;
316823
316939
  const orchestration = yield* OrchestrationEngineService;
316940
+ const spriteTaskHoldReactor = yield* require_Schema$1.serviceOption(SpriteTaskHoldReactor);
316824
316941
  const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
316825
316942
  const projectionTurns = yield* ProjectionTurnRepository;
316826
316943
  const changeInspector = yield* PipelineChangeInspector;
@@ -317548,6 +317665,23 @@ const makePipelineRunCoordinator = require_Schema$1.gen(function* () {
317548
317665
  });
317549
317666
  yield* drainReports();
317550
317667
  });
317668
+ /**
317669
+ * Holds the sprite awake around a freshly dispatched thread.turn.start, the
317670
+ * same way bootstrapLaunch.ts's withLaunchHold does for a turn started from
317671
+ * the Forge web composer or a bootstrap launch (forge#3589). A turn kicked
317672
+ * from a CMMD card reaches the engine through dispatchStage /
317673
+ * recoverMissingProviderStart below, never through that HTTP dispatch
317674
+ * route, so nothing else covers the window between this dispatch and the
317675
+ * provider's own turn.started.
317676
+ *
317677
+ * Releases only on error: a successful dispatch hands the hold off to the
317678
+ * turn's own, in SpriteTaskHoldReactor's turn.started handler.
317679
+ */
317680
+ const withPipelineLaunchHold = (threadId, dispatch) => {
317681
+ if (require_Schema$1.isNone(spriteTaskHoldReactor)) return dispatch;
317682
+ const reactor = spriteTaskHoldReactor.value;
317683
+ return require_Schema$1.uninterruptible(reactor.holdLaunch(threadId)).pipe(require_Schema$1.andThen(require_Schema$1.yieldNow), require_Schema$1.andThen(dispatch), require_Schema$1.onError(() => reactor.releaseLaunch(threadId)));
317684
+ };
317551
317685
  const dispatchStage = (binding, snapshot, authority) => require_Schema$1.gen(function* () {
317552
317686
  const thread = (yield* orchestration.getReadModel()).threads.find((candidate) => candidate.id === ThreadId.make(binding.threadId) && candidate.deletedAt === null);
317553
317687
  if (thread === void 0) {
@@ -317623,7 +317757,7 @@ const makePipelineRunCoordinator = require_Schema$1.gen(function* () {
317623
317757
  messageId: `${commandId}:message`,
317624
317758
  createdAt: startedAt
317625
317759
  });
317626
- yield* orchestration.dispatch(command).pipe(require_Schema$1.tapError(() => store.resetDispatch(binding.runId, commandId)));
317760
+ yield* withPipelineLaunchHold(binding.threadId, orchestration.dispatch(command)).pipe(require_Schema$1.tapError(() => store.resetDispatch(binding.runId, commandId)));
317627
317761
  yield* store.markDispatched(binding.runId, commandId);
317628
317762
  });
317629
317763
  const resumeRun = (runId) => require_Schema$1.gen(function* () {
@@ -318263,7 +318397,7 @@ const makePipelineRunCoordinator = require_Schema$1.gen(function* () {
318263
318397
  });
318264
318398
  if (workerCoordination.kind !== "single" && workerCoordination.kind !== "ready") return;
318265
318399
  const commandId = `${originalCommandId}:provider-start-recovery`;
318266
- yield* orchestration.dispatch(buildStageTurnCommand({
318400
+ yield* withPipelineLaunchHold(input.binding.threadId, orchestration.dispatch(buildStageTurnCommand({
318267
318401
  binding: input.binding,
318268
318402
  attempt: input.binding.attempt,
318269
318403
  snapshot: input.snapshot,
@@ -318274,7 +318408,7 @@ const makePipelineRunCoordinator = require_Schema$1.gen(function* () {
318274
318408
  commandId,
318275
318409
  messageId: `${commandId}:message`,
318276
318410
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
318277
- }));
318411
+ })));
318278
318412
  });
318279
318413
  }
318280
318414
  function reconcileActiveThread(input) {