Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions scripts/nemoclaw-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1536,18 +1536,21 @@ RUN_TIMEOUT_SECS = _env_seconds('NEMOCLAW_AUTO_PAIR_RUN_TIMEOUT_SECS', 10)
# `openclaw devices approve <scope-upgrade>` can request the upgraded scopes
# for its own connection and return the same pending-scope error it is trying
# to resolve. List calls must stay gateway-pinned so we inspect the live
# gateway, but approval calls temporarily remove OPENCLAW_GATEWAY_URL to use
# OpenClaw's local pairing fallback. Remove this when OpenClaw approve can
# complete scope upgrades through the gateway using only operator.pairing.
def run(*args, strip_gateway_url=False):
# gateway, but approval calls temporarily remove OPENCLAW_GATEWAY_URL,
# OPENCLAW_GATEWAY_PORT, and OPENCLAW_GATEWAY_TOKEN to use OpenClaw's local
# pairing fallback. Remove this when OpenClaw approve can complete scope
# upgrades through the gateway using only operator.pairing.
def run(*args, strip_gateway_env=False):
# Bound every openclaw CLI invocation so a wedged child cannot pin
# the watcher beyond DEADLINE (CodeRabbit #4292): subprocess.run with
# no timeout would hold a hung `openclaw devices list/approve` past
# the fast→slow transition and the 8h deadline check.
env = None
if strip_gateway_url:
if strip_gateway_env:
env = os.environ.copy()
env.pop('OPENCLAW_GATEWAY_URL', None)
env.pop('OPENCLAW_GATEWAY_PORT', None)
env.pop('OPENCLAW_GATEWAY_TOKEN', None)
try:
proc = subprocess.run(
args, capture_output=True, text=True, timeout=RUN_TIMEOUT_SECS, env=env,
Expand Down Expand Up @@ -1600,7 +1603,7 @@ while time.time() < DEADLINE:
print(f'[auto-pair] rejected unknown client={client_id} mode={client_mode}')
continue
arc, aout, aerr = run(
OPENCLAW, 'devices', 'approve', request_id, '--json', strip_gateway_url=True,
OPENCLAW, 'devices', 'approve', request_id, '--json', strip_gateway_env=True,
)
# rc=124 is the timeout sentinel from run() — do NOT add the
# request to HANDLED on a transient timeout, so the next poll
Expand Down Expand Up @@ -1869,7 +1872,7 @@ openclaw() {
# upgrades through the gateway without requesting the upgraded scopes for
# the approval command itself. Other commands keep OPENCLAW_GATEWAY_URL.
if [ "${1:-}" = "devices" ] && [ "${2:-}" = "approve" ]; then
( unset OPENCLAW_GATEWAY_URL; command openclaw "$@" )
( unset OPENCLAW_GATEWAY_URL OPENCLAW_GATEWAY_PORT OPENCLAW_GATEWAY_TOKEN; command openclaw "$@" )
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
return $?
fi
case "$1" in
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test-issue-4462-scope-upgrade-approval.sh
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ fi
. /tmp/nemoclaw-proxy-env.sh
printf "OPENCLAW_GATEWAY_URL=%s\n" "${OPENCLAW_GATEWAY_URL-unset}"
type openclaw 2>/dev/null | sed -n "1,12p"
grep -F "unset OPENCLAW_GATEWAY_URL; command openclaw" /tmp/nemoclaw-proxy-env.sh >/dev/null \
grep -F "unset OPENCLAW_GATEWAY_URL OPENCLAW_GATEWAY_PORT OPENCLAW_GATEWAY_TOKEN; command openclaw" /tmp/nemoclaw-proxy-env.sh >/dev/null \
&& echo "APPROVE_GUARD_PRESENT"
' 2>&1)
guard_rc=$?
Expand Down
26 changes: 15 additions & 11 deletions test/nemoclaw-start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ describe("nemoclaw-start gateway token export (#1114)", () => {
expect(result.status).toBe(0);
expect(result.stdout).toContain("TOKEN=unset");
expect(result.stderr).not.toContain("#token=");
expect(envFile).not.toContain("OPENCLAW_GATEWAY_TOKEN");
expect(envFile).not.toMatch(/^export OPENCLAW_GATEWAY_TOKEN=/m);
});
});

