Root cause: AvailableModels() with a warm persistent cache calls
startPersistentModelRefresh(), which spawns a background goroutine that
writes the refreshed model list into the test's TempDir. When the test
function returns, t.TempDir() runs RemoveAll before that goroutine
finishes its last write — manifesting as:
TempDir RemoveAll cleanup: unlinkat /tmp/.../001: directory not empty
The race window is too small to hit reliably without -cover; coverage
instrumentation slows the goroutine enough to make it reproducible.
Fix (two-part):
1. Add refreshWg sync.WaitGroup to Agent and track every background
refresh goroutine with Add(1)/Done() in startPersistentModelRefresh.
This is a pure bookkeeping addition with zero production behaviour
change.
2. In TestAvailableModels_PrefersPersistentCacheOverDiscoveredModels,
register t.Cleanup(func() { a.refreshWg.Wait() }) immediately after
creating the agent (before AvailableModels is called). Cleanup
functions run LIFO: our Wait fires before t.TempDir's RemoveAll,
guaranteeing the goroutine has finished writing before the directory
is cleaned up.
Verified: go test -count=1 -cover ./agent/opencode/... run 10 times
consecutively — 10/10 PASS, 0 failures.
Co-authored-by: root <root@UYQQVGRAEKQKNQP>
Co-authored-by: Cursor <cursoragent@cursor.com>
Add DeleteSession to the opencode agent by calling `opencode session delete <id>`
via the CLI, enabling single, batch, and range deletion from any connected platform.
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
AvailableModels now runs `<cmd> models` first and falls back to
provider-configured models and the built-in list only when the CLI
command fails or produces no output. Results are deduplicated and
sorted for stable /model output.
Co-authored-by: q107580018 <107580018@qq.com>
Made-with: Cursor
* fix(core): share provider model lookup and stabilize tests
* fix(tests): address PR review follow-ups
---------
Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>