@sema-agent/core 1.411.0 → 1.414.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.
Files changed (107) hide show
  1. package/dist/agents/roster-store.d.ts.map +1 -1
  2. package/dist/agents/roster-store.js +6 -5
  3. package/dist/agents/roster-store.js.map +1 -1
  4. package/dist/agents/subagent.d.ts.map +1 -1
  5. package/dist/agents/subagent.js +14 -1
  6. package/dist/agents/subagent.js.map +1 -1
  7. package/dist/core/auto-compaction.d.ts +5 -0
  8. package/dist/core/auto-compaction.d.ts.map +1 -1
  9. package/dist/core/auto-compaction.js +6 -4
  10. package/dist/core/auto-compaction.js.map +1 -1
  11. package/dist/core/exec-output-tail.d.ts.map +1 -1
  12. package/dist/core/exec-output-tail.js +1 -1
  13. package/dist/core/exec-output-tail.js.map +1 -1
  14. package/dist/core/mcp.d.ts.map +1 -1
  15. package/dist/core/mcp.js +2 -1
  16. package/dist/core/mcp.js.map +1 -1
  17. package/dist/core/runner/prepare-task.d.ts.map +1 -1
  18. package/dist/core/runner/prepare-task.js +18 -3
  19. package/dist/core/runner/prepare-task.js.map +1 -1
  20. package/dist/core/runner/runtask.d.ts +1 -0
  21. package/dist/core/runner/runtask.d.ts.map +1 -1
  22. package/dist/core/runner/runtask.js +45 -10
  23. package/dist/core/runner/runtask.js.map +1 -1
  24. package/dist/core/runner/turn-attachments.js +3 -0
  25. package/dist/core/runner/turn-attachments.js.map +1 -1
  26. package/dist/core/task-notification.d.ts +3 -0
  27. package/dist/core/task-notification.d.ts.map +1 -1
  28. package/dist/core/task-notification.js +27 -15
  29. package/dist/core/task-notification.js.map +1 -1
  30. package/dist/core/task-registry.d.ts.map +1 -1
  31. package/dist/core/task-registry.js +6 -1
  32. package/dist/core/task-registry.js.map +1 -1
  33. package/dist/core/tool-policy.d.ts.map +1 -1
  34. package/dist/core/tool-policy.js +61 -10
  35. package/dist/core/tool-policy.js.map +1 -1
  36. package/dist/core/tool-result-budget.d.ts +5 -0
  37. package/dist/core/tool-result-budget.d.ts.map +1 -1
  38. package/dist/core/tool-result-budget.js +58 -27
  39. package/dist/core/tool-result-budget.js.map +1 -1
  40. package/dist/core/tool-result-store.d.ts +4 -1
  41. package/dist/core/tool-result-store.d.ts.map +1 -1
  42. package/dist/core/tool-result-store.js +5 -3
  43. package/dist/core/tool-result-store.js.map +1 -1
  44. package/dist/core/types.d.ts +5 -0
  45. package/dist/core/types.d.ts.map +1 -1
  46. package/dist/core/untrusted-egress.d.ts.map +1 -1
  47. package/dist/core/untrusted-egress.js +5 -2
  48. package/dist/core/untrusted-egress.js.map +1 -1
  49. package/dist/core/untrusted-text.d.ts +1 -1
  50. package/dist/core/untrusted-text.d.ts.map +1 -1
  51. package/dist/core/untrusted-text.js +12 -3
  52. package/dist/core/untrusted-text.js.map +1 -1
  53. package/dist/engine/compaction/utils.d.ts.map +1 -1
  54. package/dist/engine/compaction/utils.js +2 -1
  55. package/dist/engine/compaction/utils.js.map +1 -1
  56. package/dist/engine/harness/types.d.ts +15 -0
  57. package/dist/engine/harness/types.d.ts.map +1 -1
  58. package/dist/engine/harness/types.js +31 -0
  59. package/dist/engine/harness/types.js.map +1 -1
  60. package/dist/engine/session/import-validate.d.ts +1 -0
  61. package/dist/engine/session/import-validate.d.ts.map +1 -1
  62. package/dist/engine/session/import-validate.js +40 -3
  63. package/dist/engine/session/import-validate.js.map +1 -1
  64. package/dist/engine/session/log-digest.d.ts +6 -0
  65. package/dist/engine/session/log-digest.d.ts.map +1 -0
  66. package/dist/engine/session/log-digest.js +23 -0
  67. package/dist/engine/session/log-digest.js.map +1 -0
  68. package/dist/engine/session/session.d.ts.map +1 -1
  69. package/dist/engine/session/session.js +8 -10
  70. package/dist/engine/session/session.js.map +1 -1
  71. package/dist/index.d.ts +1 -0
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +1 -0
  74. package/dist/index.js.map +1 -1
  75. package/dist/prompt-assembly/assemble.d.ts.map +1 -1
  76. package/dist/prompt-assembly/assemble.js +7 -6
  77. package/dist/prompt-assembly/assemble.js.map +1 -1
  78. package/dist/stores/file/background-agent-store.d.ts +1 -0
  79. package/dist/stores/file/background-agent-store.d.ts.map +1 -1
  80. package/dist/stores/file/background-agent-store.js +7 -3
  81. package/dist/stores/file/background-agent-store.js.map +1 -1
  82. package/dist/stores/file/checkpoint-store.d.ts +9 -4
  83. package/dist/stores/file/checkpoint-store.d.ts.map +1 -1
  84. package/dist/stores/file/checkpoint-store.js +56 -8
  85. package/dist/stores/file/checkpoint-store.js.map +1 -1
  86. package/dist/stores/file/fs-atomic.d.ts +1 -0
  87. package/dist/stores/file/fs-atomic.d.ts.map +1 -1
  88. package/dist/stores/file/fs-atomic.js +18 -2
  89. package/dist/stores/file/fs-atomic.js.map +1 -1
  90. package/dist/stores/file/mailbox-store.d.ts.map +1 -1
  91. package/dist/stores/file/mailbox-store.js +23 -5
  92. package/dist/stores/file/mailbox-store.js.map +1 -1
  93. package/dist/stores/file/memory-store.d.ts +3 -1
  94. package/dist/stores/file/memory-store.d.ts.map +1 -1
  95. package/dist/stores/file/memory-store.js +24 -2
  96. package/dist/stores/file/memory-store.js.map +1 -1
  97. package/dist/stores/file/session-store.d.ts.map +1 -1
  98. package/dist/stores/file/session-store.js +7 -21
  99. package/dist/stores/file/session-store.js.map +1 -1
  100. package/dist/stores/file/task-list-store.d.ts.map +1 -1
  101. package/dist/stores/file/task-list-store.js +4 -3
  102. package/dist/stores/file/task-list-store.js.map +1 -1
  103. package/dist/stores/file/workflow-run-store.d.ts +1 -0
  104. package/dist/stores/file/workflow-run-store.d.ts.map +1 -1
  105. package/dist/stores/file/workflow-run-store.js +7 -3
  106. package/dist/stores/file/workflow-run-store.js.map +1 -1
  107. package/package.json +1 -1
