orkestrator 2.38.2-beta → 2.38.3-beta

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.
@@ -249,13 +249,27 @@ var BRIDGE_LOG_AREAS = defineLogAreas({
249
249
  "plugins.read-failed": "Listing plugins failed; the route answered 500.",
250
250
  "prompt.accepted": "The route accepted a prompt and answered 202.",
251
251
  "prompt.failed": "A prompt turn failed; the session reports the error.",
252
- "prompt.processing-failed": "A prompt accepted by the route failed while processing.",
252
+ "prompt.processing-provider-refused": "A prompt accepted by the route ended on a provider refusal; the turn already logged prompt.provider-refused.",
253
+ "prompt.processing-failed": "A prompt accepted by the route failed while processing, before the turn could report it.",
254
+ "prompt.processing-reported": "A prompt accepted by the route failed; the turn already logged prompt.failed.",
253
255
  "prompt.processing-usage-limited": "A prompt accepted by the route ended on a usage limit; the turn already logged prompt.usage-limited.",
256
+ "prompt.provider-refused": "A prompt turn ended because Claude refused it on the account's or the service's state; `reason` is the SDK's API error code and the session reports the error.",
254
257
  "prompt.received": "A prompt reached the bridge; only its length is logged.",
255
258
  "prompt.send-failed": "A prompt request failed; the route answered with an error.",
256
259
  "prompt.usage-limited": "A prompt turn ended because the account's plan allowance is used up; the session reports the limit.",
257
260
  "query.close-failed": "Stopping the Claude query failed while closing a tab; the close stays pending.",
258
- "query.failed": "A Claude query ended with an error result.",
261
+ "query.failed": {
262
+ description: "A Claude query ended with an error result the bridge does not know to be the account's or the service's state: `subtype` and `isError` from the result, `reason` the SDK's API error code when the turn ended on one, `apiStatus` its HTTP status, `startupFailure` whether the CLI failed to start.",
263
+ essential: true,
264
+ fields: {
265
+ subtype: "label",
266
+ isError: "boolean",
267
+ reason: "label",
268
+ apiStatus: "number",
269
+ startupFailure: "boolean"
270
+ }
271
+ },
272
+ "query.provider-refused": "Claude refused a query on the account's or the service's state (a refused login, an account on hold, an overloaded or failing API); `reason` is the SDK's API error code and the turn reports the provider's words.",
259
273
  "query.usage-limited": "Claude refused a query because the account's plan allowance is used up; the turn reports the limit.",
260
274
  "question.answer-failed": "The answer-question route failed.",
261
275
  "question.answering": "Answering a parked question.",
@@ -848,6 +862,7 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
848
862
  "title.strategy-failed": "A session title strategy failed, so the next is tried. Content-free: the error can quote the prompt.",
849
863
  "steer.qualification-failed": "A bridge's steer qualification failed or answered non-OK, so steering is not offered. Agent and status code or error class only.",
850
864
  "steer.capability-cleared": "A projection cleared `actions.steer` because its bridge did not qualify. Identifiers and turn status only.",
865
+ "queue.turn-not-running": "A projection holds queued prompts while its turn is not `running`; once per change of phase. Identifiers, phase and queue length only.",
851
866
  ...THROTTLE_LOG_EVENTS
852
867
  }
853
868
  },
