Skip to content

fix(gateway): reject list and status as invalid model refs (#51126) - #51027

Closed
Yaohua-Leo wants to merge 14 commits into
openclaw:mainfrom
Yaohua-Leo:fix/50847-nodes-list-inconsistent
Closed

Yaohua-Leo wants to merge 14 commits into
openclaw:mainfrom
Yaohua-Leo:fix/50847-nodes-list-inconsistent

Conversation

@Yaohua-Leo

@Yaohua-Leo Yaohua-Leo commented Mar 20, 2026 •

Copy link
Copy Markdown

Summary

This PR contains two fixes:

Fix 1: Gateway - Reject 'list' and 'status' as invalid model refs (Fixes #51126)

When Control UI sends /model list or /model status commands, the Gateway now returns a clear error message instead of failing with a confusing model not allowed error.

Fix 2: CLI - Align nodes list and status to show consistent paired node count (Fixes #50847)

  • nodes status correctly shows paired nodes from node.list API
  • nodes list now uses node.list paired nodes as fallback when node.pair.list returns empty
  • Maintains consistency between both commands

Changes

Gateway (sessions-patch.ts)

  • Added validation to detect when list or status is passed as a model identifier
  • Returns user-friendly error message
  • Added 6 test cases covering both aliases in lowercase, uppercase, and mixed case

CLI (register.status.ts)

  • Always call node.list API to get paired status
  • Use node.list paired nodes as fallback when node.pair.list returns empty
  • Re-introduced hasFilters guard to avoid misleading (of N) label

Testing

  • All 33 tests passed (including 6 new tests)
  • All CI checks passed
  • Lint passed
  • TypeScript check passed

…count (#50847)

- Always call node.list API to get paired status
- Use node.list paired nodes as fallback when node.pair.list returns empty
- Fixes inconsistent display between 'nodes status' and 'nodes list' commands

Fixes #50847
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS labels Mar 20, 2026
@greptile-apps

greptile-apps Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR aligns nodes list and nodes status to use node.list as the authoritative source for paired node counts, fixing a display inconsistency when node.pair.list returns an empty paired array. The approach is broadly sound but introduces two issues:

  • Redundant parse — parseNodeList(nodeListResult) is called twice (lines 315 and 345). The second call is unnecessary since the same data was already stored in liveNodesById.
  • Missing hasFilters guard on filteredLabel — The previous code only showed the (of N) suffix when filters (--connected / --last-connected) were active. The new code drops this guard. In the edge case where node.pair.list returns empty paired but node.list reports paired nodes, an unfiltered invocation prints Paired: 0 (of N), which implies filtering occurred when it did not.

Confidence Score: 3/5

  • Mostly safe — the fix achieves its goal but introduces a misleading label edge case and a redundant parse.
  • The core fix (always fetching node.list and using it as a fallback for paired count) is correct and addresses the reported inconsistency. However, removing the hasFilters guard means users without active filters can see a confusing Paired: 0 (of N) label, which misrepresents the situation. Additionally, parseNodeList is called twice on the same result. Neither issue is a crash or data-loss bug, but the label regression is observable by end-users in a specific edge case that the PR description explicitly targets.
  • src/cli/nodes-cli/register.status.ts — specifically the filteredLabel computation and the double parseNodeList call.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/cli/nodes-cli/register.status.ts
Line: 345

Comment:
**Redundant `parseNodeList` call**

`parseNodeList(nodeListResult)` is called twice — once on line 315 to build `liveNodesById`, and again on line 345 to produce `liveNodes`. Since `liveNodesById` already holds all the same data, `liveNodes` can simply be derived from the existing map to avoid re-parsing:

```suggestion
          const liveNodes = Array.from(liveNodesById.values());
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/cli/nodes-cli/register.status.ts
Line: 348-349

Comment:
**Misleading `(of N)` label when no filters are active**

The previous code only showed the `(of N)` label when `hasFilters` was true — i.e., when `--connected` or `--last-connected` flags were passed. The new code drops that guard, so when `node.pair.list` returns an empty `paired` array but `node.list` reports paired nodes, the output becomes:

```
Pending: 0 · Paired: 0 (of 5)
```

This is misleading because the `(of N)` suffix is conventionally read as "N items exist, but they were filtered down to the displayed count." Here, there's no active filter — the two sources simply disagree. Without the `hasFilters` guard the label appears even on an unfiltered invocation, confusing users into thinking a filter removed entries.

Consider re-introducing the `hasFilters` guard so the label is only shown when filters are actually reducing the results:

```suggestion
          const hasFilters = connectedOnly || sinceMs !== undefined;
          const filteredLabel =
            hasFilters && filteredPaired.length !== totalPairedCount ? ` (of ${totalPairedCount})` : "";
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "fix(cli): align node..."

Comment thread src/cli/nodes-cli/register.status.ts Outdated
return true;
});

const liveNodes = parseNodeList(nodeListResult);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant parseNodeList call

parseNodeList(nodeListResult) is called twice — once on line 315 to build liveNodesById, and again on line 345 to produce liveNodes. Since liveNodesById already holds all the same data, liveNodes can simply be derived from the existing map to avoid re-parsing:

Suggested change
const liveNodes = parseNodeList(nodeListResult);
const liveNodes = Array.from(liveNodesById.values());
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/nodes-cli/register.status.ts
Line: 345

Comment:
**Redundant `parseNodeList` call**

`parseNodeList(nodeListResult)` is called twice — once on line 315 to build `liveNodesById`, and again on line 345 to produce `liveNodes`. Since `liveNodesById` already holds all the same data, `liveNodes` can simply be derived from the existing map to avoid re-parsing:

```suggestion
          const liveNodes = Array.from(liveNodesById.values());
```

How can I resolve this? If you propose a fix, please make it concise.

Comment thread src/cli/nodes-cli/register.status.ts Outdated
Comment on lines +348 to +349
const filteredLabel =
hasFilters && filteredPaired.length !== paired.length ? ` (of ${paired.length})` : "";
filteredPaired.length !== totalPairedCount ? ` (of ${totalPairedCount})` : "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Misleading (of N) label when no filters are active

The previous code only showed the (of N) label when hasFilters was true — i.e., when --connected or --last-connected flags were passed. The new code drops that guard, so when node.pair.list returns an empty paired array but node.list reports paired nodes, the output becomes:

Pending: 0 · Paired: 0 (of 5)

This is misleading because the (of N) suffix is conventionally read as "N items exist, but they were filtered down to the displayed count." Here, there's no active filter — the two sources simply disagree. Without the hasFilters guard the label appears even on an unfiltered invocation, confusing users into thinking a filter removed entries.

Consider re-introducing the hasFilters guard so the label is only shown when filters are actually reducing the results:

Suggested change
const filteredLabel =
hasFilters && filteredPaired.length !== paired.length ? ` (of ${paired.length})` : "";
filteredPaired.length !== totalPairedCount ? ` (of ${totalPairedCount})` : "";
const hasFilters = connectedOnly || sinceMs !== undefined;
const filteredLabel =
hasFilters && filteredPaired.length !== totalPairedCount ? ` (of ${totalPairedCount})` : "";
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/nodes-cli/register.status.ts
Line: 348-349

Comment:
**Misleading `(of N)` label when no filters are active**

The previous code only showed the `(of N)` label when `hasFilters` was true — i.e., when `--connected` or `--last-connected` flags were passed. The new code drops that guard, so when `node.pair.list` returns an empty `paired` array but `node.list` reports paired nodes, the output becomes:

```
Pending: 0 · Paired: 0 (of 5)
```

This is misleading because the `(of N)` suffix is conventionally read as "N items exist, but they were filtered down to the displayed count." Here, there's no active filter — the two sources simply disagree. Without the `hasFilters` guard the label appears even on an unfiltered invocation, confusing users into thinking a filter removed entries.

Consider re-introducing the `hasFilters` guard so the label is only shown when filters are actually reducing the results:

```suggestion
          const hasFilters = connectedOnly || sinceMs !== undefined;
          const filteredLabel =
            hasFilters && filteredPaired.length !== totalPairedCount ? ` (of ${totalPairedCount})` : "";
```

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86c92cb4ce

ℹ️ 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".

const sinceMs = parseSinceMs(opts.lastConnected, "Invalid --last-connected");
const result = await callGatewayCli("node.pair.list", opts, {});
const { pending, paired } = parsePairingList(result);
const nodeListResult = await callGatewayCli("node.list", opts, {});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid requiring node.list for plain nodes list

callGatewayCli("node.list", ...) is now unconditional, so even openclaw nodes list without --connected or --last-connected needs the node.list RPC. That regresses environments that only expose pairing capabilities: src/gateway/method-scopes.ts:38-43 puts node.pair.list behind operator.pairing, while src/gateway/method-scopes.ts:52-87 puts node.list behind operator.read, and other client code still treats node.list as optional/fallback-able when it is unavailable (src/cli/nodes-cli/rpc.ts:79-95). Before this change the unfiltered path only used node.pair.list, so least-privilege tokens and older gateways could still list paired nodes.

Useful? React with 👍 / 👎.

@Yaohua-Leo

Copy link
Copy Markdown
Author

Thanks for the review! I've addressed both issues:

  1. Redundant parse - Removed duplicate parseNodeList(nodeListResult) call. Now using Array.from(liveNodesById.values()) instead.

  2. Missing hasFilters guard - Re-introduced the hasFilters check so the (of N) suffix only appears when filters are active.

Changes pushed to the branch.

Yaohua-Leo and others added 2 commits March 20, 2026 20:26
When sessions.patch receives model='list' or model='status' from Control UI,
it now returns a clear error message instead of failing with a confusing
'model not allowed: openai-codex/list' error. These are chat command aliases,
not model identifiers.

Fixes #51126
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S and removed size: XS labels Mar 20, 2026
@Yaohua-Leo Yaohua-Leo changed the title fix(cli): align nodes list and status to show consistent paired node count (#50847) fix(gateway): reject list and status as invalid model refs (#51126) Mar 20, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71851ff56e

ℹ️ 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".

Comment thread src/cli/nodes-cli/register.status.ts Outdated
Comment on lines +347 to +349
const totalPairedCount = paired.length > 0 ? paired.length : livePairedNodes.length;
const filteredLabel = hasFilters && filteredPaired.length !== totalPairedCount
? ` (of ${totalPairedCount})`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep filtered paired counts on the same data source

totalPairedCount now falls back to node.list, but filteredPaired still comes exclusively from node.pair.list. Those RPCs are not interchangeable: node.pair.list reads the gateway-owned node-pairing store, while node.list marks nodes as paired from device pairing (src/gateway/server-methods/nodes.ts:528-540 vs. src/gateway/server-methods/nodes.ts:645-705). In the common WS-node setup where device pairing exists but the separate node-pairing store is empty, openclaw nodes list --connected or --last-connected will now print Paired: 0 (of N) and show no paired rows at all, which is a misleading regression introduced by this fallback count.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7dbb6dda2d

ℹ️ 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".

Comment on lines +392 to +395
if (trimmed.toLowerCase() === "list" || trimmed.toLowerCase() === "status") {
return invalid(
`invalid model: "${trimmed}" is a command alias, not a model. Use /models list or /model status in chat instead.`,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow configured list/status aliases through sessions.patch

src/commands/models/shared.ts:137-144 still accepts aliases like list and status, and src/agents/model-selection.ts:548-571 resolves bare aliases before parsing provider/model refs. This new early return bypasses that path, so any caller that sets a session model via sessions.patch to an allowed alias named list or status now gets invalid model even though the alias is valid everywhere else. That is a real regression for Control UI/API clients on configs that intentionally use those aliases.

Useful? React with 👍 / 👎.

Comment on lines +346 to +350
const livePairedNodes = Array.from(liveNodesById.values()).filter((n) => n.paired);
const totalPairedCount = paired.length > 0 ? paired.length : livePairedNodes.length;
const filteredLabel =
hasFilters && filteredPaired.length !== paired.length ? ` (of ${paired.length})` : "";
hasFilters && filteredPaired.length !== totalPairedCount
? ` (of ${totalPairedCount})`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the paired-node fallback for actual nodes list output

When node.pair.list is empty but node.list marks nodes as paired: true (the exact WS-node case this change is trying to cover), the fallback is only applied to totalPairedCount. The command still logs/serializes filteredPaired, so plain openclaw nodes list reports Paired: 0, --json returns "paired": [], and no Paired table is rendered even though nodes status shows those same nodes as paired. This is separate from the existing filtered-label issue because it also breaks the unfiltered and JSON paths.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 285b401c3d

ℹ️ 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".

Comment on lines +392 to +395
if (trimmed.toLowerCase() === "list" || trimmed.toLowerCase() === "status") {
return invalid(
`invalid model: "${trimmed}" is a command alias, not a model. Use /models list or /model status in chat instead.`,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid reserving bare model IDs list and status

This check now rejects valid model selections before resolveAllowedModelRef runs. src/commands/onboard-custom.ts:616-666 accepts any non-empty custom modelId, and src/agents/model-selection.ts:547-573 resolves bare refs against the session's default provider, so a gateway whose default provider exposes a real model named list or status can no longer be selected through sessions.patch even when it is allowlisted. That is a regression for Control UI/API clients on custom or local providers that use those IDs as actual model names.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a570251e45

ℹ️ 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".

Comment on lines +393 to +394
return invalid(
`invalid model: "${trimmed}" is a command alias, not a model. Use /models list or /model status in chat instead.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Point users to /models instead of /models list

When sessions.patch rejects model: "list", this new hint tells the user to run /models list, but chat only supports /models or /models <provider>. resolveModelsCommandReply strips /models and treats the next token as a provider (src/auto-reply/reply/commands-models.ts:234-279), so /models list falls into the Unknown provider: list path instead of showing models. That leaves the new "clear" error pointing affected users at another failing command.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Closing this as duplicate or superseded after Codex automated review.

PR #51027 should close as superseded. Current main already handles the shared chat /model list and /model status path before model selection, while the remaining WebUI/TUI variants are tracked by narrower open PRs (#47069 and #51270). The gateway-level sessions.patch rejection proposed here is the wrong boundary because it would block legitimate aliases or model IDs named list/status.

Best possible solution:

Close #51027 as superseded. Keep the shared chat /model implementation on main, let the remaining WebUI/TUI behavior be handled in the narrower canonical PRs (#47069 and #51270), and avoid adding hard-coded list/status rejection inside sessions.patch.

What I checked:

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against 76cf013df507.

@clawsweeper clawsweeper Bot closed this Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes gateway Gateway runtime size: S

Projects

None yet

1 participant