@sema-agent/core 1.410.0 → 1.413.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 (108) 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 +17 -11
  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 +11 -5
  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 +8 -3
  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 +37 -9
  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 +50 -9
  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 +4 -0
  27. package/dist/core/task-notification.d.ts.map +1 -1
  28. package/dist/core/task-notification.js +43 -26
  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 +14 -5
  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 +98 -16
  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 +9 -3
  52. package/dist/core/untrusted-text.js.map +1 -1
  53. package/dist/engine/compaction/compaction.d.ts.map +1 -1
  54. package/dist/engine/compaction/compaction.js +0 -10
  55. package/dist/engine/compaction/compaction.js.map +1 -1
  56. package/dist/engine/compaction/utils.d.ts.map +1 -1
  57. package/dist/engine/compaction/utils.js +2 -1
  58. package/dist/engine/compaction/utils.js.map +1 -1
  59. package/dist/engine/harness/types.d.ts +16 -0
  60. package/dist/engine/harness/types.d.ts.map +1 -1
  61. package/dist/engine/harness/types.js +31 -0
  62. package/dist/engine/harness/types.js.map +1 -1
  63. package/dist/engine/session/import-validate.d.ts +1 -0
  64. package/dist/engine/session/import-validate.d.ts.map +1 -1
  65. package/dist/engine/session/import-validate.js +40 -3
  66. package/dist/engine/session/import-validate.js.map +1 -1
  67. package/dist/engine/session/repo-utils.d.ts.map +1 -1
  68. package/dist/engine/session/repo-utils.js +15 -2
  69. package/dist/engine/session/repo-utils.js.map +1 -1
  70. package/dist/engine/session/session.d.ts.map +1 -1
  71. package/dist/engine/session/session.js +26 -2
  72. package/dist/engine/session/session.js.map +1 -1
  73. package/dist/prompt-assembly/assemble.d.ts.map +1 -1
  74. package/dist/prompt-assembly/assemble.js +7 -6
  75. package/dist/prompt-assembly/assemble.js.map +1 -1
  76. package/dist/stores/file/background-agent-store.d.ts +1 -0
  77. package/dist/stores/file/background-agent-store.d.ts.map +1 -1
  78. package/dist/stores/file/background-agent-store.js +11 -7
  79. package/dist/stores/file/background-agent-store.js.map +1 -1
  80. package/dist/stores/file/checkpoint-store.d.ts +9 -4
  81. package/dist/stores/file/checkpoint-store.d.ts.map +1 -1
  82. package/dist/stores/file/checkpoint-store.js +56 -8
  83. package/dist/stores/file/checkpoint-store.js.map +1 -1
  84. package/dist/stores/file/fs-atomic.d.ts +1 -0
  85. package/dist/stores/file/fs-atomic.d.ts.map +1 -1
  86. package/dist/stores/file/fs-atomic.js +25 -2
  87. package/dist/stores/file/fs-atomic.js.map +1 -1
  88. package/dist/stores/file/mailbox-store.d.ts.map +1 -1
  89. package/dist/stores/file/mailbox-store.js +37 -13
  90. package/dist/stores/file/mailbox-store.js.map +1 -1
  91. package/dist/stores/file/memory-store.d.ts +3 -1
  92. package/dist/stores/file/memory-store.d.ts.map +1 -1
  93. package/dist/stores/file/memory-store.js +24 -2
  94. package/dist/stores/file/memory-store.js.map +1 -1
  95. package/dist/stores/file/session-store.d.ts.map +1 -1
  96. package/dist/stores/file/session-store.js +6 -5
  97. package/dist/stores/file/session-store.js.map +1 -1
  98. package/dist/stores/file/task-list-store.d.ts.map +1 -1
  99. package/dist/stores/file/task-list-store.js +4 -3
  100. package/dist/stores/file/task-list-store.js.map +1 -1
  101. package/dist/stores/file/workflow-run-store.d.ts +1 -0
  102. package/dist/stores/file/workflow-run-store.d.ts.map +1 -1
  103. package/dist/stores/file/workflow-run-store.js +7 -3
  104. package/dist/stores/file/workflow-run-store.js.map +1 -1
  105. package/dist/tools/fs/index.d.ts.map +1 -1
  106. package/dist/tools/fs/index.js +11 -8
  107. package/dist/tools/fs/index.js.map +1 -1
  108. 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;IASj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Ga,kBAAkB;IAwBhC,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC;IAYxD,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU;YA2jBzE,SAAS;YAmiIT,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"}