@@ -1322,6 +1337,7 @@ var BUILD_PIPELINE_LOG_AREAS = defineLogAreas({
1322
1337
  "sidebar.reconcile-failed": "Sidebar activity for pipelines could not be reconciled.",
1323
1338
  "sidebar.update-failed": "The sidebar could not be updated for one pipeline.",
1324
1339
  "result.consume-deferred": "Consuming a stage's workflow result failed; it stays staged and is retried.",
1340
+ "review.prompt-reads": "A review fan-out pass built or tried to build reviewer prompts; how many it built, and how often building them read the review instruction and project notes, failed reads included. Counts only.",
1325
1341
  "consolidation.consume-deferred": "Consuming a review consolidation result failed; it stays pending and is retried.",
1326
1342
  "dispatch.prepare-failed": "Attaching the agent before dispatch failed; the prompt request does the same work and answers authoritatively.",
1327
1343
  "interaction.resolved": "A human interaction on a pipeline stage resolved. Metadata only.",
@@ -1370,6 +1386,8 @@ var CHANGE_TRACKING_LOG_AREAS = defineLogAreas({
1370
1386
  "retention.failed": "A retention pass failed partway; what it deleted stands and the next pass goes on.",
1371
1387
  "projection.failed": "Projecting a change event onto its environment failed.",
1372
1388
  "startup.reconcile-failed": "Reconciling change tracking at startup failed.",
1389
+ "deleted-environments.purge-requested": "The startup reconcile found ledger rows of environments the environment store no longer holds and requested their purge.",
1390
+ "deleted-environments.reconcile-failed": "The startup reconcile of deleted environments could not read the environment store, so it requested no purge.",
1373
1391
  "turn-start.capture-failed": "Capturing a turn's start failed, so the turn is untracked.",
1374
1392
  "dispatch.record-failed": "Recording a turn's dispatch outcome failed.",
1375
1393
  "turn.finalize-failed": "Finalizing a turn failed.",
@@ -1610,9 +1628,15 @@ var DOCKER_LOG_AREAS = defineLogAreas({
1610
1628
  essential: true,
1611
1629
  fields: { staleForMs: "number" }
1612
1630
  },
1613
- "writer-lease.listener-failed": "The callback told about a lost registry writer lease threw, so the schedules settings learn of the loss only at their next read.",
1631
+ "writer-lease.listener-failed": "The callback told about a lost, or a late-won, registry writer lease threw, so the schedules settings learn of the change only at their next read.",
1632
+ "writer-lease.acquired-late": {
1633
+ description: "A backend that started without the registry writer lease won it later, because its holder stopped refreshing it (most often a crash just before this backend started). Schedules fire and container changes are allowed from now on; the `writer-lease.regained` line before it gives the stale lease's age.",
1634
+ essential: true,
1635
+ fields: {}
1636
+ },
1637
+ "writer-lease.retry-failed": "A backend without the registry writer lease could not try for it again for a reason other than the lease being held (an unreadable data directory, say). It tries again on its next tick.",
1614
1638
  "writer-lease.not-acquired": {
1615
- description: "This backend started without the registry writer lease, for the fixed `reason` given. A second backend on one data directory is normal: it serves reads, runs no schedules and refuses container changes.",
1639
+ description: "This backend started without the registry writer lease, for the fixed `reason` given. A second backend on one data directory is normal: it serves reads, runs no schedules and refuses container changes. A `busy` one keeps trying and writes `writer-lease.acquired-late` if it wins the lease once its holder stops refreshing it.",
1616
1640
  essential: true,
1617
1641
  fields: { reason: "label" }
1618
1642
  },
@@ -1813,6 +1837,7 @@ var FEATURE_LOG_AREAS = defineLogAreas({
1813
1837
  feature: {
1814
1838
  description: "Pipeline environments started from a feature, and feature planning.",
1815
1839
  events: {
1840
+ "debug-build.launched": "The debug button's pipeline environment was launched. Ids and counts only: no ticket text, transcript or screenshot.",
1816
1841
  "naming.fallback": "Automatic naming failed, so a local fallback name is used. Error kind only: the description stays out.",
1817
1842
  "planning.legacy-adopt-failed": "Legacy planning conversations could not be adopted.",
1818
1843
  "planning.tick-retrying": "A planning tick failed on a transient error; the next tick retries."
@@ -2704,6 +2729,28 @@ var BRIDGE_LISTENER_REASONS = new Set([
2704
2729
  "no-listener",
2705
2730
  "launch-exited"
2706
2731
  ]);
2732
+ var CLAUDE_RESULT_SUBTYPES = new Set([
2733
+ "success",
2734
+ "error_during_execution",
2735
+ "error_max_turns",
2736
+ "error_max_budget_usd",
2737
+ "error_max_structured_output_retries"
2738
+ ]);
2739
+ var CLAUDE_API_ERRORS = new Set([
2740
+ "authentication_failed",
2741
+ "oauth_org_not_allowed",
2742
+ "account_on_hold",
2743
+ "verification_required",
2744
+ "billing_error",
2745
+ "rate_limit",
2746
+ "overloaded",
2747
+ "invalid_request",
2748
+ "model_not_found",
2749
+ "server_error",
2750
+ "unknown",
2751
+ "max_output_tokens",
2752
+ "cloud_credential_error"
2753
+ ]);
2707
2754
  var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
2708
2755
  var SOURCE = new RegExp(`^(?:claude|codex|opencode|cursor|grok|acp|pi):${UUID}$`, "i");
2709
2756
  var STORAGE_DATABASES = new Set(["main", "ledger", "other"]);
@@ -8780,12 +8827,23 @@ function withUnattendedOverloadRetry(sessionPolicy, environment) {
8780
8827
  }
8781
8828
  var READ_ONLY_GIT_CONFIG = Object.freeze([
8782
8829
  ["core.fsmonitor", "false"],
8783
- ["core.hooksPath", "/dev/null"]
8830
+ ["core.hooksPath", "/dev/null"],
8831
+ ["diff.submodule", "short"],
8832
+ ["log.diffMerges", "separate"],
8833
+ ["log.showSignature", "false"],
8834
+ ["gpg.program", "false"],
8835
+ ["gpg.openpgp.program", "false"],
8836
+ ["gpg.ssh.program", "false"],
8837
+ ["gpg.x509.program", "false"]
8784
8838
  ]);
8839
+ var READ_ONLY_GIT_ENV = Object.freeze({
8840
+ GIT_OPTIONAL_LOCKS: "0",
8841
+ GIT_NO_LAZY_FETCH: "1"
8842
+ });
8785
8843
  function withReadOnlyGitConfig(turnPolicy, environment) {
8786
8844
  if (turnPolicy?.id !== "coordinator-read-only")
8787
8845
  return environment;
8788
- const next = { ...environment, GIT_OPTIONAL_LOCKS: "0" };
8846
+ const next = { ...environment, ...READ_ONLY_GIT_ENV };
8789
8847
  const inherited = Number.parseInt(next.GIT_CONFIG_COUNT ?? "", 10);
8790
8848
  let count = Number.isSafeInteger(inherited) && inherited > 0 ? inherited : 0;
8791
8849
  for (const [key, value] of READ_ONLY_GIT_CONFIG) {
@@ -9185,7 +9243,10 @@ function readToolRefused(boundary, tool, input, cwd) {
9185
9243
  function shellCommandRefused(boundary, command, cwd, options) {
9186
9244
  const [program, ...tokens] = command.trim().split(/\s+/);
9187
9245
  if (options.traversal) {
9188
- const indirectOption = program === "sort" || program === "wc" ? "--files0-from" : program === "file" ? "--files-from" : ["cksum", "md5sum", "sha1sum", "sha256sum"].includes(program ?? "") ? "--check" : undefined;
9246
+ if (program === "find" && tokens.some((token) => /^--?files0-from(?:=|$)/.test(token))) {
9247
+ return true;
9248
+ }
9249
+ const indirectOption = program === "sort" || program === "wc" || program === "du" ? "--files0-from" : program === "file" ? "--files-from" : ["cksum", "md5sum", "sha1sum", "sha256sum"].includes(program ?? "") ? "--check" : undefined;
9189
9250
  if (indirectOption && tokens.some((token) => {
9190
9251
  const option = token.split("=", 1)[0];
9191
9252
  return option.startsWith("--") && indirectOption.startsWith(option) || program === "file" && /^-[^-]*f/.test(token) || indirectOption === "--check" && /^-[^-]*c/.test(token);
@@ -9354,6 +9415,41 @@ var GIT_MUTATING_ARGUMENTS = new Set([
9354
9415
  var GIT_SUBCOMMAND_MUTATING_ARGUMENTS = new Map([
9355
9416
  ["grep", new Set(["-O", "--open-files-in-pager"])]
9356
9417
  ]);
9418
+ var HARDENED_DIFF_ARGUMENTS = [
9419
+ "--no-ext-diff",
9420
+ "--no-textconv",
9421
+ "--submodule=short"
9422
+ ];
9423
+ var HARDENED_GIT_ARGUMENTS = new Map([
9424
+ ["blame", ["--no-textconv"]],
9425
+ ["diff", HARDENED_DIFF_ARGUMENTS],
9426
+ ["log", HARDENED_DIFF_ARGUMENTS],
9427
+ ["show", HARDENED_DIFF_ARGUMENTS],
9428
+ ["whatchanged", HARDENED_DIFF_ARGUMENTS]
9429
+ ]);
9430
+ var HARDENED_LOG_REFUSED_ARGUMENTS = new Set([
9431
+ "--submodule",
9432
+ "--remerge-diff"
9433
+ ]);
9434
+ var HARDENED_GIT_REFUSED_ARGUMENTS = new Map([
9435
+ ["diff", new Set(["--submodule"])],
9436
+ ["log", HARDENED_LOG_REFUSED_ARGUMENTS],
9437
+ ["show", HARDENED_LOG_REFUSED_ARGUMENTS],
9438
+ ["status", new Set(["-v", "--verbose"])],
9439
+ ["whatchanged", HARDENED_LOG_REFUSED_ARGUMENTS]
9440
+ ]);
9441
+ var HARDENED_LOG_SUBCOMMANDS = new Set(["log", "show", "whatchanged"]);
9442
+ var REMERGE_DIFF_MERGES_VALUES = new Set(["r", "remerge"]);
9443
+ function remergeDiffSelected(args) {
9444
+ return args.some((arg, index) => {
9445
+ const equals = arg.indexOf("=");
9446
+ const name = equals >= 0 ? arg.slice(0, equals) : arg;
9447
+ if (name.length <= 2 || !"--diff-merges".startsWith(name))
9448
+ return false;
9449
+ const value = equals >= 0 ? arg.slice(equals + 1) : args[index + 1];
9450
+ return value === undefined || REMERGE_DIFF_MERGES_VALUES.has(value.toLowerCase());
9451
+ });
9452
+ }
9357
9453
  var READ_ONLY_GIT_SUBCOMMANDS = Object.freeze(new Set([
9358
9454
  "blame",
9359
9455
  "cat-file",
@@ -9418,7 +9514,7 @@ var GIT_CONFIG_WRITE_SUBCOMMANDS = Object.freeze(new Set(["edit", "remove-sectio
9418
9514
  var GIT_REMOTE_READ_SUBCOMMANDS = Object.freeze(new Set(["get-url"]));
9419
9515
  function hasFlag(args, flags) {
9420
9516
  const letters = [...flags].flatMap((flag) => /^-[A-Za-z0-9]$/.test(flag) ? [flag[1]] : []);
9421
- return args.some((arg) => flags.has(arg) || flags.has(arg.split("=", 1)[0] ?? arg) || arg.startsWith("--") && [...flags].some((flag) => flag.startsWith("--") && flag.startsWith(arg.split("=", 1)[0])) || /^-[^-]/.test(arg) && letters.some((letter) => arg.slice(1).includes(letter)));
9517
+ return args.some((arg) => flags.has(arg) || flags.has(arg.split("=", 1)[0] ?? arg) || arg.startsWith("--") && arg.split("=", 1)[0].length > 2 && [...flags].some((flag) => flag.startsWith("--") && flag.startsWith(arg.split("=", 1)[0])) || /^-[^-]/.test(arg) && letters.some((letter) => arg.slice(1).includes(letter)));
9422
9518
  }
9423
9519
  function listsRefsOnly(args) {
9424
9520
  if (hasFlag(args, GIT_REF_WRITE_FLAGS))
@@ -9453,7 +9549,7 @@ var CONDITIONAL_GIT_SUBCOMMANDS = new Map([
9453
9549
  ]);
9454
9550
  var NETWORK_COMMANDS = new Set(["curl", "gh", "wget"]);
9455
9551
  var NETWORK_GIT_SUBCOMMANDS = new Set(["fetch", "ls-remote", "pull"]);
9456
- var COMPOSITION_PATTERN = /[;&|><`$(){}\n\r'"\\*?[\]]|\bsudo\b|\bexec\b/;
9552
+ var COMPOSITION_PATTERN = /[;&><`$(){}\n\r'"\\*?[\]]|\bsudo\b|\bexec\b/;
9457
9553
  function isCoordinatorReadOnlyPolicy(policy) {
9458
9554
  return policy?.id === "coordinator-read-only";
9459
9555
  }
@@ -9513,7 +9609,7 @@ function readOnlyRefusalRole(sessionPolicy, readOnlyTurn, env = process.env) {
9513
9609
  }
9514
9610
  var REFUSALS = {
9515
9611
  coordinator: {
9516
- composition: "Coordinator shells cannot use quotes, escapes, globs, pipes, redirection, substitution or command chaining, because the command that runs would not be the one checked.",
9612
+ composition: "Coordinator shells cannot use quotes, escapes, globs, redirection, substitution or command chaining (`;`, `&&`, `||`), because the command that runs would not be the one checked. A plain pipe between reading commands is allowed.",
9517
9613
  byPath: (program) => `Coordinator shells run reading programs by name only, so \`${program}\` is not available here. Use the program name, or delegate it to a worker environment.`,
9518
9614
  gitSandbox: "Coordinator Git commands require the command sandbox because Git configuration can run helpers. Use reading tools or delegate to a worker environment.",
9519
9615
  unavailable: (described) => `Coordinator is read-only, so \`${described}\` is not available here. Delegate it to a worker environment.`,
@@ -9529,7 +9625,7 @@ var REFUSALS = {
9529
9625
  dataDirectory: "Coordinators cannot read Orkestrator's data directory, which holds credentials with wider authority than this conversation. This conversation's own tool results, memory and attachments stay readable."
9530
9626
  },
9531
9627
  "read-only": {
9532
- composition: "Shell commands in this session cannot use quotes, escapes, globs, pipes, redirection, substitution or command chaining, because the command that runs would not be the one checked.",
9628
+ composition: "Shell commands in this session cannot use quotes, escapes, globs, redirection, substitution or command chaining (`;`, `&&`, `||`), because the command that runs would not be the one checked. A plain pipe between reading commands is allowed.",
9533
9629
  byPath: (program) => `This session runs reading programs by name only, so \`${program}\` is not available here. Use the program name.`,
9534
9630
  gitSandbox: "Git commands in this session require the command sandbox because Git configuration can run helpers. Use reading tools instead.",
9535
9631
  unavailable: (described) => `This session is read-only, so \`${described}\` is not available here.`,
@@ -9549,11 +9645,34 @@ function isReadOnlyShellCommand(command, options = {}) {
9549
9645
  const refusals = REFUSALS[options.role ?? "coordinator"];
9550
9646
  const trimmed = command.trim();
9551
9647
  if (!trimmed)
9552
- return { allowed: true };
9553
- if (COMPOSITION_PATTERN.test(trimmed) || /(?:^|\s)~/.test(trimmed)) {
9648
+ return { allowed: true, stages: [] };
9649
+ if (COMPOSITION_PATTERN.test(trimmed)) {
9650
+ return { allowed: false, reason: refusals.composition };
9651
+ }
9652
+ const stages = trimmed.split("|").map((stage) => stage.trim());
9653
+ if (stages.length > 1 && stages.some((stage) => !stage)) {
9654
+ return { allowed: false, reason: refusals.composition };
9655
+ }
9656
+ const runs = [];
9657
+ for (const stage of stages) {
9658
+ const verdict = isReadOnlyCommandStage(stage, options);
9659
+ if (!verdict.allowed)
9660
+ return verdict;
9661
+ runs.push(verdict.command ?? stage);
9662
+ }
9663
+ const rewritten = runs.some((run, index) => run !== stages[index]);
9664
+ return {
9665
+ allowed: true,
9666
+ stages: runs,
9667
+ ...rewritten ? { command: runs.join(" | ") } : {}
9668
+ };
9669
+ }
9670
+ function isReadOnlyCommandStage(command, options) {
9671
+ const refusals = REFUSALS[options.role ?? "coordinator"];
9672
+ if (/(?:^|\s)~/.test(command)) {
9554
9673
  return { allowed: false, reason: refusals.composition };
9555
9674
  }
9556
- const tokens = trimmed.split(/\s+/).filter(Boolean);
9675
+ const tokens = command.split(/\s+/).filter(Boolean);
9557
9676
  const first = tokens[0] ?? "";
9558
9677
  if (!first)
9559
9678
  return { allowed: true };
@@ -9564,7 +9683,8 @@ function isReadOnlyShellCommand(command, options = {}) {
9564
9683
  if (NETWORK_COMMANDS.has(program))
9565
9684
  return { allowed: false, reason: refusals.network(program) };
9566
9685
  if (program === "git") {
9567
- if (options.commandSandbox !== "required") {
9686
+ const sandboxed = options.commandSandbox === "required";
9687
+ if (!sandboxed && options.gitWithoutSandbox !== "harden") {
9568
9688
  return { allowed: false, reason: refusals.gitSandbox };
9569
9689
  }
9570
9690
  const subcommandIndex = tokens.findIndex((token, index) => index > 0 && !token.startsWith("-"));
@@ -9585,7 +9705,18 @@ function isReadOnlyShellCommand(command, options = {}) {
9585
9705
  if (hasFlag(tokens.slice(1), GIT_MUTATING_ARGUMENTS) || hasFlag(args, GIT_SUBCOMMAND_MUTATING_ARGUMENTS.get(subcommand) ?? new Set)) {
9586
9706
  return { allowed: false, reason: refusals.gitArgument(described) };
9587
9707
  }
9588
- return { allowed: true };
9708
+ if (sandboxed)
9709
+ return { allowed: true };
9710
+ if (hasFlag(args, HARDENED_GIT_REFUSED_ARGUMENTS.get(subcommand) ?? new Set) || HARDENED_LOG_SUBCOMMANDS.has(subcommand) && remergeDiffSelected(args)) {
9711
+ return { allowed: false, reason: refusals.gitArgument(described) };
9712
+ }
9713
+ const hardening = HARDENED_GIT_ARGUMENTS.get(subcommand);
9714
+ if (!hardening)
9715
+ return { allowed: true };
9716
+ return {
9717
+ allowed: true,
9718
+ command: [...tokens.slice(0, subcommandIndex + 1), ...hardening, ...args].join(" ")
9719
+ };
9589
9720
  }
9590
9721
  if (READ_ONLY_COMMANDS.has(program)) {
9591
9722
  const args = tokens.slice(1);
@@ -9685,11 +9816,22 @@ function createCoordinatorReadOnlyHook(policy, researchMcpServerNames = coordina
9685
9816
  if (!verdict.allowed)
9686
9817
  return deny(verdict.reason);
9687
9818
  const boundary = readBoundary(input.cwd);
9688
- if (boundary && shellCommandRefused(boundary, command, input.cwd, {
9819
+ if (boundary && (verdict.stages ?? [command]).some((stage) => shellCommandRefused(boundary, stage, input.cwd, {
9689
9820
  traversal: options.commandSandbox === "unavailable"
9690
- })) {
9821
+ }))) {
9691
9822
  return deny(refusals.dataDirectory);
9692
9823
  }
9824
+ if (verdict.command !== undefined) {
9825
+ return {
9826
+ hookSpecificOutput: {
9827
+ hookEventName: "PreToolUse",
9828
+ updatedInput: {
9829
+ ...input.tool_input,
9830
+ command: verdict.command
9831
+ }
9832
+ }
9833
+ };
9834
+ }
9693
9835
  return {};
9694
9836
  }
9695
9837
  if (toolName === "Read" || toolName === "Grep" || toolName === "Glob") {
@@ -10755,7 +10897,18 @@ function resumeOrphanScanOutcome(message, previous) {
10755
10897
  return LIVE_BACKGROUND_TASK_STATUSES.has(previous.status) ? undefined : "already-settled";
10756
10898
  }
10757
10899
  function createClaudeRuntimeTasks() {
10758
- return { live: new Set, candidates: new Set, settling: new Map };
10900
+ return { live: new Set, candidates: new Set, settling: new Map, stopRequested: new Set };
10901
+ }
10902
+ function stopRequestedEdge(owner, taskId, status, options = {}) {
10903
+ if (!owner?.tasks.stopRequested.has(taskId))
10904
+ return false;
10905
+ if (status !== undefined && status !== "killed" && status !== "stopped") {
10906
+ owner.tasks.stopRequested.delete(taskId);
10907
+ return false;
10908
+ }
10909
+ if (options.consume)
10910
+ owner.tasks.stopRequested.delete(taskId);
10911
+ return true;
10759
10912
  }
10760
10913
  function backgroundTaskOwner(session, taskId) {
10761
10914
  const runtime = session.claudeRuntime;
@@ -11047,6 +11200,7 @@ function releaseClaudeRuntimeTasks(owner, reason) {
11047
11200
  const { session, tasks } = owner;
11048
11201
  tasks.candidates.clear();
11049
11202
  tasks.settling.clear();
11203
+ tasks.stopRequested.clear();
11050
11204
  let changed = false;
11051
11205
  for (const task of Object.values(session.backgroundTasks ?? {})) {
11052
11206
  if (!LIVE_BACKGROUND_TASK_STATUSES.has(task.status))
@@ -11068,14 +11222,20 @@ async function stopBackgroundTask(sessionId, taskId) {
11068
11222
  if (!task) {
11069
11223
  return { ok: false, reason: "task_not_found", message: "Task not found" };
11070
11224
  }
11071
- const control = backgroundTaskOwner(session, taskId)?.control;
11225
+ const owner = backgroundTaskOwner(session, taskId);
11226
+ const control = owner?.control;
11072
11227
  const stopTask = control?.stopTask;
11073
11228
  if (typeof stopTask !== "function") {
11074
11229
  return NO_CONTROL_CHANNEL;
11075
11230
  }
11231
+ const { stopRequested } = owner.tasks;
11232
+ if (stopRequested.has(taskId) || stopRequested.size < MAX_SETTLING_BACKGROUND_TASKS) {
11233
+ stopRequested.add(taskId);
11234
+ }
11076
11235
  try {
11077
11236
  await stopTask.call(control, taskId);
11078
11237
  } catch (error) {
11238
+ stopRequested.delete(taskId);
11079
11239
  const latest = session.backgroundTasks?.[taskId];
11080
11240
  if (latest && !LIVE_BACKGROUND_TASK_STATUSES.has(latest.status)) {
11081
11241
  return { ok: true };
@@ -11134,6 +11294,7 @@ function takeQueryControls(session) {
11134
11294
  runtime.tasks.live.clear();
11135
11295
  runtime.tasks.candidates.clear();
11136
11296
  runtime.tasks.settling.clear();
11297
+ runtime.tasks.stopRequested.clear();
11137
11298
  controls.add(runtime.control);
11138
11299
  }
11139
11300
  session.queryControl = undefined;
@@ -13122,7 +13283,8 @@ function claudeLaunchProfile(session, options, readOnlyCommandSandbox) {
13122
13283
  ...policy?.approvals !== "ask" && claudeAsksForApproval(policy, options) ? { asksForApproval: true } : {},
13123
13284
  ...isCoordinatorReadOnlyPolicy(policy) ? {
13124
13285
  agentMcp: options?.agentMcp !== undefined,
13125
- commandSandbox: sandbox.commandSandbox
13286
+ commandSandbox: sandbox.commandSandbox,
13287
+ role: readOnlyRefusalRole(session.executionPolicy, options?.readOnly === true)
13126
13288
  } : {}
13127
13289
  }),
13128
13290
  outputSchema: options?.outputSchema === undefined ? null : JSON.stringify(options.outputSchema),
@@ -18170,11 +18332,13 @@ function isUsageLimitError(error) {
18170
18332
  }
18171
18333
  }
18172
18334
  var USAGE_LIMITED_ERROR_PROPERTY = "usageLimited";
18173
- function markUsageLimitError(error) {
18335
+ var PROVIDER_REFUSED_ERROR_PROPERTY = "providerRefused";
18336
+ var TURN_FAILURE_REPORTED_PROPERTY = "turnFailureReported";
18337
+ function markErrorProperty(error, property) {
18174
18338
  if (typeof error !== "object" && typeof error !== "function" || error === null)
18175
18339
  return;
18176
18340
  try {
18177
- Object.defineProperty(error, USAGE_LIMITED_ERROR_PROPERTY, {
18341
+ Object.defineProperty(error, property, {
18178
18342
  value: true,
18179
18343
  configurable: true,
18180
18344
  enumerable: false,
@@ -18182,6 +18346,15 @@ function markUsageLimitError(error) {
18182
18346
  });
18183
18347
  } catch {}
18184
18348
  }
18349
+ function markUsageLimitError(error) {
18350
+ markErrorProperty(error, USAGE_LIMITED_ERROR_PROPERTY);
18351
+ }
18352
+ function markTurnFailureReported(error) {
18353
+ markErrorProperty(error, TURN_FAILURE_REPORTED_PROPERTY);
18354
+ }
18355
+ function markProviderRefusalError(error) {
18356
+ markErrorProperty(error, PROVIDER_REFUSED_ERROR_PROPERTY);
18357
+ }
18185
18358
  function ownsActiveTurn(turn) {
18186
18359
  const { session, sessionId } = turn;
18187
18360
  return !turn.abortController.signal.aborted && sessions.get(sessionId) === session && session.abortController === turn.abortController;
@@ -18466,6 +18639,8 @@ function createTurnState(session, sessionId, init) {
18466
18639
  settlingResult: false,
18467
18640
  localCommandOutputSeen: false,
18468
18641
  rateLimitRejected: false,
18642
+ apiErrorCode: undefined,
18643
+ providerStateFailure: undefined,
18469
18644
  lastThinkingTokensEmitAt: 0,
18470
18645
  compactedTokensBefore: undefined,
18471
18646
  pendingPlanRejectionFeedback: null,
@@ -20879,6 +21054,9 @@ var WORKFLOW_RESULT_TOOL_NAMES = {
20879
21054
  "subork-answer": "submit_subork_answer"
20880
21055
  };
20881
21056
  var WORKFLOW_RESULT_VALIDATION_TOOL_NAME = "validate_workflow_result";
21057
+ var WORKFLOW_RESULT_TOOL_META = Object.freeze({
21058
+ "anthropic/alwaysLoad": true
21059
+ });
20882
21060
  var REPORT_FINDING_TOOL_NAME = "report_finding";
20883
21061
  var WORKFLOW_RESULT_KEY_MAX_LENGTH = 128;
20884
21062
  var WORKFLOW_RESULT_TURN_MAX_SLOTS = 16;
@@ -21711,7 +21889,8 @@ function getSessionInitData(sessionId) {
21711
21889
  const session = sessions.get(sessionId);
21712
21890
  return session?.initData;
21713
21891
  }
21714
- async function getClaudeRuntimeVersions() {
21892
+ var CLAUDE_CLI_VERSION_PROBE_TIMEOUT_MS = 5000;
21893
+ async function getClaudeRuntimeVersions(probeTimeoutMs = CLAUDE_CLI_VERSION_PROBE_TIMEOUT_MS) {
21715
21894
  let sdkVersion;
21716
21895
  let bundledCliVersion;
21717
21896
  try {
@@ -21727,7 +21906,7 @@ async function getClaudeRuntimeVersions() {
21727
21906
  return { sdkVersion, cliVersion: bundledCliVersion };
21728
21907
  }
21729
21908
  try {
21730
- const output = await execFileText(executable, ["--version"], 5000);
21909
+ const output = await execFileText(executable, ["--version"], probeTimeoutMs);
21731
21910
  return {
21732
21911
  sdkVersion,
21733
21912
  cliVersion: output.match(/\d+\.\d+\.\d+/)?.[0] ?? bundledCliVersion
@@ -22059,7 +22238,7 @@ async function recordBackgroundTaskHook(turn, hookInput) {
22059
22238
  }, turn.runtime, { newRun: hookInput.hook_event_name === "SubagentStart" });
22060
22239
  } else {
22061
22240
  const taskId = hookInput.hook_event_name === "TaskCompleted" ? hookInput.task_id : hookInput.agent_id;
22062
- const settlesReleasedTurn = (turn.turnReleasedToBackgroundTasks || turn.settlingResult) && backgroundTaskOwner(session, taskId) === turn.runtime && LIVE_BACKGROUND_TASK_STATUSES.has(session.backgroundTasks?.[taskId]?.status ?? "completed");
22241
+ const settlesReleasedTurn = (turn.turnReleasedToBackgroundTasks || turn.settlingResult) && backgroundTaskOwner(session, taskId) === turn.runtime && LIVE_BACKGROUND_TASK_STATUSES.has(session.backgroundTasks?.[taskId]?.status ?? "completed") && !stopRequestedEdge(turn.runtime, taskId, undefined);
22063
22242
  if (settlesReleasedTurn) {
22064
22243
  turn.receivedResult = false;
22065
22244
  waitForContinuationAfterNotification(turn);
@@ -22318,6 +22497,7 @@ function claudeQueryOptions(turn, plan, turnFor, mcp) {
22318
22497
  queryEnvironment
22319
22498
  } = plan;
22320
22499
  const managedSettings = claudeManagedSettings(policy);
22500
+ const readOnlyTurnRole = readOnlyRefusalRole(session.executionPolicy, options?.readOnly === true);
22321
22501
  const latestTurnHook = (pick) => (...args) => pick(turnFor())(...args);
22322
22502
  const backgroundTaskHook = latestTurnHook((target) => target.recordBackgroundTaskHook);
22323
22503
  const commandChangeHook = commandChangeHookFor(turnFor, session.id);
@@ -22394,7 +22574,8 @@ function claudeQueryOptions(turn, plan, turnFor, mcp) {
22394
22574
  hooks: [
22395
22575
  recordingHookDenials(createCoordinatorReadOnlyHook(policy, undefined, {
22396
22576
  ...readOnlyCommandSandbox ? { commandSandbox: readOnlyCommandSandbox.commandSandbox } : {},
22397
- role: readOnlyRefusalRole(session.executionPolicy, options?.readOnly === true)
22577
+ role: readOnlyTurnRole,
22578
+ gitWithoutSandbox: readOnlyTurnRole === "read-only" ? "harden" : "refuse"
22398
22579
  }), session.id)
22399
22580
  ]
22400
22581
  }
@@ -22449,6 +22630,29 @@ function observeClaudeMessage(diagnostics, message) {
22449
22630
  }
22450
22631
  }
22451
22632
 
22633
+ // ../../bridges/claude-bridge/src/services/claude-api-errors.ts
22634
+ var CLAUDE_API_ERROR_FATES = {
22635
+ authentication_failed: "provider-state",
22636
+ oauth_org_not_allowed: "provider-state",
22637
+ account_on_hold: "provider-state",
22638
+ verification_required: "provider-state",
22639
+ billing_error: "provider-state",
22640
+ rate_limit: "provider-state",
22641
+ overloaded: "provider-state",
22642
+ server_error: "provider-state",
22643
+ cloud_credential_error: "provider-state",
22644
+ invalid_request: "failure",
22645
+ model_not_found: "failure",
22646
+ max_output_tokens: "failure",
22647
+ unknown: "failure"
22648
+ };
22649
+ function claudeApiErrorCode(value) {
22650
+ return typeof value === "string" && Object.hasOwn(CLAUDE_API_ERROR_FATES, value) ? value : undefined;
22651
+ }
22652
+ function providerStateApiError(code) {
22653
+ return code && CLAUDE_API_ERROR_FATES[code] === "provider-state" ? code : undefined;
22654
+ }
22655
+
22452
22656
  // ../../bridges/claude-bridge/src/services/session-auth-notice.ts
22453
22657
  var CLAUDE_LOGIN_REFUSED_MESSAGE = "Claude's login was refused. Sign in to Claude again to keep working.";
22454
22658
  var MAX_NOTICE_LENGTH = 500;
@@ -22536,6 +22740,9 @@ function handleAssistantMessage(turn, message) {
22536
22740
  const receivedAt = new Date().toISOString();
22537
22741
  const recordUnknownContentBlock = (blockType) => sessionHealth(session).recordUnknown(`block:${blockType}`);
22538
22742
  const assistantError = message.error;
22743
+ if (message.parent_tool_use_id == null) {
22744
+ turn.apiErrorCode = claudeApiErrorCode(assistantError);
22745
+ }
22539
22746
  if (assistantError === "authentication_failed") {
22540
22747
  noteClaudeAuthenticationFailure();
22541
22748
  noteSessionLoginRefused(session, sessionId, typeof message.uuid === "string" ? message.uuid : crypto.randomUUID());
@@ -23105,10 +23312,23 @@ async function handleResultMessage(turn, message) {
23105
23312
  } else {
23106
23313
  const startupFailure = resultMsg.startup_failure_reason ? withStartupFailureDetail(claudeStartupFailureMessage(resultMsg.startup_failure_reason), resultMsg.errors) : undefined;
23107
23314
  const usageLimit = resultMsg.subtype === "success" && classifyUsageLimitError(resultMsg.result) ? resultMsg.result.trim().slice(0, MAX_USAGE_LIMIT_ERROR_CHARS) : undefined;
23315
+ const apiStatus = typeof resultMsg.api_error_status === "number" ? resultMsg.api_error_status : undefined;
23316
+ const apiErrorCode = resultIsError ? turn.apiErrorCode : undefined;
23317
+ const providerState = startupFailure ? undefined : providerStateApiError(apiErrorCode);
23108
23318
  if (!startupFailure && (usageLimit || turn.rateLimitRejected)) {
23109
23319
  log15.warn("query.usage-limited", { subtype: resultMsg.subtype, sessionId });
23320
+ } else if (providerState) {
23321
+ turn.providerStateFailure = providerState;
23322
+ log15.warn("query.provider-refused", { reason: providerState, apiStatus, sessionId });
23110
23323
  } else {
23111
- log15.error("query.failed", { subtype: resultMsg.subtype, sessionId, isError: resultIsError });
23324
+ log15.error("query.failed", {
23325
+ subtype: resultMsg.subtype,
23326
+ sessionId,
23327
+ isError: resultIsError,
23328
+ reason: apiErrorCode,
23329
+ apiStatus,
23330
+ startupFailure: resultMsg.startup_failure_reason !== undefined
23331
+ });
23112
23332
  }
23113
23333
  const resultError = startupFailure || resultMsg.errors?.filter(Boolean).join(`
23114
23334
  `) || usageLimit || (resultMsg.subtype === "success" ? "Claude ended the turn on an API error." : `Claude query failed: ${resultMsg.subtype}`);
@@ -23198,7 +23418,7 @@ function handleTaskEdge(turn, message) {
23198
23418
  } else {
23199
23419
  const owner = backgroundTaskOwner(session, task.id) ?? correlated.owner;
23200
23420
  session.claudeRuntime?.tasks.live.delete(task.id);
23201
- if (owner === turn.runtime && turn.turnReleasedToBackgroundTasks && previous !== undefined && LIVE_BACKGROUND_TASK_STATUSES.has(previous.status)) {
23421
+ if (owner === turn.runtime && turn.turnReleasedToBackgroundTasks && previous !== undefined && LIVE_BACKGROUND_TASK_STATUSES.has(previous.status) && !stopRequestedEdge(owner, task.id, task.status)) {
23202
23422
  turn.receivedResult = false;
23203
23423
  waitForContinuationAfterNotification(turn);
23204
23424
  }
@@ -23216,7 +23436,10 @@ function handleTaskNotification(turn, message) {
23216
23436
  if (isHookRunningBackgroundTask(session.backgroundTasks?.[notification.task_id])) {
23217
23437
  return "stop";
23218
23438
  }
23219
- turn.receivedResult = false;
23439
+ const markedRuntime = session.claudeRuntime?.tasks.stopRequested.has(notification.task_id) ? session.claudeRuntime : undefined;
23440
+ const stoppedHere = stopRequestedEdge(session.claudeRuntime, notification.task_id, notification.status, { consume: true });
23441
+ if (!stoppedHere)
23442
+ turn.receivedResult = false;
23220
23443
  const correlated = takeProvisionalBackgroundTask(session, notification.tool_use_id);
23221
23444
  const parked = takeSettlingBackgroundTask(session, notification.task_id);
23222
23445
  const previous = session.backgroundTasks?.[notification.task_id] ?? parked?.task ?? correlated.task;
@@ -23252,9 +23475,9 @@ function handleTaskNotification(turn, message) {
23252
23475
  ...session.backgroundTasks,
23253
23476
  [task.id]: task
23254
23477
  });
23255
- const owner = backgroundTaskOwner(session, task.id) ?? parked?.owner ?? correlated.owner;
23478
+ const owner = backgroundTaskOwner(session, task.id) ?? parked?.owner ?? correlated.owner ?? (stoppedHere ? undefined : markedRuntime);
23256
23479
  session.claudeRuntime?.tasks.live.delete(task.id);
23257
- if (owner === turn.runtime && turn.turnReleasedToBackgroundTasks) {
23480
+ if (!stoppedHere && owner === turn.runtime && turn.turnReleasedToBackgroundTasks) {
23258
23481
  waitForContinuationAfterNotification(turn);
23259
23482
  }
23260
23483
  emitBackgroundTasks(turn);
@@ -23324,6 +23547,8 @@ function handleBackgroundTasksChanged(turn, message) {
23324
23547
  for (const task of droppedByThisQuery) {
23325
23548
  parkSettlingBackgroundTask(runtime, task);
23326
23549
  }
23550
+ }
23551
+ if (turn.turnReleasedToBackgroundTasks && droppedByThisQuery.some((task) => !stopRequestedEdge(runtime, task.id, undefined))) {
23327
23552
  turn.receivedResult = false;
23328
23553
  waitForContinuationAfterNotification(turn);
23329
23554
  }
@@ -24359,12 +24584,20 @@ function settleFailedTurn(turn, error) {
24359
24584
  }
24360
24585
  const killedBy = killedClaudeProcessSignal(error);
24361
24586
  const usageLimited = !killedBy && (turn.rateLimitRejected || isUsageLimitError(error));
24587
+ const providerState = killedBy ? undefined : turn.providerStateFailure;
24362
24588
  if (usageLimited) {
24363
24589
  log19.warn("prompt.usage-limited", { errorClass: diagnosticErrorClass(error) });
24364
24590
  markUsageLimitError(error);
24591
+ } else if (providerState) {
24592
+ log19.warn("prompt.provider-refused", {
24593
+ errorClass: diagnosticErrorClass(error),
24594
+ reason: providerState
24595
+ });
24596
+ markProviderRefusalError(error);
24365
24597
  } else {
24366
24598
  log19.error("prompt.failed", { errorClass: diagnosticErrorClass(error) });
24367
24599
  }
24600
+ markTurnFailureReported(error);
24368
24601
  if (session.abortController === abortController) {
24369
24602
  const failure = killedBy ? claudeProcessKilledMessage(killedBy) : error instanceof Error ? error.message : String(error);
24370
24603
  if (options?.outputSchema && structuredRequestId && !session.structuredOutput) {
@@ -25750,11 +25983,33 @@ function isUsageLimitedRejection(error) {
25750
25983
  return false;
25751
25984
  }
25752
25985
  }
25986
+ function isProviderRefusedRejection(error) {
25987
+ try {
25988
+ return error?.providerRefused === true;
25989
+ } catch {
25990
+ return false;
25991
+ }
25992
+ }
25993
+ function isReportedTurnFailure(error) {
25994
+ try {
25995
+ return error?.turnFailureReported === true;
25996
+ } catch {
25997
+ return false;
25998
+ }
25999
+ }
25753
26000
  function logPromptProcessingFailure(error) {
25754
26001
  if (isUsageLimitedRejection(error)) {
25755
26002
  log24.debug("prompt.processing-usage-limited");
25756
26003
  return;
25757
26004
  }
26005
+ if (isProviderRefusedRejection(error)) {
26006
+ log24.debug("prompt.processing-provider-refused");
26007
+ return;
26008
+ }
26009
+ if (isReportedTurnFailure(error)) {
26010
+ log24.debug("prompt.processing-reported", { error: formatLogError(error) });
26011
+ return;
26012
+ }
25758
26013
  log24.error("prompt.processing-failed", { error: formatLogError(error) });
25759
26014
  }
25760
26015
  var STALE_PROMPT_STATUS = 409;