Skip to content

fix: make models list read-only - #70847

Merged
shakkernerd merged 6 commits into
mainfrom
fix/models-list-readonly
Apr 24, 2026
Merged

shakkernerd merged 6 commits into
mainfrom
fix/models-list-readonly

Conversation

@shakkernerd

Copy link
Copy Markdown
Contributor

Summary

This PR makes openclaw models list a read-only command. Before this change, list paths could call ensureOpenClawModelsJson() and rewrite the agent models.json file while only displaying available models. That made a read command mutate user state, and it also kept the command tied to heavier write-through catalog preparation.

The new path keeps the visible model-list behavior, but avoids persistence side effects.

What changed

  • Removed the models list call path to ensureOpenClawModelsJson().
  • Switched model-list auth/profile loading to read-only auth-store loading.
  • Changed PI auth discovery so models list can pass readOnly: true and avoid legacy auth cleanup/mutation.
  • Added read-only model catalog loading so supplemental catalog reads do not rewrite models.json.
  • Preserved the current Codex provider catalog fast path from main.
  • Preserved config-defined provider model visibility for the previously visible configured-provider shape.
  • Added coverage proving:
    • models list does not persist models.json
    • read-only catalog loading does not call ensureOpenClawModelsJson
    • unfiltered models list --all still includes eligible config-defined provider rows
  • Updated docs/cli/models.md to document that models list is read-only.

Before

openclaw models list --all could rewrite:

~/.openclaw/agents/<agentId>/agent/models.json

That happened through catalog preparation, even though the user only asked to list models.

The old write-through behavior also made some config-defined providers visible indirectly after persistence, so removing the write path required a read-only replacement for the visible configured-provider rows.

After

openclaw models list reads from:

  • config
  • read-only auth/profile state
  • existing registry/catalog data
  • provider-owned catalog rows

It does not rewrite models.json.

For configured provider rows, the command now preserves the verified existing visible behavior: documented custom provider entries with explicit transport/auth shape still appear in models list --all, without relying on models.json being rewritten first.

Verification

  • pnpm test src/commands/models.list.e2e.test.ts src/commands/models/list.list-command.forward-compat.test.ts src/commands/models/list.rows.test.ts
  • pnpm check:changed
  • pnpm build

I also verified the behavior against origin/main with isolated config/state directories:

  • documented custom provider with api + apiKey appeared on origin/main, and still appears on this branch
  • sparse/local no-api-key provider did not appear on origin/main, so this PR does not broaden that behavior
  • this branch shows the preserved configured-provider row without creating models.json

@aisle-research-bot

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

Copy link
Copy Markdown

🔒 Aisle Security Analysis

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

# Severity Title
1 🟡 Medium Credential injection/confusion via legacy auth.json when discovery runs in read-only mode
1. 🟡 Credential injection/confusion via legacy auth.json when discovery runs in read-only mode
Property Value
Severity Medium
CWE CWE-287
Location src/agents/pi-model-discovery.ts:325-330

Description

discoverAuthStorage() conditionally skips scrubLegacyStaticAuthJsonEntriesForDiscovery() when invoked with { readOnly: true }.

  • createAuthStorage(PiAuthStorageClass, authPath, credentials) still points pi-coding-agent’s AuthStorage at agentDir/auth.json.
  • If auth.json contains legacy {"type":"api_key"} entries (which may be stale or attacker-controlled in environments where the agent directory is writable by others), pi-coding-agent can treat those providers as authenticated.
  • This can cause credential confusion (using unintended API keys), enable providers that the current OpenClaw auth profile store would not authorize, and potentially trigger outbound requests under an injected key depending on how the registry/storage is used.

Vulnerable code (read-only skips scrubbing):

if (options?.readOnly !== true) {
  scrubLegacyStaticAuthJsonEntriesForDiscovery(authPath);
}
return createAuthStorage(PiAuthStorageClass, authPath, credentials);

Recommendation

Ensure legacy auth.json static api_key entries are not trusted even in read-only discovery.

Options:

  1. Scrub in-memory without writing to disk when readOnly is true (preferred): load and filter the file content before constructing the auth storage.

  2. Or, bypass auth.json entirely in read-only mode by using an in-memory backend:

