Repository navigation
🩺 fix: Report Why a Worker Command Was Unavailable - #409
Conversation
A paired worker that could not run a command settled only `COMMAND_UNAVAILABLE` and, for an executor failure that was not a WorkspaceToolError, the generic "Native executor request failed". The sanitized diagnostic that explains the failure stayed in the worker's local journal. Rejected COMMAND_UNAVAILABLE settlements now carry an optional `commandFailure` (stage, reason and, when known, an allowlisted errno `osCode`, a Node.js `nodeCode` and a built-in `errorName`). The protocol owns one strict reader that the worker's diagnostic extraction, the executor IPC and the Code API all share. The Code API stores the validated value, returns it beside `code` in workspace tool errors, and logs it on the request outcome and the durable admission transition. A missing field is the normal case for older workers, older Code API replicas ignore it, and an invalid or unknown value is dropped rather than refused. A retried rejection is still recognized when replicas handled its cause differently. Quarantine and mutation decisions are unchanged.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
The packed-package smoke forks the installed executor and checks its unprepared-close reply. That reply now names the built-in error class, and still carries no message.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
When a paired worker cannot run a command, the caller sees only that it failed, never why. LibreChat shows
Workspace tool request rejected (upstreamStatus: 503) (upstreamCode: COMMAND_UNAVAILABLE), and the Code API stores just:{"status":"rejected","errorCode":"COMMAND_UNAVAILABLE","error":"Native executor request failed"}How it happens. The worker's executor child already classifies a failure into a sanitized diagnostic (stage, reason, allowlisted errno). When the error is not a
WorkspaceToolError, the child sends no message, so the parent falls back toNative executor request failed. The worker logs the diagnostic only to its own stderr (workspace_command_unavailable, added in #349) and settles without it. The cause exists only in the worker machine's journal, which the operator of the Code API or LibreChat usually cannot reach. The failure is rare: about 2 in 11,000 commands on one worker over a week. That makes it hard to reproduce, which is why the settlement needs to carry the cause.The fix. Rejected
COMMAND_UNAVAILABLEsettlements now carry an optionalcommandFailurebuilt from that same diagnostic:{ "status": "rejected", "errorCode": "COMMAND_UNAVAILABLE", "error": "Native executor request failed", "commandFailure": { "stage": "dispatch", "reason": "executor_rejected", "osCode": "EAGAIN", "errorName": "Error" } }packages/code/src/protocol.ts):BridgeCommandFailureandreadBridgeCommandFailure, the single strict reader.stageandreasonmust be known values, or the whole value is dropped. Each optional field is dropped on its own when it fails its check:osCodemust be an allowlisted errno (the existing list plusEAGAIN,EBUSY,E2BIG,ENOEXEC,ENOBUFS,ESRCH,ECHILD,EBADF,EROFSandECONNREFUSED),nodeCodemust match^ERR_[A-Z0-9_]{1,60}$, anderrorNamemust be a built-in error class. The reader reads only own data properties, never runs getters, and never throws. It cannot carry a path, command text, environment value, token or error message.command-diagnostics.tsnow uses the protocol's stages, reasons and reader instead of its own copies, and also records the error's Node.js code and class name. The class name comes from the nearestnamedata property; it never calls an accessor. The worker attachescommandFailureunder exactly the condition that already emits the localworkspace_command_unavailablerecord (COMMAND_UNAVAILABLEonexecute_commandor workspace-programmatic). It does so inside the same guarded block, so a diagnostic can never change the settlement's status, code or message.RedisBridgeStore.settlestores the validated value. An invalid value is dropped rather than refused, the same waylaneGitis handled, and a valid value is stored byte-identical so retries still match.code: as{ error, code, commandFailure }for/workspace-tools/execute, and aserror.commandFailureon the durable request status.commandFailureonWorkspace tool request completed, and ascodeapi.command_failure.{stage,reason,os_code,node_code,error_name}on the failedDurable workspace admission transitionlog line and span. Building those attributes moved intoadmissionTransitionAttributesso they can be tested.scripts/smoke-code-package.mjs) now expects the executor's unprepared-close reply to name its error class, and checks that the reply still carries no message.Compatibility
commandFailure, which is the normal case. The settlement, status code, message and log line are unchanged apart from the missing attributes.ASSIGNMENT_FENCED.LibreChat does not display the new field yet.
WorkspaceToolHttpErrorformats onlyupstreamStatusandupstreamCode, and the durable path rebuilds the error body from the code alone. Showing the cause needs a small LibreChat change, tracked separately. Until then, the Code API's response and logs carry it.Change Type
Testing
packages/code: fullnode --test dist/*.test.json Node 24: 1016 passed, 24 failed, 22 skipped. The same 24 tests fail on unchangedmainin this environment (Bash 5.2/jq programmatic prerequisites, worktree fixtures). Linux CI is the full-suite gate.tsc --noEmitpasses.ERR_codes, embedded newline, custom class names), drops the whole value for an unknown stage or reason or a non-object, and never invokes getters or lets a throwing proxy escape.EAGAINerror with a path, syscall and arguments keeps onlyosCodeanderrorName; a NodeERR_IPC_CHANNEL_CLOSEDTypeErrorkeepsnodeCodeanderrorName; anamegetter is never called.WorkspaceToolErrorfailure with the sanitized diagnostic and no message.Native executor request failedwithcommandFailure: { stage: 'sandbox_startup', reason: 'startup_failed', osCode: 'ENOENT', errorName: 'Error' }. The settlement includes neither the root path nor the command. A failure that carries no diagnostic settles without the field.service, against Redis 7.2:requests.test.tsandfleet.test.tscover the stored settlement, the durableerror.commandFailureand the transition attributes, in four cases: valid, older worker, unknown stage, and non-object. They also check a partially valid cause and a retried rejection across a replica that predates the change, plus a genuinely different retry, which is still fenced. 82 passed.workspace-tools/router.test.tscovers the response body and the outcome log for a valid, an invalid and an absent cause. 68 passed.bun run test: 1306 passed, 17 skipped, 5 failed. The same 5 tests fail on unchangedmainhere (native mutation handoff, and jq number canonicalization).tsc --noEmitreports the same diagnostics asmain, all in untouched files. ESLint on the touched files adds oneindentfinding: one line added inside an import block whose existing lines use the same indentation.Checklist