#20014: fix(nodes): use formatExecCommand for approval request command text
cli
agents
size: XS
Cluster:
Device Pairing and Gateway Fixes
## Summary
This PR fixes a bug where `nodes.run` would consistently fail with an `approval id does not match request` error when the command contained arguments with spaces. The root cause was a command string mismatch between the approval request creation and the gateway-side validation.
- The gateway normalizes the command text using `formatExecCommand` to handle shell quoting correctly.
- However, the `nodes.run` tool and `nodes invoke` CLI were creating the approval request command text using a simple `command.join(" ")`, which does not preserve quoting for arguments with spaces (e.g., `bash -lc "echo ..."`).
This change updates both `nodes-tool.ts` and `register.invoke.ts` to use the canonical `formatExecCommand` helper, ensuring that the command text is consistent across both the request creation and validation paths. This resolves the approval ID correlation failure.
## Test Plan
The `formatExecCommand` helper is already covered by unit tests in `system-run-command.test.ts`.
For commands without spaces, `formatExecCommand` produces identical output to `join(" ")`,
so there is no regression risk for the common case. The fix aligns the approval request
creation path with the existing gateway validation path (`getCmdText` in
`node-invoke-system-run-approval.ts`), which already uses `formatExecCommand`.
Fixes #19862
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes a bug where `nodes.run` failed with `approval id does not match request` when the command contained arguments with spaces. The root cause was that the approval request was created using `command.join(" ")`, which loses quoting information, while the gateway-side validation uses `formatExecCommand()` which correctly quotes arguments containing spaces. The fix updates both `nodes-tool.ts` (agent tool path) and `register.invoke.ts` (CLI path) to use `formatExecCommand()`, ensuring the command text is consistent between approval request creation and gateway validation.
- Both callsites now use the canonical `formatExecCommand` helper from `system-run-command.ts`
- The fix is minimal, targeted, and consistent with how the gateway normalizes command text in `getCmdText()` (`node-invoke-system-run-approval.ts:47-59`)
- No remaining `command.join(" ")` patterns for approval command text were found in the codebase
- Existing tests in `system-run-command.test.ts` cover the behavior of `formatExecCommand`
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it's a minimal, well-scoped bug fix with no behavioral side effects for commands without spaces.
- The change is two one-line fixes that align the approval request creation with the existing gateway validation logic. The `formatExecCommand` function is well-tested and already used by the gateway. For commands without spaces, `formatExecCommand` produces the same output as `join(" ")`, so there are no regressions for the common case.
- No files require special attention.
<sub>Last reviewed commit: ed334fb</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#8683: fix: Exec approval bypass via client-controlled flags in system.run
by coygeek · 2026-02-04
76.6%
#14127: fix(exec): return command output when gateway approval is Always Allow
by Siziff · 2026-02-11
74.6%
#16525: fix(shell): stop rejecting newlines in double-quoted args (#16470)
by yinghaosang · 2026-02-14
74.0%
#9433: fix: pass raw command string to node exec instead of argv array
by dbottme · 2026-02-05
73.9%
#9250: Fix: Add shell:true for Windows .cmd files to prevent spawn EINVAL ...
by vishaltandale00 · 2026-02-05
73.5%
#20209: fix(node): respect tools.exec.notifyOnExit for node exec events
by zerone0x · 2026-02-18
73.4%
#5496: Fix: Windows path separators stripped in Gateway scheduled task
by giuliozelante · 2026-01-31
72.7%
#15306: fix: explicit exit after onboarding command completes
by jeroenbaas · 2026-02-13
72.6%
#11961: fix: exec tool wraps shebang scripts in heredoc to use correct inte...
by scott-memco · 2026-02-08
72.5%
#22700: fix: support node binaries named like `node22`
by lictex · 2026-02-21
72.5%