@@ -9,6 +9,7 @@ export declare const DEFAULT_MAX_TURNS = 1000;
9
9
  export type ResumeTaskConfig = Omit<TaskSpec, "objective" | "sessionId">;
10
10
  interface ResumeRun {
11
11
  cp: Checkpoint;
12
+ pendingActionStarted?: boolean;
12
13
  outcome: Extract<ResumeOutcome, {
13
14
  gate: "policy_ask" | "resource_limit" | "dry_run_review" | "plan_review" | "wake";
14
15
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"runtask.d.ts","sourceRoot":"","sources":["../../../src/core/runner/runtask.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EASL,KAAK,UAAU,EAEf,KAAK,eAAe,EACpB,KAAK,YAAY,EAGjB,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAgC,YAAY,EAAE,MAAM,mBAAmB,CAAC;AASpF,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAQvE,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAM1F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAyBlD,OAAO,KAAK,EAAE,eAAe,EAAsC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAwBhJ,eAAO,MAAM,iBAAiB,OAAO,CAAC;AA4HtC,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,EAAE,WAAW,GAAG,WAAW,CAAC,CAAC;AAGzE,UAAU,SAAS;IACjB,EAAE,EAAE,UAAU,CAAC;IAQf,OAAO,EAAE,OAAO,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,aAAa,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;IAMvH,WAAW,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IASjD,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI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AAe,CAAC;IAYxD,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU;YA0iBzE,SAAS;YAqkIT,iBAAiB;YAsGjB,kBAAkB;YAsElB,YAAY;IA0EpB,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAmDtE,MAAM,CACV,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,gBAAgB,EAI5B,SAAS,CAAC,EAAE,YAAY,GACvB,OAAO,CAAC,UAAU,CAAC;IAyBhB,YAAY,CAChB,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,gBAAgB,EAoB5B,SAAS,CAAC,EAAE,YAAY,GACvB,OAAO,CAAC,UAAU,CAAC;YAygBR,mBAAmB;YA4GnB,kBAAkB;IAmKhC,OAAO,CAAC,sBAAsB;YA6BhB,kBAAkB;IAkDhC,OAAO,CAAC,qBAAqB;IAwD7B,OAAO,CAAC,qBAAqB;YAKf,MAAM;YA0HN,gBAAgB;CAc/B;AAGD,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAE7E;AA0DD,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
@@ -397,15 +397,13 @@ export class Runner {
397
397
  })();
398
398
  const settled = run.catch(async (err) => {
399
399
  let code = errorCodeOf(err);
400
- const reopenReason = code === "resume.env_failed" || code === "resume.session_not_found"
401
- ? "env_failed"
402
- : code === "resume.tool_unavailable"
403
- ? "tool_unavailable"
404
- : undefined;
405
- const reopenable = reopenReason !== undefined;
400
+ const reopenReason = code === "resume.tool_unavailable" ? "tool_unavailable" : "env_failed";
401
+ const reopenable = resume !== undefined && resume.pendingActionStarted !== true && reopenReason !== undefined;
402
+ let reopenCommitted = false;
406
403
  if (reopenable && resume?.onEnvRestoreFailed) {
407
404
  try {
408
405
  await resume.onEnvRestoreFailed(reopenReason);
406
+ reopenCommitted = true;
409
407
  }
410
408
  catch (reopenErr) {
411
409
  this.parentConstraintRegistry.delete(resume.cp.token);
@@ -418,7 +416,7 @@ export class Runner {
418
416
  code = "checkpoint.reopen_failed";
419
417
  }
420
418
  }
421
- else if (resume) {
419
+ if (resume && !reopenCommitted) {
422
420
  this.parentConstraintRegistry.delete(resume.cp.token);
423
421
  try {
424
422
  await this.sessions.unpin?.(resume.cp.sessionId);
@@ -2271,6 +2269,9 @@ export class Runner {
2271
2269
  compactionBreaker.failures = 0;
2272
2270
  }
2273
2271
  trimForceBackoff = nextTrimForceBackoff(trimForceBackoff, comp, trimPressure);
2272
+ if (comp.contextUsage) {
2273
+ queue.push({ type: "context_usage", ...comp.contextUsage, ...ident() });
2274
+ }
2274
2275
  if (comp.suppressedByFloor) {
2275
2276
  const s = comp.suppressedByFloor;
2276
2277
  emitTrace(tracer, () => ({
@@ -2407,7 +2408,12 @@ export class Runner {
2407
2408
  stampWriteAnchor(attachState, family, cadenceTurns);
2408
2409
  if (details !== undefined)
2409
2410
  reduceToolEnd(attachState, details);
2410
- }, (toolCallId) => startedToolCallIds.add(toolCallId));
2411
+ }, (toolCallId) => {
2412
+ startedToolCallIds.add(toolCallId);
2413
+ if (resume !== undefined && resume.cp.pendingAction.kind === "tool_approval" && toolCallId === resume.cp.pendingAction.toolCallId) {
2414
+ resume.pendingActionStarted = true;
2415
+ }
2416
+ });
2411
2417
  }
2412
2418
  if (walltimeExhaustedResume) {
2413
2419
  timeout.fired = true;
@@ -2705,6 +2711,23 @@ export class Runner {
2705
2711
  ? { token: prepared.reviewRef.token, gate: prepared.reviewRef.gate }
2706
2712
  : undefined,
2707
2713
  });
2714
+ if (resume !== undefined &&
2715
+ resume.pendingActionStarted !== true &&
2716
+ result.status !== "completed" &&
2717
+ result.status !== "suspended" &&
2718
+ resume.onEnvRestoreFailed !== undefined) {
2719
+ try {
2720
+ await resume.onEnvRestoreFailed("env_failed");
2721
+ const r = result;
2722
+ r.errorCode ??= "resume.reopened_unstarted";
2723
+ r.errorMessage = `${r.errorMessage ?? "the resume leg did not complete"} — the approved action never started, so the checkpoint was REOPENED (pending): the same approval can be resumed again, do not ask for a fresh one`;
2724
+ }
2725
+ catch {
2726
+ const r = result;
2727
+ r.errorCode ??= "resume.reopen_failed_unstarted";
2728
+ r.errorMessage = `${r.errorMessage ?? "the resume leg did not complete"} — the approved action never started, and reopening the checkpoint FAILED: its state is unprovable from here. Re-read it before deciding; do NOT issue a fresh approval on the assumption the old one is dead`;
2729
+ }
2730
+ }
2708
2731
  {
2709
2732
  const wss = prepared.workspaceStateSettle;
2710
2733
  if (wss !== undefined && result.status !== "suspended" && result.status !== "needs_review") {
@@ -3227,8 +3250,10 @@ export class Runner {
3227
3250
  this.parentConstraintRegistry.delete(token);
3228
3251
  throw new CheckpointError("checkpoint.already_resolved", "checkpoint already resolved or expired — not re-executed (idempotent)");
3229
3252
  }
3253
+ let consumeFlipDone = false;
3230
3254
  if (internals?.afterCheckpointResolve !== undefined) {
3231
3255
  await internals.afterCheckpointResolve();
3256
+ consumeFlipDone = true;
3232
3257
  }
3233
3258
  const spec = {
3234
3259
  ...taskConfig,
@@ -3246,15 +3271,25 @@ export class Runner {
3246
3271
  }
3247
3272
  }
3248
3273
  : undefined;
3274
+ if (taskConfig.signal?.aborted === true && consumeFlipDone) {
3275
+ throw new CheckpointError("checkpoint.resume_aborted", "the resume was aborted after its row was already claimed — the checkpoint stays consumed and the caller's rollback settles the outcome-unknown terminal (reopening here would strand a pending approval no redemption path can reach)");
3276
+ }
3249
3277
  if (taskConfig.signal?.aborted === true) {
3278
+ let reopenOutcome = "refused";
3250
3279
  if (onEnvRestoreFailed !== undefined) {
3251
3280
  try {
3252
3281
  await onEnvRestoreFailed("env_failed");
3282
+ reopenOutcome = "reopened";
3253
3283
  }
3254
- catch {
3284
+ catch (err) {
3285
+ reopenOutcome = errorCodeOf(err) === "checkpoint.reopen_failed" ? "refused" : "unknown";
3255
3286
  }
3256
3287
  }
3257
- throw new CheckpointError("checkpoint.resume_aborted", "the resume was aborted before the approved action could run — the checkpoint was reopened (where the store supports it) so the same approval can be resumed with a live signal");
3288
+ throw reopenOutcome === "reopened"
3289
+ ? new CheckpointError("checkpoint.resume_aborted", "the resume was aborted before the approved action could run — the checkpoint was reopened, so the same approval can be resumed with a live signal")
3290
+ : reopenOutcome === "refused"
3291
+ ? new CheckpointError("checkpoint.reopen_failed", "the resume was aborted before the approved action could run AND the store refused to reopen the checkpoint — the approval is terminally consumed and the suspended work was not executed; a retry needs a fresh approval")
3292
+ : new CheckpointError("checkpoint.reopen_failed", "the resume was aborted before the approved action could run and the reopen attempt FAILED IN FLIGHT — the checkpoint's state is unprovable from here: it may already be pending again. Re-read it before deciding; do NOT issue a fresh approval on the assumption the old one is dead (the approved action did NOT run either way)");
3258
3293
  }
3259
3294
  return this.runTaskStream(spec, { cp, outcome, onEnvRestoreFailed, ...(wakeMessage !== undefined ? { wakeMessage } : {}) }, internals);
3260
3295
  }