Skip to content

feat: Add /models add hot-reload model registration - #70211

Merged
Takhoffman merged 9 commits into
mainfrom
codex/models-add-transplant
Apr 22, 2026
Merged

Takhoffman merged 9 commits into
mainfrom
codex/models-add-transplant

Conversation

@Takhoffman

@Takhoffman Takhoffman commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This change adds a chat-driven model registration flow so operators can add configured models from /models add <provider> <modelId> and use them right away without restarting the gateway.

It keeps /models simple as a provider browser, adds lightweight guidance for the add flow, and improves the Telegram menu so the add path is discoverable without reintroducing a larger CRUD-style model manager.

What changed

  • add /models add <provider> <modelId> with config writes plus gateway-visible hot reload behavior
  • bootstrap supported self-hosted providers when needed and auto-detect model metadata when available
  • keep /models as a lightweight provider list while adding a small add entrypoint and copy-friendly add examples
  • add Telegram Add model affordances for the top-level menu and callback-driven provider picker
  • broaden config-write authorization checks to the paths the add flow actually mutates
  • add focused tests and docs for add behavior, Telegram wiring, and hot-reload visibility

User benefit

  • new models can be registered from chat instead of editing config by hand first
  • added models become selectable immediately instead of requiring a gateway restart
  • Telegram users get a clearer path into the add flow with example commands they can copy directly

@greptile-apps

greptile-apps Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds /models add <provider> <modelId> with config-write authorization, gateway-visible hot-reload cache invalidation (resetModelCatalogCache on relevant path changes), bootstrapping for self-hosted providers (ollama, lmstudio), and Telegram affordances for the add flow.

  • P1: In addModelToConfig, validated.issues[0] is accessed without a null guard; if validateConfigObjectWithPlugins ever returns { ok: false, issues: [] } (valid per the return type), the command handler crashes with an unhandled TypeError instead of returning a clean error message.

Confidence Score: 4/5

Safe to merge after fixing the unguarded issues[0] access in addModelToConfig.

One P1 null-dereference in the add command handler (validated.issues[0] without a guard) that would crash the handler if the issues array is ever empty. The rest of the change is well-structured with good test coverage, correct auth layering, and a clean hot-reload integration.

src/auto-reply/reply/models-add.ts — the validateConfigObjectWithPlugins error-handling block around line 419–425.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/models-add.ts
Line: 419-425

Comment:
**Potential crash: unguarded access on `validated.issues[0]`**

If `validateConfigObjectWithPlugins` returns `{ ok: false, issues: [] }` (an empty issues array, which the type permits), `issue` is `undefined` and accessing `issue.path` / `issue.message` throws a `TypeError` — crashing the `/models add` command handler with no user-visible error message.

```suggestion
  const validated = validateConfigObjectWithPlugins(allowlisted.nextConfig);
  if (!validated.ok) {
    const issue = validated.issues[0];
    const detail = issue ? `${issue.path}: ${issue.message}` : "unknown validation error";
    return {
      ok: false,
      error: `Config invalid after /models add (${detail}).`,
    };
  }
```

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

---

This is a comment left during a code review.
Path: CHANGELOG.md
Line: 13

Comment:
**`(#PR)` placeholder not replaced**

The PR number placeholder `(#PR)` was never substituted with the actual pull request number before merging.

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/auto-reply/reply/commands-models.ts
Line: 284-298

Comment:
**`lmstudio` missing from hardcoded add-examples**

`buildAddExamples` generates copy-friendly examples for `ollama`, `codex`, and `openai-codex`, but not for `lmstudio`, even though `lmstudio` is a fully supported provider in `MODEL_ADD_ADAPTERS`. Users on LM Studio will only see the generic `/models add <provider> <modelId>` fallback when `lmstudio` is actually in their `addableProviders` list.

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

Reviews (1): Last reviewed commit: "docs(changelog): add models entry for pr..." | Re-trigger Greptile

Comment thread src/auto-reply/reply/models-add.ts Resolved
Comment thread CHANGELOG.md Resolved
Comment thread src/auto-reply/reply/commands-models.ts Resolved

@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: 507190141b

ℹ️ 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/auto-reply/reply/models-add.ts Resolved
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: slack Channel integration: slack channel: telegram Channel integration: telegram gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Apr 22, 2026
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui scripts Repository scripts labels Apr 22, 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: d62a767c10

ℹ️ 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/auto-reply/reply/models-add.ts Resolved
@Takhoffman

Copy link
Copy Markdown
Contributor Author

Addressed the actionable bot review items in f309243334:

  • guarded /models add validation failures when issues is empty, so the command returns a clean error instead of risking a crash
  • added an LM Studio example to the /models add helper text
  • hardened LM Studio metadata auto-detection so it only runs for loopback/local base URLs, applies an SSRF policy on the fetch path, and no longer exposes raw exception text in user-facing warnings

I left the overall feature scope unchanged: /models add still hot-reloads newly added models without turning /models back into a broader CRUD surface.

@Takhoffman Takhoffman changed the title Add /models add hot-reload model registration feat: Add /models add hot-reload model registration Apr 22, 2026
@Takhoffman

Copy link
Copy Markdown
Contributor Author

Addressed the remaining safe Aisle findings in 8357b96c11:

  • /models add now uses conflict-aware config replacement (replaceConfigFile with the snapshot hash) instead of a blind read-modify-write, so concurrent config changes return a retryable error instead of risking a lost update
  • LM Studio detection logging now sanitizes the configured baseUrl before writing it to logs

I did not widen the feature scope or change the hot-reload behavior; this keeps the add flow intact while tightening correctness and log safety.

@Takhoffman

Copy link
Copy Markdown
Contributor Author

Follow-up on the Aisle summary:

  • The config-write lost-update concern is addressed in 8357b96c11 by moving /models add onto conflict-aware replaceConfigFile(...) with the loaded snapshot hash, so concurrent config changes now fail with a retryable error instead of risking a silent overwrite.
  • The LM Studio log-safety concern is also addressed in 8357b96c11 by sanitizing the logged baseUrl.
  • I am intentionally leaving the Ollama SSRF note as follow-up hardening rather than changing behavior in this PR. The current /models add ollama ... detection path uses an already-configured privileged provider base URL, so I do not want to narrow or reinterpret Ollama remote-provider behavior here without a separate product/security decision.

That means the remaining Aisle point is documented, but it is not being treated as a blocker for the narrow /models add hot-reload feature in this PR.

@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: 8357b96c11

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

@aisle-research-bot

aisle-research-bot Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🟡 Medium SSRF via Ollama model metadata detection in /models add
1. 🟡 SSRF via Ollama model metadata detection in /models add
Property Value
Severity Medium
CWE CWE-918
Location src/auto-reply/reply/models-add.ts:178-193

Description

The new /models add implementation performs Ollama model metadata detection by making an HTTP request to providerConfig.baseUrl without restricting it to loopback/local addresses.

  • providerConfig.baseUrl comes from the persisted config (or bootstrapped), and can be set to an arbitrary URL/hostname.
  • During detection, /models add calls queryOllamaModelShowInfo(baseUrl, modelId), which issues a POST request to ${baseUrl}/api/show.
  • The Ollama SSRF policy (buildOllamaBaseUrlSsrFPolicy) allows private network targets (allowPrivateNetwork: true) and only pins to the configured hostname. This means a configured base URL such as http://10.0.0.5:11434 (or an internal DNS name) will be reachable from the server running OpenClaw.

This introduces an SSRF/internal network probing primitive reachable via the command flow (even if owner/admin-gated, SSRF still matters in multi-tenant deployments, compromised accounts, or overly broad admin roles).

Vulnerable code (call site):

const info = (await queryOllamaModelShowInfo(providerConfig.baseUrl, modelId)) ?? {};

Network sink (Ollama extension):

const { response, release } = await fetchWithSsrFGuard({
  url: `${normalizedApiBase}/api/show`,
  ...,
  policy: buildOllamaBaseUrlSsrFPolicy(normalizedApiBase),
});

Recommendation

Restrict or harden Ollama metadata detection so it cannot be used for arbitrary outbound/internal requests.

Options (choose one or combine):

  1. Limit detection to local Ollama only (mirrors LM Studio behavior):
if (!isLoopbackOrLocalhost(providerConfig.baseUrl)) {
  return { found: false, warnings: ["Ollama metadata detection is limited to local baseUrl values; using defaults."] };
}
  1. Enforce a stricter SSRF policy for Ollama detection that does not allow private network access unless explicitly opted-in by an admin setting:
  • Use a policy similar to ssrfPolicyFromHttpBaseUrlAllowedHostname(baseUrl) but without allowPrivateNetwork: true.
  • Consider blocking link-local and RFC1918 ranges by default.
  1. Validate and normalize baseUrl at configuration time:
  • Only allow http(s).
  • Disallow credentials, unusual ports if not needed, and consider blocking non-loopback by default.

These measures prevent /models add from being repurposed for internal network scanning/SSRF while keeping the UX of local model detection.


Analyzed PR: #70211 at commit bda238f

Last updated on: 2026-04-22T16:50:19Z

@Takhoffman
Takhoffman merged commit f328c21 into main Apr 22, 2026
86 of 87 checks passed
@Takhoffman
Takhoffman deleted the codex/models-add-transplant branch April 22, 2026 17:00
medikoo pushed a commit to medikoo/openclaw that referenced this pull request Apr 24, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
zhonghe0615 pushed a commit to zhonghe0615/openclaw that referenced this pull request May 7, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
Heetisk pushed a commit to Heetisk/openclaw that referenced this pull request Sep 28, 2026
* feat(models): add chat model registration with hot reload

* docs(changelog): add models entry for pr 70211

* fix(models): harden add flow follow-ups

* fix models add review follow-ups

* harden models add config writes

* tighten plugin boundary invariant

* move models add adapters behind sdk facades

* avoid ollama-specific core facade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui channel: discord Channel integration: discord channel: slack Channel integration: slack channel: telegram Channel integration: telegram docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant