@sema-agent/core 7.0.2 → 7.1.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 (41) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/agents/repair-loop.d.ts +8 -7
  3. package/dist/agents/roster-store.d.ts +7 -2
  4. package/dist/brain/errors.d.ts +18 -0
  5. package/dist/brain/errors.js +3 -0
  6. package/dist/brain/stream-engine.js +6 -4
  7. package/dist/core/context-edit.d.ts +3 -0
  8. package/dist/core/governance-codes.d.ts +1 -1
  9. package/dist/core/governance-codes.js +4 -0
  10. package/dist/core/hooks.d.ts +26 -6
  11. package/dist/core/hooks.js +8 -5
  12. package/dist/core/image-downsample.d.ts +4 -3
  13. package/dist/core/roles.d.ts +30 -8
  14. package/dist/core/roles.js +12 -8
  15. package/dist/core/runner/prepare-task.d.ts +2 -1
  16. package/dist/core/runner/prepare-task.js +75 -39
  17. package/dist/core/runner/runtask.d.ts +12 -3
  18. package/dist/core/runner/runtask.js +32 -4
  19. package/dist/core/safety-axis-vocab.d.ts +1 -1
  20. package/dist/core/strategy-store.d.ts +4 -1
  21. package/dist/core/task-registry-shared.d.ts +7 -3
  22. package/dist/core/tool-errors.d.ts +1 -1
  23. package/dist/core/tool-policy.d.ts +40 -7
  24. package/dist/core/tool-policy.js +63 -9
  25. package/dist/core/types.d.ts +87 -9
  26. package/dist/engine/compaction/compaction.js +6 -2
  27. package/dist/engine/harness/agent-harness.d.ts +28 -6
  28. package/dist/engine/harness/agent-harness.js +34 -2
  29. package/dist/engine/harness/messages.js +4 -0
  30. package/dist/engine/harness/types.d.ts +37 -0
  31. package/dist/engine/harness/types.js +5 -0
  32. package/dist/engine/session/session.js +3 -2
  33. package/dist/internal/harness.d.ts +1 -0
  34. package/dist/internal/harness.js +1 -0
  35. package/dist/orchestration/builtin-workflows.d.ts +17 -9
  36. package/dist/orchestration/run-workflow-tool.js +7 -2
  37. package/dist/orchestration/workflow-governance.js +1 -1
  38. package/dist/orchestration/workflow-types.d.ts +1 -0
  39. package/dist/orchestration/workflow.js +1 -1
  40. package/dist/stores/file/mailbox-store.d.ts +2 -1
  41. package/package.json +1 -1
@@ -3941,8 +3941,11 @@ export interface TaskEventIdentity {
3941
3941
  }
3942
3942
  /**
3943
3943
  * design/99 §E3/§E10 — a BRAIN-LAYER liveness phase, surfaced so a UI can show why a
3944
- * turn is stalled (the brain otherwise absorbs these silently in its connect/retry loop). Provider-NEUTRAL:
3945
- * carries only the graduated phase + a neutral hint, NEVER an HTTP status / provider taxonomy / stop_reason.
3944
+ * turn is stalled (the brain otherwise absorbs these silently in its connect/retry loop). The PHASE
3945
+ * itself is provider-NEUTRAL a graduated bucket this engine mints, never a provider taxonomy or a
3946
+ * `stop_reason`. The one provider-stated number that does cross this channel is the failing attempt's
3947
+ * HTTP status, and it travels on its own named seat ({@link BrainStatus.errorStatus}) in the retry
3948
+ * context only; the phase and the {@link BrainStatus.detail} hint stay free of it.
3946
3949
  * A CLOSED union (type-safe) covering the core brain layer; a deployment that surfaces its OWN states
3947
3950
  * (e.g. E25 token-refresh `authenticating`) does so on its own channel, not by widening this.
3948
3951
  */
@@ -3960,8 +3963,10 @@ export type BrainStatusPhase = "rate_limited" | "retrying" | "reconnecting" | "c
3960
3963
  * WHY a retry wait is happening, as a closed, provider-NEUTRAL bucket — the companion to
3961
3964
  * {@link BrainStatusPhase}, which says what the brain is doing about it. A consumer rendering an
3962
3965
  * unattended progress line ("no answer for three minutes") needs the reason, and until this existed the
3963
- * only carriers of it were the HTTP status and the syscall code, neither of which may cross this
3964
- * channel. Values are about the SHAPE of the failure, never its provider taxonomy:
3966
+ * only carriers of it were the HTTP status and the syscall code, neither of which crossed this channel
3967
+ * at the time. (The status has since gained its own seat, {@link BrainStatus.errorStatus}; this bucket
3968
+ * remains the reason a consumer RENDERS, and it is the only carrier for the transport classes, which
3969
+ * have no status at all.) Values are about the SHAPE of the failure, never its provider taxonomy:
3965
3970
  * - `connect_refused` — the attempt got a definite negative about the target itself (nothing accepts
3966
3971
  * at that address, or the name has no address). This is the class the SHORT retry lane serves.
3967
3972
  * - `transport` — any other transport-level failure: a connect timeout, a reset, a mid-stream
@@ -3977,7 +3982,11 @@ export type BrainRetryErrClass = "connect_refused" | "transport" | "rate_limit"
3977
3982
  /** design/99 §E3/§E10 — the payload of a {@link TaskEvent} `status` event (and the brain→runner signal). */
3978
3983
  export interface BrainStatus {
3979
3984
  phase: BrainStatusPhase;
3980
- /** Optional neutral, human-readable hint (NO provider/HTTP detail). */
3985
+ /** Optional neutral, human-readable hint. Stays free of provider/HTTP detail even now that
3986
+ * {@link errorStatus} exists: the machine-readable status has its own seat, and interpolating it
3987
+ * into the prose too would make one fact travel in two spellings a consumer has to reconcile.
3988
+ * (CC parity: its own retry banner renders a TRANSLATED sentence — "No response from API",
3989
+ * "Connection dropped" — while the raw status rides the structured key beside it.) */
3981
3990
  detail?: string;
3982
3991
  /** Seconds until the brain's next retry attempt (from the honored backoff / `Retry-After`), when known. */
3983
3992
  retryInSec?: number;
@@ -4015,6 +4024,41 @@ export interface BrainStatus {
4015
4024
  * the engine classified; absent on frames that are not a retry wait (`recovered`/`gave_up`) and on a
4016
4025
  * `circuit_open` fast-fail, which is a local verdict rather than an observed failure. */
4017
4026
  errClass?: BrainRetryErrClass;
4027
+ /**
4028
+ * #506 ㋑ — the HTTP status of the attempt that just failed, on the frame announcing the RETRY of it.
4029
+ * The one provider-stated number this channel carries; everything else about the failure still
4030
+ * crosses as the engine's own graduated buckets ({@link phase} / {@link errClass}).
4031
+ *
4032
+ * WHY IT IS HERE AT ALL, given the channel spent its life refusing it: a UI that must tell an
4033
+ * operator whether to wait or to go fix something needs the status, and the two neutral buckets
4034
+ * cannot supply it — `rate_limit` covers a 429 the provider will clear on its own AND a 429 that
4035
+ * means the account is out of quota, and `server` covers a 500 alongside a 503 behind a load
4036
+ * balancer. CC states the same number on the same occasion (`system/api_retry.error_status`, read
4037
+ * off `APIError.status`), so a serving layer forwarding this frame no longer has to choose between
4038
+ * matching CC's payload and honoring this channel's contract.
4039
+ *
4040
+ * PRESENCE — an api_retry context whose attempt got a response that NAMES the failure, and nothing
4041
+ * else. Present on the connect-ladder retry wait (`rate_limited` / `retrying` / `reconnecting` when
4042
+ * a response came back) and on the output-cap re-send (the provider's own 400). ABSENT — never
4043
+ * zeroed, never null — for:
4044
+ * · a transport failure (`connect_refused` / `transport` at the connect leg): no response existed,
4045
+ * so no status was ever stated. This is the arm CC spells as an explicit `null`; here it is
4046
+ * absence, for the same reason every other seat on this interface uses absence, and the fact is
4047
+ * still TOTAL rather than guessable — {@link errClass} names those two classes by construction.
4048
+ * · a mid-stream tear (tiers B/C): its response's own status was a SUCCESS, and a status that
4049
+ * failed nothing must not be published as the cause of a retry.
4050
+ * · a `circuit_open` fast-fail: a local verdict, nothing was sent, nobody answered.
4051
+ * · the terminal `recovered` / `gave_up` frames: they announce no attempt.
4052
+ * Same "only a status that names the failure travels" predicate as the assistant frame's
4053
+ * {@link AssistantMessage.apiErrorStatus} (one helper, both sites) — a 2xx never travels here either,
4054
+ * which is reachable on this path via a provider's own `x-should-retry` verdict on a success status.
4055
+ *
4056
+ * OPTIONAL, not CC's nullable-REQUIRED, and the difference is CC's own: CC dedicates a whole message
4057
+ * (`system/api_retry`) to the retry occasion and can therefore require the key on it, while this
4058
+ * interface is ONE shape shared by every phase — the same geometry as CC's shared
4059
+ * `control_request_progress` frame, where CC itself makes the key optional.
4060
+ */
4061
+ errorStatus?: number;
4018
4062
  }
4019
4063
  /**
4020
4064
  * design/97 CORE-8 (③): one lightweight TOOL-ACTIVITY beat surfaced from a running task, for a per-agent live
@@ -4575,7 +4619,9 @@ export type TaskEvent = ({
4575
4619
  * silently (a 429 rate-limit / a 5xx or network retry / a reconnect / an open circuit breaker). Emitted
4576
4620
  * the moment the brain decides to wait/retry, carrying the graduated {@link BrainStatusPhase} + an
4577
4621
  * optional `retryInSec` so a UI can show "rate limited, retrying in Ns". EPHEMERAL — a pure liveness
4578
- * signal, never persisted or replayed on resume. Provider-neutral (no HTTP status / stop_reason).
4622
+ * signal, never persisted or replayed on resume. The phase and the hint are provider-neutral (no
4623
+ * provider taxonomy, no `stop_reason`); the failing attempt's HTTP status rides its own seat in the
4624
+ * retry context only — see {@link BrainStatus.errorStatus}.
4579
4625
  * SCOPE: reflects THIS task's own (top-level) brain calls. A delegated sub-agent's brain liveness routes
4580
4626
  * to the SUB-AGENT's own stream (isolated, like every child event — §E2); a background internal brain
4581
4627
  * call (memory recall/consolidation) is intentionally not surfaced.
@@ -5168,9 +5214,15 @@ export interface WorkflowGovernanceBaseline {
5168
5214
  * The allowed model NAMES an LLM-authored script may pick (design/98 §2.5 新洞2). A script gives a
5169
5215
  * `modelName` string (never a `Model` object — that carries `baseUrl`/`headers` = exfil); the engine
5170
5216
  * resolves it against this list to a deploy-configured `Model` (the script never sees the object).
5171
- * **FAIL-CLOSED**: `undefined`/empty ⇒ the script CANNOT pick a model (its `modelName` is rejected the
5172
- * child falls back to the workflow's default role). NEVER fail-open to the whole `models` catalog for an
5173
- * LLM-authored workflow.
5217
+ * **FAIL-CLOSED**: `undefined`/empty ⇒ the script CANNOT pick a model a spec that names `modelName`
5218
+ * THROWS `WorkflowModelNotAllowedError` and the child is never spawned. The refusal is loud, not a
5219
+ * silent downgrade: the script asked for a model it may not have, so the agent call FAILS rather than
5220
+ * quietly running on the workflow's default role (a script that wants the default must simply OMIT
5221
+ * the field). The same throw covers a name that is off the list, and a listed name the `models`
5222
+ * catalog does not hold — so the legal set is the INTERSECTION of this list and the catalog keys
5223
+ * (note the catalog is the Runner's TIER-EXPANDED one, so on a deployment with `RunnerDeps.tiers`
5224
+ * the tier words and CC aliases are catalog keys here too, still gated by this list).
5225
+ * NEVER fail-open to the whole `models` catalog for an LLM-authored workflow.
5174
5226
  */
5175
5227
  workflowModelAllowlist?: string[];
5176
5228
  }
