fix(gateway): return structured capability error when node lacks exec approvals#98823
fix(gateway): return structured capability error when node lacks exec approvals#98823yplongapp wants to merge 4 commits into
Conversation
… approvals When openclaw approvals get --node <node-id> is run against a node that does not advertise system.execApprovals.get or system.execApprovals.set, the CLI previously exposed a raw "Cannot read properties of undefined (reading 'socket')" TypeError that hid the real problem. Check the node's declared commands before invoking. If the node is connected but does not support the requested exec approvals command, return a structured UNAVAILABLE error that tells the operator exactly which capability is missing and how to resolve it. Fixes openclaw#97578
|
Codex review: stale review; fresh review needed. Summary Next step |
… tests ClawSweeper review identified two P1 issues: 1. Use node.declaredCommands instead of node.commands for the capability check, because gateway command reconciliation can filter out exec approvals commands from the effective surface even when the node advertised them. 2. Remove the early disconnected-node return so missing/not-connected nodes fall through to nodeRegistry.invoke which returns proper NOT_CONNECTED error with details.nodeError. Add test coverage for all four combinations: - node.get rejects when capability is missing - node.get accepts when capability is present - node.set rejects when capability is missing - node.set accepts when capability is present
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
…e on effective node surface ClawSweeper identified that using node.declaredCommands could allow forwarding exec-approval RPCs even when the command was not approved for the session. Fix: 1. Add NODE_EXEC_APPROVALS_COMMANDS to SYSTEM_COMMANDS in node-command-policy.ts so they survive gateway command reconciliation for node hosts that advertise them. 2. Check node.commands (the effective approved surface) instead of node.declaredCommands for the capability preflight.
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
…mmands Adding NODE_EXEC_APPROVALS_COMMANDS to SYSTEM_COMMANDS made them available through the default desktop command surface, but the pairing authorization (resolveNodePairApprovalScopes) did not escalate them to operator.admin scope. A node advertising exec-approval commands could be paired without admin approval. Check NODE_EXEC_APPROVALS_COMMANDS alongside NODE_SYSTEM_RUN_COMMANDS in resolveNodePairApprovalScopes so both command groups require admin scope for pairing approval.
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Superseded by the stronger landed fix #100505 / fccb888. The landed version preserves capable desktop-node commands through pairing/reconnect and gates the dedicated relay on the effective approved surface plus the current Gateway allowlist. This covers the structured-error case without broadening raw node invocation. Thank you @yplongapp for the implementation and evidence. |
What Problem This Solves
openclaw approvals get --node <node-id> --jsoncurrently fails with a raw JavaScript TypeError when the selected node does not advertise the exec approvals capability.Observed output:
Why This Change Was Made
Two-part fix:
Preserve exec-approval commands through reconciliation: Added
NODE_EXEC_APPROVALS_COMMANDS(system.execApprovals.get,system.execApprovals.set) toSYSTEM_COMMANDSinnode-command-policy.ts. Previously these commands were not in the allowlist, so gateway command reconciliation filtered them out ofnode.commandseven when the node host advertised them.Gate on the effective approved surface: Check
node.commands(the reconciled, approved command list) before invoking. If the node is connected but does not have the requested command in its effective surface, return a structuredUNAVAILABLEerror telling the operator which capability is missing.Changes
src/gateway/node-command-policy.ts: AddNODE_EXEC_APPROVALS_COMMANDStoSYSTEM_COMMANDS(3 files, +11/-11 total)Real behavior proof
Behavior addressed: Return structured UNAVAILABLE error instead of raw TypeError when node lacks exec approvals capability.
Environment tested: Node 22.x on Linux
Steps run after the patch: Called production error formatting function via node --import tsx
Evidence after fix:
The structured error produced by the fix code path:
{ "code": "UNAVAILABLE", "message": "Node node-win-01 does not support exec approvals management. The node must advertise system.execApprovals.get, or the operator must edit the node host approvals file directly.", "details": { "nodeId": "node-win-01", "missingCommand": "system.execApprovals.get", "nodeCommands": ["system.run", "system.which", "system.run.prepare"] } }Test results (6/6 passed):
Observed result: All 6 tests pass. Code produces structured error with code, message, and details showing the missing command and the node's available commands.
Not tested: Live Docker-plus-Windows-node reproduction with a real node that lacks exec approvals commands.
Fixes #97578