data(例如 retryable、reason、capability)的 JSON-RPC 错误;连接以 WebSocket 关闭码结束。各 SDK 都把它们暴露为类型化错误。
由 bma-executor-sdk 1.12.2 及其契约(
contracts/bma/executor,协议 bma.executor.v1.1)生成。安装、凭据与快速开始见 bma-executor-sdk 概览;协议本身见 Executor 协议。RPC 错误
对端返回的 JSON-RPC 错误,或处理器返回以用特定错误码和 data 应答的错误。export class RpcError extends Error {
constructor(
static withReason(code: number, reason: string, message: string): RpcError
toJSON(): JsonRpcError
}
class RPCError(ExecutorError):
"""A JSON-RPC error. A handler that raises it keeps its code on the wire."""
def __init__(self, code: int, message: str, data: dict[str, Any] | None = None) -> None: ...
@classmethod
def with_reason(cls, code: int, reason: str, message: str) -> RPCError: ...
@property
def retryable(self) -> bool | None: ...
def to_wire(self) -> dict[str, Any]: ...
type RPCError struct {
Code int
Message string
Data *JSONRPCErrorData
}
客户端错误
Executor 端:未连接、已停止、被同一身份的另一个 executor 替换(关闭码 4004:停止,不要重连)、重连次数耗尽。export class NotConnectedError extends Error {
constructor(message = 'executor channel is not connected')
}
export class ClientStoppedError extends Error {
constructor()
}
export class RequestTimeoutError extends Error {
constructor(method: string)
}
class NotConnectedError(ExecutorError):
"""The channel is not connected (yet, or any more)."""
def __init__(self, message: str = "executor channel is not connected") -> None: ...
class ClientStoppedError(ExecutorError):
"""The client was stopped, or closed with a terminal close code."""
def __init__(self, message: str = "client stopped") -> None: ...
var (
// ErrNotConnected is returned when a call is attempted before the channel opens.
ErrNotConnected = errors.New("bmaexecutor: executor channel is not connected")
// ErrClientStopped is returned after Stop or a terminal close code.
ErrClientStopped = errors.New("bmaexecutor: client stopped")
// ErrReplaced is Err after the harness closed with 4004: a newer
// connection for this executor is authoritative and this one must stop.
ErrReplaced = errors.New("bmaexecutor: executor connection was replaced (4004)")
// errResumedFromSuspend ends a connection the host was suspended with.
errResumedFromSuspend = errors.New("bmaexecutor: host resumed from suspend")
// ErrReconnectExhausted is Err after a positive MaxReconnectAttempts
// failed; it wraps the last failure.
ErrReconnectExhausted = errors.New("bmaexecutor: executor reconnect attempts exhausted")
// ErrCredentialRejected is wrapped by the token request error when the
// token endpoint answers 401 or 403 (an invalid or revoked environment
// key or machine token). A reconnect does not retry it: the client ends
// with it as Err. A TokenSource may wrap it for the same effect.
ErrCredentialRejected = errors.New("bmaexecutor: executor credential rejected")
// ErrRegistrationRefused is Err after the platform refused the
// executor's registration maxRefusedRegistrations times in a row: the
// close 4002 "runtime registration refused" right after
// executor.register, or an executor.register error for the executor's
// capabilities. It is a configuration error (a machine-scoped executor
// must declare the process or agent capability) that reconnecting
// cannot fix. It wraps the last refusal.
ErrRegistrationRefused = errors.New("bmaexecutor: executor registration refused")
)
Harness 错误
Harness 端:会话已结束、executor 在tool.result 之前丢失(工具结果未知),或 executor 拒绝了 session.assign。
export class SessionEndedError extends Error {
constructor()
}
export class ToolOutcomeUnknownError extends Error {
constructor()
}
export class AssignRejectedError extends Error {
constructor()
}
class SessionEndedError(ExecutorError):
"""A request on a session that has ended."""
def __init__(self) -> None: ...
class ToolOutcomeUnknownError(ExecutorError):
"""The executor was lost (lease expiry, executor.close, session ended, or a"""
def __init__(self) -> None: ...
class AssignRejectedError(ExecutorError):
"""session.assign answered accepted=false."""
def __init__(self) -> None: ...
var (
// ErrSessionEnded is returned for requests on a session that has ended.
ErrSessionEnded = errors.New("bmaexecutor: session ended")
// ErrToolOutcomeUnknown means the executor was lost (lease expiry,
// executor.close, session ended, or a restarted executor that no longer
// reports the session) before a tool.result arrived. The tool may or may
// not have run; the caller decides whether a retry is safe.
ErrToolOutcomeUnknown = errors.New("bmaexecutor: tool outcome unknown: executor lost before tool.result")
// ErrAssignRejected is returned when session.assign answers accepted=false.
ErrAssignRejected = errors.New("bmaexecutor: executor rejected session.assign")
)
关闭码
哪些关闭码会让客户端永久停止。export function isTerminalCloseCode(code: number): boolean
# Python SDK 1.12.2 中没有此接口。
func CloseCode(err error) int
JSON-RPC 错误码
| 错误码 | 消息 |
|---|---|
-32700 | parse_error |
-32600 | invalid_request |
-32601 | method_not_found |
-32602 | invalid_params |
-32603 | internal_error |
-32000 | unauthorized |
-32001 | forbidden |
-32002 | not_found |
-32003 | lease_expired |
-32004 | timeout |
-32005 | canceled |
-32006 | payload_too_large |
-32007 | session_not_active |
-32008 | mcp_unavailable |
-32009 | executor_busy |
-32010 | unsupported_protocol |
-32011 | resource_unavailable |
-32012 | capability_unavailable |
-32013 | conflict |
错误 data
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
retryable | boolean | 否 | 调用方应以退避方式重试的容量或超时失败。 |
detail | string | 否 | |
capability | string | 否 | -32012 时缺失的能力,例如 “tool:read” 或 “process.pty”。 |
reason | string | 否 | 机器可读的原因;一个开放集合,harness 原样透传(process.start:工具结果的 error_code 与进程状态的 reason;turn.start:session.error 的 code)。推荐值:workspace_unavailable、workspace_boundary、workspace_read_only、session_rejected、local_confirmation_denied、local_confirmation_expired,process.start 的 spawn_failed / process_id_spec_mismatch,executor.register 的 capability_missing,model_token.refresh 的 turn_inactive / forbidden / model_token_unavailable,以及 tools_token.refresh 的 turn_inactive / forbidden / tools_token_unavailable(契约 1.4.0)。平台工具调用(平台工具端点,AsyncAPI x-bma-platform-tools 中的 ToolErrorCode)的工具结果 error_code 也是一个开放集合,还包括 environment_unavailable、machine_starting、machine_rebuilding、permission_denied、approval_required、approval_invalid、in_progress 与 idempotency_key_reused(契约 1.4.0),对于 computer use 调用还包括 desktop_busy(另一个会话的回合占用了该机器的桌面)与 desktop_human_control(有人持有桌面的控制租约:computer_observe 与 computer_action 均被拒绝,不执行任何操作也不截屏;交还控制后,调用方须先重新观察再行动)。接收方必须接受自己不认识的值。 |
terminal_code | string | 否 | terminal.* 调用失败时的 bma.terminal.v1 错误码。 |
expected_sequence | integer | 否 | Agent session.event 出现空缺(-32013):harness 期望的下一个序号。 |
关闭码
| 错误码 | 含义 |
|---|---|
4001 | token 已过期 |
4003 | 不支持的协议 |
4004 | 已被替换 |
4005 | 已 drain |