@@ -5749,6 +5801,32 @@ export interface EngineNotice {
5749
5801
  * implemented, so the unhonored-knob disclosure it carried has no referent; consumers must
5750
5802
  * judge ladder support by VERSION, never by that code's absence.
5751
5803
  *
5804
+ * - `"task.halt_unconsumed"` (design/384 slice 1) — the user's stop verb ({@link TaskStream.halt})
5805
+ * was ANSWERED (not refused) while the run's ending was already owned by its own abort: nothing
5806
+ * was cut and nothing was stopped by the halt, the run's own ending stands, and the result will
5807
+ * NOT carry `haltedByUser` for it (the attribution seat never signs someone else's stop). This
5808
+ * notice is the halt's only trace on that arm — without it the verb receipt (`{turnCut:false}`)
5809
+ * was the sole record and the caller could not tell "my stop did nothing because the run beat
5810
+ * me to ending" from "my stop is being honored at the next boundary". Minted once per such verb
5811
+ * call (each arrival is a distinct fact); `detail: { sessionId, runId, taskId? }` — `runId` is
5812
+ * the run whose ending the halt failed to claim. Audience `"user"` (the person who pressed
5813
+ * stop). A REFUSED halt (typed `steering.not_running` throw) mints nothing: the refusal itself
5814
+ * is the loud answer.
5815
+ *
5816
+ * - `"task.late_approval"` (design/384 slice 1) — a synchronous ask approval was NOT CONSUMED:
5817
+ * a run or turn interrupt released the wait (the `resolveAsk` race arm detached the approver's
5818
+ * promise; an unconsumed resolve is the approver releasing its wait, never a verdict), so the
5819
+ * tool did NOT run and the approval was not honored. The notice asserts non-consumption ONLY —
5820
+ * never an arrival order: an approval and an abort settling close together read as the abort
5821
+ * (the resolver's documented one-directional residual — the engine never claims a person
5822
+ * decided something it cannot show they did, and it equally never claims which came first).
5823
+ * Minted only for a value that reads as an APPROVAL — an unconsumed
5824
+ * deny/refusal is an ordinary release and leaves no trace, and an unconsumed REJECTION goes to
5825
+ * `onError(phase:"hook")` instead (a failing callback, not an answer). One notice per
5826
+ * unconsumed approval; `detail: { toolName, toolCallId, sessionId, runId, taskId? }`. Audience `"user"`
5827
+ * (whoever answered the card is the one entitled to hear the answer ran nothing); a host may
5828
+ * forward it on its own wire.
5829
+ *
5752
5830
  * - `"steering.parked_input_blocked"` (design/373 §4.3) — a PARKED steer entry was withheld when
5753
5831
  * a resume redelivered it (any resume kind that drains parked steers — wake included) by the
5754
5832
  * deployment's `userPromptSubmit` screen (block verdict, or a fail-closed non-answer/crash):
@@ -1,7 +1,7 @@
1
1
  import { resolveAgentCoreCompleteFn, } from "../loop/runtime-deps.js";
2
2
  import { asAgentMessage, convertToLlm, createCompactionSummaryMessage, createCustomMessage, } from "../harness/messages.js";
3
3
  import { buildSessionContext } from "../session/session.js";
4
- import { CompactionError, err, ok, } from "../harness/types.js";
4
+ import { CompactionError, err, isSyntheticApiErrorMessage, ok, } from "../harness/types.js";
5
5
  import { budgetInvokedSkillsRetention, computeFileLists, createFileOps, extractFileOpsFromMessage, extractInvokedSkills, extractPersistedOutputRefs, formatFileOperations, formatPersistedOutputRefs, PERSISTED_OUTPUT_REFS_MAX_ENTRIES, readElidedMessages, readPersistedOutputRefs, readRetainedInvokedSkills, readUnsummarizedMessages, replaceInvokedSkillBodiesForSummary, serializeConversation, stripFileOperationsFooter, } from "./utils.js";
6
6
  import { ENGINE_AUTHORITY_ENVELOPE_TAGS, sanitizeUntrustedText } from "../../core/untrusted-text.js";
7
7
  import { sliceHeadSafe } from "../../core/surrogate-safe-slice.js";
@@ -223,9 +223,13 @@ function findValidCutPoints(entries, startIndex, endIndex) {
223
223
  case "custom":
224
224
  case "compactionSummary":
225
225
  case "user":
226
- case "assistant":
227
226
  cutPoints.push(i);
228
227
  break;
228
+ case "assistant":
229
+ if (!isSyntheticApiErrorMessage(entry.message)) {
230
+ cutPoints.push(i);
231
+ }
232
+ break;
229
233
  case "toolResult":
230
234
  break;
231
235
  }
@@ -168,16 +168,17 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
168
168
  * gated: its splice opens a NEW run (idle-park redelivery), and a halt belongs to the run that
169
169
  * minted it. */
170
170
  engineInjectionsHeld?: () => boolean;
171
- /** RB-30: shared recovery sweep — collects engine-note payloads from the given queues
172
- * in DELIVERY order (steer before followUp, each queue forward — the live loop serves steering
173
- * first, so the recovered redelivery must not present "later" frames ahead of "now/next"),
174
- * removes those entries, and hands the payloads to the runner sink. Called from BOTH terminal
175
- * paths: the natural agent_end AND abort() (which clears the queues before agent_end would see
176
- * them — the hard-abort race that round-1 shipped would have lost). */
177
171
  /** RB-30 R2 belt-and-braces: runner-callable idempotent recovery for exit paths that reach
178
172
  * neither agent_end nor abort() (a pre-prompt throw after prepare). Swept entries are removed,
179
173
  * so a double call is a no-op. */
180
174
  recoverUndrainedEngineNotes(): void;
175
+ /** RB-30: shared recovery sweep — collects engine-note payloads from the given queues
176
+ * in DELIVERY order (steer before followUp, each queue forward — the live loop serves steering
177
+ * first, so the recovered redelivery must not present "later" frames ahead of "now/next"),
178
+ * removes those entries, and hands the payloads to the runner sink. Called from BOTH terminal
179
+ * paths: the natural agent_end AND abort() — which does NOT clear the queues: #389 retired that
180
+ * clearing, so they are LEFT STANDING (the durable-park migration reads them AFTER abort()
181
+ * returns) and the abort-side pass is the belt for an exit that never reached agent_end. */
181
182
  private sweepUndrainedEngineNotes;
182
183
  /** backlog #259 — what remains in the steer/follow-up queues AFTER the engine-note sweep is USER
183
184
  * input that was accepted ("queued") and will never be consumed: the run reached agent_end first.
@@ -261,6 +262,27 @@ export declare class AgentHarness<TSkill extends Skill = Skill, TPromptTemplate
261
262
  setStopGate(gate: (() => Promise<AgentMessage[]>) | undefined): void;
262
263
  private validateToolNames;
263
264
  private flushPendingSessionWrites;
265
+ /**
266
+ * #506 ㋐ — write the transcript's record of a TERMINAL provider failure (CC 2.1.250 parity, `Oo`/`CIt`).
267
+ *
268
+ * A SEPARATE object, never the live frame: `failure` is the engine's terminal error shell and every
269
+ * other consumer of it (the run result, failover, telemetry, usage accounting) reads its real
270
+ * `model`, so re-stamping that field in place would corrupt all of them. The record is minted here
271
+ * with the reserved {@link SYNTHETIC_MESSAGE_MODEL} instead, which is what makes it recognizable — and
272
+ * therefore droppable — at the request boundary and at the derived-state walks.
273
+ *
274
+ * Two CC fields are deliberately NOT copied, because this tree already states the same facts more
275
+ * honestly: CC writes `stop_reason: "stop_sequence"` on an entry that stopped for no such reason (its
276
+ * own consumers must read `isApiErrorMessage` to know better), and CC writes a zero `usage` with
277
+ * nothing marking it synthetic. Here the stop reason stays `"error"` and `usageMissing` says the zeros
278
+ * are a shell rather than a measurement — the same discipline the live frame already carries.
279
+ *
280
+ * BEST-EFFORT: a record of a failure must never become a second failure. The append can lose the
281
+ * session's optimistic lock (another writer moved the leaf) or hit a storage fault, and the run is
282
+ * already over — swallowing that leaves the pre-#506 behavior (no record) rather than converting a
283
+ * provider outage into a harness throw on the teardown path.
284
+ */
285
+ private recordApiFailure;
264
286
  private handleAgentEvent;
265
287
  private emitRunFailure;
266
288
  private executeTurn;
@@ -4,7 +4,8 @@ import { resolveAgentCoreStreamFn } from "../loop/runtime-deps.js";
4
4
  import { normalizeEngineSegments } from "../../core/untrusted-text.js";
5
5
  import { AUTH_CARRIER_NAMES } from "../../brain/request-params.js";
6
6
  import { convertToLlm } from "./messages.js";
7
- import { AgentHarnessError, CompactionError, SessionError, toError, } from "./types.js";
7
+ import { AgentHarnessError, CompactionError, SessionError, SYNTHETIC_MESSAGE_MODEL, toError, } from "./types.js";
8
+ const API_FAILURE_RECORD_MAX_CHARS = 2000;
8
9
  function createUserMessage(text, images, provenance) {
9
10
  const content = text.length > 0 ? [{ type: "text", text }] : [];
10
11
  if (images) {
@@ -603,12 +604,13 @@ export class AgentHarness {
603
604
  },
604
605
  };
605
606
  },
606
- beforeToolCall: async ({ toolCall, args }) => {
607
+ beforeToolCall: async ({ toolCall, args }, signal) => {
607
608
  const result = await this.emitHook({
608
609
  type: "tool_call",
609
610
  toolCallId: toolCall.id,
610
611
  toolName: toolCall.name,
611
612
  input: args,
613
+ ...(signal !== undefined ? { signal } : {}),
612
614
  });
613
615
  return result;
614
616
  },
@@ -726,6 +728,33 @@ export class AgentHarness {
726
728
  this.pendingSessionWrites.shift();
727
729
  }
728
730
  }
731
+ async recordApiFailure(failure) {
732
+ const raw = failure.errorMessage?.trim();
733
+ const detail = raw !== undefined && raw.length > API_FAILURE_RECORD_MAX_CHARS
734
+ ? `${raw.slice(0, API_FAILURE_RECORD_MAX_CHARS)}… (truncated)`
735
+ : raw;
736
+ const record = {
737
+ role: "assistant",
738
+ content: [{ type: "text", text: detail ? `API Error: ${detail}` : "API Error" }],
739
+ api: failure.api,
740
+ provider: failure.provider,
741
+ model: SYNTHETIC_MESSAGE_MODEL,
742
+ isApiErrorMessage: true,
743
+ ...(failure.apiErrorStatus !== undefined ? { apiErrorStatus: failure.apiErrorStatus } : {}),
744
+ ...(failure.requestId !== undefined ? { requestId: failure.requestId } : {}),
745
+ usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
746
+ usageMissing: true,
747
+ stopReason: "error",
748
+ ...(failure.errorMessage !== undefined ? { errorMessage: failure.errorMessage } : {}),
749
+ ...(failure.errorKind !== undefined ? { errorKind: failure.errorKind } : {}),
750
+ timestamp: failure.timestamp,
751
+ };
752
+ try {
753
+ await this.session.appendMessage(record);
754
+ }
755
+ catch {
756
+ }
757
+ }
729
758
  async handleAgentEvent(event, signal) {
730
759
  if (event.type === "message_end") {
731
760
  let entryId;
@@ -733,6 +762,9 @@ export class AgentHarness {
733
762
  entryId = await this.session.appendMessage(event.message);
734
763
  this.settleInjectedFrame(event.message);
735
764
  }
765
+ else if (event.message.isApiErrorMessage === true) {
766
+ await this.recordApiFailure(event.message);
767
+ }
736
768
  await this.emitAny(entryId !== undefined ? { ...event, entryId } : event, signal);
737
769
  return;
738
770
  }
@@ -1,3 +1,4 @@
1
+ import { isSyntheticApiErrorMessage } from "./types.js";
1
2
  import { parseSessionTimestampMs, requireSessionTimestampMs } from "../session/timestamps.js";
2
3
  export function asAgentMessage(message) {
3
4
  return message;
@@ -155,6 +156,9 @@ export function convertToLlm(messages) {
155
156
  case "user":
156
157
  case "assistant":
157
158
  case "toolResult":
159
+ if (isSyntheticApiErrorMessage(message)) {
160
+ return undefined;
161
+ }
158
162
  return normalizeLlmMessageContent(message);
159
163
  default:
160
164
  return undefined;
@@ -754,6 +754,37 @@ export declare function isValidModelChange(e: {
754
754
  provider?: unknown;
755
755
  modelId?: unknown;
756
756
  }): boolean;
757
+ /**
758
+ * #506 ㋐ — the reserved `model` value on a transcript entry NO MODEL PRODUCED. CC-verbatim
759
+ * (`"<synthetic>"`, CC 2.1.250's own single-occurrence constant), and single-occurrence here for the
760
+ * same reason: the mint site and the recognition predicate must read the same literal or the entry
761
+ * becomes unrecognizable the first time one of them is retyped.
762
+ *
763
+ * It is deliberately a MODEL-SHAPED string (non-empty, bounded), so an entry carrying it survives this
764
+ * session's own import door and round-trips — a self-generated entry its own validator rejected would
765
+ * be the worse failure.
766
+ *
767
+ * ACCEPTED RESIDUAL, recorded rather than defended against: nothing RESERVES this id, because model ids
768
+ * are caller-supplied and `isModelIdentifier` admits any bounded non-empty string. A deployment that
769
+ * names a real model literally `<synthetic>` AND whose Brain stamps `isApiErrorMessage` on
770
+ * content-bearing output would have that output treated as a record. Both halves are required, the
771
+ * spelling is chosen to be one no catalog would use, and CC carries the same residual for the same
772
+ * reason — a reserved-word door here would refuse ids this engine has no business refusing.
773
+ */
774
+ export declare const SYNTHETIC_MESSAGE_MODEL = "<synthetic>";
775
+ /**
776
+ * #506 ㋐ — is this transcript entry the engine's own SYNTHETIC record of a terminal API failure?
777
+ *
778
+ * Such an entry is real transcript (a session that died on a provider failure must say so when it is
779
+ * re-read) but it is NOT model output, so it is dropped wherever transcript becomes model input, and
780
+ * it must not move any state derived from real turns. This predicate is the single gate for both.
781
+ *
782
+ * THREE keys, CC-anchored (`Hje`: `type==="assistant" && isApiErrorMessage===true && model===<synthetic>`),
783
+ * and the narrowness is the whole point. `isApiErrorMessage` alone would also match an assistant message
784
+ * a foreign Brain stamped while it carried REAL output — dropping that from the request view would
785
+ * silently delete the model's own words from its context. Only the engine's own mint sets all three.
786
+ */
787
+ export declare function isSyntheticApiErrorMessage(m: unknown): boolean;
757
788
  /** RB-128: a `label` / `session_info.name` that is not a string reaches `.trim()` inside
758
789
  * `BaseSessionStorage`'s CONSTRUCTOR — and the file backend validates BEFORE constructing any storage, so
759
790
  * the contamination lands on disk and every later `open()` throws a raw `TypeError` (not even a `SessionError`).
@@ -1077,6 +1108,12 @@ export interface ToolCallEvent {
1077
1108
  toolCallId: string;
1078
1109
  toolName: string;
1079
1110
  input: Record<string, unknown>;
1111
+ /** The per-call abort signal (additive, design/384 slice 1). Present iff the loop handed its
1112
+ * turn-scoped signal to `beforeToolCall` — the run-level abort is composed into that controller,
1113
+ * so this signal fires on a turn interrupt (bare halt / steer-now) AND on a run abort. Absent on
1114
+ * emits that carry no per-call signal; a subscriber gating a wait on it must then fall back to
1115
+ * whatever run-level signal it already holds (the historical shape, byte-identical). */
1116
+ signal?: AbortSignal;
1080
1117
  }
1081
1118
  export interface ToolResultEvent {
1082
1119
  type: "tool_result";
@@ -155,6 +155,11 @@ export function isValidThinkingLevelChange(e) {
155
155
  export function isValidModelChange(e) {
156
156
  return isModelIdentifier(e.provider) && isModelIdentifier(e.modelId);
157
157
  }
158
+ export const SYNTHETIC_MESSAGE_MODEL = "<synthetic>";
159
+ export function isSyntheticApiErrorMessage(m) {
160
+ const a = m;
161
+ return a?.role === "assistant" && a.isApiErrorMessage === true && a.model === SYNTHETIC_MESSAGE_MODEL;
162
+ }
158
163
  export function isOptionalDisplayString(v, max = 4096) {
159
164
  return v === undefined || v === null || (typeof v === "string" && v.length <= max);
160
165
  }
@@ -1,5 +1,5 @@
1
1
  import { asAgentMessage, createCompactionSummaryMessage, createCustomMessage, } from "../harness/messages.js";
2
- import { SessionError, isValidModelChange, normalizeAnnouncedListing, normalizeCompactionStateCarrier, normalizeGitAnnouncement, normalizeReminderMark, normalizeWorkspaceState } from "../harness/types.js";
2
+ import { SessionError, isSyntheticApiErrorMessage, isValidModelChange, normalizeAnnouncedListing, normalizeCompactionStateCarrier, normalizeGitAnnouncement, normalizeReminderMark, normalizeWorkspaceState } from "../harness/types.js";
3
3
  import { normalizePromptEpoch } from "../../prompt-assembly/epoch.js";
4
4
  import { budgetInvokedSkillsRetention, readElidedMessages, readRetainedInvokedSkills, readUnsummarizedMessages, renderInvokedSkillsRetention, } from "../compaction/utils.js";
5
5
  const RETENTION_CLAMP_DEFAULT_CHARS_PER_TOKEN = 3;
@@ -25,7 +25,8 @@ export function buildSessionContext(pathEntries, opts) {
25
25
  model = { provider: entry.provider, modelId: entry.modelId };
26
26
  }
27
27
  else if (entry.type === "message" && entry.message.role === "assistant") {
28
- if (isValidModelChange({ provider: entry.message.provider, modelId: entry.message.model })) {
28
+ if (!isSyntheticApiErrorMessage(entry.message) &&
29
+ isValidModelChange({ provider: entry.message.provider, modelId: entry.message.model })) {
29
30
  model = { provider: entry.message.provider, modelId: entry.message.model };
30
31
  }
31
32
  }
@@ -25,3 +25,4 @@ export { uuidv7 } from "../engine/session/uuid.js";
25
25
  export { SessionError } from "../engine/harness/types.js";
26
26
  export { normalizeGitAnnouncement } from "../engine/harness/types.js";
27
27
  export { gitFrameContextVisible } from "../engine/session/session.js";
28
+ export { isSyntheticApiErrorMessage } from "../engine/harness/types.js";
@@ -14,3 +14,4 @@ export { uuidv7 } from "../engine/session/uuid.js";
14
14
  export { SessionError } from "../engine/harness/types.js";
15
15
  export { normalizeGitAnnouncement } from "../engine/harness/types.js";
16
16
  export { gitFrameContextVisible } from "../engine/session/session.js";
17
+ export { isSyntheticApiErrorMessage } from "../engine/harness/types.js";
@@ -22,12 +22,17 @@ import type { NamedWorkflowListing } from "./workflow-script-store.js";
22
22
  /** The built-in round-based discussion workflow's registered name. */
23
23
  export declare const DISCUSSION_WORKFLOW_NAME = "discussion";
24
24
  /**
25
- * The registered name this built-in carried before the C-R14 vocabulary ruling (2026-08-16), kept
26
- * resolvable for ONE minor: "team" now names the agent-teams family (persistent named teammates) only,
27
- * and a one-off multi-agent debate is a "discussion".
25
+ * The registered name this built-in carried before the C-R14 vocabulary ruling (2026-08-16): "team" now
26
+ * names the agent-teams family (persistent named teammates) only, and a one-off multi-agent debate is a
27
+ * "discussion".
28
28
  *
29
- * @deprecated Use {@link DISCUSSION_WORKFLOW_NAME}. Removed in the next minor; the retired spelling still
30
- * RESOLVES via {@link canonicalWorkflowName} until then, but the listing/card face shows the new name only.
29
+ * RETENTION, as a fact rather than a plan: the ruling's original "kept resolvable for ONE minor" window
30
+ * LAPSED. The alias has stayed on the public export surface from the 5.37.0 window through 7.x, across
31
+ * BOTH the 6.0.0 and 7.0.0 BREAKING windows. It is therefore retained until a removal is announced in a
32
+ * named BREAKING window's ship post — no minor removes it by default.
33
+ *
34
+ * @deprecated Use {@link DISCUSSION_WORKFLOW_NAME}. The retired spelling still RESOLVES via
35
+ * {@link canonicalWorkflowName}, but the listing/card face shows the new name only.
31
36
  */
32
37
  export declare const TEAM_DISCUSSION_WORKFLOW_NAME = "discussion";
33
38
  /**
@@ -35,7 +40,8 @@ export declare const TEAM_DISCUSSION_WORKFLOW_NAME = "discussion";
35
40
  * retired alias. The canonical name is the authority: a resolution reached through an alias returns the
36
41
  * canonical definition (its `meta.name`, hence every run/card projection, is the new name).
37
42
  *
38
- * @deprecated together with the alias table — this becomes an identity function next minor (C-R14).
43
+ * @deprecated together with the alias table — it becomes an identity function when that table is removed
44
+ * in an announced BREAKING window (C-R14).
39
45
  */
40
46
  export declare function canonicalWorkflowName(name: string): string;
41
47
  /**
@@ -72,7 +78,8 @@ export declare function retiredWorkflowNameAliases(canonicalName: string): strin
72
78
  * Callers must apply the deployment's `builtinWorkflows` opt-out BEFORE using this: the equivalence is a
73
79
  * fact about the built-in registry, so a deployment that removed the built-ins removed the alias with them.
74
80
  *
75
- * @deprecated together with the alias table — collapses to `[requested]` next minor (C-R14).
81
+ * @deprecated together with the alias table — collapses to `[requested]` when that table is removed in an
82
+ * announced BREAKING window (C-R14).
76
83
  */
77
84
  export declare function workflowNameProbeOrder(requested: string): string[];
78
85
  /**
@@ -82,8 +89,9 @@ export declare function workflowNameProbeOrder(requested: string): string[];
82
89
  */
83
90
  export declare const DISCUSSION_SCRIPT = "export const meta = {\n name: \"discussion\",\n description: \"Round-based discussion: configurable members debate a topic across rounds (each member sees the transcript so far), then a finalizer synthesizes a structured verdict.\",\n whenToUse: \"Use for a genuinely contested question that benefits from several perspectives arguing across rounds - design trade-offs, plan or risk reviews, adversarial critique of a proposal. Do NOT use it for a single factual question, a task with one obvious answer, or a budget-sensitive run: every round costs one agent call per member, so a discussion is never cheaper than asking once. args (all optional): { topic, members?: [{ role, prompt?, model? }], rounds?, finalizer?: { prompt?, model? } }. Hard ceilings: members is capped at 6 and rounds is capped at 5 regardless of what you pass; the run reports it via log() and a capped field on the result when a request exceeds either.\",\n phases: [\n { title: \"Discussion\" },\n { title: \"Synthesis\" },\n ],\n};\n// Zero-config runnable (design/140 \u00A76 1c): every arg has an opinionated fallback.\nconst raw = args;\nconst a = raw !== null && typeof raw === \"object\" && !Array.isArray(raw) ? raw : {};\nconst topic =\n typeof a.topic === \"string\" && a.topic.trim() !== \"\"\n ? a.topic\n : typeof raw === \"string\" && raw.trim() !== \"\"\n ? raw // ergonomic form: a bare string args IS the topic\n : \"No topic was provided. Discuss: what information should a caller supply to make a discussion like this productive, and when should they NOT convene one?\";\nconst defaultMembers = [\n { role: \"advocate\", prompt: \"Make the strongest constructive case. Propose concrete options and argue their benefits with specifics.\" },\n { role: \"skeptic\", prompt: \"Stress-test every claim made so far. Surface risks, hidden costs, failure modes, and cheaper alternatives.\" },\n];\nconst rawMembers = Array.isArray(a.members) && a.members.length > 0 ? a.members : defaultMembers;\nconst members = rawMembers.slice(0, 6).map((m, i) => {\n const mm = m !== null && typeof m === \"object\" ? m : {};\n const member = {\n role: typeof mm.role === \"string\" && mm.role.trim() !== \"\" ? mm.role : \"member-\" + (i + 1),\n prompt: typeof mm.prompt === \"string\" && mm.prompt.trim() !== \"\" ? mm.prompt : \"Contribute your own distinct perspective: be concrete, give reasons, and engage with what others said.\",\n };\n if (typeof mm.model === \"string\" && mm.model.trim() !== \"\") member.model = mm.model;\n // Slot-tools carrier (design/140 \u2461-3 + F4): a member may BE a registered agent type ({agent:\"reviewer\"}) \u2014\n // persona/tools/model then come from the deployment's AgentDefinition (role library), args stay thin.\n if (typeof mm.agent === \"string\" && mm.agent.trim() !== \"\") member.agent = mm.agent;\n return member;\n});\n// Deterministic budget truncation (design/140 \u00A71 \u9884\u7B97 row): a HARD rounds ceiling + member cap \u2014 never an\n// evaluator agent. The engine's budget/maxAgents hard stops remain the backstop.\nconst requestedRounds = Math.floor(Number(a.rounds));\nconst normalizedRounds = Number.isFinite(requestedRounds) && requestedRounds >= 1 ? requestedRounds : 2;\nconst rounds = Math.min(normalizedRounds, 5);\n// RB-380 disclosure: the member/round slices above are silent by construction (Array.prototype.slice /\n// Math.min just drop the excess) \u2014 record + surface it instead of a caller finding out only by counting\n// transcript entries. Fires only when a request actually exceeded a ceiling (never on the common path).\nconst capNotes = [];\nif (rawMembers.length > 6) capNotes.push(\"requested \" + rawMembers.length + \" members, capped at 6\");\nif (normalizedRounds > 5) capNotes.push(\"requested \" + normalizedRounds + \" rounds, capped at 5\");\nfor (const note of capNotes) log(\"discussion: \" + note);\nconst fin = a.finalizer !== null && typeof a.finalizer === \"object\" && !Array.isArray(a.finalizer) ? a.finalizer : {};\nconst finalizerPrompt = typeof fin.prompt === \"string\" && fin.prompt.trim() !== \"\"\n ? fin.prompt\n : \"You are the synthesis lead. Read the full discussion transcript and produce the final verdict: the decision/answer, the key supporting points, and the strongest unresolved dissent (if any). Do not introduce new arguments of your own.\";\nconst clip = (s) => { const t = String(s); return t.length > 4000 ? t.slice(0, 4000) + \" ...[truncated]\" : t; };\nconst isBudgetStop = (e) => e !== null && typeof e === \"object\" && e.code === \"workflow.budget_exceeded\";\n\nphase(\"Discussion\");\nconst transcript = [];\nlet truncated = null;\nfor (let r = 1; r <= rounds && truncated === null; r++) {\n // Deterministic early stop on an exhausted budget (a live read of the engine budget; the engine's\n // hard WorkflowBudgetExceededError remains the backstop if a member call itself crosses the line).\n if (budget.total !== null && budget.remaining() <= 0) { truncated = \"budget exhausted before round \" + r; break; }\n for (const m of members) {\n const history = transcript.length === 0 ? \"(none yet - you open the discussion)\" : transcript.join(\"\\n\\n\");\n const spec = {\n objective:\n \"Discussion on: \" + topic + \"\\n\\n\" +\n 'You are \"' + m.role + '\" in round ' + r + \" of \" + rounds + \".\\n\" +\n \"Your brief: \" + m.prompt + \"\\n\\n\" +\n \"Transcript so far:\\n\" + history + \"\\n\\n\" +\n \"Respond to the strongest points others made (do not repeat yourself), then advance your own position. Be concise: a few tight paragraphs at most.\",\n };\n if (m.model !== undefined) spec.modelName = m.model;\n let res;\n try {\n res = await agent(spec, m.agent !== undefined ? { label: m.role + \"-r\" + r, phase: \"Discussion\", agentType: m.agent } : { label: m.role + \"-r\" + r, phase: \"Discussion\" });\n } catch (e) {\n // The engine's budget hard stop: keep what the discussion already produced instead of failing the run.\n if (isBudgetStop(e)) { truncated = \"budget exhausted at \" + m.role + \", round \" + r; break; }\n throw e;\n }\n const text = res && res.status === \"completed\" ? clip(res.result) : \"(no contribution - agent ended \" + (res ? res.status : \"unknown\") + \")\";\n transcript.push(m.role + \" (round \" + r + \"): \" + text);\n }\n}\n\nphase(\"Synthesis\");\nconst finalSpec = {\n objective:\n finalizerPrompt + \"\\n\\nTopic: \" + topic + \"\\n\\nFull transcript:\\n\" +\n (transcript.length === 0 ? \"(the discussion produced no contributions)\" : transcript.join(\"\\n\\n\")) +\n (truncated ? \"\\n\\nNote: the discussion was cut short (\" + truncated + \").\" : \"\"),\n};\nif (typeof fin.model === \"string\" && fin.model.trim() !== \"\") finalSpec.modelName = fin.model;\nlet verdict = null;\ntry {\n verdict = await agent(finalSpec, {\n label: \"finalizer\",\n phase: \"Synthesis\",\n schema: {\n type: \"object\",\n properties: {\n decision: { type: \"string\", description: \"The final answer/decision, one paragraph.\" },\n keyPoints: { type: \"array\", items: { type: \"string\" }, description: \"The strongest supporting points from the discussion.\" },\n dissent: { type: \"string\", description: \"The strongest unresolved counter-position, if any.\" },\n },\n required: [\"decision\", \"keyPoints\"],\n },\n });\n} catch (e) {\n // Budget died before synthesis: return the transcript honestly rather than failing the whole run.\n if (!isBudgetStop(e)) throw e;\n truncated = truncated === null ? \"budget exhausted before synthesis\" : truncated;\n}\n\nreturn {\n topic,\n rounds,\n members: members.map((m) => m.role),\n ...(capNotes.length > 0 ? { capped: capNotes } : {}),\n ...(truncated ? { truncated } : {}),\n transcript,\n verdict: verdict && verdict.structuredOutput !== undefined ? verdict.structuredOutput : (verdict ? verdict.result : null),\n};\n";
84
91
  /**
85
- * @deprecated Use {@link DISCUSSION_SCRIPT}. Retired spelling kept for one minor (C-R14) so a deployment
86
- * importing the constant by its old name keeps compiling; the value is the SAME script (its `meta.name`
92
+ * @deprecated Use {@link DISCUSSION_SCRIPT}. Retired spelling retained (C-R14; the original one-minor
93
+ * window lapsed removal needs an announced BREAKING window) so a deployment importing the constant by
94
+ * its old name keeps compiling; the value is the SAME script (its `meta.name`
87
95
  * is the new `discussion`).
88
96
  */
89
97
  export declare const TEAM_DISCUSSION_SCRIPT = "export const meta = {\n name: \"discussion\",\n description: \"Round-based discussion: configurable members debate a topic across rounds (each member sees the transcript so far), then a finalizer synthesizes a structured verdict.\",\n whenToUse: \"Use for a genuinely contested question that benefits from several perspectives arguing across rounds - design trade-offs, plan or risk reviews, adversarial critique of a proposal. Do NOT use it for a single factual question, a task with one obvious answer, or a budget-sensitive run: every round costs one agent call per member, so a discussion is never cheaper than asking once. args (all optional): { topic, members?: [{ role, prompt?, model? }], rounds?, finalizer?: { prompt?, model? } }. Hard ceilings: members is capped at 6 and rounds is capped at 5 regardless of what you pass; the run reports it via log() and a capped field on the result when a request exceeds either.\",\n phases: [\n { title: \"Discussion\" },\n { title: \"Synthesis\" },\n ],\n};\n// Zero-config runnable (design/140 \u00A76 1c): every arg has an opinionated fallback.\nconst raw = args;\nconst a = raw !== null && typeof raw === \"object\" && !Array.isArray(raw) ? raw : {};\nconst topic =\n typeof a.topic === \"string\" && a.topic.trim() !== \"\"\n ? a.topic\n : typeof raw === \"string\" && raw.trim() !== \"\"\n ? raw // ergonomic form: a bare string args IS the topic\n : \"No topic was provided. Discuss: what information should a caller supply to make a discussion like this productive, and when should they NOT convene one?\";\nconst defaultMembers = [\n { role: \"advocate\", prompt: \"Make the strongest constructive case. Propose concrete options and argue their benefits with specifics.\" },\n { role: \"skeptic\", prompt: \"Stress-test every claim made so far. Surface risks, hidden costs, failure modes, and cheaper alternatives.\" },\n];\nconst rawMembers = Array.isArray(a.members) && a.members.length > 0 ? a.members : defaultMembers;\nconst members = rawMembers.slice(0, 6).map((m, i) => {\n const mm = m !== null && typeof m === \"object\" ? m : {};\n const member = {\n role: typeof mm.role === \"string\" && mm.role.trim() !== \"\" ? mm.role : \"member-\" + (i + 1),\n prompt: typeof mm.prompt === \"string\" && mm.prompt.trim() !== \"\" ? mm.prompt : \"Contribute your own distinct perspective: be concrete, give reasons, and engage with what others said.\",\n };\n if (typeof mm.model === \"string\" && mm.model.trim() !== \"\") member.model = mm.model;\n // Slot-tools carrier (design/140 \u2461-3 + F4): a member may BE a registered agent type ({agent:\"reviewer\"}) \u2014\n // persona/tools/model then come from the deployment's AgentDefinition (role library), args stay thin.\n if (typeof mm.agent === \"string\" && mm.agent.trim() !== \"\") member.agent = mm.agent;\n return member;\n});\n// Deterministic budget truncation (design/140 \u00A71 \u9884\u7B97 row): a HARD rounds ceiling + member cap \u2014 never an\n// evaluator agent. The engine's budget/maxAgents hard stops remain the backstop.\nconst requestedRounds = Math.floor(Number(a.rounds));\nconst normalizedRounds = Number.isFinite(requestedRounds) && requestedRounds >= 1 ? requestedRounds : 2;\nconst rounds = Math.min(normalizedRounds, 5);\n// RB-380 disclosure: the member/round slices above are silent by construction (Array.prototype.slice /\n// Math.min just drop the excess) \u2014 record + surface it instead of a caller finding out only by counting\n// transcript entries. Fires only when a request actually exceeded a ceiling (never on the common path).\nconst capNotes = [];\nif (rawMembers.length > 6) capNotes.push(\"requested \" + rawMembers.length + \" members, capped at 6\");\nif (normalizedRounds > 5) capNotes.push(\"requested \" + normalizedRounds + \" rounds, capped at 5\");\nfor (const note of capNotes) log(\"discussion: \" + note);\nconst fin = a.finalizer !== null && typeof a.finalizer === \"object\" && !Array.isArray(a.finalizer) ? a.finalizer : {};\nconst finalizerPrompt = typeof fin.prompt === \"string\" && fin.prompt.trim() !== \"\"\n ? fin.prompt\n : \"You are the synthesis lead. Read the full discussion transcript and produce the final verdict: the decision/answer, the key supporting points, and the strongest unresolved dissent (if any). Do not introduce new arguments of your own.\";\nconst clip = (s) => { const t = String(s); return t.length > 4000 ? t.slice(0, 4000) + \" ...[truncated]\" : t; };\nconst isBudgetStop = (e) => e !== null && typeof e === \"object\" && e.code === \"workflow.budget_exceeded\";\n\nphase(\"Discussion\");\nconst transcript = [];\nlet truncated = null;\nfor (let r = 1; r <= rounds && truncated === null; r++) {\n // Deterministic early stop on an exhausted budget (a live read of the engine budget; the engine's\n // hard WorkflowBudgetExceededError remains the backstop if a member call itself crosses the line).\n if (budget.total !== null && budget.remaining() <= 0) { truncated = \"budget exhausted before round \" + r; break; }\n for (const m of members) {\n const history = transcript.length === 0 ? \"(none yet - you open the discussion)\" : transcript.join(\"\\n\\n\");\n const spec = {\n objective:\n \"Discussion on: \" + topic + \"\\n\\n\" +\n 'You are \"' + m.role + '\" in round ' + r + \" of \" + rounds + \".\\n\" +\n \"Your brief: \" + m.prompt + \"\\n\\n\" +\n \"Transcript so far:\\n\" + history + \"\\n\\n\" +\n \"Respond to the strongest points others made (do not repeat yourself), then advance your own position. Be concise: a few tight paragraphs at most.\",\n };\n if (m.model !== undefined) spec.modelName = m.model;\n let res;\n try {\n res = await agent(spec, m.agent !== undefined ? { label: m.role + \"-r\" + r, phase: \"Discussion\", agentType: m.agent } : { label: m.role + \"-r\" + r, phase: \"Discussion\" });\n } catch (e) {\n // The engine's budget hard stop: keep what the discussion already produced instead of failing the run.\n if (isBudgetStop(e)) { truncated = \"budget exhausted at \" + m.role + \", round \" + r; break; }\n throw e;\n }\n const text = res && res.status === \"completed\" ? clip(res.result) : \"(no contribution - agent ended \" + (res ? res.status : \"unknown\") + \")\";\n transcript.push(m.role + \" (round \" + r + \"): \" + text);\n }\n}\n\nphase(\"Synthesis\");\nconst finalSpec = {\n objective:\n finalizerPrompt + \"\\n\\nTopic: \" + topic + \"\\n\\nFull transcript:\\n\" +\n (transcript.length === 0 ? \"(the discussion produced no contributions)\" : transcript.join(\"\\n\\n\")) +\n (truncated ? \"\\n\\nNote: the discussion was cut short (\" + truncated + \").\" : \"\"),\n};\nif (typeof fin.model === \"string\" && fin.model.trim() !== \"\") finalSpec.modelName = fin.model;\nlet verdict = null;\ntry {\n verdict = await agent(finalSpec, {\n label: \"finalizer\",\n phase: \"Synthesis\",\n schema: {\n type: \"object\",\n properties: {\n decision: { type: \"string\", description: \"The final answer/decision, one paragraph.\" },\n keyPoints: { type: \"array\", items: { type: \"string\" }, description: \"The strongest supporting points from the discussion.\" },\n dissent: { type: \"string\", description: \"The strongest unresolved counter-position, if any.\" },\n },\n required: [\"decision\", \"keyPoints\"],\n },\n });\n} catch (e) {\n // Budget died before synthesis: return the transcript honestly rather than failing the whole run.\n if (!isBudgetStop(e)) throw e;\n truncated = truncated === null ? \"budget exhausted before synthesis\" : truncated;\n}\n\nreturn {\n topic,\n rounds,\n members: members.map((m) => m.role),\n ...(capNotes.length > 0 ? { capped: capNotes } : {}),\n ...(truncated ? { truncated } : {}),\n transcript,\n verdict: verdict && verdict.structuredOutput !== undefined ? verdict.structuredOutput : (verdict ? verdict.result : null),\n};\n";
@@ -332,8 +332,13 @@ export async function createRunWorkflowTool(d) {
332
332
  "body (equivalently, pass { phase: 'Fix' } in an agent's opts). Give each stage a phase so progress " +
333
333
  "renders as stage groups; use the same titles you declared in meta.phases.\n" +
334
334
  "• spec.modelName works only when the deployment configured a workflow model allowlist, and its legal " +
335
- "values are that deployment's own model CATALOG KEYS not generic tier words (a bare 'opus'/'sonnet'/" +
336
- "'haiku' is a name the catalog almost certainly does not hold, and is refused rather than approximated). " +
335
+ "values are the names on THAT allowlist which the deployment's model CATALOG KEYS also hold a name " +
336
+ "off the allowlist, and a listed name the catalog lacks, are both refused rather than approximated. " +
337
+ "Generic tier words ('opus'/'sonnet'/'haiku'/'pro'/'flash'/'best') are not a separate namespace: on a " +
338
+ "deployment that configured tier bindings they become ordinary catalog keys, but only the ones its " +
339
+ "bindings actually resolve; on one that did not they are simply absent, unless its catalog happens to " +
340
+ "declare that literal name. Either way the allowlist is the gate, so a tier word is legal here only " +
341
+ "when this deployment allowlisted it, never as a shortcut around it. " +
337
342
  "It also goes on the SPEC (the first argument), never in an agent()'s options object; `model` is accepted " +
338
343
  "there as an alias for the same field. If unsure, omit it and the agent runs on the deployment's default " +
339
344
  "role.\n" +
@@ -99,7 +99,7 @@ export function resolveModelName(name, allowlist, models) {
99
99
  if (!allowlist.includes(name)) {
100
100
  throw new WorkflowModelNotAllowedError(name, `not in the workflow model allowlist [${allowlist.join(", ")}]`);
101
101
  }
102
- const model = models?.[name];
102
+ const model = models !== undefined && Object.hasOwn(models, name) ? models[name] : undefined;
103
103
  if (!model) {
104
104
  throw new WorkflowModelNotAllowedError(name, "allowed by name but not present in RunnerDeps.models");
105
105
  }
@@ -392,6 +392,7 @@ export type WorkflowEvent = {
392
392
  output?: string;
393
393
  errorCode?: string;
394
394
  toolCalls?: number;
395
+ modelResolved?: string;
395
396
  replayed?: boolean;
396
397
  ts: number;
397
398
  } | {
@@ -60,7 +60,7 @@ function workflowModelLabel(spec, catalog) {
60
60
  return undefined;
61
61
  if (typeof model !== "string")
62
62
  return model.id ?? model.name;
63
- const served = catalog?.[model]?.id;
63
+ const served = catalog !== undefined && Object.hasOwn(catalog, model) ? catalog[model]?.id : undefined;
64
64
  return served ?? resolveModelDisplayLabel(model);
65
65
  }
66
66
  export const WORKFLOW_SUBAGENT_PROMPT = `You are a subagent spawned by a workflow orchestration script. Use the tools available to complete the task.
@@ -30,7 +30,8 @@ export declare class FileMailboxStore implements MailboxStore {
30
30
  * file can never disagree. Before this, `AgentOne` and `agentone` produced two DIFFERENT shared-state
31
31
  * keys but the SAME file on a case-insensitive filesystem (macOS/Windows default) — one recipient read
32
32
  * the other's messages after a restart. Folding is also the semantically correct answer, not just the
33
- * safe one: the addressing layer's `normalizeAgentName` (task-registry.ts:621) already lowercases, so
33
+ * safe one: the addressing layer's `normalizeAgentName` (defined in core/task-registry-shared.ts and
34
+ * re-exported by task-registry.ts) already lowercases, so
34
35
  * two case-variant handles ARE the same agent; this makes the storage layer say so explicitly instead of
35
36
  * depending on an upstream coincidence, and behave identically on case-SENSITIVE filesystems (Linux),
36
37
  * where the old code silently split one logical agent's mail across two boxes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/core",
3
- "version": "7.0.2",
3
+ "version": "7.1.0",
4
4
  "description": "Stateless, task-oriented AI agent core",
5
5
  "type": "module",
6
6
  "license": "BUSL-1.1",