Expand All @@ -805,7 +805,7 @@ describe("nemoclaw-start configure guard behavior", () => {
fs.mkdirSync(fakeBin);
fs.writeFileSync(
path.join(fakeBin, "openclaw"),
`#!/usr/bin/env bash\nprintf 'ARGS=%s URL=%s\\n' "$*" "\${OPENCLAW_GATEWAY_URL-unset}" >> ${JSON.stringify(commandLog)}\nexit 0\n`,
`#!/usr/bin/env bash\nprintf 'ARGS=%s URL=%s PORT=%s TOKEN=%s\\n' "$*" "\${OPENCLAW_GATEWAY_URL-unset}" "\${OPENCLAW_GATEWAY_PORT-unset}" "\${OPENCLAW_GATEWAY_TOKEN-unset}" >> ${JSON.stringify(commandLog)}\nexit 0\n`,
{ mode: 0o755 },
);
const runtimeBlock = `${runtimeShellEnvBlock(src)}\nwrite_runtime_shell_env`.replaceAll(
Expand All @@ -827,6 +827,8 @@ describe("nemoclaw-start configure guard behavior", () => {
'_CIAO_GUARD_SCRIPT="/tmp/ciao-guard.js"',
'_SLACK_GUARD_SCRIPT="/nonexistent/slack-guard.js"',
'export OPENCLAW_GATEWAY_URL="ws://127.0.0.1:18789"',
'export OPENCLAW_GATEWAY_PORT="18789"',
'export OPENCLAW_GATEWAY_TOKEN="test-gateway-token"',
"_TOOL_REDIRECTS=()",
"set +u",
runtimeBlock,
Expand Down Expand Up @@ -904,7 +906,7 @@ describe("nemoclaw-start configure guard behavior", () => {
}
});

it("#4462: unsets OPENCLAW_GATEWAY_URL only for devices approve", () => {
it("#4462: unsets OPENCLAW_GATEWAY_URL, PORT, and TOKEN for devices approve", () => {
const setup = writeProxyEnvWithGuard();
try {
const result = runGuardedShell(setup, [
Expand All @@ -916,10 +918,10 @@ describe("nemoclaw-start configure guard behavior", () => {

expect(result.status).toBe(0);
expect(fs.readFileSync(setup.commandLog, "utf-8").trim().split("\n")).toEqual([
"ARGS=devices list --json URL=ws://127.0.0.1:18789",
"ARGS=devices approve request-1 --json URL=unset",
"ARGS=devices list --json URL=ws://127.0.0.1:18789 PORT=18789 TOKEN=test-gateway-token",
"ARGS=devices approve request-1 --json URL=unset PORT=unset TOKEN=unset",
"SHELL_URL=ws://127.0.0.1:18789",
"ARGS=agent --agent main -m hello URL=ws://127.0.0.1:18789",
"ARGS=agent --agent main -m hello URL=ws://127.0.0.1:18789 PORT=18789 TOKEN=test-gateway-token",
]);
} finally {
fs.rmSync(setup.tmpDir, { recursive: true, force: true });
Expand Down Expand Up @@ -1467,7 +1469,7 @@ describe("nemoclaw-start auto-pair client whitelisting (#117)", () => {
`#!/usr/bin/env bash
set -euo pipefail
if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then
printf 'list:%s\n' "\${OPENCLAW_GATEWAY_URL-unset}" >> ${JSON.stringify(envLog)}
printf 'list:%s:%s:%s\n' "\${OPENCLAW_GATEWAY_URL-unset}" "\${OPENCLAW_GATEWAY_PORT-unset}" "\${OPENCLAW_GATEWAY_TOKEN-unset}" >> ${JSON.stringify(envLog)}
count="$(cat ${JSON.stringify(stateFile)} 2>/dev/null || echo 0)"
count=$((count + 1))
echo "$count" > ${JSON.stringify(stateFile)}
Expand All @@ -1479,7 +1481,7 @@ if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "list" ]; then
exit 0
fi
if [ "\${1:-}" = "devices" ] && [ "\${2:-}" = "approve" ]; then
printf 'approve:%s:%s\n' "$3" "\${OPENCLAW_GATEWAY_URL-unset}" >> ${JSON.stringify(envLog)}
printf 'approve:%s:%s:%s:%s\n' "$3" "\${OPENCLAW_GATEWAY_URL-unset}" "\${OPENCLAW_GATEWAY_PORT-unset}" "\${OPENCLAW_GATEWAY_TOKEN-unset}" >> ${JSON.stringify(envLog)}
echo "$3" >> ${JSON.stringify(approveLog)}
printf '{}\n'
exit 0
Expand All @@ -1502,6 +1504,8 @@ exit 2
...process.env,
OPENCLAW_BIN: fakeOpenclaw,
OPENCLAW_GATEWAY_URL: "ws://127.0.0.1:18789",
OPENCLAW_GATEWAY_PORT: "18789",
OPENCLAW_GATEWAY_TOKEN: "test-gateway-token",
// Cap the slow-mode keepalive (NemoClaw#4263) so the test
// terminates without waiting out the default 8h deadline.
NEMOCLAW_AUTO_PAIR_DEADLINE_SECS: "5",
Expand All @@ -1523,9 +1527,9 @@ exit 2
"ok-webchat",
]);
const envLogLines = fs.readFileSync(envLog, "utf-8").trim().split("\n");
expect(envLogLines).toContain("list:ws://127.0.0.1:18789");
expect(envLogLines).toContain("approve:ok-browser:unset");
expect(envLogLines).toContain("approve:ok-webchat:unset");
expect(envLogLines).toContain("list:ws://127.0.0.1:18789:18789:test-gateway-token");
expect(envLogLines).toContain("approve:ok-browser:unset:unset:unset");
expect(envLogLines).toContain("approve:ok-webchat:unset:unset:unset");
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
Expand Down
Loading