Merge pull request #8361 from deepseek-harness/refactor/tool-errors-consolidation

refactor(shell,fs,jobs): consolidate unadvertised-argument and image-input error codes
This commit is contained in:
Jiawei Song authored and GitHub committed 2026-11-12 15:50:34 +08:00
commit fbcc66220c
31 files changed
+253 -105

No files matched your search

+2 -2
View File
@@ -4140,7 +4140,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. */
@@ -4405,7 +4405,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. */
+2 -2
View File
@@ -4142,7 +4142,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. */
@@ -4407,7 +4407,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. */
@@ -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: 623c6bfe8ffcfe7d
zh: ee26abc3d312b93b
/shell-and-read-image-failures-use-consolidated-error-codes/migration:
en: 24d3f8972933bbe6
zh: f03379efdb5809b2
@@ -0,0 +1,30 @@
---
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` 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. 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`, 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 earlier shell messages, which had no `invalid arguments: ` prefix and named only `sandbox_permissions`.
@@ -0,0 +1,30 @@
---
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` 与 `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 里,模型的修正办法是去掉它。在没有沙箱后端时,若 `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` 的统计或重试规则中,把 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: ` 前缀,且只点名 `sandbox_permissions`。
+7 -3
View File
@@ -403,6 +403,10 @@ export function createRunCodeTransport(
}
const runtime = getRuntime()
const run = async (callSignal: AbortSignal): Promise<RunCodeOutput> => {
// 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()
@@ -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<ToolCallId>('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() }
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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: <message>` 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 <max>`, `cannot read "<path>": not found`, `cannot read "<path>": not a regular file`, and the image-route refusal `cannot read "<path>" as an image: model "<model>" does not declare image input; switch to an image-capable model to read images`. `FS_NOT_OBSERVED` is normalized to `cannot modify "<path>": 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.
+1 -1
View File
@@ -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: <message>`,并为调用方保留结构化错误码。稳定消息包括 `ToolArgsError`(`INVALID_ARGS`)消息 `invalid arguments: file_path must be a non-empty string` 与 `invalid arguments: limit must be less than or equal to <max>`、`cannot read "<path>": not found`、`cannot read "<path>": not a regular file`,以及图像路由拒绝 `cannot read "<path>" as an image: model "<model>" does not declare image input; switch to an image-capable model to read images`。无论拒绝来自策略还是提供方,`FS_NOT_OBSERVED` 都规范化为 `cannot modify "<path>": file has not been read — read the file, then retry`;`FS_STALE_VERSION` 保留提供方原因并追加 `— re-read the file, then retry`。该次重新读取确认缺失后,`edit` 报告 `FS_NOT_FOUND` 而不会重复陈旧恢复指令,`write` 则使用防护创建。
+2 -2
View File
@@ -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
+2 -2
View File
@@ -120,7 +120,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<void> {
const routed = exec.agent?.session.requestHeader()?.config
@@ -134,7 +134,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',
)
}
}
+4 -3
View File
@@ -87,6 +87,10 @@ export class FsSandboxController {
* unsandboxed backend.
*/
async resolvePolicy(toolName: string, args: FsEscalationArgs, exec: ToolExecution): Promise<SandboxExecutionPolicy | undefined> {
// 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' },
+1 -1
View File
@@ -561,7 +561,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 () => {
+7 -3
View File
@@ -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' })
})
})
-2
View File
@@ -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',
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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> 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> 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
+1 -1
View File
@@ -63,7 +63,7 @@ kind: "package-reference"
### 被拒绝的调用与升权
受限调用被拒绝时,操作会报告指明模式的拒绝标记——`[sandbox: file access denied under <mode> 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> mode]`——组合声明升权能力时还会给出升权提示。模型可以用 `sandbox_permissions`(足以放行的最窄更宽模式)加 `justification` 重试一次完全相同的调用;审批服务为操作取得同意。请求保留审计原因,同时从 `src/locales.ts` 提供英文、中文和日文展示文案,模型给出的理由保持原样。缺失的译文遵循语言服务的回退链,最终回退到英文;请求方负责自己的展示译文。更宽的模式需要审批,且只作用于该次调用。重复指定调用的生效模式无需审批即可成功;更窄的目标仍然无效。未取得授权的升权会在任何命令运行前抛出 `SandboxEscalationError`:字段未配对、理由为空或目标并非严格更宽时为 `SANDBOX_ESCALATION_INVALID_ARGUMENT`;组合中没有审批服务、调用方 Agent 或审批通道时为 `SANDBOX_ESCALATION_UNAVAILABLE`;用户拒绝时为 `SANDBOX_ESCALATION_REJECTED`;审批请求未作决定即结束时为 `SANDBOX_ESCALATION_CANCELLED`。若调用本身已被取消,则改为传播该调用的取消。
### 故障关闭行为
+2 -2
View File
@@ -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.
*/
+4 -4
View File
@@ -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: 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: 1772eedea1c1ee6a
zh: a0d77bdd515cb517
en: a59c3d16f59c7577
zh: 24dd44d419e240a0
/deepseek-ai-dsh-tool-bash/model-experience/tool-errors/token-effect:
en: a3a78ef476ec5e56
zh: dd2c8ad0f69e8ff1
+2 -2
View File
@@ -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` 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: <message>`. 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 <value>`, 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: <message>`. 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 <value>`, 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
+2 -2
View File
@@ -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` 或 `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: <message>`。本包的稳定消息包括 `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 <value>`、升权配对失败、`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: <message>`。本包的稳定消息包括 `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 <value>`、升权配对失败、`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 影响
+37 -20
View File
@@ -19,12 +19,11 @@ 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'
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'
@@ -73,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'])
}
@@ -83,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
@@ -234,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,
@@ -247,12 +274,6 @@ export function apply(ctx: Context, config: Config = {}): void {
exec: ToolExecution,
standingPolicy: SandboxExecutionPolicy | undefined,
): Promise<SandboxMode> => {
if (escalationModes.length === 0) {
throw new SandboxEscalationError(
'sandbox_permissions is not available in this composition (no sandboxing executor to escalate)',
'SANDBOX_ESCALATION_UNAVAILABLE',
)
}
const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode
return approveEscalation(
{ requestedMode: mode, justification, effectiveMode, subject: 'command' },
@@ -502,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
@@ -520,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 JobError('run_in_background is disabled for this deployment (enableRunInBackground: false)', 'JOB_BACKGROUND_DISABLED')
}
if (jobs === undefined) {
throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs')
}
+21 -7
View File
@@ -215,7 +215,7 @@ class CountingStartExecutor extends ShellExecutor {
}
}
async function setupSandboxed(withApproval = false) {
async function setupSandboxed(withApproval = false, toolConfig: Partial<ToolBash.Config> = {}) {
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 }
}
@@ -721,8 +721,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)
})
@@ -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<ApprovalOutcome>('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('not available in this composition')
expect(unavailable).toMatchObject({ error: { info: { name: 'SandboxEscalationError', code: 'SANDBOX_ESCALATION_UNAVAILABLE' } } })
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()
+4 -4
View File
@@ -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: 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: c71e7f547de19d3d
zh: a9d9c3a84e1618b9
en: 828df448c1128f2f
zh: 720c590c01089651
/deepseek-ai-dsh-tool-pwsh/model-experience/tool-errors/token-effect:
en: 243bad012dd99c7f
zh: 5ee74905020bd49a
+2 -2
View File
@@ -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` 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: <message>`. 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 <value>`, 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: <message>`. 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 <value>`, 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
+2 -2
View File
@@ -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` 或 `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: <message>`。本包的稳定消息包括 `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 <value>`、升权配对失败、`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: <message>`。本包的稳定消息包括 `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 <value>`、升权配对失败、`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 影响
+37 -21
View File
@@ -28,12 +28,11 @@ 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'
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'
@@ -107,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'])
}
@@ -117,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 */
@@ -246,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,
@@ -260,12 +286,6 @@ export function apply(ctx: Context, config: Config = {}): void {
exec: ToolExecution,
standingPolicy: SandboxExecutionPolicy | undefined,
): Promise<SandboxMode> => {
if (escalationModes.length === 0) {
throw new SandboxEscalationError(
'sandbox_permissions is not available in this composition (no sandboxing executor to escalate)',
'SANDBOX_ESCALATION_UNAVAILABLE',
)
}
const effectiveMode = (standingPolicy as SandboxExecutionPolicy).mode
return approveEscalation(
{ requestedMode: mode, justification, effectiveMode, subject: 'command' },
@@ -524,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
@@ -543,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 JobError('run_in_background is disabled for this deployment (enableRunInBackground: false)', 'JOB_BACKGROUND_DISABLED')
}
if (jobs === undefined) {
throw new ToolContextUnavailableError('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs')
}
+21 -7
View File
@@ -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<ToolPwsh.Config> = {}) {
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<ApprovalOutcome>('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('not available in this composition')
expect(unavailable).toMatchObject({ error: { info: { name: 'SandboxEscalationError', code: 'SANDBOX_ESCALATION_UNAVAILABLE' } } })
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()
@@ -925,8 +939,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)
})
@@ -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"}