chatroom-cli 1.112.0 → 1.113.0

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.js CHANGED
@@ -28823,7 +28823,7 @@ function normalizeAgentLifecycleFact(raw) {
28823
28823
  emittedAt: Number(rest.emittedAt)
28824
28824
  };
28825
28825
  }
28826
- if (kind === "spawned" || kind === "exited" || kind === "activity") {
28826
+ if (kind === "spawned" || kind === "exited" || kind === "activity" || kind === "turn_failed") {
28827
28827
  return rest;
28828
28828
  }
28829
28829
  throw new Error(`Unknown agent lifecycle fact kind: ${String(kind)}`);
@@ -30154,11 +30154,10 @@ class AgentProcessManager {
30154
30154
  wantResume: slot?.wantResume
30155
30155
  });
30156
30156
  const completionStatus = opts.completion?.status ?? "completed";
30157
- console.log(`[AgentProcessManager] lifecycle.turn.${completionStatus === "completed" ? "completed" : "terminal"}: role=${opts.role} pid=${opts.pid} harness=${opts.harness} status=${completionStatus}${opts.completion ? ` source=${opts.completion.source}` : ""}`);
30157
+ console.log(`[AgentProcessManager] lifecycle.turn.${completionStatus === "completed" ? "completed" : "failed"}: role=${opts.role} pid=${opts.pid} harness=${opts.harness} status=${completionStatus} completion=${JSON.stringify(opts.completion ?? { status: "completed" })}`);
30158
30158
  if (capabilities.supportsNativeIntegration) {
30159
- if (completionStatus !== "completed") {
30159
+ if (completionStatus === "process_exited") {
30160
30160
  setNativeTurnPhase(slot, defaultNativeTurnPhase());
30161
- console.warn(`[AgentProcessManager] Native turn did not complete successfully for ${opts.role}: ${completionStatus}`);
30162
30161
  return;
30163
30162
  }
30164
30163
  this.maybeEmitProviderUnavailable(opts.chatroomId, opts.role, slot);
@@ -30168,11 +30167,25 @@ class AgentProcessManager {
30168
30167
  pid: opts.pid,
30169
30168
  harness: opts.harness,
30170
30169
  slot,
30171
- eventId: `${opts.pid}:${++this.agentTurnEndedSequence}`
30170
+ eventId: `${opts.pid}:${++this.agentTurnEndedSequence}`,
30171
+ completion: opts.completion ?? {
30172
+ turnId: `${opts.pid}:${this.agentTurnEndedSequence}`,
30173
+ status: "completed",
30174
+ source: "agent-process-manager.agent-end"
30175
+ }
30172
30176
  };
30173
- await Promise.all([...this.agentTurnEndedHandlers].map((handler) => handler(event)));
30177
+ const dispositions = await Promise.all([...this.agentTurnEndedHandlers].map((handler) => handler(event)));
30178
+ const held = dispositions.find((disposition) => disposition?.kind === "hold-slot");
30179
+ if (held?.kind === "hold-slot") {
30180
+ console.warn(`[AgentProcessManager] Native turn slot held after ${completionStatus}: role=${opts.role} pid=${opts.pid} reason=${held.reason}`);
30181
+ return;
30182
+ }
30183
+ if (completionStatus !== "completed" && !dispositions.some((disposition) => disposition?.kind === "release-slot")) {
30184
+ console.warn(`[AgentProcessManager] Native turn slot held: no task-service disposition returned role=${opts.role} pid=${opts.pid} status=${completionStatus}`);
30185
+ return;
30186
+ }
30174
30187
  setNativeTurnPhase(slot, defaultNativeTurnPhase());
30175
- console.log(`[AgentProcessManager] ✅ Native agent_end completed for ${opts.role}`);
30188
+ console.log(`[AgentProcessManager] Native agent_end disposition accepted: role=${opts.role} status=${completionStatus} disposition=release-slot`);
30176
30189
  return;
30177
30190
  }
30178
30191
  const result = await handleTurnCompleted({
@@ -32255,7 +32268,41 @@ class NativeDeliveryService {
32255
32268
  });
32256
32269
  }
32257
32270
  async handleAgentTurnEnded(event) {
32271
+ const completion = event.completion;
32272
+ if (completion && completion.status !== "completed") {
32273
+ const activeTask = this.deps.agentTaskState.get({
32274
+ chatroomId: event.chatroomId,
32275
+ role: event.role
32276
+ });
32277
+ const errorDetail = completion.error;
32278
+ console.error(`[NativeDelivery:turn-failed] chatroom=${event.chatroomId} role=${event.role} task=${activeTask?.taskId ?? "none"} turn=${completion.turnId} status=${completion.status} source=${completion.source} error=${errorDetail ?? "none"}`);
32279
+ const fact = {
32280
+ kind: "turn_failed",
32281
+ chatroomId: event.chatroomId,
32282
+ role: event.role,
32283
+ ...activeTask?.taskId ? { taskId: activeTask.taskId } : {},
32284
+ ...event.slot.harnessSessionId ? { harnessSessionId: event.slot.harnessSessionId } : {},
32285
+ turnId: completion.turnId,
32286
+ status: completion.status,
32287
+ source: completion.source,
32288
+ ...errorDetail ? { error: errorDetail } : {},
32289
+ revisionKey: buildAgentLifecycleRevisionKey("turn_failed", {
32290
+ chatroomId: event.chatroomId,
32291
+ role: event.role,
32292
+ turnId: completion.turnId
32293
+ }),
32294
+ emittedAt: Date.now()
32295
+ };
32296
+ try {
32297
+ await this.deps.lifecycleOutbox.enqueue(fact);
32298
+ } catch (error) {
32299
+ console.error(`[NativeDelivery:turn-failed-outbox-error] chatroom=${event.chatroomId} role=${event.role} turn=${completion.turnId} error=${error instanceof Error ? error.stack ?? error.message : String(error)}`);
32300
+ return { kind: "hold-slot", reason: "turn-failed-outbox-enqueue-failed" };
32301
+ }
32302
+ return { kind: "release-slot" };
32303
+ }
32258
32304
  this.scheduleRoleDelivery(event.chatroomId, event.role);
32305
+ return { kind: "release-slot" };
32259
32306
  }
32260
32307
  scheduleRoleDelivery(chatroomId, role) {
32261
32308
  setTimeout(() => {
@@ -47341,7 +47388,7 @@ class MachineTaskSnapshotState {
47341
47388
  function asChatroomId(chatroomId) {
47342
47389
  return chatroomId;
47343
47390
  }
47344
- function buildSubscribeTaskStatusSignalsSinceArgs(input) {
47391
+ function buildSubscribeTaskDeliverySignalsSinceArgs(input) {
47345
47392
  return {
47346
47393
  sessionId: input.sessionId,
47347
47394
  machineId: input.machineId,
@@ -47350,7 +47397,7 @@ function buildSubscribeTaskStatusSignalsSinceArgs(input) {
47350
47397
  ...input.limit === undefined ? {} : { limit: input.limit }
47351
47398
  };
47352
47399
  }
47353
- function buildListTasksForMachineSignalRangeArgs(input) {
47400
+ function buildListTasksForMachineTaskDeliverySignalRangeArgs(input) {
47354
47401
  return {
47355
47402
  sessionId: input.sessionId,
47356
47403
  machineId: input.machineId,
@@ -47400,7 +47447,7 @@ function waitForTaskSignalPage(options, afterSignalKey) {
47400
47447
  settle(() => reject(error51));
47401
47448
  return;
47402
47449
  }
47403
- unsubscribe = options.client.onUpdate(api.messageList.subscribeTaskStatusSignalsSince, buildSubscribeTaskStatusSignalsSinceArgs({
47450
+ unsubscribe = options.client.onUpdate(api.taskDelivery.subscribeTaskDeliverySignalsSince, buildSubscribeTaskDeliverySignalsSinceArgs({
47404
47451
  sessionId: options.sessionId,
47405
47452
  machineId: options.machineId,
47406
47453
  chatroomId: options.chatroomId,
@@ -47437,7 +47484,7 @@ async function fetchSnapshotsForSignalPage(options, page) {
47437
47484
  let afterSignalKey = page.afterSignalKey;
47438
47485
  while (true) {
47439
47486
  throwIfAborted(options.signal);
47440
- const result = await options.client.query(api.tasks.listTasksForMachineSignalRange, buildListTasksForMachineSignalRangeArgs({
47487
+ const result = await options.client.query(api.taskDelivery.listTasksForMachineTaskDeliverySignalRange, buildListTasksForMachineTaskDeliverySignalRangeArgs({
47441
47488
  sessionId: options.sessionId,
47442
47489
  machineId: options.machineId,
47443
47490
  chatroomId: options.chatroomId,
@@ -104587,7 +104634,7 @@ function toConvexLifecycleFact(fact) {
104587
104634
  return {
104588
104635
  ...normalized,
104589
104636
  chatroomId: normalized.chatroomId,
104590
- ...normalized.kind === "activity" && normalized.taskId ? { taskId: normalized.taskId } : {}
104637
+ ...(normalized.kind === "activity" || normalized.kind === "turn_failed") && normalized.taskId ? { taskId: normalized.taskId } : {}
104591
104638
  };
104592
104639
  }
104593
104640
  function createAgentLifecycleSend(session2) {
@@ -135820,4 +135867,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
135820
135867
  });
135821
135868
  program2.parse();
135822
135869
 
135823
- //# debugId=B512277D42B2480364756E2164756E21
135870
+ //# debugId=2166B04C5CAC31EC64756E2164756E21