Bug
opencode fails to start intermittently with:
Error: 2 of 5 requests failed: Unexpected server error. Check server logs for details.
Affected startup requests: config.providers, provider.list
Root Cause (from server logs)
The actual error in the server log is:
ERROR service=server error=JSON Parse error: Unexpected EOF cause=SyntaxError: JSON Parse error: Unexpected EOF
at ModelsDev.populate
at Provider.list
at ConfigHttpApi.providers
~/.cache/opencode/models.json gets corrupted (truncated/empty) if opencode is terminated while writing an updated model catalog to that file. On the next launch, ModelsDev.populate fails to parse the truncated JSON, which causes both config.providers and provider.list to fail, producing the "Unexpected server error" shown to the user.
Steps to Reproduce
- While opencode is running, hard-kill the process (e.g. close terminal, kill PID, machine sleep/wake) during a model catalog refresh
- Re-launch opencode — it fails with the error above
Expected Behaviour
opencode should handle a corrupted/missing models.json gracefully by re-downloading the model catalog rather than failing startup.
Suggested Fix
Write the updated catalog to a temp file and atomically rename it to models.json, so a mid-write kill cannot leave a partially-written file. Also add a fallback: if readJson throws a parse error on the cache file, delete it and re-fetch rather than propagating the error up to the startup requests.
Environment
- Platform: Windows 11 (win32)
- Shell: PowerShell 5.1
- opencode: 1.15.13
Bug
opencode fails to start intermittently with:
Root Cause (from server logs)
The actual error in the server log is:
~/.cache/opencode/models.jsongets corrupted (truncated/empty) if opencode is terminated while writing an updated model catalog to that file. On the next launch,ModelsDev.populatefails to parse the truncated JSON, which causes bothconfig.providersandprovider.listto fail, producing the "Unexpected server error" shown to the user.Steps to Reproduce
Expected Behaviour
opencode should handle a corrupted/missing
models.jsongracefully by re-downloading the model catalog rather than failing startup.Suggested Fix
Write the updated catalog to a temp file and atomically rename it to
models.json, so a mid-write kill cannot leave a partially-written file. Also add a fallback: ifreadJsonthrows a parse error on the cache file, delete it and re-fetch rather than propagating the error up to the startup requests.Environment