e863f520c33972cea0404c4bf87341ea4db9504e
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
194b2fd3c5 |
plugin: the host keeps models.dev's catalog through a half-written refresh, and #1928's start test leaves a loaded runner room (#1928 review)
Review of Totopo27's bfd56fab (the commit before this one), which makes the
plugin host start without waiting on models.dev and read the catalog again
once it is written.
What this changes on top of it:
- host.js mdev(): catalog.Sync writes models.json in place, so a host
listing providers during a refresh could read it half written. That
read replaced the catalog it had with {}, and the Go side kept that
list until its next refresh. A read that fails now keeps what was read
before (a failed read means unknown) and is tried again next time.
TestHostKeepsTheCatalogThroughAHalfWrite: red with bfd56fab's mdev()
("a catalog read half written dropped the catalog read before"), green
with this.
- TestHostStartDoesNotWaitOnHangingModelsDev bounded a real bun host start
by 3s, which a loaded runner can exceed. It now allows 15s within a 25s
context: the old blocking start still fails it (the hanging sync holds
the start until the context ends).
What was run at this head (Go 1.26.8, worktree of origin/main
|
||
|
|
78e337a20e |
plugin: sync models.dev in background and reload in host when available (#1928)
What: - In internal/catalog, serialize Sync using a buffered channel (syncCh) so lock acquisition honours ctx.Done(), and add SyncIfMissing to avoid redundant downloads if a catalog appears while waiting for the lock. - In internal/plugin/host.go, run catalog.SyncIfMissing in the background when starting without a cache, tracked by a WaitGroup and cancellable context so startOn never blocks on models.dev network I/O. - Always pass catalog.CachePath() to host.js via modelsDevPath when Source() is empty. - In internal/plugin/host.js, reload models.json in mdev() when the file appears or its modification time (mtimeMs) changes. - In internal/plugin/providers.go, cancel and wait for in-flight background syncs in Settle() to guarantee clean test teardown. - In internal/plugin/modelsdev_wait_test.go, install dial hook with sync.Once and an atomic stop channel to eliminate races and goroutine leaks, and add TestHostBackgroundSyncForgetsProviders to verify Cached() reloads upon background sync completion. - In internal/catalog/sync_ctx_test.go, add TestSyncIfMissingSkipsFetchWhenCacheAppearsWhileLocked. Why: - In #1928, startOn blocked up to 30s when models.dev hung. - Making Sync non-blocking during startup while allowing host.js to hot-reload once background sync completes gives fast startup on offline/slow networks without sacrificing catalog data. - Context-aware lock acquisition prevents calls from stalling behind an active sync when their deadline expires. What was run: - go test -count=1 -tags nogui -v ./internal/catalog/... (PASS) - go test -count=5 -tags nogui -v ./internal/catalog/ -run "TestSync.*" (PASS) - go test -count=5 -tags nogui -v ./internal/plugin/ -run "TestHostStartDoesNotWaitOnHangingModelsDev|TestHostReloadsCatalogWhenFileAppears|TestHostBackgroundSyncForgetsProviders" (PASS) - go vet -tags nogui on windows, linux and darwin (clean) - gofmt -l (clean) |