@@ -367,6 +367,19 @@ export class Runner {
367
367
  await this.runLocked(spec, queue, (r) => {
368
368
  resultValue = r;
369
369
  const pcs = internals?.inheritedGate?.parentConstraints;
370
+ if (resume !== undefined &&
371
+ resume.pendingActionStarted !== true &&
372
+ r.status !== "completed" &&
373
+ r.status !== "suspended" &&
374
+ resume.onEnvRestoreFailed !== undefined) {
375
+ void resume
376
+ .onEnvRestoreFailed("env_failed")
377
+ .then(() => {
378
+ r.errorCode ??= "resume.reopened_unstarted";
379
+ })
380
+ .catch(() => {
381
+ });
382
+ }
370
383
  if (resume !== undefined && r.checkpointToken !== resume.cp.token) {
371
384
  this.parentConstraintRegistry.delete(resume.cp.token);
372
385
  }
@@ -397,15 +410,13 @@ export class Runner {
397
410
  })();
398
411
  const settled = run.catch(async (err) => {
399
412
  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;
413
+ const reopenReason = code === "resume.tool_unavailable" ? "tool_unavailable" : "env_failed";
414
+ const reopenable = resume !== undefined && resume.pendingActionStarted !== true && reopenReason !== undefined;
415
+ let reopenCommitted = false;
406
416
  if (reopenable && resume?.onEnvRestoreFailed) {
407
417
  try {
408
418
  await resume.onEnvRestoreFailed(reopenReason);
419
+ reopenCommitted = true;
409
420
  }
410
421
  catch (reopenErr) {
411
422
  this.parentConstraintRegistry.delete(resume.cp.token);
@@ -418,7 +429,7 @@ export class Runner {
418
429
  code = "checkpoint.reopen_failed";
419
430
  }
420
431
  }
421
- else if (resume) {
432
+ if (resume && !reopenCommitted) {
422
433
  this.parentConstraintRegistry.delete(resume.cp.token);
423
434
  try {
424
435
  await this.sessions.unpin?.(resume.cp.sessionId);
@@ -2271,6 +2282,9 @@ export class Runner {
2271
2282
  compactionBreaker.failures = 0;
2272
2283
  }
2273
2284
  trimForceBackoff = nextTrimForceBackoff(trimForceBackoff, comp, trimPressure);
2285
+ if (comp.contextUsage) {
2286
+ queue.push({ type: "context_usage", ...comp.contextUsage, ...ident() });
2287
+ }
2274
2288
  if (comp.suppressedByFloor) {
2275
2289
  const s = comp.suppressedByFloor;
2276
2290
  emitTrace(tracer, () => ({
@@ -2407,7 +2421,12 @@ export class Runner {
2407
2421
  stampWriteAnchor(attachState, family, cadenceTurns);
2408
2422
  if (details !== undefined)
2409
2423
  reduceToolEnd(attachState, details);
2410
- }, (toolCallId) => startedToolCallIds.add(toolCallId));
2424
+ }, (toolCallId) => {
2425
+ startedToolCallIds.add(toolCallId);
2426
+ if (resume !== undefined && resume.cp.pendingAction.kind === "tool_approval" && toolCallId === resume.cp.pendingAction.toolCallId) {
2427
+ resume.pendingActionStarted = true;
2428
+ }
2429
+ });
2411
2430
  }
2412
2431
  if (walltimeExhaustedResume) {
2413
2432
  timeout.fired = true;
@@ -3197,7 +3216,7 @@ export class Runner {
3197
3216
  if (checkpointVersionOf(cp) > MAX_SUPPORTED_CHECKPOINT_VERSION) {
3198
3217
  throw new CheckpointError("checkpoint.unsupported_version", `checkpoint version ${checkpointVersionOf(cp)} is newer than this worker supports (max ${MAX_SUPPORTED_CHECKPOINT_VERSION})`);
3199
3218
  }
3200
- if (taskConfig.signal?.aborted === true) {
3219
+ if (taskConfig.signal?.aborted === true && cp.status === "pending") {
3201
3220
  throw new CheckpointError("checkpoint.resume_aborted", "the resume was handed an ALREADY-ABORTED signal — refusing to consume the approval on a leg that cannot run it (the checkpoint stays pending and is resumable with a live signal)");
3202
3221
  }
3203
3222
  if (cp.state.workspaceHandle !== undefined && this.deps.executionEnvFactory === undefined) {
@@ -3227,8 +3246,10 @@ export class Runner {
3227
3246
  this.parentConstraintRegistry.delete(token);
3228
3247
  throw new CheckpointError("checkpoint.already_resolved", "checkpoint already resolved or expired — not re-executed (idempotent)");
3229
3248
  }
3249
+ let consumeFlipDone = false;
3230
3250
  if (internals?.afterCheckpointResolve !== undefined) {
3231
3251
  await internals.afterCheckpointResolve();
3252
+ consumeFlipDone = true;
3232
3253
  }
3233
3254
  const spec = {
3234
3255
  ...taskConfig,
@@ -3246,6 +3267,26 @@ export class Runner {
3246
3267
  }
3247
3268
  }
3248
3269
  : undefined;
3270
+ if (taskConfig.signal?.aborted === true && consumeFlipDone) {
3271
+ 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)");
3272
+ }
3273
+ if (taskConfig.signal?.aborted === true) {
3274
+ let reopenOutcome = "refused";
3275
+ if (onEnvRestoreFailed !== undefined) {
3276
+ try {
3277
+ await onEnvRestoreFailed("env_failed");
3278
+ reopenOutcome = "reopened";
3279
+ }
3280
+ catch (err) {
3281
+ reopenOutcome = errorCodeOf(err) === "checkpoint.reopen_failed" ? "refused" : "unknown";
3282
+ }
3283
+ }
3284
+ throw reopenOutcome === "reopened"
3285
+ ? 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")
3286
+ : reopenOutcome === "refused"
3287
+ ? 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")
3288
+ : 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)");
3289
+ }
3249
3290
  return this.runTaskStream(spec, { cp, outcome, onEnvRestoreFailed, ...(wakeMessage !== undefined ? { wakeMessage } : {}) }, internals);
3250
3291
  }
3251
3292
  async applyResumeDecision(prepared, resume, emit, emitCommitted, onResolvedToolSuccess, onExecuteStart) {