export function discoverAuthStorage(agentDir: string, options?: DiscoverAuthStorageOptions): PiAuthStorage {
  const credentials = resolvePiCredentialsForDiscovery(agentDir, options);
  const authPath = path.join(agentDir, "auth.json");

  ​// In read-only mode, never consume legacy static api_key entries from disk
  if (options?.readOnly === true) {
    ​// Construct storage from `credentials` only (no file)
    return createAuthStorage(PiAuthStorageClass, "", credentials); // or use inMemory/fromStorage path explicitly
  }

  scrubLegacyStaticAuthJsonEntriesForDiscovery(authPath);
  return createAuthStorage(PiAuthStorageClass, authPath, credentials);
}

If pi-coding-agent requires a file path, then parse auth.json, drop type: "api_key" entries, and pass the sanitized object via inMemory(...) / fromStorage(...) rather than relying on the on-disk file.


Analyzed PR: #70847 at commit ad54de3

Last updated on: 2026-04-24T01:01:37Z

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Apr 24, 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: 1476475ea5

ℹ️ 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 thread src/commands/models/list.rows.ts Resolved
@greptile-apps

greptile-apps Bot commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes openclaw models list read-only by removing all calls to ensureOpenClawModelsJson, switching auth-store loading to the read-only loadAuthProfileStoreWithoutExternalProfiles variant, and replacing the write-through configured-provider path with a new appendConfiguredProviderRows helper that reads directly from config. The change is well-scoped, correctly threaded through loadModelCatalog, discoverAuthStorage, and loadModelRegistry, and the test coverage confirms models.json is no longer written during list operations.

Confidence Score: 5/5

Safe to merge; all remaining findings are minor P2 observability concerns that do not affect correctness.

The changes are logically sound, well-tested with new assertions that confirm no models.json writes occur, and the read-only path is correctly propagated through all affected layers. The single flagged issue (shared hasLoggedModelCatalogError flag) is a pre-existing pattern and is P2.

No files require special attention.

Comments Outside Diff (1)

  1. src/agents/model-catalog.ts, line 200-203 (link)

    P2 Shared error-log flag suppresses write-mode errors after a read-only failure

    hasLoggedModelCatalogError is a module-level singleton shared between read-only and write-mode calls. If a read-only catalog load (e.g. from models list) throws and sets this flag to true, any subsequent write-mode catalog load failure in the same process will be silently swallowed — the log.warn inside if (!hasLoggedModelCatalogError) is never reached. Consider resetting or splitting this flag per mode so write-mode errors are always logged.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/model-catalog.ts
    Line: 200-203
    
    Comment:
    **Shared error-log flag suppresses write-mode errors after a read-only failure**
    
    `hasLoggedModelCatalogError` is a module-level singleton shared between read-only and write-mode calls. If a read-only catalog load (e.g. from `models list`) throws and sets this flag to `true`, any subsequent write-mode catalog load failure in the same process will be silently swallowed — the `log.warn` inside `if (!hasLoggedModelCatalogError)` is never reached. Consider resetting or splitting this flag per mode so write-mode errors are always logged.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/model-catalog.ts
Line: 200-203

Comment:
**Shared error-log flag suppresses write-mode errors after a read-only failure**

`hasLoggedModelCatalogError` is a module-level singleton shared between read-only and write-mode calls. If a read-only catalog load (e.g. from `models list`) throws and sets this flag to `true`, any subsequent write-mode catalog load failure in the same process will be silently swallowed — the `log.warn` inside `if (!hasLoggedModelCatalogError)` is never reached. Consider resetting or splitting this flag per mode so write-mode errors are always logged.

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

Reviews (1): Last reviewed commit: "fix: include configured provider rows in..." | Re-trigger Greptile

@shakkernerd
shakkernerd force-pushed the fix/models-list-readonly branch from 1476475 to 2487843 Compare April 24, 2026 00:43

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

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

@shakkernerd
shakkernerd force-pushed the fix/models-list-readonly branch from 2487843 to 2a4778d Compare April 24, 2026 00:51
@shakkernerd
shakkernerd force-pushed the fix/models-list-readonly branch from 2a4778d to ad54de3 Compare April 24, 2026 00:56
@shakkernerd
shakkernerd merged commit c42ae0a into main Apr 24, 2026
70 checks passed
@shakkernerd
shakkernerd deleted the fix/models-list-readonly branch April 24, 2026 01:02
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Merged via rebase.

Thanks @shakkernerd!

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

ℹ️ 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 thread src/commands/models/list.rows.ts Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant