@steerable/agent-shell 0.10.2 → 0.10.3

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.
@@ -60,6 +60,15 @@ export interface TurnFailureInfo {
60
60
  export interface CoreLoopTurnOutcome {
61
61
  status: string;
62
62
  reason?: string;
63
+ /**
64
+ * The sidecar process disappeared before the turn reached a terminal
65
+ * notification (crash, SIGKILL, host teardown that skipped the shutdown
66
+ * RPC). Distinct from `cancelled` — which is the user pressing Stop and the
67
+ * sidecar *answering* — because only this case leaves the durable record
68
+ * mid-turn. The router uses it to keep `turn_active` and to withhold the
69
+ * assistant row, so a reopened chat still offers "continue".
70
+ */
71
+ sidecarLost?: boolean;
63
72
  /** Sidecar trace id for this turn — the router persists it into
64
73
  * harness_traces so the CoreLoop path leaves the same audit trail as the
65
74
  * TS loop (and dogfood traces can be replayed/diffed). */
@@ -277,6 +277,20 @@ export async function streamCoreLoopTurn(options) {
277
277
  let settled = false;
278
278
  let cancelling = false;
279
279
  let abortGraceTimer = null;
280
+ /**
281
+ * The sidecar died before answering. Resolve rather than reject: the turn
282
+ * has a real outcome (it never finished), and the router must record it as
283
+ * interrupted — a rejected promise takes the `failed` path, which persists
284
+ * an assistant row and clears `turn_active`, making the crash look like a
285
+ * settled turn and hiding "continue" from the user.
286
+ */
287
+ const onSidecarLost = () => {
288
+ if (settled)
289
+ return;
290
+ settled = true;
291
+ cleanup();
292
+ resolve({ status: 'interrupted', reason: 'sidecar-lost', sidecarLost: true });
293
+ };
280
294
  const onAbort = () => {
281
295
  if (settled || cancelling)
282
296
  return;
@@ -297,8 +311,13 @@ export async function streamCoreLoopTurn(options) {
297
311
  }, CANCEL_GRACE_MS);
298
312
  };
299
313
  signal?.addEventListener('abort', onAbort);
314
+ // A sidecar that dies mid-turn never answers with `stream.done`, so
315
+ // without this the promise floats forever and the router cannot tell a
316
+ // crash from a turn still running.
317
+ supervisor.on('exit', onSidecarLost);
300
318
  const cleanup = () => {
301
319
  signal?.removeEventListener('abort', onAbort);
320
+ supervisor.off('exit', onSidecarLost);
302
321
  if (abortGraceTimer)
303
322
  clearTimeout(abortGraceTimer);
304
323
  activeCoreLoopStreams.delete(options.chatId);
@@ -3907,6 +3907,12 @@ export class LocalBackendRouter {
3907
3907
  // `completionReason` but no per-request detail.
3908
3908
  let failureInfo;
3909
3909
  let outcomeTraceId;
3910
+ // The sidecar vanished mid-turn (crash / SIGKILL / teardown that skipped
3911
+ // the shutdown RPC). Such a turn has no terminal state to persist: the
3912
+ // record stops mid-flight, so the assistant row is withheld and the
3913
+ // `turn_active` marker survives — that marker is exactly what
3914
+ // `detectInterruptedTurn` reads to offer "continue" on the next open.
3915
+ let sidecarLost = false;
3910
3916
  // Every pass records its own sidecar trace; all of them are persisted
3911
3917
  // against the one assistant message this turn produces.
3912
3918
  const passTraceIds = [];
@@ -4247,6 +4253,7 @@ export class LocalBackendRouter {
4247
4253
  completionReason = finalOutcome.reason ?? '';
4248
4254
  outcomeTraceId = finalOutcome.traceId;
4249
4255
  autoContinuations = finalContinuations;
4256
+ sidecarLost = finalOutcome.sidecarLost === true;
4250
4257
  // 干净失败的趟(sidecar 正常收流但 status=failed,如 LLM 401/超时)
4251
4258
  // 不走下面的 catch——这里补发 error 事件,否则前端只渲染一条空消息,
4252
4259
  // 用户完全看不到失败原因。
@@ -4289,7 +4296,10 @@ export class LocalBackendRouter {
4289
4296
  promptTokens: 0,
4290
4297
  completionTokens: 0,
4291
4298
  totalTokens: 0,
4292
- outcome: completionStatus === 'failed'
4299
+ outcome:
4300
+ // An interrupted turn (sidecar lost) never finished either: counting
4301
+ // it as `completed` would make crash reports look like successes.
4302
+ completionStatus === 'failed' || completionStatus === 'interrupted'
4293
4303
  ? 'failed'
4294
4304
  : completionStatus === 'cancelled'
4295
4305
  ? 'cancelled'
@@ -4325,7 +4335,7 @@ export class LocalBackendRouter {
4325
4335
  serviceName: telemetryForTurn.serviceName,
4326
4336
  samples: [
4327
4337
  {
4328
- outcome: completionStatus === 'failed'
4338
+ outcome: completionStatus === 'failed' || completionStatus === 'interrupted'
4329
4339
  ? 'failed'
4330
4340
  : completionStatus === 'cancelled'
4331
4341
  ? 'cancelled'
@@ -4360,40 +4370,54 @@ export class LocalBackendRouter {
4360
4370
  console.warn('[local-backend] collect turn files failed', turnFilesErr);
4361
4371
  }
4362
4372
  freezeTimelineReasoning(timeline);
4363
- const assistant = await this.store.addMessage(chatId, 'assistant', assistantText, JSON.stringify({
4364
- completionStatus,
4365
- completionReason,
4366
- executedActions,
4367
- timeline,
4368
- mode: chatMode,
4369
- coreloop: true,
4370
- traceId: outcomeTraceId,
4371
- ...(parentAgentId ? { agentId: parentAgentId } : {}),
4372
- ...(children.length > 0 ? { orchestrationChildEvents: children } : {}),
4373
- ...(durationMs != null ? { durationMs } : {}),
4374
- ...(autoContinuations > 0 ? { autoContinuations } : {}),
4375
- ...(turnFiles.length > 0 ? { turnFiles } : {}),
4376
- ...(failureInfo ? { failure: failureInfo } : {}),
4377
- }));
4378
- try {
4379
- await recordInsightTurn(this.store, {
4380
- chatId,
4381
- mode: chatMode,
4382
- modelId: overrideModel || settings.model,
4373
+ // A crash has no reply to persist. Writing an empty assistant row here
4374
+ // would (a) show the user a blank message, and (b) make
4375
+ // `detectInterruptedTurn` see a trailing assistant and conclude the turn
4376
+ // settled — the crash would then look like a normal stopped turn and
4377
+ // "continue last reply" would never be offered. The record stays on the
4378
+ // user turn, which is what the resume path replays.
4379
+ const assistant = sidecarLost
4380
+ ? null
4381
+ : await this.store.addMessage(chatId, 'assistant', assistantText, JSON.stringify({
4383
4382
  completionStatus,
4384
- durationMs,
4385
- toolNames: executedActions,
4386
- userText: firstUserMessageForTitle,
4387
- assistantText,
4388
- });
4389
- }
4390
- catch (insightErr) {
4391
- console.warn('[insights] turn record failed', insightErr);
4383
+ completionReason,
4384
+ executedActions,
4385
+ timeline,
4386
+ mode: chatMode,
4387
+ coreloop: true,
4388
+ traceId: outcomeTraceId,
4389
+ ...(parentAgentId ? { agentId: parentAgentId } : {}),
4390
+ ...(children.length > 0 ? { orchestrationChildEvents: children } : {}),
4391
+ ...(durationMs != null ? { durationMs } : {}),
4392
+ ...(autoContinuations > 0 ? { autoContinuations } : {}),
4393
+ ...(turnFiles.length > 0 ? { turnFiles } : {}),
4394
+ ...(failureInfo ? { failure: failureInfo } : {}),
4395
+ }));
4396
+ if (!sidecarLost) {
4397
+ try {
4398
+ await recordInsightTurn(this.store, {
4399
+ chatId,
4400
+ mode: chatMode,
4401
+ modelId: overrideModel || settings.model,
4402
+ completionStatus,
4403
+ durationMs,
4404
+ toolNames: executedActions,
4405
+ userText: firstUserMessageForTitle,
4406
+ assistantText,
4407
+ });
4408
+ }
4409
+ catch (insightErr) {
4410
+ console.warn('[insights] turn record failed', insightErr);
4411
+ }
4392
4412
  }
4393
4413
  // W7-1: 回复落库后才清标记(顺序不能反——先清后写的话,两者之间崩溃
4394
4414
  // 会丢回复且无任何续跑入口;这个顺序的最坏情况是残留标记被检测器的
4395
4415
  // 「末尾已是 assistant」规则判定为已完结)。
4396
- await this.store.clearTurnActive(chatId);
4416
+ //
4417
+ // 崩溃时**不清**:标记就是「这一轮没跑完」的唯一证据,清掉就再也
4418
+ // 找不回那个子代理/那条回复可续跑的事实。
4419
+ if (!sidecarLost)
4420
+ await this.store.clearTurnActive(chatId);
4397
4421
  // 回合落库即结束——移除实时快照,后续 GET /live-stream 返回 active=false。
4398
4422
  removeLiveStream(chatId);
4399
4423
  // Persist the sidecar-recorded traces into harness_traces so the CoreLoop
@@ -4425,7 +4449,9 @@ export class LocalBackendRouter {
4425
4449
  await this.store.saveTrace({
4426
4450
  id: traceId,
4427
4451
  chatId,
4428
- messageId: assistant.id,
4452
+ // No assistant row on a crashed turn, so the trace hangs off the
4453
+ // chat alone — still fetchable by `listTracesByChat`.
4454
+ messageId: assistant?.id ?? null,
4429
4455
  startedAtMs: durationMs != null ? Date.now() - durationMs : Date.now(),
4430
4456
  durationMs,
4431
4457
  status: passStatus,
@@ -4477,16 +4503,20 @@ export class LocalBackendRouter {
4477
4503
  if (turnFiles.length > 0) {
4478
4504
  emit(this.sseData({ type: 'turn_files', files: turnFiles }));
4479
4505
  }
4480
- emit(this.sseData({ type: 'message_id', messageId: assistant.id }));
4506
+ if (assistant) {
4507
+ emit(this.sseData({ type: 'message_id', messageId: assistant.id }));
4508
+ }
4481
4509
  emit('data: [DONE]\n\n');
4482
4510
  this.runTitleGenInBackground(chatId, shouldGenerateTitle, firstUserMessageForTitle);
4483
- this.runSuggestedRepliesInBackground({
4484
- chatId,
4485
- messageId: assistant.id,
4486
- userText: firstUserMessageForTitle,
4487
- assistantText,
4488
- completionStatus,
4489
- });
4511
+ if (assistant) {
4512
+ this.runSuggestedRepliesInBackground({
4513
+ chatId,
4514
+ messageId: assistant.id,
4515
+ userText: firstUserMessageForTitle,
4516
+ assistantText,
4517
+ completionStatus,
4518
+ });
4519
+ }
4490
4520
  return {
4491
4521
  status: 200,
4492
4522
  turn: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-shell",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "Steerable framework — product-neutral Node HostRuntime and headless HTTP server shared by Tauri desktop and browser deployments; scenario packs extend it through @steerable/pack-sdk.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://steerableframework.com/",
@@ -53,10 +53,10 @@
53
53
  "jpeg-js": "^0.4.4",
54
54
  "node-pty": "^1.1.0",
55
55
  "pngjs": "^7.0.0",
56
- "@steerable/agent-harness": "0.10.2",
57
- "@steerable/agent-protocol": "0.10.2",
58
- "@steerable/agent-runtime": "0.10.2",
59
- "@steerable/pack-sdk": "0.10.2"
56
+ "@steerable/agent-harness": "0.10.3",
57
+ "@steerable/agent-runtime": "0.10.3",
58
+ "@steerable/agent-protocol": "0.10.3",
59
+ "@steerable/pack-sdk": "0.10.3"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/better-sqlite3": "^7.6.13",