Skip to content

fix(tui): handle /model list and /model status as commands - #51270

Closed
dinakars777 wants to merge 5 commits into
openclaw:mainfrom
dinakars777:pr/model-commands-all
Closed

dinakars777 wants to merge 5 commits into
openclaw:mainfrom
dinakars777:pr/model-commands-all

Conversation

@dinakars777

@dinakars777 dinakars777 commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fix /model list being parsed as model ID "list" instead of opening model selector
  • Fix /model status being parsed as model ID "status" instead of showing current model
  • Guard against undefined session info in /model status
  • Strengthen test to verify listModels is actually called

Issue

Fixes #51126

Testing

  • Tests verify both commands work correctly

@greptile-apps

greptile-apps Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a parsing bug in the /model TUI command handler where the subcommands list and status were incorrectly forwarded to patchSession as literal model IDs. The fix adds two early-exit branches in case "model" — args === "list" opens the model selector (the same as bare /model) and args === "status" reads state.sessionInfo and prints the current model, with a graceful fallback when the session hasn't loaded yet.

Key changes:

  • tui-command-handlers.ts — case "model" now handles "list" and "status" as reserved subcommands before reaching the patchSession path; sessionInfo fields are guarded with a truthiness check consistent with every other read of that object in the file.
  • tui-command-handlers.test.ts — The harness is refactored to accept arbitrary additional client methods via params?.client, and two new tests assert the correct behaviour for /model list and /model status.
  • The "session not loaded" fallback branch ("model: unknown (session not loaded)") introduced in the handler is not covered by any new test.
  • The /model list test unnecessarily initialises sessionInfo, which openModelSelector never reads.

Confidence Score: 4/5

  • Safe to merge — the handler change is a small, correct guard; no existing behaviour is broken.
  • The logic fix is straightforward and consistent with existing patterns (e.g. /fast status). The only gap is a missing test for the "session not loaded" fallback path, and a minor noise item in the /model list test — neither affects runtime correctness.
  • No files require special attention.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/tui/tui-command-handlers.test.ts
Line: 223-231

Comment:
**Missing test for "session not loaded" fallback**

The `else` branch added for `/model status` — `chatLog.addSystem("model: unknown (session not loaded)")` — is never exercised by the new tests. The PR description specifically calls out "Guard against undefined session info" as one of the goals, but the corresponding test only covers the happy path where both `modelProvider` and `model` are populated.

Consider adding a test where `sessionInfo` is left as the default empty object `{}` (or has neither field set) and asserting that the `"model: unknown (session not loaded)"` message is emitted:

```ts
it("handles /model status when session info is not loaded", async () => {
  const harness = createHarness();
  // sessionInfo stays as {} (default)
  const { handleCommand, addSystem } = harness;

  await handleCommand("/model status");

  expect(addSystem).toHaveBeenCalledWith("model: unknown (session not loaded)");
});
```

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/tui/tui-command-handlers.test.ts
Line: 214-216

Comment:
**Unnecessary `sessionInfo` assignment in `/model list` test**

`harness.state.sessionInfo` is set to `{ modelProvider: "openai", model: "gpt-4" }` here, but `openModelSelector` never reads `state.sessionInfo` — it only calls `client.listModels()` and then conditionally calls `client.patchSession()` (which is only triggered by an overlay selection that never happens in this test). The extra setup adds noise without adding coverage.

```suggestion
    const harness = createHarness({ client });
    const { handleCommand } = harness;
```

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

Last reviewed commit: "fix(tui): guard /mod..."

Comment on lines +223 to +231
it("handles /model status by showing current model", async () => {
const harness = createHarness();
harness.state.sessionInfo = { modelProvider: "anthropic", model: "claude-3" };
const { handleCommand, addSystem } = harness;

await handleCommand("/model status");

expect(addSystem).toHaveBeenCalledWith("model: anthropic/claude-3");
});

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 Missing test for "session not loaded" fallback

The else branch added for /model status — chatLog.addSystem("model: unknown (session not loaded)") — is never exercised by the new tests. The PR description specifically calls out "Guard against undefined session info" as one of the goals, but the corresponding test only covers the happy path where both modelProvider and model are populated.

Consider adding a test where sessionInfo is left as the default empty object {} (or has neither field set) and asserting that the "model: unknown (session not loaded)" message is emitted:

