From bb1c5afcb04823211828222f363f3566a71e3ff0 Mon Sep 17 00:00:00 2001 From: sjw1231 Date: Mon, 9 Nov 2026 17:35:22 +0800 Subject: [PATCH 1/5] refactor(bash,pwsh): report unadvertised sandbox_permissions as ToolArgsError Without a sandboxing executor the schema omits sandbox_permissions, so a forced value is an argument the model must drop rather than an approval that cannot be routed. Report it as ToolArgsError / INVALID_ARGS, matching tool-fs, and keep SANDBOX_ESCALATION_UNAVAILABLE for compositions that lack an approval service, calling Agent, or approval channel. Refs #7869 --- packages/sandbox/sandbox/README.i18n.yaml | 4 ++-- packages/sandbox/sandbox/README.md | 2 +- packages/sandbox/sandbox/README.zh.md | 2 +- packages/sandbox/sandbox/src/escalation.ts | 4 ++-- packages/shell/tool-bash/README.i18n.yaml | 8 ++++---- packages/shell/tool-bash/README.md | 4 ++-- packages/shell/tool-bash/README.zh.md | 4 ++-- packages/shell/tool-bash/src/index.ts | 7 ++----- packages/shell/tool-bash/tests/tools.spec.ts | 4 ++-- packages/shell/tool-pwsh/README.i18n.yaml | 8 ++++---- packages/shell/tool-pwsh/README.md | 4 ++-- packages/shell/tool-pwsh/README.zh.md | 4 ++-- packages/shell/tool-pwsh/src/index.ts | 7 ++----- packages/shell/tool-pwsh/tests/tools.spec.ts | 4 ++-- 14 files changed, 30 insertions(+), 36 deletions(-) diff --git a/packages/sandbox/sandbox/README.i18n.yaml b/packages/sandbox/sandbox/README.i18n.yaml index 7cd5cd3e7c..0f01c40f28 100644 --- a/packages/sandbox/sandbox/README.i18n.yaml +++ b/packages/sandbox/sandbox/README.i18n.yaml @@ -27,8 +27,8 @@ en: d3c906ddb4c47cbc zh: d264b9103e3566d6 /deepseek-ai-dsh-sandbox/use-this-package/denied-calls-and-escalation: - en: 0572a2aa3208873f - zh: 07e5d481a637a5af + en: a0d3b28a785797fa + zh: b45bd41a97d51b0a /deepseek-ai-dsh-sandbox/use-this-package/fail-closed-behavior: en: b3d36b28566cadd4 zh: 22cf905bf574865a diff --git a/packages/sandbox/sandbox/README.md b/packages/sandbox/sandbox/README.md index 3db483c834..c2d5eacd3f 100644 --- a/packages/sandbox/sandbox/README.md +++ b/packages/sandbox/sandbox/README.md @@ -63,7 +63,7 @@ Enforcement is reported per call: `full` means the backend governs every promise ### Denied calls and escalation -When a confined call is denied, the operation reports a denial marker naming the mode — `[sandbox: file access denied under mode]` — and, when the composition advertises escalation, an escalation hint. The model may retry the exact call once with `sandbox_permissions` (the narrowest wider mode that suffices) plus a `justification`; the approval service obtains consent for the operation. The request retains its audit reason and supplies English, Chinese, and Japanese presentation copy from `src/locales.ts`, with the model's justification unchanged. Missing translations follow the locale service's fallback chain, ultimately English; requesters own their translated presentation text. A wider mode requires approval and applies to that one call only. Repeating the call's effective mode succeeds without approval; narrower targets remain invalid. An escalation that yields no grant throws `SandboxEscalationError` before anything runs: `SANDBOX_ESCALATION_INVALID_ARGUMENT` for unpaired fields, a blank justification, or a target that is not strictly wider; `SANDBOX_ESCALATION_UNAVAILABLE` when the composition has no sandboxing executor, approval service, calling Agent, or approval channel; `SANDBOX_ESCALATION_REJECTED` when the user declines; and `SANDBOX_ESCALATION_CANCELLED` when the approval request ends without a decision. If the call itself was cancelled, the call's cancellation propagates instead. +When a confined call is denied, the operation reports a denial marker naming the mode — `[sandbox: file access denied under mode]` — and, when the composition advertises escalation, an escalation hint. The model may retry the exact call once with `sandbox_permissions` (the narrowest wider mode that suffices) plus a `justification`; the approval service obtains consent for the operation. The request retains its audit reason and supplies English, Chinese, and Japanese presentation copy from `src/locales.ts`, with the model's justification unchanged. Missing translations follow the locale service's fallback chain, ultimately English; requesters own their translated presentation text. A wider mode requires approval and applies to that one call only. Repeating the call's effective mode succeeds without approval; narrower targets remain invalid. An escalation that yields no grant throws `SandboxEscalationError` before anything runs: `SANDBOX_ESCALATION_INVALID_ARGUMENT` for unpaired fields, a blank justification, or a target that is not strictly wider; `SANDBOX_ESCALATION_UNAVAILABLE` when the composition has no approval service, calling Agent, or approval channel; `SANDBOX_ESCALATION_REJECTED` when the user declines; and `SANDBOX_ESCALATION_CANCELLED` when the approval request ends without a decision. If the call itself was cancelled, the call's cancellation propagates instead. ### Fail-closed behavior diff --git a/packages/sandbox/sandbox/README.zh.md b/packages/sandbox/sandbox/README.zh.md index 6e9710cde9..7c2df4bdb6 100644 --- a/packages/sandbox/sandbox/README.zh.md +++ b/packages/sandbox/sandbox/README.zh.md @@ -63,7 +63,7 @@ kind: "package-reference" ### 被拒绝的调用与升权 -受限调用被拒绝时,操作会报告指明模式的拒绝标记——`[sandbox: file access denied under mode]`——组合声明升权能力时还会给出升权提示。模型可以用 `sandbox_permissions`(足以放行的最窄更宽模式)加 `justification` 重试一次完全相同的调用;审批服务为操作取得同意。请求保留审计原因,同时从 `src/locales.ts` 提供英文、中文和日文展示文案,模型给出的理由保持原样。缺失的译文遵循语言服务的回退链,最终回退到英文;请求方负责自己的展示译文。更宽的模式需要审批,且只作用于该次调用。重复指定调用的生效模式无需审批即可成功;更窄的目标仍然无效。未取得授权的升权会在任何命令运行前抛出 `SandboxEscalationError`:字段未配对、理由为空或目标并非严格更宽时为 `SANDBOX_ESCALATION_INVALID_ARGUMENT`;组合中没有受限执行器、审批服务、调用方 Agent 或审批通道时为 `SANDBOX_ESCALATION_UNAVAILABLE`;用户拒绝时为 `SANDBOX_ESCALATION_REJECTED`;审批请求未作决定即结束时为 `SANDBOX_ESCALATION_CANCELLED`。若调用本身已被取消,则改为传播该调用的取消。 +受限调用被拒绝时,操作会报告指明模式的拒绝标记——`[sandbox: file access denied under mode]`——组合声明升权能力时还会给出升权提示。模型可以用 `sandbox_permissions`(足以放行的最窄更宽模式)加 `justification` 重试一次完全相同的调用;审批服务为操作取得同意。请求保留审计原因,同时从 `src/locales.ts` 提供英文、中文和日文展示文案,模型给出的理由保持原样。缺失的译文遵循语言服务的回退链,最终回退到英文;请求方负责自己的展示译文。更宽的模式需要审批,且只作用于该次调用。重复指定调用的生效模式无需审批即可成功;更窄的目标仍然无效。未取得授权的升权会在任何命令运行前抛出 `SandboxEscalationError`:字段未配对、理由为空或目标并非严格更宽时为 `SANDBOX_ESCALATION_INVALID_ARGUMENT`;组合中没有审批服务、调用方 Agent 或审批通道时为 `SANDBOX_ESCALATION_UNAVAILABLE`;用户拒绝时为 `SANDBOX_ESCALATION_REJECTED`;审批请求未作决定即结束时为 `SANDBOX_ESCALATION_CANCELLED`。若调用本身已被取消,则改为传播该调用的取消。 ### 故障关闭行为 diff --git a/packages/sandbox/sandbox/src/escalation.ts b/packages/sandbox/sandbox/src/escalation.ts index 7e0193b6c8..86b6a30307 100644 --- a/packages/sandbox/sandbox/src/escalation.ts +++ b/packages/sandbox/sandbox/src/escalation.ts @@ -25,8 +25,8 @@ import type { SandboxMode } from './index.ts' * Every {@link SandboxEscalationError} code: * - `SANDBOX_ESCALATION_INVALID_ARGUMENT` — the escalation fields are unpaired, the justification is blank, or the * target is not strictly wider than the call's effective mode; the model corrects the request. - * - `SANDBOX_ESCALATION_UNAVAILABLE` — the composition cannot ask for approval: no sandboxing executor, no approval - * service, no calling Agent, or no approval channel. + * - `SANDBOX_ESCALATION_UNAVAILABLE` — the composition cannot ask for approval: no approval service, no calling Agent, + * or no approval channel. * - `SANDBOX_ESCALATION_REJECTED` — the user declined the escalation; the operation stays denied. * - `SANDBOX_ESCALATION_CANCELLED` — the approval request ended without a decision while the call itself was not cancelled. */ diff --git a/packages/shell/tool-bash/README.i18n.yaml b/packages/shell/tool-bash/README.i18n.yaml index 95fd6ed161..1de4085f2d 100644 --- a/packages/shell/tool-bash/README.i18n.yaml +++ b/packages/shell/tool-bash/README.i18n.yaml @@ -33,8 +33,8 @@ en: 472beeb895ca46cf zh: ba110c9f62f7d5b8 /deepseek-ai-dsh-tool-bash/use-this-package/what-can-go-wrong: - en: cc9a6cc87468d73a - zh: aaa94162ef9de2f0 + en: c1f4b88a5fd84616 + zh: 8f7328b9edab462f /deepseek-ai-dsh-tool-bash/understand-the-implementation: en: 165313776a851b51 zh: 828f48807036aff0 @@ -111,8 +111,8 @@ en: 2d4f2c8605eccab3 zh: 67f1f0218f73c6bf /deepseek-ai-dsh-tool-bash/model-experience/tool-errors/what-the-model-sees: - en: 1772eedea1c1ee6a - zh: a0d77bdd515cb517 + en: 138222f326a3ade3 + zh: 9cd72b361b65fe2b /deepseek-ai-dsh-tool-bash/model-experience/tool-errors/token-effect: en: a3a78ef476ec5e56 zh: dd2c8ad0f69e8ff1 diff --git a/packages/shell/tool-bash/README.md b/packages/shell/tool-bash/README.md index 7c1a498b13..56be60c947 100644 --- a/packages/shell/tool-bash/README.md +++ b/packages/shell/tool-bash/README.md @@ -71,7 +71,7 @@ When the mounted executor confines commands (for example `dsh-bash-sandbox`), a ### What can go wrong -A composition with no executor provider never activates the tool. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` without a sandboxing executor fails with `sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`. `enableRunInBackground: false` removes the parameter and rejects a forced background call at execution time. +A composition with no executor provider never activates the tool. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` without a sandboxing executor fails with `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`. `enableRunInBackground: false` removes the parameter and rejects a forced background call at execution time. ----- @@ -196,7 +196,7 @@ Append-only; newly visible content follows the reusable request prefix and does #### What the model sees -Validation and policy failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a disabled background call is `JobError` (`JOB_BACKGROUND_DISABLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. +Validation and policy failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a disabled background call is `JobError` (`JOB_BACKGROUND_DISABLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. #### Token effect diff --git a/packages/shell/tool-bash/README.zh.md b/packages/shell/tool-bash/README.zh.md index 1e0f96c57f..12dc77c4ec 100644 --- a/packages/shell/tool-bash/README.zh.md +++ b/packages/shell/tool-bash/README.zh.md @@ -71,7 +71,7 @@ kind: "package-reference" ### 可能出什么问题 -没有执行器提供方的组合永远不会激活该工具。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时的 `sandbox_permissions` 会以 `sandbox_permissions is not available in this composition (no sandboxing executor to escalate)` 失败。`enableRunInBackground: false` 会移除该参数,并在执行时拒绝强制后台调用。 +没有执行器提供方的组合永远不会激活该工具。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时的 `sandbox_permissions` 会以 `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)` 失败。`enableRunInBackground: false` 会移除该参数,并在执行时拒绝强制后台调用。 ----- @@ -196,7 +196,7 @@ renderer 输出依数据而定的 stdout 尾部,再输出可选的 `[stderr]` #### 模型看到什么 -验证与策略失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),被禁用的后台调用为 `JobError`(`JOB_BACKGROUND_DISABLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 +验证与策略失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),被禁用的后台调用为 `JobError`(`JOB_BACKGROUND_DISABLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 #### Token 影响 diff --git a/packages/shell/tool-bash/src/index.ts b/packages/shell/tool-bash/src/index.ts index f3e8b14eb2..2e2a473b5c 100644 --- a/packages/shell/tool-bash/src/index.ts +++ b/packages/shell/tool-bash/src/index.ts @@ -24,7 +24,7 @@ import type { JobId, JobRegistry, JobView } from '@deepseek-ai/dsh-jobs' import type {} from '@deepseek-ai/dsh-user-approval' import type {} from '@deepseek-ai/dsh-shell-env' import type { SandboxExecutionPolicy, SandboxMode } from '@deepseek-ai/dsh-sandbox' -import { ESCALATION_TARGETS, SandboxEscalationError, approveEscalation, sandboxPermissionsDescription, validateEscalationArgs } from '@deepseek-ai/dsh-sandbox' +import { ESCALATION_TARGETS, approveEscalation, sandboxPermissionsDescription, validateEscalationArgs } from '@deepseek-ai/dsh-sandbox' import { subprocessSpawnFailure } from '@deepseek-ai/dsh-subprocess' import type { SandboxPolicyService } from '@deepseek-ai/dsh-sandbox-policy' import { DSH_ENV_PREFIX } from '@deepseek-ai/dsh-shell' @@ -248,10 +248,7 @@ export function apply(ctx: Context, config: Config = {}): void { standingPolicy: SandboxExecutionPolicy | undefined, ): Promise => { if (escalationModes.length === 0) { - throw new SandboxEscalationError( - 'sandbox_permissions is not available in this composition (no sandboxing executor to escalate)', - 'SANDBOX_ESCALATION_UNAVAILABLE', - ) + throw new ToolArgsError(['sandbox_permissions is not available in this composition (no sandboxing executor to escalate)']) } const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode return approveEscalation( diff --git a/packages/shell/tool-bash/tests/tools.spec.ts b/packages/shell/tool-bash/tests/tools.spec.ts index 45e92e05d5..a87562fa80 100644 --- a/packages/shell/tool-bash/tests/tools.spec.ts +++ b/packages/shell/tool-bash/tests/tools.spec.ts @@ -800,8 +800,8 @@ describe('sandbox escalation through the generic task producer', () => { it('rejects injected escalation without a sandbox and narrower escalation without prompting', async () => { const plain = await setup() const unavailable = await call(plain, 'bash', escalate) - expect(text(unavailable)).toContain('not available in this composition') - expect(unavailable).toMatchObject({ error: { info: { name: 'SandboxEscalationError', code: 'SANDBOX_ESCALATION_UNAVAILABLE' } } }) + expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions is not available in this composition') + expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) const { ctx } = await setupSandboxed(true) const prompted = vi.fn() diff --git a/packages/shell/tool-pwsh/README.i18n.yaml b/packages/shell/tool-pwsh/README.i18n.yaml index e4c8f16b4b..d633341650 100644 --- a/packages/shell/tool-pwsh/README.i18n.yaml +++ b/packages/shell/tool-pwsh/README.i18n.yaml @@ -33,8 +33,8 @@ en: 76f3f791f53d1005 zh: e5b262db24e6eb83 /deepseek-ai-dsh-tool-pwsh/use-this-package/what-can-go-wrong: - en: c1a9cc1201ed3a89 - zh: a43a659d350e9d4a + en: b59d36b896c2d2e8 + zh: f0145138ec8ca116 /deepseek-ai-dsh-tool-pwsh/understand-the-implementation: en: 165313776a851b51 zh: 828f48807036aff0 @@ -108,8 +108,8 @@ en: 2d4f2c8605eccab3 zh: 67f1f0218f73c6bf /deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/what-the-model-sees: - en: c71e7f547de19d3d - zh: a9d9c3a84e1618b9 + en: d700f97ccd108cdf + zh: e9192e0ce69b5a15 /deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/token-effect: en: 243bad012dd99c7f zh: 5ee74905020bd49a diff --git a/packages/shell/tool-pwsh/README.md b/packages/shell/tool-pwsh/README.md index ff35a8068d..c63bc1bdc2 100644 --- a/packages/shell/tool-pwsh/README.md +++ b/packages/shell/tool-pwsh/README.md @@ -66,7 +66,7 @@ Under a sandboxing executor, denied commands report `[sandbox: file access denie ### What can go wrong -A composition with no PowerShell executor never activates the tool, and the injected services (`tools`, `shell`, `systemPrompt`, `shellEnv`) must all exist. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` without a sandboxing executor fails with `sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`. +A composition with no PowerShell executor never activates the tool, and the injected services (`tools`, `shell`, `systemPrompt`, `shellEnv`) must all exist. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` without a sandboxing executor fails with `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`. ----- @@ -188,7 +188,7 @@ Append-only; newly visible content follows the reusable request prefix and does #### What the model sees -Validation and infrastructure failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the shared escalation failures (not strictly wider / no approval service / no agent to route / no approval channel / user rejected / was cancelled), `run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a disabled background call is `JobError` (`JOB_BACKGROUND_DISABLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. +Validation and infrastructure failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the shared escalation failures (not strictly wider / no approval service / no agent to route / no approval channel / user rejected / was cancelled), `run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a disabled background call is `JobError` (`JOB_BACKGROUND_DISABLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. #### Token effect diff --git a/packages/shell/tool-pwsh/README.zh.md b/packages/shell/tool-pwsh/README.zh.md index 6225e8ad33..f7a91e5215 100644 --- a/packages/shell/tool-pwsh/README.zh.md +++ b/packages/shell/tool-pwsh/README.zh.md @@ -66,7 +66,7 @@ kind: "package-reference" ### 可能出什么问题 -没有 PowerShell 执行器的组合永远不会激活该工具,且注入的服务(`tools`、`shell`、`systemPrompt`、`shellEnv`)必须全部存在。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时的 `sandbox_permissions` 会以 `sandbox_permissions is not available in this composition (no sandboxing executor to escalate)` 失败。 +没有 PowerShell 执行器的组合永远不会激活该工具,且注入的服务(`tools`、`shell`、`systemPrompt`、`shellEnv`)必须全部存在。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时的 `sandbox_permissions` 会以 `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)` 失败。 ----- @@ -188,7 +188,7 @@ Non-zero exits are reported as `[exit code: N]` markers; investigate failures be #### 模型看到什么 -验证与基础设施失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、共享升权失败(未严格加宽/无审批服务/无 agent 可路由/无审批通道/用户拒绝/已取消)、`run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),被禁用的后台调用为 `JobError`(`JOB_BACKGROUND_DISABLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 +验证与基础设施失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、共享升权失败(未严格加宽/无审批服务/无 agent 可路由/无审批通道/用户拒绝/已取消)、`run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),被禁用的后台调用为 `JobError`(`JOB_BACKGROUND_DISABLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 #### Token 影响 diff --git a/packages/shell/tool-pwsh/src/index.ts b/packages/shell/tool-pwsh/src/index.ts index 1a5eac1e7d..b0cc564d63 100644 --- a/packages/shell/tool-pwsh/src/index.ts +++ b/packages/shell/tool-pwsh/src/index.ts @@ -33,7 +33,7 @@ import type { JobId, JobRegistry, JobView } from '@deepseek-ai/dsh-jobs' import type {} from '@deepseek-ai/dsh-shell-env' import type {} from '@deepseek-ai/dsh-user-approval' import type { SandboxExecutionPolicy, SandboxMode } from '@deepseek-ai/dsh-sandbox' -import { ESCALATION_TARGETS, SandboxEscalationError, approveEscalation, sandboxPermissionsDescription, validateEscalationArgs } from '@deepseek-ai/dsh-sandbox' +import { ESCALATION_TARGETS, approveEscalation, sandboxPermissionsDescription, validateEscalationArgs } from '@deepseek-ai/dsh-sandbox' import { subprocessSpawnFailure } from '@deepseek-ai/dsh-subprocess' import type { SandboxPolicyService } from '@deepseek-ai/dsh-sandbox-policy' import type { ShellExecRequest, ShellExecSpec, ShellExecution, ShellRunResult } from '@deepseek-ai/dsh-shell' @@ -261,10 +261,7 @@ export function apply(ctx: Context, config: Config = {}): void { standingPolicy: SandboxExecutionPolicy | undefined, ): Promise => { if (escalationModes.length === 0) { - throw new SandboxEscalationError( - 'sandbox_permissions is not available in this composition (no sandboxing executor to escalate)', - 'SANDBOX_ESCALATION_UNAVAILABLE', - ) + throw new ToolArgsError(['sandbox_permissions is not available in this composition (no sandboxing executor to escalate)']) } const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode return approveEscalation( diff --git a/packages/shell/tool-pwsh/tests/tools.spec.ts b/packages/shell/tool-pwsh/tests/tools.spec.ts index 7db5c6fc5d..2b0f0f53e2 100644 --- a/packages/shell/tool-pwsh/tests/tools.spec.ts +++ b/packages/shell/tool-pwsh/tests/tools.spec.ts @@ -684,8 +684,8 @@ describe('sandbox escalation through ctx.approval', () => { it('rejects injected escalation without a sandbox and narrower escalation without prompting', async () => { const plain = await setup() const unavailable = await call(plain.ctx, 'pwsh', escalate) - expect(text(unavailable)).toContain('not available in this composition') - expect(unavailable).toMatchObject({ error: { info: { name: 'SandboxEscalationError', code: 'SANDBOX_ESCALATION_UNAVAILABLE' } } }) + expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions is not available in this composition') + expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) const { ctx } = await setupSandboxed(true) const prompted = vi.fn() From abbb742d19ddf29672ecb607d946b6b433c94f8e Mon Sep 17 00:00:00 2001 From: sjw1231 Date: Mon, 9 Nov 2026 17:39:01 +0800 Subject: [PATCH 2/5] refactor(tool-fs): use MODEL_DOES_NOT_SUPPORT_IMAGES for read_image model refusals The subagent attachment path, session-controller, and client labels already name this failure MODEL_DOES_NOT_SUPPORT_IMAGES. Rename the unreleased ImageInputError code IMAGE_UNSUPPORTED_MODEL so one fact has one code. Refs #7869 --- packages/fs/tool-fs/README.i18n.yaml | 4 ++-- packages/fs/tool-fs/README.md | 2 +- packages/fs/tool-fs/README.zh.md | 2 +- packages/fs/tool-fs/src/image-error.ts | 4 ++-- packages/fs/tool-fs/src/read-image.ts | 4 ++-- packages/fs/tool-fs/tests/read-image.spec.ts | 2 +- snapshots/session/read-image-text-route/session.v4.jsonl | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/fs/tool-fs/README.i18n.yaml b/packages/fs/tool-fs/README.i18n.yaml index f9d9c8ac82..69acb22a04 100644 --- a/packages/fs/tool-fs/README.i18n.yaml +++ b/packages/fs/tool-fs/README.i18n.yaml @@ -30,8 +30,8 @@ en: 9bddebaf4aff0a8d zh: fea0196162e3fcd1 /deepseek-ai-dsh-tool-fs/use-this-package/failures-and-recovery: - en: 4e33f0736e64c72b - zh: b7a0f2386760e08e + en: c11d53e4d0b9c13f + zh: 229b232009c42986 /deepseek-ai-dsh-tool-fs/understand-the-implementation: en: e30f7038c28e93f8 zh: a3868dbd90367b13 diff --git a/packages/fs/tool-fs/README.md b/packages/fs/tool-fs/README.md index 93985eeb21..d77f4e791b 100644 --- a/packages/fs/tool-fs/README.md +++ b/packages/fs/tool-fs/README.md @@ -83,7 +83,7 @@ With the policy plugin mounted, `write` and `edit` obtain their guard from the ` For `apply_patch`, syntax and preflight refusals throw with `isError: true` before any disk change. `FsError` preserves filesystem codes; `PatchToolError extends HarnessError` carries `PATCH_SYNTAX` and `PATCH_SYMLINK_SOURCE`. Once commit starts, the tool returns a value with `isError: false` even on failure or uncertainty, so known partial effects retain their diff metadata; a call cancelled during commit receives the tool registry's abort result like every other tool, and its completed changes remain visible through Review. `phase`, `cancelled`, ordered `operations` and `affectedPaths` describe the commit; each operation retains its index, kind, display paths, patch line, status, diagnostic and known changes. Full `before`/`after` text serves rendering and PTC; the Session stores the rendered result plus `meta.diffs` and `meta.stopped`. Creations store no diff, as for `write`; deletions and move sources store a removal diff only when the provider returned a bounded basis, using `newText: ''` because `FileDiff.newText` cannot be null. -`read_image` refusals it makes before storing the image throw `ImageInputError extends HarnessError` with an `ImageInputErrorCode`: `IMAGE_UNSUPPORTED_MODEL` (switch to an image-capable model) or `IMAGE_UNSUPPORTED_FORMAT` (the extension, file signature, or deployment media types exclude the format; convert the file). Refusals from the attachment store keep their `AttachmentError` `name` and `code`, such as `INVALID_IMAGE`, `IMAGE_TYPE_MISMATCH`, or `IMAGE_DIMENSION_TOO_LARGE`; for codes with a known remedy, the message names the file and the next step, and the store error is the `cause`. An empty `file_path` throws `ToolArgsError` (`INVALID_ARGS`); a missing attachment service or an unresolvable model route throws `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`); filesystem failures keep their `FsError` codes; any other store failure, such as an `AbortError`, another `HarnessError`, or a defect, passes through unchanged. +`read_image` refusals it makes before storing the image throw `ImageInputError extends HarnessError` with an `ImageInputErrorCode`: `MODEL_DOES_NOT_SUPPORT_IMAGES` (switch to an image-capable model) or `IMAGE_UNSUPPORTED_FORMAT` (the extension, file signature, or deployment media types exclude the format; convert the file). Refusals from the attachment store keep their `AttachmentError` `name` and `code`, such as `INVALID_IMAGE`, `IMAGE_TYPE_MISMATCH`, or `IMAGE_DIMENSION_TOO_LARGE`; for codes with a known remedy, the message names the file and the next step, and the store error is the `cause`. An empty `file_path` throws `ToolArgsError` (`INVALID_ARGS`); a missing attachment service or an unresolvable model route throws `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`); filesystem failures keep their `FsError` codes; any other store failure, such as an `AbortError`, another `HarnessError`, or a defect, passes through unchanged. Failures are normalized as `Error: ` with a structured code preserved for callers. Stable messages include the `ToolArgsError` (`INVALID_ARGS`) messages `invalid arguments: file_path must be a non-empty string` and `invalid arguments: limit must be less than or equal to `, `cannot read "": not found`, `cannot read "": not a regular file`, and the image-route refusal `cannot read "" as an image: model "" does not declare image input; switch to an image-capable model to read images`. `FS_NOT_OBSERVED` is normalized to `cannot modify "": file has not been read — read the file, then retry`, independent of whether the policy or provider rejected the operation; `FS_STALE_VERSION` retains the provider's reason and appends `— re-read the file, then retry`. After the reread confirms absence, `edit` reports `FS_NOT_FOUND` instead of repeating a stale remedy, while `write` uses guarded creation. diff --git a/packages/fs/tool-fs/README.zh.md b/packages/fs/tool-fs/README.zh.md index ec28bf145c..eb74e5837c 100644 --- a/packages/fs/tool-fs/README.zh.md +++ b/packages/fs/tool-fs/README.zh.md @@ -83,7 +83,7 @@ kind: "package-reference" `apply_patch` 的语法与预检拒绝在磁盘变更前抛错,结果为 `isError: true`。`FsError` 保留文件系统错误码;`PatchToolError extends HarnessError` 携带 `PATCH_SYNTAX` 和 `PATCH_SYMLINK_SOURCE`。进入提交后,即使失败或结果不确定也返回 `isError: false` 的值,确保已知部分效果的 diff 元数据得以保留;提交期间被取消的调用与其他工具一样收到工具注册表的中止结果,已完成的变更仍可通过 Review 查看。`phase`、`cancelled`、有序 `operations` 与 `affectedPaths` 描述提交;每条操作保留索引、种类、展示路径、补丁行号、状态、诊断与已知变更。完整 `before`/`after` 文本供渲染和 PTC 使用;Session 保存渲染文本以及 `meta.diffs` 与 `meta.stopped`。新建与 `write` 一样不保存 diff;删除与移动源仅在提供方返回有界基线时保存删除 diff,并使用 `newText: ''`,因为 `FileDiff.newText` 不可为 null。 -`read_image` 在存储图像前自行作出的拒绝抛出 `ImageInputError extends HarnessError`,错误码为 `ImageInputErrorCode`:`IMAGE_UNSUPPORTED_MODEL`(切换到支持图像的模型)或 `IMAGE_UNSUPPORTED_FORMAT`(扩展名、文件签名或部署接受的媒体类型排除了该格式;转换文件)。附件存储作出的拒绝保留其 `AttachmentError` 的 `name` 与 `code`,例如 `INVALID_IMAGE`、`IMAGE_TYPE_MISMATCH` 或 `IMAGE_DIMENSION_TOO_LARGE`;对有明确补救办法的错误码,消息会写明文件与下一步,存储错误作为 `cause`。空 `file_path` 抛出 `ToolArgsError`(`INVALID_ARGS`);缺少附件服务或无法解析模型路由时抛出 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`);文件系统失败保留其 `FsError` 错误码;存储抛出的其他失败(例如 `AbortError`、其他 `HarnessError` 或缺陷)原样传递。 +`read_image` 在存储图像前自行作出的拒绝抛出 `ImageInputError extends HarnessError`,错误码为 `ImageInputErrorCode`:`MODEL_DOES_NOT_SUPPORT_IMAGES`(切换到支持图像的模型)或 `IMAGE_UNSUPPORTED_FORMAT`(扩展名、文件签名或部署接受的媒体类型排除了该格式;转换文件)。附件存储作出的拒绝保留其 `AttachmentError` 的 `name` 与 `code`,例如 `INVALID_IMAGE`、`IMAGE_TYPE_MISMATCH` 或 `IMAGE_DIMENSION_TOO_LARGE`;对有明确补救办法的错误码,消息会写明文件与下一步,存储错误作为 `cause`。空 `file_path` 抛出 `ToolArgsError`(`INVALID_ARGS`);缺少附件服务或无法解析模型路由时抛出 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`);文件系统失败保留其 `FsError` 错误码;存储抛出的其他失败(例如 `AbortError`、其他 `HarnessError` 或缺陷)原样传递。 失败被规范化为 `Error: `,并为调用方保留结构化错误码。稳定消息包括 `ToolArgsError`(`INVALID_ARGS`)消息 `invalid arguments: file_path must be a non-empty string` 与 `invalid arguments: limit must be less than or equal to `、`cannot read "": not found`、`cannot read "": not a regular file`,以及图像路由拒绝 `cannot read "" as an image: model "" does not declare image input; switch to an image-capable model to read images`。无论拒绝来自策略还是提供方,`FS_NOT_OBSERVED` 都规范化为 `cannot modify "": file has not been read — read the file, then retry`;`FS_STALE_VERSION` 保留提供方原因并追加 `— re-read the file, then retry`。该次重新读取确认缺失后,`edit` 报告 `FS_NOT_FOUND` 而不会重复陈旧恢复指令,`write` 则使用防护创建。 diff --git a/packages/fs/tool-fs/src/image-error.ts b/packages/fs/tool-fs/src/image-error.ts index ccacb48744..8ddb9af2dc 100644 --- a/packages/fs/tool-fs/src/image-error.ts +++ b/packages/fs/tool-fs/src/image-error.ts @@ -5,14 +5,14 @@ import { HarnessError } from '@deepseek-ai/dsh-error' /** * Every `read_image` failure the tool classifies itself, before the attachment store sees the bytes: * - * - `IMAGE_UNSUPPORTED_MODEL`: the calling route does not declare image input; switch to an image-capable model. + * - `MODEL_DOES_NOT_SUPPORT_IMAGES`: the calling route does not declare image input; switch to an image-capable model. * - `IMAGE_UNSUPPORTED_FORMAT`: the extension, the file signature, or the deployment's accepted media types * exclude the format; convert the file to an accepted format or read another file. * * Failures the attachment store classifies keep their `AttachmentError` codes. */ export const IMAGE_INPUT_ERROR_CODES = [ - 'IMAGE_UNSUPPORTED_MODEL', + 'MODEL_DOES_NOT_SUPPORT_IMAGES', 'IMAGE_UNSUPPORTED_FORMAT', ] as const diff --git a/packages/fs/tool-fs/src/read-image.ts b/packages/fs/tool-fs/src/read-image.ts index be422b38aa..0fd68bdd12 100644 --- a/packages/fs/tool-fs/src/read-image.ts +++ b/packages/fs/tool-fs/src/read-image.ts @@ -119,7 +119,7 @@ export function imageMediaTypeForPath(filePath: string): ImageMediaType | undefi * @param exec - the tool-execution context supplying the calling agent. * @param requestedPath - the raw, not-yet-resolved path rendered in refusal messages. * @throws ToolContextUnavailableError when no Agent route or `llm` service is available. - * @throws ImageInputError `IMAGE_UNSUPPORTED_MODEL` when the route does not declare image input. + * @throws ImageInputError `MODEL_DOES_NOT_SUPPORT_IMAGES` when the route does not declare image input. */ export async function assertImageCapableRoute(ctx: Context, exec: ToolExecution, requestedPath: string): Promise { const routed = exec.agent?.session.requestHeader()?.config @@ -133,7 +133,7 @@ export async function assertImageCapableRoute(ctx: Context, exec: ToolExecution, if (active.inputModalities === undefined || !active.inputModalities.includes('image')) { throw new ImageInputError( `cannot read "${requestedPath}" as an image: model "${model}" does not declare image input; switch to an image-capable model to read images`, - 'IMAGE_UNSUPPORTED_MODEL', + 'MODEL_DOES_NOT_SUPPORT_IMAGES', ) } } diff --git a/packages/fs/tool-fs/tests/read-image.spec.ts b/packages/fs/tool-fs/tests/read-image.spec.ts index a55bb1c717..de28c8d775 100644 --- a/packages/fs/tool-fs/tests/read-image.spec.ts +++ b/packages/fs/tool-fs/tests/read-image.spec.ts @@ -490,7 +490,7 @@ describe('strict image-modality gate', () => { const result = await readImage(ctx, { file_path: 'red.png' }, agentOn(model)) expect(result.isError).toBe(true) expect(text(result)).toContain('does not declare image input') - expect(result.error?.info).toEqual({ name: 'ImageInputError', code: 'IMAGE_UNSUPPORTED_MODEL' }) + expect(result.error?.info).toEqual({ name: 'ImageInputError', code: 'MODEL_DOES_NOT_SUPPORT_IMAGES' }) }) it('refuses when the route cannot be resolved (no agent, or no header and no options)', async () => { diff --git a/snapshots/session/read-image-text-route/session.v4.jsonl b/snapshots/session/read-image-text-route/session.v4.jsonl index 3c4c5b47e6..3bd285baf2 100644 --- a/snapshots/session/read-image-text-route/session.v4.jsonl +++ b/snapshots/session/read-image-text-route/session.v4.jsonl @@ -14,7 +14,7 @@ {"type":"session/title","data":{"title":"Use read_image on red.png in","messageSeqs":[8],"source":{"kind":"fallback"}}} {"type":"assistant/message","data":{"turn":1,"step":1,"message":{"role":"assistant","content":[{"type":"tool-call","id":"read-image-refused","name":"read_image","arguments":"{\"file_path\":\"red.png\"}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:4}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1788699420816,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1788699420816,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"read-image-refused","name":"read_image","arguments":"{\"file_path\":\"red.png\"}"}}},{"type":"chunk","time":1788699420816,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1788699420816,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"} {"type":"tool/call","data":{"turn":1,"step":1,"callId":"read-image-refused","name":"read_image","arguments":"{\"file_path\":\"red.png\"}"}} -{"type":"tool/result","data":{"turn":1,"step":1,"message":{"role":"tool","source":{"kind":"tool","callId":"read-image-refused"},"toolCallId":"read-image-refused","content":[{"type":"text","text":"Error: cannot read \"red.png\" as an image: model \"deepseek-v4-flash\" does not declare image input; switch to an image-capable model to read images"}],"isError":true,"id":"{{message:5}}"},"error":{"name":"ImageInputError","code":"IMAGE_UNSUPPORTED_MODEL"}},"sourceEventSeqs":[14],"surfaceOp":"append"} +{"type":"tool/result","data":{"turn":1,"step":1,"message":{"role":"tool","source":{"kind":"tool","callId":"read-image-refused"},"toolCallId":"read-image-refused","content":[{"type":"text","text":"Error: cannot read \"red.png\" as an image: model \"deepseek-v4-flash\" does not declare image input; switch to an image-capable model to read images"}],"isError":true,"id":"{{message:5}}"},"error":{"name":"ImageInputError","code":"MODEL_DOES_NOT_SUPPORT_IMAGES"}},"sourceEventSeqs":[14],"surfaceOp":"append"} {"type":"step/end","data":{"turn":1,"step":1}} {"type":"step/start","data":{"turn":1,"step":2}} {"type":"assistant/message","data":{"turn":1,"step":2,"message":{"role":"assistant","content":[{"type":"text","text":"UNAVAILABLE"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:6}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1788699420834,"chunk":{"type":"block-start","index":0,"blockType":"text"}},{"type":"chunk","time":1788699420834,"chunk":{"type":"block-end","index":0,"block":{"type":"text","text":"UNAVAILABLE"}}},{"type":"chunk","time":1788699420834,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1788699420834,"chunk":{"type":"finish","reason":{"kind":"stop"}}}]},"surfaceOp":"append"} From a10f0eb7a060a4f92a95e9fbcb623db979766a36 Mon Sep 17 00:00:00 2001 From: sjw1231 Date: Mon, 9 Nov 2026 17:40:04 +0800 Subject: [PATCH 3/5] refactor(bash,pwsh): report a forced run_in_background as ToolArgsError With enableRunInBackground: false the schema omits run_in_background, so a forced value is an argument the model must drop. Report it as ToolArgsError / INVALID_ARGS and keep the configuration name in the message. Refs #7869 --- docs/config-catalog.md | 4 ++-- docs/config-catalog.zh.md | 4 ++-- packages/jobs/jobs/src/error.ts | 2 -- packages/shell/tool-bash/README.i18n.yaml | 4 ++-- packages/shell/tool-bash/README.md | 2 +- packages/shell/tool-bash/README.zh.md | 2 +- packages/shell/tool-bash/src/index.ts | 3 +-- packages/shell/tool-bash/tests/tools.spec.ts | 4 ++-- packages/shell/tool-pwsh/README.i18n.yaml | 4 ++-- packages/shell/tool-pwsh/README.md | 2 +- packages/shell/tool-pwsh/README.zh.md | 2 +- packages/shell/tool-pwsh/src/index.ts | 3 +-- packages/shell/tool-pwsh/tests/tools.spec.ts | 4 ++-- 13 files changed, 18 insertions(+), 22 deletions(-) diff --git a/docs/config-catalog.md b/docs/config-catalog.md index 8ff3224180..48400a4f87 100644 --- a/docs/config-catalog.md +++ b/docs/config-catalog.md @@ -4145,7 +4145,7 @@ export interface Config { ## `@deepseek-ai/dsh-tool-bash` - `inject`: `tools` · `shell` · `systemPrompt` · `shellEnv` · `workingDirectory` -- `source`: [`packages/shell/tool-bash/src/index.ts:40`](../packages/shell/tool-bash/src/index.ts) +- `source`: [`packages/shell/tool-bash/src/index.ts:39`](../packages/shell/tool-bash/src/index.ts) ```ts config-catalog /** Configuration for the bash tool. */ @@ -4410,7 +4410,7 @@ export interface Config { ## `@deepseek-ai/dsh-tool-pwsh` - `inject`: `tools` · `shell` · `systemPrompt` · `shellEnv` · `workingDirectory` -- `source`: [`packages/shell/tool-pwsh/src/index.ts:57`](../packages/shell/tool-pwsh/src/index.ts) +- `source`: [`packages/shell/tool-pwsh/src/index.ts:56`](../packages/shell/tool-pwsh/src/index.ts) ```ts config-catalog /** Configuration for the pwsh tool. */ diff --git a/docs/config-catalog.zh.md b/docs/config-catalog.zh.md index 704d37d959..727389ce76 100644 --- a/docs/config-catalog.zh.md +++ b/docs/config-catalog.zh.md @@ -4147,7 +4147,7 @@ export interface Config { ## `@deepseek-ai/dsh-tool-bash` - `inject`: `tools` · `shell` · `systemPrompt` · `shellEnv` · `workingDirectory` -- `source`: [`packages/shell/tool-bash/src/index.ts:40`](../packages/shell/tool-bash/src/index.ts) +- `source`: [`packages/shell/tool-bash/src/index.ts:39`](../packages/shell/tool-bash/src/index.ts) ```ts config-catalog /** Configuration for the bash tool. */ @@ -4412,7 +4412,7 @@ export interface Config { ## `@deepseek-ai/dsh-tool-pwsh` - `inject`: `tools` · `shell` · `systemPrompt` · `shellEnv` · `workingDirectory` -- `source`: [`packages/shell/tool-pwsh/src/index.ts:57`](../packages/shell/tool-pwsh/src/index.ts) +- `source`: [`packages/shell/tool-pwsh/src/index.ts:56`](../packages/shell/tool-pwsh/src/index.ts) ```ts config-catalog /** Configuration for the pwsh tool. */ diff --git a/packages/jobs/jobs/src/error.ts b/packages/jobs/jobs/src/error.ts index 28c2984382..6070b66305 100644 --- a/packages/jobs/jobs/src/error.ts +++ b/packages/jobs/jobs/src/error.ts @@ -4,7 +4,6 @@ import { HarnessError } from '@deepseek-ai/dsh-error' /** * Every {@link JobError} code: - * - `JOB_BACKGROUND_DISABLED` — the calling tool's configuration turns background execution off. * - `JOB_CONTROLLER_UNAVAILABLE` — the jobs service is composed but no attached job controller serves the * job's owner. A call whose composition lacks the jobs service itself throws `ToolContextUnavailableError`. * - `JOB_NOT_FOUND` — the job id names no listed job. @@ -14,7 +13,6 @@ import { HarnessError } from '@deepseek-ai/dsh-error' * - `JOB_LIMIT_REACHED` — the registry's configured job limit is reached. */ export const JOB_ERROR_CODES = [ - 'JOB_BACKGROUND_DISABLED', 'JOB_CONTROLLER_UNAVAILABLE', 'JOB_NOT_FOUND', 'JOB_FOREIGN_SESSION', diff --git a/packages/shell/tool-bash/README.i18n.yaml b/packages/shell/tool-bash/README.i18n.yaml index 1de4085f2d..728123f70d 100644 --- a/packages/shell/tool-bash/README.i18n.yaml +++ b/packages/shell/tool-bash/README.i18n.yaml @@ -111,8 +111,8 @@ en: 2d4f2c8605eccab3 zh: 67f1f0218f73c6bf /deepseek-ai-dsh-tool-bash/model-experience/tool-errors/what-the-model-sees: - en: 138222f326a3ade3 - zh: 9cd72b361b65fe2b + en: 5dc3bd182ef54b08 + zh: be8a55f8aefada5a /deepseek-ai-dsh-tool-bash/model-experience/tool-errors/token-effect: en: a3a78ef476ec5e56 zh: dd2c8ad0f69e8ff1 diff --git a/packages/shell/tool-bash/README.md b/packages/shell/tool-bash/README.md index 56be60c947..e1b0328dea 100644 --- a/packages/shell/tool-bash/README.md +++ b/packages/shell/tool-bash/README.md @@ -196,7 +196,7 @@ Append-only; newly visible content follows the reusable request prefix and does #### What the model sees -Validation and policy failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a disabled background call is `JobError` (`JOB_BACKGROUND_DISABLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. +Validation and policy failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` or `run_in_background` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. #### Token effect diff --git a/packages/shell/tool-bash/README.zh.md b/packages/shell/tool-bash/README.zh.md index 12dc77c4ec..5b64623210 100644 --- a/packages/shell/tool-bash/README.zh.md +++ b/packages/shell/tool-bash/README.zh.md @@ -196,7 +196,7 @@ renderer 输出依数据而定的 stdout 尾部,再输出可选的 `[stderr]` #### 模型看到什么 -验证与策略失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),被禁用的后台调用为 `JobError`(`JOB_BACKGROUND_DISABLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 +验证与策略失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 #### Token 影响 diff --git a/packages/shell/tool-bash/src/index.ts b/packages/shell/tool-bash/src/index.ts index 2e2a473b5c..1cc603b0da 100644 --- a/packages/shell/tool-bash/src/index.ts +++ b/packages/shell/tool-bash/src/index.ts @@ -19,7 +19,6 @@ import { isAbsolute, sep } from 'node:path' import { defineTool, TOOL_ABORTED, ToolArgsError, ToolContextUnavailableError } from '@deepseek-ai/dsh-tools' import type { GenericCallView, TerminalCallView, ToolDefinition, ToolExecution, ToolResult, ToolResultView } from '@deepseek-ai/dsh-tools' import { HarnessError } from '@deepseek-ai/dsh-llm' -import { JobError } from '@deepseek-ai/dsh-jobs' import type { JobId, JobRegistry, JobView } from '@deepseek-ai/dsh-jobs' import type {} from '@deepseek-ai/dsh-user-approval' import type {} from '@deepseek-ai/dsh-shell-env' @@ -519,7 +518,7 @@ export function apply(ctx: Context, config: Config = {}): void { if (args.run_in_background === true) { // Undeclared keys are allowed, so schema omission also needs enforcement. if (!backgroundEnabled) { - throw new JobError('run_in_background is disabled for this deployment (enableRunInBackground: false)', 'JOB_BACKGROUND_DISABLED') + throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)']) } if (jobs === undefined) { throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs') diff --git a/packages/shell/tool-bash/tests/tools.spec.ts b/packages/shell/tool-bash/tests/tools.spec.ts index a87562fa80..586d70412a 100644 --- a/packages/shell/tool-bash/tests/tools.spec.ts +++ b/packages/shell/tool-bash/tests/tools.spec.ts @@ -720,8 +720,8 @@ describe('background execution through the job runtime', () => { // Schema omission is advertising; execution must also enforce the opt-out. const forced = await call(ctx, 'bash', { command: 'echo hi', description: 'test command', run_in_background: true }) - expect(forced).toMatchObject({ isError: true, error: { info: { name: 'JobError', code: 'JOB_BACKGROUND_DISABLED' } } }) - expect(text(forced)).toContain('run_in_background is disabled for this deployment') + expect(forced).toMatchObject({ isError: true, error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) + expect(text(forced)).toContain('invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)') const foreground = await call(ctx, 'bash', { command: 'echo hi', description: 'test command' }) expect(foreground.isError).toBe(false) }) diff --git a/packages/shell/tool-pwsh/README.i18n.yaml b/packages/shell/tool-pwsh/README.i18n.yaml index d633341650..6aebdcb45a 100644 --- a/packages/shell/tool-pwsh/README.i18n.yaml +++ b/packages/shell/tool-pwsh/README.i18n.yaml @@ -108,8 +108,8 @@ en: 2d4f2c8605eccab3 zh: 67f1f0218f73c6bf /deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/what-the-model-sees: - en: d700f97ccd108cdf - zh: e9192e0ce69b5a15 + en: efc9d4c72556b355 + zh: 9b959bb612d39108 /deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/token-effect: en: 243bad012dd99c7f zh: 5ee74905020bd49a diff --git a/packages/shell/tool-pwsh/README.md b/packages/shell/tool-pwsh/README.md index c63bc1bdc2..456c57d628 100644 --- a/packages/shell/tool-pwsh/README.md +++ b/packages/shell/tool-pwsh/README.md @@ -188,7 +188,7 @@ Append-only; newly visible content follows the reusable request prefix and does #### What the model sees -Validation and infrastructure failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the shared escalation failures (not strictly wider / no approval service / no agent to route / no approval channel / user rejected / was cancelled), `run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a disabled background call is `JobError` (`JOB_BACKGROUND_DISABLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. +Validation and infrastructure failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the shared escalation failures (not strictly wider / no approval service / no agent to route / no approval channel / user rejected / was cancelled), `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` or `run_in_background` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. #### Token effect diff --git a/packages/shell/tool-pwsh/README.zh.md b/packages/shell/tool-pwsh/README.zh.md index f7a91e5215..d60a056501 100644 --- a/packages/shell/tool-pwsh/README.zh.md +++ b/packages/shell/tool-pwsh/README.zh.md @@ -188,7 +188,7 @@ Non-zero exits are reported as `[exit code: N]` markers; investigate failures be #### 模型看到什么 -验证与基础设施失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、共享升权失败(未严格加宽/无审批服务/无 agent 可路由/无审批通道/用户拒绝/已取消)、`run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),被禁用的后台调用为 `JobError`(`JOB_BACKGROUND_DISABLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 +验证与基础设施失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、共享升权失败(未严格加宽/无审批服务/无 agent 可路由/无审批通道/用户拒绝/已取消)、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 #### Token 影响 diff --git a/packages/shell/tool-pwsh/src/index.ts b/packages/shell/tool-pwsh/src/index.ts index b0cc564d63..a343d78159 100644 --- a/packages/shell/tool-pwsh/src/index.ts +++ b/packages/shell/tool-pwsh/src/index.ts @@ -28,7 +28,6 @@ import z from '@deepseek-ai/schemastery' import { defineTool, TOOL_ABORTED, ToolArgsError, ToolContextUnavailableError } from '@deepseek-ai/dsh-tools' import type { GenericCallView, TerminalCallView, ToolDefinition, ToolExecution, ToolResult, ToolResultView } from '@deepseek-ai/dsh-tools' import { HarnessError } from '@deepseek-ai/dsh-llm' -import { JobError } from '@deepseek-ai/dsh-jobs' import type { JobId, JobRegistry, JobView } from '@deepseek-ai/dsh-jobs' import type {} from '@deepseek-ai/dsh-shell-env' import type {} from '@deepseek-ai/dsh-user-approval' @@ -542,7 +541,7 @@ export function apply(ctx: Context, config: Config = {}): void { if (args.run_in_background === true) { // Undeclared keys are allowed, so schema omission also needs enforcement. if (!backgroundEnabled) { - throw new JobError('run_in_background is disabled for this deployment (enableRunInBackground: false)', 'JOB_BACKGROUND_DISABLED') + throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)']) } if (jobs === undefined) { throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs') diff --git a/packages/shell/tool-pwsh/tests/tools.spec.ts b/packages/shell/tool-pwsh/tests/tools.spec.ts index 2b0f0f53e2..7272eb1c9f 100644 --- a/packages/shell/tool-pwsh/tests/tools.spec.ts +++ b/packages/shell/tool-pwsh/tests/tools.spec.ts @@ -924,8 +924,8 @@ describe('background execution through the job runtime', () => { // Schema omission is advertising; execution must also enforce the opt-out. const forced = await call(ctx, 'pwsh', { command: 'Write-Output hi', description: 'test command', run_in_background: true }) - expect(forced).toMatchObject({ isError: true, error: { info: { name: 'JobError', code: 'JOB_BACKGROUND_DISABLED' } } }) - expect(text(forced)).toContain('run_in_background is disabled for this deployment') + expect(forced).toMatchObject({ isError: true, error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) + expect(text(forced)).toContain('invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)') const foreground = await call(ctx, 'pwsh', { command: 'Write-Output hi', description: 'test command' }) expect(foreground.isError).toBe(false) }) From 0fe47c32ba3a2c8f14620518f22d111d2bad15a8 Mon Sep 17 00:00:00 2001 From: sjw1231 Date: Thu, 12 Nov 2026 14:59:04 +0800 Subject: [PATCH 4/5] docs(upgrade-guide): record consolidated shell and read_image error codes dsh-v0.2.2-rc.2 shipped JOB_BACKGROUND_DISABLED, IMAGE_UNSUPPORTED_MODEL, and SANDBOX_ESCALATION_UNAVAILABLE for unadvertised bash/pwsh sandbox_permissions, so their replacement is a released break. Refs #7869 --- .../shell-fs-tool-error-codes/guide.i18n.yaml | 16 +++++++++++ .../shell-fs-tool-error-codes/guide.md | 28 +++++++++++++++++++ .../shell-fs-tool-error-codes/guide.zh.md | 28 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.i18n.yaml create mode 100644 docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md create mode 100644 docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.zh.md diff --git a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.i18n.yaml b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.i18n.yaml new file mode 100644 index 0000000000..1c0edd4899 --- /dev/null +++ b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.i18n.yaml @@ -0,0 +1,16 @@ +# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading +# section, a hash of its English and Chinese blocks outside code blocks and generated regions. +# After editing either side, bring the other along and re-record with: +# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md +/: + en: 4acb940add80fb71 + zh: 33b2d046478b2cf3 +/shell-and-read-image-failures-use-consolidated-error-codes: + en: f67fb81f55897105 + zh: f74bb4d9e995f156 +/shell-and-read-image-failures-use-consolidated-error-codes/change: + en: 16595e7db2999ca3 + zh: 42b44f7ea29ddfb1 +/shell-and-read-image-failures-use-consolidated-error-codes/migration: + en: 0e111ffbadee4e2e + zh: cb1e8d6ef74f5cee diff --git a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md new file mode 100644 index 0000000000..bb52b0ff26 --- /dev/null +++ b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md @@ -0,0 +1,28 @@ +--- +kind: upgrade-guide +description: "bash and pwsh report unadvertised sandbox_permissions and run_in_background as ToolArgsError, JOB_BACKGROUND_DISABLED is removed, and read_image reports MODEL_DOES_NOT_SUPPORT_IMAGES instead of IMAGE_UNSUPPORTED_MODEL." +--- + +# Shell and read_image failures use consolidated error codes + +English | [中文](guide.zh.md) + +## Change + +Three `tool/result` error identities recorded by v0.2.2-rc.2 change: + +| Failure | v0.2.2-rc.2 | Now | +| --- | --- | --- | +| `bash` or `pwsh` receives `sandbox_permissions` in a composition without a sandboxing executor | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` | +| `bash` or `pwsh` receives `run_in_background: true` with `enableRunInBackground: false` | `JobError` / `JOB_BACKGROUND_DISABLED` | `ToolArgsError` / `INVALID_ARGS` | +| `read_image` runs on a model route without image input | `ImageInputError` / `IMAGE_UNSUPPORTED_MODEL` | `ImageInputError` / `MODEL_DOES_NOT_SUPPORT_IMAGES` | + +In both shell cases the schema does not advertise the rejected argument, so the model's fix is to drop it. Both shell messages now start with `invalid arguments: `, which the model and transcript readers see. `SANDBOX_ESCALATION_UNAVAILABLE` remains for compositions that cannot route an approval. + +`JOB_BACKGROUND_DISABLED` is removed from `JOB_ERROR_CODES` and the `JobErrorCode` type in `@deepseek-ai/dsh-jobs`. `ImageInputErrorCode` in `@deepseek-ai/dsh-tool-fs` replaces `IMAGE_UNSUPPORTED_MODEL` with `MODEL_DOES_NOT_SUPPORT_IMAGES`, the value subagent attachments and Session attachment rejections already use. + +## Migration + +1. In analytics or retry rules that read `tool/result` `error`, map `JOB_BACKGROUND_DISABLED` and the shell `SANDBOX_ESCALATION_UNAVAILABLE` case to `INVALID_ARGS`, and `IMAGE_UNSUPPORTED_MODEL` to `MODEL_DOES_NOT_SUPPORT_IMAGES`. Session logs written by v0.2.2-rc.2 keep the old values. +2. Replace TypeScript references to `'JOB_BACKGROUND_DISABLED'` or `'IMAGE_UNSUPPORTED_MODEL'`; `pnpm run typecheck` reports any that remain. +3. Update text matchers that expect the shell messages without the `invalid arguments: ` prefix. diff --git a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.zh.md b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.zh.md new file mode 100644 index 0000000000..672a2e4074 --- /dev/null +++ b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.zh.md @@ -0,0 +1,28 @@ +--- +kind: upgrade-guide +description: "bash 与 pwsh 把 schema 未公开的 sandbox_permissions 与 run_in_background 报为 ToolArgsError,删除 JOB_BACKGROUND_DISABLED,read_image 改报 MODEL_DOES_NOT_SUPPORT_IMAGES 而非 IMAGE_UNSUPPORTED_MODEL。" +--- + +# Shell 与 read_image 的失败改用统一的错误 code + +[English](guide.md) | 中文 + +## 变更 + +v0.2.2-rc.2 记录的三种 `tool/result` 错误标识发生变化: + +| 失败 | v0.2.2-rc.2 | 现在 | +| --- | --- | --- | +| 在没有沙箱执行器的组合中,`bash` 或 `pwsh` 收到 `sandbox_permissions` | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` | +| `enableRunInBackground: false` 时,`bash` 或 `pwsh` 收到 `run_in_background: true` | `JobError` / `JOB_BACKGROUND_DISABLED` | `ToolArgsError` / `INVALID_ARGS` | +| `read_image` 运行在不支持图像输入的模型路由上 | `ImageInputError` / `IMAGE_UNSUPPORTED_MODEL` | `ImageInputError` / `MODEL_DOES_NOT_SUPPORT_IMAGES` | + +两个 shell 情形中,被拒绝的参数都没有出现在 schema 里,模型的修正办法是去掉它。这两条 shell 消息现在以 `invalid arguments: ` 开头,模型和对话记录的读者都能看到。`SANDBOX_ESCALATION_UNAVAILABLE` 仍用于组合无法发起审批的情形。 + +`@deepseek-ai/dsh-jobs` 的 `JOB_ERROR_CODES` 与 `JobErrorCode` 类型删除了 `JOB_BACKGROUND_DISABLED`。`@deepseek-ai/dsh-tool-fs` 的 `ImageInputErrorCode` 用 `MODEL_DOES_NOT_SUPPORT_IMAGES` 替换 `IMAGE_UNSUPPORTED_MODEL`,子 agent 附件与 Session 附件拒绝已在使用这个值。 + +## 迁移 + +1. 读取 `tool/result` `error` 的统计或重试规则中,把 `JOB_BACKGROUND_DISABLED` 与 shell 的 `SANDBOX_ESCALATION_UNAVAILABLE` 情形映射为 `INVALID_ARGS`,把 `IMAGE_UNSUPPORTED_MODEL` 映射为 `MODEL_DOES_NOT_SUPPORT_IMAGES`。v0.2.2-rc.2 写入的 Session 日志保留旧值。 +2. 替换 TypeScript 中对 `'JOB_BACKGROUND_DISABLED'` 或 `'IMAGE_UNSUPPORTED_MODEL'` 的引用;`pnpm run typecheck` 会报出剩余的引用。 +3. 更新那些期望 shell 消息不带 `invalid arguments: ` 前缀的文本匹配。 From efc62d7b060ea61eccb34a2539ad8b78e8a47d4c Mon Sep 17 00:00:00 2001 From: sjw1231 Date: Thu, 12 Nov 2026 15:29:38 +0800 Subject: [PATCH 5/5] fix(bash,pwsh,fs,ptc): reject unadvertised arguments before pairing and approval Without a sandboxing backend, a lone sandbox_permissions or justification failed the pairing check and asked the model to add the other field, and bash/pwsh checked a disabled run_in_background only after an escalation approval. Reject unadvertised escalation fields and a disabled background request during argument validation in bash, pwsh, write/edit/apply_patch, and run_code, and name both escalation fields in the message. Update the upgrade guide to identify rc.2 shell records by message. Refs #7869 --- .../shell-fs-tool-error-codes/guide.i18n.yaml | 8 +-- .../shell-fs-tool-error-codes/guide.md | 10 ++-- .../shell-fs-tool-error-codes/guide.zh.md | 10 ++-- packages/core/tool-executor-ptc/src/ptc.ts | 10 ++-- .../core/tool-executor-ptc/tests/ptc.spec.ts | 10 ++-- packages/fs/tool-fs/src/sandbox.ts | 7 +-- packages/fs/tool-fs/tests/tools.spec.ts | 10 ++-- packages/shell/tool-bash/README.i18n.yaml | 8 +-- packages/shell/tool-bash/README.md | 4 +- packages/shell/tool-bash/README.zh.md | 4 +- packages/shell/tool-bash/src/index.ts | 51 ++++++++++++------ packages/shell/tool-bash/tests/tools.spec.ts | 24 +++++++-- packages/shell/tool-pwsh/README.i18n.yaml | 8 +-- packages/shell/tool-pwsh/README.md | 4 +- packages/shell/tool-pwsh/README.zh.md | 4 +- packages/shell/tool-pwsh/src/index.ts | 52 +++++++++++++------ packages/shell/tool-pwsh/tests/tools.spec.ts | 24 +++++++-- 17 files changed, 167 insertions(+), 81 deletions(-) diff --git a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.i18n.yaml b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.i18n.yaml index 1c0edd4899..2e675bd3f4 100644 --- a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.i18n.yaml +++ b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.i18n.yaml @@ -9,8 +9,8 @@ en: f67fb81f55897105 zh: f74bb4d9e995f156 /shell-and-read-image-failures-use-consolidated-error-codes/change: - en: 16595e7db2999ca3 - zh: 42b44f7ea29ddfb1 + en: 623c6bfe8ffcfe7d + zh: ee26abc3d312b93b /shell-and-read-image-failures-use-consolidated-error-codes/migration: - en: 0e111ffbadee4e2e - zh: cb1e8d6ef74f5cee + en: 24d3f8972933bbe6 + zh: f03379efdb5809b2 diff --git a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md index bb52b0ff26..d0c1e0c378 100644 --- a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md +++ b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.md @@ -13,16 +13,18 @@ Three `tool/result` error identities recorded by v0.2.2-rc.2 change: | Failure | v0.2.2-rc.2 | Now | | --- | --- | --- | -| `bash` or `pwsh` receives `sandbox_permissions` in a composition without a sandboxing executor | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` | +| `bash` or `pwsh` receives `sandbox_permissions` and `justification` in a composition without a sandboxing executor | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` | | `bash` or `pwsh` receives `run_in_background: true` with `enableRunInBackground: false` | `JobError` / `JOB_BACKGROUND_DISABLED` | `ToolArgsError` / `INVALID_ARGS` | | `read_image` runs on a model route without image input | `ImageInputError` / `IMAGE_UNSUPPORTED_MODEL` | `ImageInputError` / `MODEL_DOES_NOT_SUPPORT_IMAGES` | -In both shell cases the schema does not advertise the rejected argument, so the model's fix is to drop it. Both shell messages now start with `invalid arguments: `, which the model and transcript readers see. `SANDBOX_ESCALATION_UNAVAILABLE` remains for compositions that cannot route an approval. +In both shell cases the schema does not advertise the rejected argument, so the model's fix is to drop it. When only one of `sandbox_permissions` and `justification` reaches `bash`, `pwsh`, `write`, `edit`, or `apply_patch` without a sandboxing backend, the call previously failed the pairing check with `SandboxEscalationError` / `SANDBOX_ESCALATION_INVALID_ARGUMENT`; it now reports `INVALID_ARGS` as well. These calls are rejected before any approval request. + +The shell messages now start with `invalid arguments: `, and the escalation message names both fields: `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`. `SANDBOX_ESCALATION_UNAVAILABLE` keeps its meaning for compositions that have a sandboxing executor but no approval service, calling Agent, or approval channel. `JOB_BACKGROUND_DISABLED` is removed from `JOB_ERROR_CODES` and the `JobErrorCode` type in `@deepseek-ai/dsh-jobs`. `ImageInputErrorCode` in `@deepseek-ai/dsh-tool-fs` replaces `IMAGE_UNSUPPORTED_MODEL` with `MODEL_DOES_NOT_SUPPORT_IMAGES`, the value subagent attachments and Session attachment rejections already use. ## Migration -1. In analytics or retry rules that read `tool/result` `error`, map `JOB_BACKGROUND_DISABLED` and the shell `SANDBOX_ESCALATION_UNAVAILABLE` case to `INVALID_ARGS`, and `IMAGE_UNSUPPORTED_MODEL` to `MODEL_DOES_NOT_SUPPORT_IMAGES`. Session logs written by v0.2.2-rc.2 keep the old values. +1. In analytics or retry rules that read `tool/result` `error`, treat v0.2.2-rc.2 `JOB_BACKGROUND_DISABLED` results as `INVALID_ARGS` and `IMAGE_UNSUPPORTED_MODEL` as `MODEL_DOES_NOT_SUPPORT_IMAGES`. For `SANDBOX_ESCALATION_UNAVAILABLE`, `error` alone does not identify the shell case: treat a v0.2.2-rc.2 `bash` or `pwsh` result as `INVALID_ARGS` only when its message contains `no sandboxing executor to escalate`, and keep every other `SANDBOX_ESCALATION_UNAVAILABLE` result unchanged. Session logs keep the values they were written with. 2. Replace TypeScript references to `'JOB_BACKGROUND_DISABLED'` or `'IMAGE_UNSUPPORTED_MODEL'`; `pnpm run typecheck` reports any that remain. -3. Update text matchers that expect the shell messages without the `invalid arguments: ` prefix. +3. Update text matchers that expect the earlier shell messages, which had no `invalid arguments: ` prefix and named only `sandbox_permissions`. diff --git a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.zh.md b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.zh.md index 672a2e4074..d446ad3263 100644 --- a/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.zh.md +++ b/docs/upgrade-guide/v0.2.2-rc.2/shell-fs-tool-error-codes/guide.zh.md @@ -13,16 +13,18 @@ v0.2.2-rc.2 记录的三种 `tool/result` 错误标识发生变化: | 失败 | v0.2.2-rc.2 | 现在 | | --- | --- | --- | -| 在没有沙箱执行器的组合中,`bash` 或 `pwsh` 收到 `sandbox_permissions` | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` | +| 在没有沙箱执行器的组合中,`bash` 或 `pwsh` 收到 `sandbox_permissions` 与 `justification` | `SandboxEscalationError` / `SANDBOX_ESCALATION_UNAVAILABLE` | `ToolArgsError` / `INVALID_ARGS` | | `enableRunInBackground: false` 时,`bash` 或 `pwsh` 收到 `run_in_background: true` | `JobError` / `JOB_BACKGROUND_DISABLED` | `ToolArgsError` / `INVALID_ARGS` | | `read_image` 运行在不支持图像输入的模型路由上 | `ImageInputError` / `IMAGE_UNSUPPORTED_MODEL` | `ImageInputError` / `MODEL_DOES_NOT_SUPPORT_IMAGES` | -两个 shell 情形中,被拒绝的参数都没有出现在 schema 里,模型的修正办法是去掉它。这两条 shell 消息现在以 `invalid arguments: ` 开头,模型和对话记录的读者都能看到。`SANDBOX_ESCALATION_UNAVAILABLE` 仍用于组合无法发起审批的情形。 +两个 shell 情形中,被拒绝的参数都没有出现在 schema 里,模型的修正办法是去掉它。在没有沙箱后端时,若 `bash`、`pwsh`、`write`、`edit` 或 `apply_patch` 只收到 `sandbox_permissions` 与 `justification` 之一,此前会在配对校验中以 `SandboxEscalationError` / `SANDBOX_ESCALATION_INVALID_ARGUMENT` 失败;现在同样报 `INVALID_ARGS`。这些调用会在任何审批请求之前被拒绝。 + +shell 消息现在以 `invalid arguments: ` 开头,升权消息同时点名两个字段:`invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`。对于有沙箱执行器、但缺少审批服务、调用方 Agent 或审批通道的组合,`SANDBOX_ESCALATION_UNAVAILABLE` 的含义不变。 `@deepseek-ai/dsh-jobs` 的 `JOB_ERROR_CODES` 与 `JobErrorCode` 类型删除了 `JOB_BACKGROUND_DISABLED`。`@deepseek-ai/dsh-tool-fs` 的 `ImageInputErrorCode` 用 `MODEL_DOES_NOT_SUPPORT_IMAGES` 替换 `IMAGE_UNSUPPORTED_MODEL`,子 agent 附件与 Session 附件拒绝已在使用这个值。 ## 迁移 -1. 读取 `tool/result` `error` 的统计或重试规则中,把 `JOB_BACKGROUND_DISABLED` 与 shell 的 `SANDBOX_ESCALATION_UNAVAILABLE` 情形映射为 `INVALID_ARGS`,把 `IMAGE_UNSUPPORTED_MODEL` 映射为 `MODEL_DOES_NOT_SUPPORT_IMAGES`。v0.2.2-rc.2 写入的 Session 日志保留旧值。 +1. 读取 `tool/result` `error` 的统计或重试规则中,把 v0.2.2-rc.2 的 `JOB_BACKGROUND_DISABLED` 结果视为 `INVALID_ARGS`,把 `IMAGE_UNSUPPORTED_MODEL` 视为 `MODEL_DOES_NOT_SUPPORT_IMAGES`。仅凭 `error` 无法从 `SANDBOX_ESCALATION_UNAVAILABLE` 中分出 shell 情形:只有 v0.2.2-rc.2 的 `bash` 或 `pwsh` 结果的消息含 `no sandboxing executor to escalate` 时,才视为 `INVALID_ARGS`;其余 `SANDBOX_ESCALATION_UNAVAILABLE` 结果保持原义。Session 日志保留写入时的值。 2. 替换 TypeScript 中对 `'JOB_BACKGROUND_DISABLED'` 或 `'IMAGE_UNSUPPORTED_MODEL'` 的引用;`pnpm run typecheck` 会报出剩余的引用。 -3. 更新那些期望 shell 消息不带 `invalid arguments: ` 前缀的文本匹配。 +3. 更新那些期望旧 shell 消息的文本匹配:旧消息没有 `invalid arguments: ` 前缀,且只点名 `sandbox_permissions`。 diff --git a/packages/core/tool-executor-ptc/src/ptc.ts b/packages/core/tool-executor-ptc/src/ptc.ts index 928fb7996d..e8682f041a 100644 --- a/packages/core/tool-executor-ptc/src/ptc.ts +++ b/packages/core/tool-executor-ptc/src/ptc.ts @@ -403,6 +403,10 @@ export function createRunCodeTransport( } const runtime = getRuntime() const run = async (callSignal: AbortSignal): Promise => { + // The schema omits both fields without runtime confinement; reject them before pairing checks. + if (runtime.sandboxMode === undefined && (args.sandbox_permissions !== undefined || args.justification !== undefined)) { + throw new ToolArgsError(['sandbox_permissions and justification are not available for this PTC runtime']) + } validateEscalationArgs(args.sandbox_permissions, args.justification) if (args.timeoutMs !== undefined && runtime.timeout === undefined) { throw new ToolArgsError(['timeoutMs is not available for this PTC runtime']) @@ -413,17 +417,17 @@ export function createRunCodeTransport( const standingPolicy = runtime.sandboxMode === undefined ? undefined : resolveSandboxPolicy(ctx, exec) let policy = standingPolicy if (args.sandbox_permissions !== undefined && args.justification !== undefined) { - if (standingPolicy === undefined) throw new ToolArgsError(['sandbox_permissions is not available for this PTC runtime']) + const confined = standingPolicy as SandboxExecutionPolicy const approvedMode = await approveEscalation({ requestedMode: args.sandbox_permissions, justification: args.justification, - effectiveMode: standingPolicy.mode, + effectiveMode: confined.mode, subject: 'program', }, { approver: ctx.get('approval'), agent: exec.agent, callId: exec.callId, toolName, signal: callSignal, }) - policy = { ...standingPolicy, mode: approvedMode } + policy = { ...confined, mode: approvedMode } } const cwd = await resolveWorkingDirectory(ctx, { ...exec, signal: callSignal }) callSignal.throwIfAborted() diff --git a/packages/core/tool-executor-ptc/tests/ptc.spec.ts b/packages/core/tool-executor-ptc/tests/ptc.spec.ts index 99c7285569..78a8fd402d 100644 --- a/packages/core/tool-executor-ptc/tests/ptc.spec.ts +++ b/packages/core/tool-executor-ptc/tests/ptc.spec.ts @@ -2890,15 +2890,19 @@ describe('per-program execution controls', () => { } finally { await ctx.fiber.dispose() } }) - it('rejects escalation fields for a runtime without confinement support', async () => { + it.each([ + { sandbox_permissions: 'workspace-write', justification: 'Need file writes' }, + { sandbox_permissions: 'workspace-write' }, + { justification: 'Need file writes' }, + ])('rejects escalation fields for a runtime without confinement support: %o', async (fields) => { const { ctx, tools, runtime } = await setup() try { const result = await tools.execute({ callId: brandString('unsupported-escalation'), name: RUN_CODE_NAME, signal: testToolSignal, - arguments: { code: 'return 1', description: 'Try an unsupported mode', sandbox_permissions: 'workspace-write', justification: 'Need file writes' }, + arguments: { code: 'return 1', description: 'Try an unsupported mode', ...fields }, }) expect(result.isError).toBe(true) - expect(JSON.stringify(result.content)).toContain('sandbox_permissions is not available for this PTC runtime') + expect(JSON.stringify(result.content)).toContain('invalid arguments: sandbox_permissions and justification are not available for this PTC runtime') expect(result.error?.info).toEqual({ name: 'ToolArgsError', code: 'INVALID_ARGS' }) expect(runtime.lastRequest).toBeUndefined() } finally { await ctx.fiber.dispose() } diff --git a/packages/fs/tool-fs/src/sandbox.ts b/packages/fs/tool-fs/src/sandbox.ts index 08b776fd92..c4c7ea744f 100644 --- a/packages/fs/tool-fs/src/sandbox.ts +++ b/packages/fs/tool-fs/src/sandbox.ts @@ -87,6 +87,10 @@ export class FsSandboxController { * unsandboxed backend. */ async resolvePolicy(toolName: string, args: FsEscalationArgs, exec: ToolExecution): Promise { + // The schema omits both fields without a sandboxing filesystem; reject them before pairing checks. + if (this.escalationModes.length === 0 && (args.sandbox_permissions !== undefined || (args.justification ?? '').trim() !== '')) { + throw new ToolArgsError(['sandbox_permissions and justification are not available in this composition (no sandboxing filesystem to escalate)']) + } const standingPolicy = this.policy?.resolve({ ...exec.agent ? { session: exec.agent.session } : {} }) if (args.sandbox_permissions !== undefined && args.sandbox_permissions === standingPolicy?.mode) return standingPolicy const justification = args.sandbox_permissions === undefined && args.justification?.trim() === '' @@ -96,9 +100,6 @@ export class FsSandboxController { if (args.sandbox_permissions === undefined || args.justification === undefined) { return standingPolicy } - if (this.escalationModes.length === 0) { - throw new ToolArgsError(['sandbox_permissions is not available in this composition (no sandboxing filesystem to escalate)']) - } const policy = standingPolicy as SandboxExecutionPolicy const approvedMode = await approveEscalation( { requestedMode: args.sandbox_permissions, justification: args.justification, effectiveMode: policy.mode, subject: 'operation' }, diff --git a/packages/fs/tool-fs/tests/tools.spec.ts b/packages/fs/tool-fs/tests/tools.spec.ts index 2f47c0774c..f7482e8145 100644 --- a/packages/fs/tool-fs/tests/tools.spec.ts +++ b/packages/fs/tool-fs/tests/tools.spec.ts @@ -1146,11 +1146,15 @@ describe('sandbox escalation API (write/edit)', () => { expect(text(orphan)).toContain('justification is only valid together with sandbox_permissions') }) - it('sandbox_permissions under a non-confining backend fails closed (unadvertised field still reaches execute)', async () => { + it.each([ + { sandbox_permissions: 'workspace-write', justification: 'why' }, + { sandbox_permissions: 'workspace-write' }, + { justification: 'why' }, + ])('rejects unadvertised escalation fields under a non-confining backend as argument errors: %o', async (fields) => { const { ctx } = await setup() - const result = await call(ctx, 'write', { file_path: 'a.txt', content: 'x', sandbox_permissions: 'workspace-write', justification: 'why' }, escalationAgent()) + const result = await call(ctx, 'write', { file_path: 'a.txt', content: 'x', ...fields }, escalationAgent()) expect(result.isError).toBe(true) - expect(text(result)).toContain('not available in this composition') + expect(text(result)).toContain('invalid arguments: sandbox_permissions and justification are not available in this composition') expect(result.error?.info).toEqual({ name: 'ToolArgsError', code: 'INVALID_ARGS' }) }) }) diff --git a/packages/shell/tool-bash/README.i18n.yaml b/packages/shell/tool-bash/README.i18n.yaml index 728123f70d..b1e527980b 100644 --- a/packages/shell/tool-bash/README.i18n.yaml +++ b/packages/shell/tool-bash/README.i18n.yaml @@ -33,8 +33,8 @@ en: 472beeb895ca46cf zh: ba110c9f62f7d5b8 /deepseek-ai-dsh-tool-bash/use-this-package/what-can-go-wrong: - en: c1f4b88a5fd84616 - zh: 8f7328b9edab462f + en: 52c02853f32bf6f9 + zh: 77355e3df066527b /deepseek-ai-dsh-tool-bash/understand-the-implementation: en: 165313776a851b51 zh: 828f48807036aff0 @@ -111,8 +111,8 @@ en: 2d4f2c8605eccab3 zh: 67f1f0218f73c6bf /deepseek-ai-dsh-tool-bash/model-experience/tool-errors/what-the-model-sees: - en: 5dc3bd182ef54b08 - zh: be8a55f8aefada5a + en: a59c3d16f59c7577 + zh: 24dd44d419e240a0 /deepseek-ai-dsh-tool-bash/model-experience/tool-errors/token-effect: en: a3a78ef476ec5e56 zh: dd2c8ad0f69e8ff1 diff --git a/packages/shell/tool-bash/README.md b/packages/shell/tool-bash/README.md index e1b0328dea..d52456d45a 100644 --- a/packages/shell/tool-bash/README.md +++ b/packages/shell/tool-bash/README.md @@ -71,7 +71,7 @@ When the mounted executor confines commands (for example `dsh-bash-sandbox`), a ### What can go wrong -A composition with no executor provider never activates the tool. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` without a sandboxing executor fails with `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`. `enableRunInBackground: false` removes the parameter and rejects a forced background call at execution time. +A composition with no executor provider never activates the tool. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` or `justification` without a sandboxing executor fails with `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`. `enableRunInBackground: false` removes the parameter and rejects a forced background call at execution time. ----- @@ -196,7 +196,7 @@ Append-only; newly visible content follows the reusable request prefix and does #### What the model sees -Validation and policy failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` or `run_in_background` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. +Validation and policy failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`, the approval availability/rejection/cancellation variants, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including `sandbox_permissions`, `justification`, or `run_in_background` when the schema does not advertise them, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. #### Token effect diff --git a/packages/shell/tool-bash/README.zh.md b/packages/shell/tool-bash/README.zh.md index 5b64623210..440c0411c5 100644 --- a/packages/shell/tool-bash/README.zh.md +++ b/packages/shell/tool-bash/README.zh.md @@ -71,7 +71,7 @@ kind: "package-reference" ### 可能出什么问题 -没有执行器提供方的组合永远不会激活该工具。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时的 `sandbox_permissions` 会以 `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)` 失败。`enableRunInBackground: false` 会移除该参数,并在执行时拒绝强制后台调用。 +没有执行器提供方的组合永远不会激活该工具。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时传入 `sandbox_permissions` 或 `justification` 会以 `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)` 失败。`enableRunInBackground: false` 会移除该参数,并在执行时拒绝强制后台调用。 ----- @@ -196,7 +196,7 @@ renderer 输出依数据而定的 stdout 尾部,再输出可选的 `[stderr]` #### 模型看到什么 -验证与策略失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 +验证与策略失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`、`invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`、审批不可用/拒绝/取消变体,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions`、`justification` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 #### Token 影响 diff --git a/packages/shell/tool-bash/src/index.ts b/packages/shell/tool-bash/src/index.ts index 1cc603b0da..e607a0d22a 100644 --- a/packages/shell/tool-bash/src/index.ts +++ b/packages/shell/tool-bash/src/index.ts @@ -72,7 +72,35 @@ interface BashToolArgs { justification?: string } -function validateBashArgs(args: BashToolArgs, effectiveMode: SandboxMode | undefined): void { +/** Which optional argument groups the registered schema advertises in this composition. */ +interface AdvertisedArgs { + /** `sandbox_permissions` and `justification`; advertised only with a sandboxing executor. */ + escalation: boolean + /** `run_in_background`; advertised unless `enableRunInBackground: false`. */ + background: boolean +} + +/** + * Reject arguments the schema does not advertise. Schema validation checks + * advertised keys only, so these still reach `execute`; the model fixes the call + * by dropping them, which makes them argument errors. Runs before escalation + * pairing checks, approval, and working-directory setup. + * @param args - the call's arguments. + * @param advertised - the argument groups this composition advertises. + */ +function rejectUnadvertisedArgs( + args: { sandbox_permissions?: string; justification?: string; run_in_background?: boolean }, + advertised: AdvertisedArgs, +): void { + if (!advertised.escalation && (args.sandbox_permissions !== undefined || (args.justification ?? '').trim() !== '')) { + throw new ToolArgsError(['sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)']) + } + if (!advertised.background && args.run_in_background === true) { + throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)']) + } +} + +function validateBashArgs(args: BashToolArgs, effectiveMode: SandboxMode | undefined, advertised: AdvertisedArgs): void { if (args.command.trim().length === 0) { throw new ToolArgsError(['invalid command: expected a non-empty string']) } @@ -82,6 +110,7 @@ function validateBashArgs(args: BashToolArgs, effectiveMode: SandboxMode | undef if (args.timeoutMs !== undefined && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) { throw new ToolArgsError([`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`]) } + rejectUnadvertisedArgs(args, advertised) if (args.sandbox_permissions !== undefined && args.sandbox_permissions === effectiveMode) return const justification = args.sandbox_permissions === undefined && args.justification?.trim() === '' ? undefined @@ -233,12 +262,11 @@ export function apply(ctx: Context, config: Config = {}): void { * Resolve a sandbox-escalation request through `ctx.approval` BEFORE * anything executes, delegating the shared fail-closed sequence (strict * widening, channel resolution, outcome mapping) to - * {@link approveEscalation}. This tool contributes only the composition - * guard (the fields are unadvertised without a sandboxing executor, yet - * schema validation checks advertised keys only, so an unadvertised - * `sandbox_permissions` still reaches execute) and the approval - * ingredients. The shared policy resolver is required whenever the executor - * advertises confinement, so a split composition fails at tool-plugin load. + * {@link approveEscalation}. This tool contributes only the approval + * ingredients; {@link validateBashArgs} has already rejected the fields when + * no sandboxing executor advertises them. The shared policy resolver is + * required whenever the executor advertises confinement, so a split + * composition fails at tool-plugin load. */ const approveBashEscalation = ( mode: string, @@ -246,9 +274,6 @@ export function apply(ctx: Context, config: Config = {}): void { exec: ToolExecution, standingPolicy: SandboxExecutionPolicy | undefined, ): Promise => { - if (escalationModes.length === 0) { - throw new ToolArgsError(['sandbox_permissions is not available in this composition (no sandboxing executor to escalate)']) - } const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode return approveEscalation( { requestedMode: mode, justification, effectiveMode, subject: 'command' }, @@ -498,7 +523,7 @@ export function apply(ctx: Context, config: Config = {}): void { async execute(args: BashToolArgs, exec) { // Description is display metadata; workdir defaults to the caller's session. const standingPolicy = resolveSandboxPolicy(exec) - validateBashArgs(args, standingPolicy?.mode) + validateBashArgs(args, standingPolicy?.mode, { escalation: escalationModes.length > 0, background: backgroundEnabled }) const approvedMode = args.sandbox_permissions !== undefined && args.justification !== undefined ? await approveBashEscalation(args.sandbox_permissions, args.justification, exec, standingPolicy) : undefined @@ -516,10 +541,6 @@ export function apply(ctx: Context, config: Config = {}): void { ...policy !== undefined ? { sandboxPolicy: policy } : {}, } if (args.run_in_background === true) { - // Undeclared keys are allowed, so schema omission also needs enforcement. - if (!backgroundEnabled) { - throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)']) - } if (jobs === undefined) { throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs') } diff --git a/packages/shell/tool-bash/tests/tools.spec.ts b/packages/shell/tool-bash/tests/tools.spec.ts index ed3aea4cf0..8fa050009b 100644 --- a/packages/shell/tool-bash/tests/tools.spec.ts +++ b/packages/shell/tool-bash/tests/tools.spec.ts @@ -215,7 +215,7 @@ class CountingStartExecutor extends ShellExecutor { } } -async function setupSandboxed(withApproval = false) { +async function setupSandboxed(withApproval = false, toolConfig: Partial = {}) { const ctx = new Context() provideWorkingDirectoryFixture(ctx) await ctx.plugin(SystemPrompt) @@ -229,7 +229,7 @@ async function setupSandboxed(withApproval = false) { await ctx.plugin(RecordingSandboxExecutor) if (withApproval) await ctx.plugin(ApprovalService) await ctx.plugin(BashEnvPlugin) - await ctx.plugin(ToolBash) + await ctx.plugin(ToolBash, toolConfig) return { ctx, bash: ctx.shell as RecordingSandboxExecutor } } @@ -798,11 +798,25 @@ describe('sandbox escalation through the generic task producer', () => { } }) + it('rejects a forced background call before asking for an escalation', async () => { + const { ctx, bash } = await setupSandboxed(true, { enableRunInBackground: false }) + const prompted = vi.fn() + ctx.on('approval/request', () => { prompted(); return Promise.resolve('allowed-once') }) + const result = await call(ctx, 'bash', { ...escalate, run_in_background: true }, sandboxAgent()) + expect(text(result)).toContain('invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)') + expect(result).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) + expect(prompted).not.toHaveBeenCalled() + expect(bash.modes).toEqual([]) + }) + it('rejects injected escalation without a sandbox and narrower escalation without prompting', async () => { const plain = await setup() - const unavailable = await call(plain, 'bash', escalate) - expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions is not available in this composition') - expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) + const { command, description, sandbox_permissions, justification } = escalate + for (const args of [escalate, { command, description, sandbox_permissions }, { command, description, justification }]) { + const unavailable = await call(plain, 'bash', args) + expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions and justification are not available in this composition') + expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) + } const { ctx } = await setupSandboxed(true) const prompted = vi.fn() diff --git a/packages/shell/tool-pwsh/README.i18n.yaml b/packages/shell/tool-pwsh/README.i18n.yaml index 6aebdcb45a..110d0f9114 100644 --- a/packages/shell/tool-pwsh/README.i18n.yaml +++ b/packages/shell/tool-pwsh/README.i18n.yaml @@ -33,8 +33,8 @@ en: 76f3f791f53d1005 zh: e5b262db24e6eb83 /deepseek-ai-dsh-tool-pwsh/use-this-package/what-can-go-wrong: - en: b59d36b896c2d2e8 - zh: f0145138ec8ca116 + en: 4a1fae5d79a4d13d + zh: 0b5206086a58ee9c /deepseek-ai-dsh-tool-pwsh/understand-the-implementation: en: 165313776a851b51 zh: 828f48807036aff0 @@ -108,8 +108,8 @@ en: 2d4f2c8605eccab3 zh: 67f1f0218f73c6bf /deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/what-the-model-sees: - en: efc9d4c72556b355 - zh: 9b959bb612d39108 + en: 828df448c1128f2f + zh: 720c590c01089651 /deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/token-effect: en: 243bad012dd99c7f zh: 5ee74905020bd49a diff --git a/packages/shell/tool-pwsh/README.md b/packages/shell/tool-pwsh/README.md index 456c57d628..c8c338307b 100644 --- a/packages/shell/tool-pwsh/README.md +++ b/packages/shell/tool-pwsh/README.md @@ -66,7 +66,7 @@ Under a sandboxing executor, denied commands report `[sandbox: file access denie ### What can go wrong -A composition with no PowerShell executor never activates the tool, and the injected services (`tools`, `shell`, `systemPrompt`, `shellEnv`) must all exist. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` without a sandboxing executor fails with `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`. +A composition with no PowerShell executor never activates the tool, and the injected services (`tools`, `shell`, `systemPrompt`, `shellEnv`) must all exist. Background calls without the job runtime fail with `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `sandbox_permissions` or `justification` without a sandboxing executor fails with `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`. ----- @@ -188,7 +188,7 @@ Append-only; newly visible content follows the reusable request prefix and does #### What the model sees -Validation and infrastructure failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`, the shared escalation failures (not strictly wider / no approval service / no agent to route / no approval channel / user rejected / was cancelled), `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including a `sandbox_permissions` or `run_in_background` the schema does not advertise, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. +Validation and infrastructure failures are normalized as `Error: `. This package's stable messages are `invalid arguments: invalid command: expected a non-empty string`, `invalid arguments: invalid description: expected a non-empty string`, `invalid arguments: invalid timeoutMs: expected a positive number, got `, the escalation pairing failures, `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`, the shared escalation failures (not strictly wider / no approval service / no agent to route / no approval channel / user rejected / was cancelled), `invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`, `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`, and `tool call aborted`. Each failure also records `error.name` and `error.code` on `tool/result`: argument violations, including `sandbox_permissions`, `justification`, or `run_in_background` when the schema does not advertise them, are `ToolArgsError` (`INVALID_ARGS`, message prefix `invalid arguments: `), escalation failures are `SandboxEscalationError` (`SANDBOX_ESCALATION_INVALID_ARGUMENT`, `_UNAVAILABLE`, `_REJECTED`, `_CANCELLED`), a missing job runtime is `ToolContextUnavailableError` (`TOOL_CONTEXT_UNAVAILABLE`), and cancellation is `AbortError` (`ABORTED`). A launch or preparation failure keeps the class and code it was thrown with, such as `SandboxUnavailableError` or `SandboxPreparationError`, whether the call waited on a job or not; a platform spawn error, recognized by its errno `code`, becomes `SubprocessError` (`SUBPROCESS_SPAWN_NOT_FOUND` for `ENOENT`, otherwise `SUBPROCESS_SPAWN_FAILED`), even when it settles after the call was cancelled. #### Token effect diff --git a/packages/shell/tool-pwsh/README.zh.md b/packages/shell/tool-pwsh/README.zh.md index d60a056501..861836442f 100644 --- a/packages/shell/tool-pwsh/README.zh.md +++ b/packages/shell/tool-pwsh/README.zh.md @@ -66,7 +66,7 @@ kind: "package-reference" ### 可能出什么问题 -没有 PowerShell 执行器的组合永远不会激活该工具,且注入的服务(`tools`、`shell`、`systemPrompt`、`shellEnv`)必须全部存在。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时的 `sandbox_permissions` 会以 `invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)` 失败。 +没有 PowerShell 执行器的组合永远不会激活该工具,且注入的服务(`tools`、`shell`、`systemPrompt`、`shellEnv`)必须全部存在。没有任务运行时的后台调用会以 `background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs` 失败;没有沙箱执行器时传入 `sandbox_permissions` 或 `justification` 会以 `invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)` 失败。 ----- @@ -188,7 +188,7 @@ Non-zero exits are reported as `[exit code: N]` markers; investigate failures be #### 模型看到什么 -验证与基础设施失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`invalid arguments: sandbox_permissions is not available in this composition (no sandboxing executor to escalate)`、共享升权失败(未严格加宽/无审批服务/无 agent 可路由/无审批通道/用户拒绝/已取消)、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 +验证与基础设施失败统一为 `Error: `。本包的稳定消息包括 `invalid arguments: invalid command: expected a non-empty string`、`invalid arguments: invalid description: expected a non-empty string`、`invalid arguments: invalid timeoutMs: expected a positive number, got `、升权配对失败、`invalid arguments: sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)`、共享升权失败(未严格加宽/无审批服务/无 agent 可路由/无审批通道/用户拒绝/已取消)、`invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)`、`background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs`,以及 `tool call aborted`。每个失败还会在 `tool/result` 上记录 `error.name` 与 `error.code`:参数违规(包括 schema 未公开时传入的 `sandbox_permissions`、`justification` 或 `run_in_background`)为 `ToolArgsError`(`INVALID_ARGS`,消息前缀为 `invalid arguments: `),升权失败为 `SandboxEscalationError`(`SANDBOX_ESCALATION_INVALID_ARGUMENT`、`_UNAVAILABLE`、`_REJECTED`、`_CANCELLED`),缺少任务运行时为 `ToolContextUnavailableError`(`TOOL_CONTEXT_UNAVAILABLE`),取消为 `AbortError`(`ABORTED`)。启动或准备阶段的失败保留其抛出时的类与 code(例如 `SandboxUnavailableError` 或 `SandboxPreparationError`),无论调用是否在 job 上等待;按 errno `code` 识别的平台 spawn 错误转为 `SubprocessError`(`ENOENT` 为 `SUBPROCESS_SPAWN_NOT_FOUND`,其余为 `SUBPROCESS_SPAWN_FAILED`),在调用取消后才出现时也是如此。 #### Token 影响 diff --git a/packages/shell/tool-pwsh/src/index.ts b/packages/shell/tool-pwsh/src/index.ts index a343d78159..f7e6bbb6da 100644 --- a/packages/shell/tool-pwsh/src/index.ts +++ b/packages/shell/tool-pwsh/src/index.ts @@ -106,7 +106,35 @@ interface PwshForegroundResult { } /* jscpd:ignore-start -- minimal mirror of dsh-tool-bash's validation and execute plumbing (Agent Note). */ -function validatePwshArgs(args: PwshToolArgs): void { +/** Which optional argument groups the registered schema advertises in this composition. */ +interface AdvertisedArgs { + /** `sandbox_permissions` and `justification`; advertised only with a sandboxing executor. */ + escalation: boolean + /** `run_in_background`; advertised unless `enableRunInBackground: false`. */ + background: boolean +} + +/** + * Reject arguments the schema does not advertise. Schema validation checks + * advertised keys only, so these still reach `execute`; the model fixes the call + * by dropping them, which makes them argument errors. Runs before escalation + * pairing checks, approval, and working-directory setup. + * @param args - the call's arguments. + * @param advertised - the argument groups this composition advertises. + */ +function rejectUnadvertisedArgs( + args: { sandbox_permissions?: string; justification?: string; run_in_background?: boolean }, + advertised: AdvertisedArgs, +): void { + if (!advertised.escalation && (args.sandbox_permissions !== undefined || (args.justification ?? '').trim() !== '')) { + throw new ToolArgsError(['sandbox_permissions and justification are not available in this composition (no sandboxing executor to escalate)']) + } + if (!advertised.background && args.run_in_background === true) { + throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)']) + } +} + +function validatePwshArgs(args: PwshToolArgs, advertised: AdvertisedArgs): void { if (args.command.trim().length === 0) { throw new ToolArgsError(['invalid command: expected a non-empty string']) } @@ -116,6 +144,7 @@ function validatePwshArgs(args: PwshToolArgs): void { if (args.timeoutMs !== undefined && (!Number.isFinite(args.timeoutMs) || args.timeoutMs <= 0)) { throw new ToolArgsError([`invalid timeoutMs: expected a positive number, got ${JSON.stringify(args.timeoutMs)}`]) } + rejectUnadvertisedArgs(args, advertised) validateEscalationArgs(args.sandbox_permissions, args.justification) } /* jscpd:ignore-end */ @@ -245,13 +274,11 @@ export function apply(ctx: Context, config: Config = {}): void { * Resolve a sandbox-escalation request through `ctx.approval` BEFORE * anything executes, delegating the shared fail-closed sequence (strict * widening, channel resolution, outcome mapping) to - * {@link approveEscalation}. This tool contributes only the composition - * guard (the fields are unadvertised without a sandboxing executor, yet - * schema validation checks advertised keys only, so an unadvertised - * `sandbox_permissions` still reaches execute) and the approval - * ingredients. The shared policy resolver is required whenever the - * executor advertises confinement, so a split composition fails at - * tool-plugin load. + * {@link approveEscalation}. This tool contributes only the approval + * ingredients; {@link validatePwshArgs} has already rejected the fields when + * no sandboxing executor advertises them. The shared policy resolver is + * required whenever the executor advertises confinement, so a split + * composition fails at tool-plugin load. */ const approvePwshEscalation = ( mode: string, @@ -259,9 +286,6 @@ export function apply(ctx: Context, config: Config = {}): void { exec: ToolExecution, standingPolicy: SandboxExecutionPolicy | undefined, ): Promise => { - if (escalationModes.length === 0) { - throw new ToolArgsError(['sandbox_permissions is not available in this composition (no sandboxing executor to escalate)']) - } const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode return approveEscalation( { requestedMode: mode, justification, effectiveMode, subject: 'command' }, @@ -520,7 +544,7 @@ export function apply(ctx: Context, config: Config = {}): void { }, /* jscpd:ignore-start -- the execute path mirrors dsh-tool-bash's by design (see the pwsh-tool-and-executor Agent Note). */ async execute(args: PwshToolArgs, exec) { - validatePwshArgs(args) + validatePwshArgs(args, { escalation: escalationModes.length > 0, background: backgroundEnabled }) // Description is display metadata; workdir defaults to the caller's session. const standingPolicy = resolveSandboxPolicy(exec) const approvedMode = args.sandbox_permissions !== undefined && args.justification !== undefined @@ -539,10 +563,6 @@ export function apply(ctx: Context, config: Config = {}): void { ...policy !== undefined ? { sandboxPolicy: policy } : {}, } if (args.run_in_background === true) { - // Undeclared keys are allowed, so schema omission also needs enforcement. - if (!backgroundEnabled) { - throw new ToolArgsError(['run_in_background is disabled for this deployment (enableRunInBackground: false)']) - } if (jobs === undefined) { throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs') } diff --git a/packages/shell/tool-pwsh/tests/tools.spec.ts b/packages/shell/tool-pwsh/tests/tools.spec.ts index 1082195d64..f77bb5a045 100644 --- a/packages/shell/tool-pwsh/tests/tools.spec.ts +++ b/packages/shell/tool-pwsh/tests/tools.spec.ts @@ -228,7 +228,7 @@ class ConfiningFakeBash extends ShellExecutor { } /** Sandboxed composition: the shared policy service + a confining executor + the pwsh tool (+ optional approval). */ -async function setupSandboxed(withApproval = false) { +async function setupSandboxed(withApproval = false, toolConfig: Partial = {}) { const ctx = new Context() provideWorkingDirectoryFixture(ctx) await ctx.plugin(SystemPrompt) @@ -245,7 +245,7 @@ async function setupSandboxed(withApproval = false) { await ctx.plugin(SandboxPolicyService, {}) await ctx.plugin(ConfiningFakeBash) if (withApproval) await ctx.plugin(ApprovalService) - await ctx.plugin(ToolPwsh) + await ctx.plugin(ToolPwsh, toolConfig) const bash = ctx.shell as ConfiningFakeBash return { ctx, bash } } @@ -682,11 +682,25 @@ describe('sandbox escalation through ctx.approval', () => { expect(schema.parameters.properties).not.toHaveProperty('sandbox_permissions') }) + it('rejects a forced background call before asking for an escalation', async () => { + const { ctx, bash } = await setupSandboxed(true, { enableRunInBackground: false }) + const prompted = vi.fn() + ctx.on('approval/request', () => { prompted(); return Promise.resolve('allowed-once') }) + const result = await call(ctx, 'pwsh', { ...escalate, run_in_background: true }, sandboxAgent()) + expect(text(result)).toContain('invalid arguments: run_in_background is disabled for this deployment (enableRunInBackground: false)') + expect(result).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) + expect(prompted).not.toHaveBeenCalled() + expect(bash.modes).toEqual([]) + }) + it('rejects injected escalation without a sandbox and narrower escalation without prompting', async () => { const plain = await setup() - const unavailable = await call(plain.ctx, 'pwsh', escalate) - expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions is not available in this composition') - expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) + const { command, description, sandbox_permissions, justification } = escalate + for (const args of [escalate, { command, description, sandbox_permissions }, { command, description, justification }]) { + const unavailable = await call(plain.ctx, 'pwsh', args) + expect(text(unavailable)).toContain('invalid arguments: sandbox_permissions and justification are not available in this composition') + expect(unavailable).toMatchObject({ error: { info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } } }) + } const { ctx } = await setupSandboxed(true) const prompted = vi.fn()