#16988: fix: always regenerate models.json from gateway config
agents
stale
size: XS
trusted-contributor
Cluster:
Wizard Enhancements and Config Fixes
## Summary
Fixes the stale-data bug where new models added to gateway config were not picked up because models.json was treated as a static snapshot.
Previously, `ensureOpenClawModelsJson` would compare the existing models.json with the new content and only write if different. This caused issues when the gateway config changed - the file was not properly updated.
Now the function always regenerates models.json from the current gateway config, ensuring agents always have access to the latest models.
## Changes
- Removed the comparison logic that would skip writing models.json if content was the same
- Removed the merge mode that would merge existing models.json with new config (which was causing stale data)
- Now always regenerates models.json from the current gateway config on every call
## Testing
- Built the project successfully
- Ran models-config tests: 7 tests passed
- Ran model-catalog tests: 3 tests passed
- Ran model-selection tests: 10 tests passed
Fixes openclaw/openclaw#16976
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Removes the merge mode and comparison logic that caused stale data bugs when gateway config changed. The function now always regenerates `models.json` from the current gateway config on every call, ensuring agents always have access to the latest models. Also fixes the directory creation to use `path.dirname(targetPath)` instead of `agentDir` directly (addressing previous review feedback).
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change simplifies the code by removing problematic merge/comparison logic that caused stale data bugs. The fix is straightforward: always regenerate models.json from current config. Tests pass (7 models-config + 3 model-catalog + 10 model-selection). Only minor cleanup opportunity exists (removing unused constants/functions).
- No files require special attention
<sub>Last reviewed commit: 6b529ab</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17021: fix(agents): read models from gateway config first
by Limitless2023 · 2026-02-15
81.6%
#9739: #9291 fix(models): preserve existing models in models.json when mer...
by ximzzzzz · 2026-02-05
80.3%
#18988: feat(config): add support for config warnings and improve validation
by saurav470 · 2026-02-17
79.3%
#9064: fix: validate model references against catalog in config.set/patch/...
by joetomasone · 2026-02-04
79.1%
#9163: Fix: Save Anthropic setup token to config file
by vishaltandale00 · 2026-02-04
77.5%
#11602: fix(config): skip stale legacy config files when openclaw.json exists
by akoscz · 2026-02-08
77.2%
#19020: bugfix(gateway): Handle invalid model provider API config gracefully\…
by funkyjonx · 2026-02-17
76.9%
#10608: fix(agents): honor spawn model override in gateway and session spaw...
by 1kuna · 2026-02-06
76.7%
#21963: fix(cli): models fallbacks add now includes primary model in allowlist
by ashiabbott · 2026-02-20
76.5%
#21882: feat(gateway): filter models.list by agents.defaults.models allowlist
by kckylechen1 · 2026-02-20
76.3%