it("handles /model status when session info is not loaded", async () => {
  const harness = createHarness();
  // sessionInfo stays as {} (default)
  const { handleCommand, addSystem } = harness;

  await handleCommand("/model status");

  expect(addSystem).toHaveBeenCalledWith("model: unknown (session not loaded)");
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tui/tui-command-handlers.test.ts
Line: 223-231

Comment:
**Missing test for "session not loaded" fallback**

The `else` branch added for `/model status` — `chatLog.addSystem("model: unknown (session not loaded)")` — is never exercised by the new tests. The PR description specifically calls out "Guard against undefined session info" as one of the goals, but the corresponding test only covers the happy path where both `modelProvider` and `model` are populated.

Consider adding a test where `sessionInfo` is left as the default empty object `{}` (or has neither field set) and asserting that the `"model: unknown (session not loaded)"` message is emitted:

```ts
it("handles /model status when session info is not loaded", async () => {
  const harness = createHarness();
  // sessionInfo stays as {} (default)
  const { handleCommand, addSystem } = harness;

  await handleCommand("/model status");

  expect(addSystem).toHaveBeenCalledWith("model: unknown (session not loaded)");
});
```

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

Comment on lines +214 to +216
const harness = createHarness({ client });
harness.state.sessionInfo = { modelProvider: "openai", model: "gpt-4" };
const { handleCommand } = harness;

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 Unnecessary sessionInfo assignment in /model list test

harness.state.sessionInfo is set to { modelProvider: "openai", model: "gpt-4" } here, but openModelSelector never reads state.sessionInfo — it only calls client.listModels() and then conditionally calls client.patchSession() (which is only triggered by an overlay selection that never happens in this test). The extra setup adds noise without adding coverage.

Suggested change
const harness = createHarness({ client });
harness.state.sessionInfo = { modelProvider: "openai", model: "gpt-4" };
const { handleCommand } = harness;
const harness = createHarness({ client });
const { handleCommand } = harness;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tui/tui-command-handlers.test.ts
Line: 214-216

Comment:
**Unnecessary `sessionInfo` assignment in `/model list` test**

`harness.state.sessionInfo` is set to `{ modelProvider: "openai", model: "gpt-4" }` here, but `openModelSelector` never reads `state.sessionInfo` — it only calls `client.listModels()` and then conditionally calls `client.patchSession()` (which is only triggered by an overlay selection that never happens in this test). The extra setup adds noise without adding coverage.

```suggestion
    const harness = createHarness({ client });
    const { handleCommand } = harness;
```

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

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@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: f21b078b5c

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

Comment on lines +298 to 299
if (!args || args === "list") {
await openModelSelector();

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 /model list routed through the agent-aware command path

In the TUI, /model list now aliases to openModelSelector(), which ultimately calls models.list. That RPC is global-only (src/gateway/server-methods/models.ts) and does not receive the current agentId, agentDir, or sessionEntry, while the previous text command path in src/auto-reply/reply/commands-models.ts:379-395 resolved the catalog against the active agent/session. In multi-agent setups with agent-specific model fallbacks or provider config, typing /model list in the TUI can now show the wrong catalog and suggestions for the selected agent.

Useful? React with 👍 / 👎.

Comment on lines +300 to +305
} else if (args === "status") {
const { modelProvider, model } = state.sessionInfo;
if (modelProvider && model) {
chatLog.addSystem(`model: ${modelProvider}/${model}`);
} else {
chatLog.addSystem("model: unknown (session not loaded)");

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 Preserve the full /model status diagnostic output

This branch now short-circuits /model status to a single state.sessionInfo line, but the existing command handler in src/auto-reply/reply/directive-handling.model.ts:242-357 returned much richer diagnostics: selected vs active runtime model, default model, agent, auth file, and per-provider auth state. After this change, TUI users lose that troubleshooting output entirely, and before session info is loaded they can even get model: unknown even though the gateway could still answer the command correctly.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open, but this PR is not merge-ready: it targets a real TUI /model command bug, but the patch bypasses the shared agent/session-aware model command path, reduces /model status diagnostics, and still lacks real TUI behavior proof.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level. Current main sends non-empty TUI /model arguments to sessions.patch, while the shared command path and docs reserve list and status as command actions.

Is this the best way to solve the issue?

No. Reserving list and status is the right direction, but this patch solves it with duplicate local behavior instead of the shared session-aware model command path.

Security review:

Security review cleared: The diff only touches TUI command handling and colocated tests; I found no dependency, CI, secret, permission, packaging, or supply-chain change.

What I checked:

  • stale F-rated PR: PR was opened 2026-03-20T20:57:23Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Git history shows Peter Steinberger split src/tui/tui-command-handlers.ts and later finished the shared model-list alias work. (role: introduced TUI command-handler split and shared model-list follow-up; confidence: high; commits: 32cfc4900273, 39073d5196e1; files: src/tui/tui-command-handlers.ts, src/auto-reply/reply/directive-handling.model.ts, src/auto-reply/reply/commands-models.ts)
  • vignesh07: Git history shows Vignesh Natarajan added /models and fixed /model listing UX in the shared model command files. (role: shared model command UX contributor; confidence: high; commits: 41d56c06b941; files: src/auto-reply/reply/directive-handling.model.ts, src/auto-reply/reply/commands-models.ts)
  • Takhoffman: Recent history shows Tak Hoffman preserved target-agent and session context for the shared model-list path this TUI fix should not bypass. (role: recent shared model-list context contributor; confidence: high; commits: de74d843f5d4, 58020ab759b4; files: src/auto-reply/reply/commands-models.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 578e73f66763.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 18, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /model list and /model status are parsed as model IDs (openai-codex/list, openai-codex/status)

1 participant