fix(subagent): give SubagentError a closed code union and stop reusing codes
Route refusals from the Session model-selection policy reused UNAUTHORIZED, which existing consumers such as tool-office, team, and the SDK server read as a failed caller-identity check, and an unregistered LLM provider reused NO_PROVIDER, which means no subagent provider. They now use MODEL_ROUTE_NOT_ALLOWED and LLM_PROVIDER_NOT_FOUND. SubagentError's code is typed by the closed SubagentErrorCode union, each member documented with its condition, so a new failure cannot silently reuse an existing code. Refs #7869
This commit is contained in:
1 parent
1f4642535d
commit
d2d79aae65
16 files changed
+111
-28
No files matched your search
@@ -39,8 +39,8 @@
|
||||
en: bf3175c2218a16dd
|
||||
zh: 4be9271efe71ddb7
|
||||
/deepseek-ai-dsh-subagent/use-this-package/failure-and-recovery:
|
||||
en: 808628bbe038f6c2
|
||||
zh: 913ad8f71fde72b0
|
||||
en: c097c297e75f3bd4
|
||||
zh: 0b09f2870ccc6a64
|
||||
/deepseek-ai-dsh-subagent/understand-the-implementation:
|
||||
en: 74d91b364b23f88d
|
||||
zh: 19cc558105efe8df
|
||||
|
||||
@@ -79,7 +79,7 @@ In-process spawn accepts an independent `agentPreset`; fork and external backend
|
||||
|
||||
### Failure and recovery
|
||||
|
||||
Starting without the `agents` service rejects with `CONTINUATION_UNAVAILABLE`; an available runtime rejects a missing or replaced parent with `UNAUTHORIZED`. Providers implementing neither execution method are rejected at registration with `UNSUPPORTED_CAPABILITY`; unsupported requested capabilities reject creation with the same code. If a provider is removed or replaced while directory resolution is pending, creation rejects with `PROVIDER_CHANGED` before invoking either provider; retry the delegation against the current registration. Every creation failure below is a `SubagentError`: a child beyond the requested depth rejects with the `SubagentDepthError` subclass and `DEPTH_EXCEEDED`, an invalid runtime `subagentDepth` with `INVALID_DEPTH`, a selected preset without the preset service with `PRESET_UNAVAILABLE` (an unknown or unloadable selected preset keeps the registry's `RemoteError` code), a local child without the working-directory service with `WORKING_DIRECTORY_UNAVAILABLE`, and an out-of-process child whose cwd is relative or not enterable with `INVALID_CWD`. A cold target whose persisted descriptor is corrupt rejects with `NOT_RESUMABLE`, and `structured_output` called while input is pending fails with `STRUCTURED_OUTPUT_PENDING_INPUT`. The caller signal cancels only unpublished work; after publication, `dispose()` cancels the exact activation and waits for its resource cleanup. Creation descendants continue independently; hosts must await `drainDescendants([root])` before disposing the root handle to stop all members and await pending startup. `result` settles after teardown and notifications, carrying output, optional structured data, and a stop reason; capture failures reject it after teardown. Cleanup failures reject `dispose()` and mark the lifecycle end as failed; the result promise and parent notification retain the captured execution result.
|
||||
Every `SubagentError` carries one code from the closed `SubagentErrorCode` union in [`src/error.ts`](src/error.ts), which documents each condition. Starting without the `agents` service rejects with `CONTINUATION_UNAVAILABLE`; an available runtime rejects a missing or replaced parent with `UNAUTHORIZED`. Providers implementing neither execution method are rejected at registration with `UNSUPPORTED_CAPABILITY`; unsupported requested capabilities reject creation with the same code. If a provider is removed or replaced while directory resolution is pending, creation rejects with `PROVIDER_CHANGED` before invoking either provider; retry the delegation against the current registration. Every creation failure below is a `SubagentError`: a child beyond the requested depth rejects with the `SubagentDepthError` subclass and `DEPTH_EXCEEDED`, an invalid runtime `subagentDepth` with `INVALID_DEPTH`, a selected preset without the preset service with `PRESET_UNAVAILABLE` (an unknown or unloadable selected preset keeps the registry's `RemoteError` code), a local child without the working-directory service with `WORKING_DIRECTORY_UNAVAILABLE`, and an out-of-process child whose cwd is relative or not enterable with `INVALID_CWD`. A cold target whose persisted descriptor is corrupt rejects with `NOT_RESUMABLE`, and `structured_output` called while input is pending fails with `STRUCTURED_OUTPUT_PENDING_INPUT`. The caller signal cancels only unpublished work; after publication, `dispose()` cancels the exact activation and waits for its resource cleanup. Creation descendants continue independently; hosts must await `drainDescendants([root])` before disposing the root handle to stop all members and await pending startup. `result` settles after teardown and notifications, carrying output, optional structured data, and a stop reason; capture failures reject it after teardown. Cleanup failures reject `dispose()` and mark the lifecycle end as failed; the result promise and parent notification retain the captured execution result.
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ kind: "package-reference"
|
||||
|
||||
### 失败与恢复
|
||||
|
||||
缺少 `agents` 服务时,启动请求以 `CONTINUATION_UNAVAILABLE` 拒绝;运行时可用但父级缺失或被替换时,以 `UNAUTHORIZED` 拒绝。未实现任何执行方法的提供方会在注册时以 `UNSUPPORTED_CAPABILITY` 被拒绝;请求不受支持的能力会以同一码使创建失败。如果等待目录解析期间提供方被移除或替换,创建会在调用任何一方之前以 `PROVIDER_CHANGED` 拒绝;调用方可根据当前注册重试委派。以下创建失败均为 `SubagentError`:超出请求深度的子代以 `SubagentDepthError` 子类和 `DEPTH_EXCEEDED` 拒绝,无效的运行时 `subagentDepth` 以 `INVALID_DEPTH` 拒绝,选择了 preset 但缺少 preset 服务时以 `PRESET_UNAVAILABLE` 拒绝(所选 preset 未知或无法加载时保留 registry 的 `RemoteError` code),缺少工作目录服务的本地子代以 `WORKING_DIRECTORY_UNAVAILABLE` 拒绝,cwd 为相对路径或不可进入的进程外子代以 `INVALID_CWD` 拒绝。持久化 descriptor 损坏的冷目标以 `NOT_RESUMABLE` 拒绝,有待处理输入时调用 `structured_output` 以 `STRUCTURED_OUTPUT_PENDING_INPUT` 失败。调用方信号仅取消尚未发布的工作;发布后通过 `dispose()` 取消该次 activation,并等待其资源清理完成。创建后代独立继续运行;宿主必须在释放根句柄前等待 `drainDescendants([root])`,以停止所有成员并等待正在启动的工作。`result` 在清理与通知结束后完成,携带输出、可选结构化数据与停止原因;结果捕获故障在清理后使其拒绝。清理失败使 `dispose()` 拒绝,并将生命周期结束事件标记为失败;结果 promise 与父级通知保留已捕获的执行结果。
|
||||
每个 `SubagentError` 都携带 [`src/error.ts`](src/error.ts) 中封闭联合类型 `SubagentErrorCode` 的一个 code,该文件逐条说明各条件。缺少 `agents` 服务时,启动请求以 `CONTINUATION_UNAVAILABLE` 拒绝;运行时可用但父级缺失或被替换时,以 `UNAUTHORIZED` 拒绝。未实现任何执行方法的提供方会在注册时以 `UNSUPPORTED_CAPABILITY` 被拒绝;请求不受支持的能力会以同一码使创建失败。如果等待目录解析期间提供方被移除或替换,创建会在调用任何一方之前以 `PROVIDER_CHANGED` 拒绝;调用方可根据当前注册重试委派。以下创建失败均为 `SubagentError`:超出请求深度的子代以 `SubagentDepthError` 子类和 `DEPTH_EXCEEDED` 拒绝,无效的运行时 `subagentDepth` 以 `INVALID_DEPTH` 拒绝,选择了 preset 但缺少 preset 服务时以 `PRESET_UNAVAILABLE` 拒绝(所选 preset 未知或无法加载时保留 registry 的 `RemoteError` code),缺少工作目录服务的本地子代以 `WORKING_DIRECTORY_UNAVAILABLE` 拒绝,cwd 为相对路径或不可进入的进程外子代以 `INVALID_CWD` 拒绝。持久化 descriptor 损坏的冷目标以 `NOT_RESUMABLE` 拒绝,有待处理输入时调用 `structured_output` 以 `STRUCTURED_OUTPUT_PENDING_INPUT` 失败。调用方信号仅取消尚未发布的工作;发布后通过 `dispose()` 取消该次 activation,并等待其资源清理完成。创建后代独立继续运行;宿主必须在释放根句柄前等待 `drainDescendants([root])`,以停止所有成员并等待正在启动的工作。`result` 在清理与通知结束后完成,携带输出、可选结构化数据与停止原因;结果捕获故障在清理后使其拒绝。清理失败使 `dispose()` 拒绝,并将生命周期结束事件标记为失败;结果 promise 与父级通知保留已捕获的执行结果。
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -6,10 +6,92 @@
|
||||
|
||||
import { HarnessError } from '@deepseek-ai/dsh-llm'
|
||||
|
||||
/** Typed failure for the subagent seam. */
|
||||
/**
|
||||
* Every machine-routable subagent failure. Each code names one condition;
|
||||
* reuse one only when the consumer action is the same.
|
||||
*/
|
||||
export type SubagentErrorCode =
|
||||
/** A provider registration or a request needs a capability the selected backend lacks. */
|
||||
| 'UNSUPPORTED_CAPABILITY'
|
||||
/** A provider with the same name is already registered. */
|
||||
| 'DUPLICATE_PROVIDER'
|
||||
/** No subagent provider is registered under the requested name. */
|
||||
| 'NO_PROVIDER'
|
||||
/** The provider was removed or replaced while a delegation was starting; retry against the current registration. */
|
||||
| 'PROVIDER_CHANGED'
|
||||
/** A child preset was selected but the agent-presets service is absent. */
|
||||
| 'PRESET_UNAVAILABLE'
|
||||
/** The tool instance exposes no agent preset choice. */
|
||||
| 'PRESET_SELECTION_DISABLED'
|
||||
/** The selected agent preset is outside the tool's allowlist. */
|
||||
| 'PRESET_NOT_ALLOWED'
|
||||
/** The tool instance does not accept child model selection. */
|
||||
| 'MODEL_SELECTION_DISABLED'
|
||||
/** The Session's model-selection policy does not authorize the requested child provider or route. */
|
||||
| 'MODEL_ROUTE_NOT_ALLOWED'
|
||||
/** The requested LLM provider is not registered with the LLM runtime. */
|
||||
| 'LLM_PROVIDER_NOT_FOUND'
|
||||
/** The child's target model cannot accept image input. */
|
||||
| 'MODEL_DOES_NOT_SUPPORT_IMAGES'
|
||||
/** Starting the child would exceed the requested delegation depth; thrown as `SubagentDepthError`. */
|
||||
| 'DEPTH_EXCEEDED'
|
||||
/** A runtime delegation depth is not a non-negative safe integer. */
|
||||
| 'INVALID_DEPTH'
|
||||
/** An out-of-process child's working directory is relative or not enterable. */
|
||||
| 'INVALID_CWD'
|
||||
/** A local child cannot start because the working-directory service is absent. */
|
||||
| 'WORKING_DIRECTORY_UNAVAILABLE'
|
||||
/** The caller is not the exact live agent, or does not own the target in its subagent tree. */
|
||||
| 'UNAUTHORIZED'
|
||||
/** The tree's activation capacity is exhausted. */
|
||||
| 'ACTIVATION_LIMIT_REACHED'
|
||||
/** The target activation is closing. */
|
||||
| 'ACTIVATION_CLOSING'
|
||||
/** Releasing an activation's resources failed. */
|
||||
| 'ACTIVATION_TEARDOWN_FAILED'
|
||||
/** A child with the same Session id already exists. */
|
||||
| 'DUPLICATE_CHILD'
|
||||
/** The subagent tree is draining and admits no new work. */
|
||||
| 'DRAINING'
|
||||
/** The child accepts no more input after its structured result. */
|
||||
| 'INPUT_CLOSED'
|
||||
/** `structured_output` was called while accepted input is still pending. */
|
||||
| 'STRUCTURED_OUTPUT_PENDING_INPUT'
|
||||
/** The operation was cancelled by its caller. */
|
||||
| 'CANCELLED'
|
||||
/** A cold child cannot be restored from its persisted state. */
|
||||
| 'NOT_RESUMABLE'
|
||||
/** The child was not started as continuable and accepts no follow-up. */
|
||||
| 'NOT_CONTINUABLE'
|
||||
/** Continuation needs the agent runtime or a live tree root that is absent. */
|
||||
| 'CONTINUATION_UNAVAILABLE'
|
||||
/** Continuation needs Session persistence that is absent or failed. */
|
||||
| 'PERSISTENCE_UNAVAILABLE'
|
||||
/** A requested agent name does not satisfy the naming rule. */
|
||||
| 'INVALID_AGENT_NAME'
|
||||
/** A requested agent name is already used by a sibling. */
|
||||
| 'DUPLICATE_AGENT_NAME'
|
||||
/** An agent path names no member of the tree. */
|
||||
| 'AGENT_NAME_NOT_FOUND'
|
||||
/** Listing children needs the session-query service. */
|
||||
| 'SUBAGENT_CONTROL_QUERY_UNAVAILABLE'
|
||||
/** Listing children needs the session-projection service. */
|
||||
| 'SUBAGENT_CONTROL_PROJECTIONS_UNAVAILABLE'
|
||||
/** Listing children needs the Session store. */
|
||||
| 'SUBAGENT_CONTROL_SESSION_STORE_UNAVAILABLE'
|
||||
|
||||
/** Typed failure for the subagent seam; `code` is one {@link SubagentErrorCode}. */
|
||||
export class SubagentError extends HarnessError {
|
||||
constructor(message: string, code: string, options?: ErrorOptions) {
|
||||
override readonly code: SubagentErrorCode
|
||||
|
||||
/**
|
||||
* @param message - reason and next step for the caller.
|
||||
* @param code - failure class.
|
||||
* @param options - standard `cause` chaining.
|
||||
*/
|
||||
constructor(message: string, code: SubagentErrorCode, options?: ErrorOptions) {
|
||||
super(message, code, options)
|
||||
this.name = 'SubagentError'
|
||||
this.code = code
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ export type {
|
||||
SubagentDescriptorData,
|
||||
} from './descriptor.ts'
|
||||
export { STRUCTURED_OUTPUT_TOOL } from './structured.ts'
|
||||
export { SubagentError } from './error.ts'
|
||||
export { SubagentError, type SubagentErrorCode } from './error.ts'
|
||||
export { assertSubagentMaxDepth, delegationDepthOf } from './depth.ts'
|
||||
export {
|
||||
appendDelegatedPolicyOverrides,
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { MessageId } from '@deepseek-ai/dsh-llm'
|
||||
import { SessionId } from '@deepseek-ai/dsh-session'
|
||||
import SubagentRuntime, {
|
||||
SubagentError,
|
||||
type SubagentErrorCode,
|
||||
type SubagentPromptRequestId,
|
||||
} from '@deepseek-ai/dsh-subagent'
|
||||
import { subagentManager } from './manager-internals.ts'
|
||||
@@ -251,7 +252,7 @@ describe('subagent prompt Remote', () => {
|
||||
it('maps each admission failure onto its stable code and hides the rest', async () => {
|
||||
const { ctx, subagents } = await bench({ [PARENT]: { status: 'idle' } })
|
||||
const delivery = promptDelivery(ctx)
|
||||
const cases: readonly [string, string][] = [
|
||||
const cases: readonly [SubagentErrorCode, string][] = [
|
||||
['NOT_RESUMABLE', 'subagent/not-resumable'],
|
||||
['UNAUTHORIZED', 'subagent/unauthorized'],
|
||||
['DRAINING', 'subagent/delivery-unavailable'],
|
||||
|
||||
@@ -258,7 +258,7 @@ describe('dsh-tool-subagent-control', () => {
|
||||
|
||||
it.each([
|
||||
new Error('root lookup failed'),
|
||||
new SubagentError('root data is unreadable', 'CORRUPT'),
|
||||
new SubagentError('root data is unreadable', 'PERSISTENCE_UNAVAILABLE'),
|
||||
])('propagates identity lookup errors other than an unavailable root: $message', async (error) => {
|
||||
const { ctx, parent } = await setup([])
|
||||
const lookup = vi.spyOn(ctx.subagents, 'namesOf').mockImplementation(() => { throw error })
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
en: 373abf7c7aa3e4f1
|
||||
zh: be0b4d4a7371d360
|
||||
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/activation-ownership:
|
||||
en: a72ddd82ad7810a1
|
||||
zh: 738f8fb157e51c59
|
||||
en: 801820b3e64494ef
|
||||
zh: 3d81e9ffe69cd7da
|
||||
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/result-acknowledgement:
|
||||
en: 3c2d70d479be8e38
|
||||
zh: 9aebdb72223a086e
|
||||
|
||||
@@ -94,7 +94,7 @@ One instance is one provider plus one tool name. The plugin registers its defini
|
||||
|
||||
### Activation ownership
|
||||
|
||||
The tool calls `ctx.subagents.startActivation()` with parent delivery selected. The runtime owns startup cancellation, execution, outcome reporting, and cleanup. A startup failure is an errored tool result. Rejections before startup are coded: a missing calling Agent, `llm` service, or effective parent route throws `ToolContextUnavailableError`; an empty or unpaired route field throws `ToolArgsError`; and `SubagentError` reports a disabled selection (`MODEL_SELECTION_DISABLED`, `PRESET_SELECTION_DISABLED`), a preset outside the allowlist (`PRESET_NOT_ALLOWED`), an unauthorized route (`UNAUTHORIZED`), an unregistered discovery provider (`NO_PROVIDER`), or a provider replaced during route preflight (`PROVIDER_CHANGED`). Failures after publication arrive through the completion notice, with diagnostics and partial output preserved by the runtime.
|
||||
The tool calls `ctx.subagents.startActivation()` with parent delivery selected. The runtime owns startup cancellation, execution, outcome reporting, and cleanup. A startup failure is an errored tool result. Rejections before startup are coded: a missing calling Agent, `llm` service, or effective parent route throws `ToolContextUnavailableError`; an empty or unpaired route field throws `ToolArgsError`; and `SubagentError` reports a disabled selection (`MODEL_SELECTION_DISABLED`, `PRESET_SELECTION_DISABLED`), a preset outside the allowlist (`PRESET_NOT_ALLOWED`), a route the Session does not authorize (`MODEL_ROUTE_NOT_ALLOWED`), an LLM provider unknown to discovery (`LLM_PROVIDER_NOT_FOUND`), or a provider replaced during route preflight (`PROVIDER_CHANGED`). Failures after publication arrive through the completion notice, with diagnostics and partial output preserved by the runtime.
|
||||
|
||||
### Result acknowledgement
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ kind: "package-reference"
|
||||
|
||||
### Activation 所有权
|
||||
|
||||
工具调用 `ctx.subagents.startActivation()`,并选择向父任务交付。运行时拥有启动取消、执行、结果汇报与清理。启动失败产生出错的工具结果。启动前的拒绝都带 code:缺少调用方 Agent、`llm` 服务或有效的父级路由时抛出 `ToolContextUnavailableError`;路由字段为空或未成对提供时抛出 `ToolArgsError`;`SubagentError` 报告选择被禁用(`MODEL_SELECTION_DISABLED`、`PRESET_SELECTION_DISABLED`)、preset 不在允许列表中(`PRESET_NOT_ALLOWED`)、路由未授权(`UNAUTHORIZED`)、发现查询的提供方未注册(`NO_PROVIDER`),或路由预检期间提供方被替换(`PROVIDER_CHANGED`)。发布后的失败通过完成通知到达,运行时保留诊断和部分输出。
|
||||
工具调用 `ctx.subagents.startActivation()`,并选择向父任务交付。运行时拥有启动取消、执行、结果汇报与清理。启动失败产生出错的工具结果。启动前的拒绝都带 code:缺少调用方 Agent、`llm` 服务或有效的父级路由时抛出 `ToolContextUnavailableError`;路由字段为空或未成对提供时抛出 `ToolArgsError`;`SubagentError` 报告选择被禁用(`MODEL_SELECTION_DISABLED`、`PRESET_SELECTION_DISABLED`)、preset 不在允许列表中(`PRESET_NOT_ALLOWED`)、会话未授权该路由(`MODEL_ROUTE_NOT_ALLOWED`)、发现查询的 LLM 提供方未注册(`LLM_PROVIDER_NOT_FOUND`),或路由预检期间提供方被替换(`PROVIDER_CHANGED`)。发布后的失败通过完成通知到达,运行时保留诊断和部分输出。
|
||||
|
||||
### 结果确认
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ function registeredProvider(
|
||||
.filter(candidate => policy.routes.some(route => route.provider === candidate.id))
|
||||
.map(candidate => candidate.id)
|
||||
.join(', ') || '(none)'
|
||||
throw new SubagentError(`LLM provider "${providerId}" is not registered; available providers: ${available}`, 'NO_PROVIDER')
|
||||
throw new SubagentError(`LLM provider "${providerId}" is not registered; available providers: ${available}`, 'LLM_PROVIDER_NOT_FOUND')
|
||||
}
|
||||
|
||||
/** Render one advertised or resolved model. */
|
||||
@@ -73,7 +73,7 @@ async function listSubagentModels(
|
||||
const allowedRoutes = policy.routes.filter(route => route.provider === request.provider)
|
||||
const [firstRoute] = allowedRoutes
|
||||
if (firstRoute === undefined) {
|
||||
throw new SubagentError(`LLM provider "${request.provider}" is not allowed for this Session`, 'UNAUTHORIZED')
|
||||
throw new SubagentError(`LLM provider "${request.provider}" is not allowed for this Session`, 'MODEL_ROUTE_NOT_ALLOWED')
|
||||
}
|
||||
const provider = registeredProvider(llm, policy, request.provider)
|
||||
if (request.model === undefined) {
|
||||
@@ -87,7 +87,7 @@ async function listSubagentModels(
|
||||
}
|
||||
if (request.model.length === 0) throw new ToolArgsError(['`model` must be non-empty'])
|
||||
if (!allowedRoutes.some(route => route.model === request.model)) {
|
||||
throw new SubagentError(`child LLM route "${provider.id}/${request.model}" is not allowed for this Session`, 'UNAUTHORIZED')
|
||||
throw new SubagentError(`child LLM route "${provider.id}/${request.model}" is not allowed for this Session`, 'MODEL_ROUTE_NOT_ALLOWED')
|
||||
}
|
||||
const model = await llm.resolveModelInfo(provider.id, request.model, signal)
|
||||
const efforts = model.reasoning?.efforts.map(effort => (
|
||||
|
||||
@@ -99,7 +99,7 @@ function assertNonEmpty(value: string | undefined, field: keyof DelegationModelR
|
||||
* @param parentOptions - Current parent route used when no policy is recorded.
|
||||
* @returns Child Agent options, preserving omission when no layer contributes one.
|
||||
* @throws {SubagentError} `MODEL_SELECTION_DISABLED` when this tool instance
|
||||
* forbids selection, or `UNAUTHORIZED` when the Session does not allow the route.
|
||||
* forbids selection, or `MODEL_ROUTE_NOT_ALLOWED` when the Session does not allow the route.
|
||||
* @throws {ToolArgsError} when a field is empty or `provider` and `model` are not supplied together.
|
||||
*/
|
||||
export function requestedAgentOptions(
|
||||
@@ -137,7 +137,7 @@ export function requestedAgentOptions(
|
||||
* @param policy - Session allowlist; omission permits only the current parent route.
|
||||
* @param parentOptions - Current parent route used when no policy is recorded.
|
||||
* @param route - Validated provider/model pair from the tool call.
|
||||
* @throws {SubagentError} `UNAUTHORIZED` when the Session does not allow the route.
|
||||
* @throws {SubagentError} `MODEL_ROUTE_NOT_ALLOWED` when the Session does not allow the route.
|
||||
*/
|
||||
export function assertAllowedModelSelection(
|
||||
policy: ModelSelectionPolicy | undefined,
|
||||
@@ -152,7 +152,7 @@ export function assertAllowedModelSelection(
|
||||
throw new SubagentError(`child LLM route "${provider}/${model}" is not allowed for this Session`
|
||||
+ (policy === undefined
|
||||
? '; without a recorded model-selection policy, explicit selection is limited to the parent route'
|
||||
: ''), 'UNAUTHORIZED')
|
||||
: ''), 'MODEL_ROUTE_NOT_ALLOWED')
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -264,7 +264,7 @@ describe('list_subagent_models', () => {
|
||||
const denied = await call(ctx, { provider: 'alpha', model: 'plain' })
|
||||
expect(denied.isError).toBe(true)
|
||||
expect(text(denied)).toContain('is not allowed for this Session')
|
||||
expect(denied.error?.info).toEqual({ name: 'SubagentError', code: 'UNAUTHORIZED' })
|
||||
expect(denied.error?.info).toEqual({ name: 'SubagentError', code: 'MODEL_ROUTE_NOT_ALLOWED' })
|
||||
})
|
||||
|
||||
it('rejects an unauthorized provider before calling its adapter catalog', async () => {
|
||||
@@ -277,7 +277,7 @@ describe('list_subagent_models', () => {
|
||||
|
||||
expect(result.isError).toBe(true)
|
||||
expect(text(result)).toContain('provider "secret" is not allowed for this Session')
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'UNAUTHORIZED' })
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'MODEL_ROUTE_NOT_ALLOWED' })
|
||||
expect(listModels).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -385,7 +385,7 @@ describe('list_subagent_models', () => {
|
||||
it.each([
|
||||
{ args: { model: 'fast' }, expected: '`model` requires `provider`', info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } },
|
||||
{ args: { provider: '' }, expected: '`provider` must be non-empty', info: { name: 'ToolArgsError', code: 'INVALID_ARGS' } },
|
||||
{ args: { provider: 'missing' }, expected: 'is not allowed for this Session', info: { name: 'SubagentError', code: 'UNAUTHORIZED' } },
|
||||
{ args: { provider: 'missing' }, expected: 'is not allowed for this Session', info: { name: 'SubagentError', code: 'MODEL_ROUTE_NOT_ALLOWED' } },
|
||||
])('rejects incomplete or unavailable provider requests', async ({ args, expected, info }) => {
|
||||
const ctx = await setupListTool()
|
||||
const result = await call(ctx, args)
|
||||
@@ -412,7 +412,7 @@ describe('list_subagent_models', () => {
|
||||
const result = await call(ctx, { provider: 'missing' })
|
||||
expect(result.isError).toBe(true)
|
||||
expect(text(result)).toContain('available providers: alpha')
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'NO_PROVIDER' })
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'LLM_PROVIDER_NOT_FOUND' })
|
||||
expect(text(result)).not.toContain('secret')
|
||||
})
|
||||
|
||||
@@ -421,6 +421,6 @@ describe('list_subagent_models', () => {
|
||||
const result = await call(ctx, { provider: 'missing' })
|
||||
expect(result.isError).toBe(true)
|
||||
expect(text(result)).toContain('available providers: (none)')
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'NO_PROVIDER' })
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'LLM_PROVIDER_NOT_FOUND' })
|
||||
})
|
||||
})
|
||||
@@ -285,7 +285,7 @@ describe('SubagentModelSelectionConfig', () => {
|
||||
|
||||
expect(result.isError).toBe(true)
|
||||
expect(text(result)).toContain('is not allowed for this Session')
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'UNAUTHORIZED' })
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'MODEL_ROUTE_NOT_ALLOWED' })
|
||||
await ctx.fiber.dispose()
|
||||
})
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ describe('dsh-tool-subagent model selection', () => {
|
||||
})
|
||||
expect(result.isError).toBe(true)
|
||||
expect(text(result)).toContain('is not allowed for this Session')
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'UNAUTHORIZED' })
|
||||
expect(result.error?.info).toEqual({ name: 'SubagentError', code: 'MODEL_ROUTE_NOT_ALLOWED' })
|
||||
})
|
||||
|
||||
it('discovers only the parent route without a Session policy and permits its explicit route and effort', async () => {
|
||||
@@ -578,7 +578,7 @@ describe('dsh-tool-subagent model selection', () => {
|
||||
})
|
||||
expect(denied.isError).toBe(true)
|
||||
expect(text(denied)).toContain('is not allowed for this Session')
|
||||
expect(denied.error?.info).toEqual({ name: 'SubagentError', code: 'UNAUTHORIZED' })
|
||||
expect(denied.error?.info).toEqual({ name: 'SubagentError', code: 'MODEL_ROUTE_NOT_ALLOWED' })
|
||||
|
||||
const invalidEffort = await callSubagent(ctx, {
|
||||
description: 'unsupported effort', prompt: 'do it', provider: 'alpha', model: 'fast-model', reasoning_effort: 'invalid',
|
||||
|
||||
@@ -1033,7 +1033,7 @@ describe('dsh-tool-team', () => {
|
||||
|
||||
it.each([
|
||||
new Error('root lookup failed'),
|
||||
new SubagentError('root lookup failed', 'INTERNAL_FAILURE'),
|
||||
new SubagentError('root lookup failed', 'CONTINUATION_UNAVAILABLE'),
|
||||
])('propagates unexpected identity lookup failures: %s', async (failure) => {
|
||||
const { ctx, lead } = await setup([])
|
||||
vi.spyOn(ctx.subagents, 'rootOf').mockImplementation(() => { throw failure })
|
||||
|
||||
Reference in new issue
Block a user