fix(exec): skip gateway cwd injection for remote node host#58977
Conversation
Greptile SummaryThis PR fixes a cross-platform The logic in Confidence Score: 4/5Mostly safe, but a TypeScript type mismatch in the approval-request types should be fixed before merging to avoid a build failure. The core fix is correct and well-scoped. However, RequestExecApprovalDecisionParams.cwd was not widened to string | undefined alongside HostExecApprovalParams.workdir, causing buildHostApprovalDecisionParams to produce a type error. This is a P1 build-time issue that needs to be resolved before the PR is ready to merge. src/agents/bash-tools.exec-approval-request.ts — the RequestExecApprovalDecisionParams.cwd field (line 14) needs to be updated to string | undefined.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c05131da83
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Fixes cross-platform exec failures when running with host=node and no explicit cwd by preventing the gateway from injecting its own process.cwd() into remote node execution requests.
Changes:
- Track whether
workdirwas explicitly provided; forhost=nodewith no explicit workdir, forwardundefinedso the node can use its own default cwd. - Update node-host execution plumbing to accept
workdir: string | undefinedand only includecwdinsystem.run.preparewhen defined. - Align exec approval request types to allow
workdirto bestring | undefined(but see comment about a remaining type mismatch).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/agents/bash-tools.exec.ts |
Avoids forwarding gateway-derived cwd to remote node exec when cwd is omitted. |
src/agents/bash-tools.exec-host-node.ts |
Makes node-host exec accept optional workdir and omits cwd in prepare calls when undefined. |
src/agents/bash-tools.exec-approval-request.ts |
Updates approval request host params to allow optional workdir (currently inconsistent with RequestExecApprovalDecisionParams.cwd). |
295161c to
6dba270
Compare
6dba270 to
0cb531e
Compare
fb68288 to
f198470
Compare
When exec runs with host=node and no explicit cwd is provided, the gateway was injecting its own process.cwd() as the default working directory. In cross-platform setups (e.g. Linux gateway + Windows node), this gateway-local path does not exist on the node, causing "SYSTEM_RUN_DENIED: approval requires an existing canonical cwd". This change detects when no explicit workdir was provided (neither via the tool call params.workdir nor via agent defaults.cwd) and passes undefined instead of the gateway cwd. This lets the remote node use its own default working directory. Changes: - bash-tools.exec.ts: Track whether workdir was explicitly provided; when host=node and no explicit workdir, pass undefined instead of gateway process.cwd() - bash-tools.exec-host-node.ts: Accept workdir as string | undefined; only send cwd to system.run.prepare when defined - bash-tools.exec-approval-request.ts: Accept workdir as string | undefined in HostExecApprovalParams Fixes openclaw#58934 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…string-only params After the node early-return, narrow workdir back to string via resolvedWorkdir for gateway/sandbox paths. Update buildExecApprovalPendingToolResult and buildApprovalPendingMessage to accept string | undefined for cwd since node execution may omit it.
Remote node exec may have no explicit cwd when the gateway's own process.cwd() is omitted. Allow undefined to flow through the approval request type.
9a520a3 to
2a1ecda
Compare
|
Landed via temp rebase onto main.
Thanks @Starhappysh! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a1ecdab17
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| - Telegram/exec approvals: rewrite shared `/approve … allow-always` callback payloads to `/approve … always` before Telegram button rendering so plugin approval IDs still fit Telegram's `callback_data` limit and keep the Allow Always action visible. (#59217) Thanks @jameslcowan. | ||
| - Cron/exec timeouts: surface timed-out `exec` and `bash` failures in isolated cron runs even when `verbose: off`, including custom session-target cron jobs, so scheduled runs stop failing silently. (#58247) Thanks @skainguyen1412. | ||
| - Telegram/exec approvals: fall back to the origin session key for async approval followups and keep resume-failure status delivery sanitized so Telegram followups still land without leaking raw exec metadata. (#59351) Thanks @seonang. | ||
| <<<<<<< HEAD |
There was a problem hiding this comment.
Remove unresolved merge-conflict marker from changelog
The changelog entry includes a literal merge-conflict marker (<<<<<<< HEAD), which is an accidental artifact rather than release-note content. Leaving this in place pollutes user-facing release notes and can break any tooling that parses changelog bullets for automation or publishing.
Useful? React with 👍 / 👎.
Summary
When
execruns withhost=nodeand no explicitcwdis provided, the gateway injects its ownprocess.cwd()as the default working directory for the remote node. In cross-platform setups (e.g. Linux gateway + Windows node), this Linux path does not exist on Windows, causing:PR #50961 fixed explicit-cwd path preservation but did not address the omitted-cwd default behavior.
Changes
bash-tools.exec.ts: Track whether workdir was explicitly provided by the user or agent config. Whenhost=nodeand no explicit workdir exists, passundefinedinstead of the gateway'sprocess.cwd(), allowing the remote node to use its own default working directory.bash-tools.exec-host-node.ts: Acceptworkdirasstring | undefined. Only sendcwdtosystem.run.preparewhen it is defined.bash-tools.exec-approval-request.ts: UpdateHostExecApprovalParams.workdirtype tostring | undefinedfor consistency.Fixes #58934
Test plan
execwithhost=nodewithout explicitcwd-- should succeed using node's default cwdcwd-- should still forward the explicit cwd to the nodeprocess.cwd()defaultCo-Authored-By: Claude Opus 4.6 (1M context) [email protected]