Compare commits

..

5 Commits

Author SHA1 Message Date
Frank a6cee985e9 refactor(stats): fall through to partial sync 2026-08-09 14:39:14 +00:00
Frank 3d73360e06 refactor(stats): simplify full sync check 2026-08-09 14:15:15 +00:00
Frank 8e1dd8b757 refactor(stats): inline sync fallback 2026-08-09 14:09:05 +00:00
Jay 21acab0565 test(stats): remove sync fallback coverage 2026-08-09 14:01:21 +00:00
Jay 1090d72ea2 fix(stats): fall back after full sync failure 2026-08-09 13:59:59 +00:00
3 changed files with 14 additions and 29 deletions
+1 -7
View File
@@ -228,13 +228,7 @@ const layer = Layer.effect(
}),
)
return JSON.parse(text) as Record<string, Provider>
}).pipe(
Effect.withSpan("ModelsDev.populate"),
Effect.catch((error) =>
Effect.logError("Failed to fetch models.dev", { error }).pipe(Effect.as({} as Record<string, Provider>)),
),
Effect.orDie,
)
}).pipe(Effect.withSpan("ModelsDev.populate"), Effect.orDie)
const [cachedGet, invalidate] = yield* Effect.cachedInvalidateWithTTL(populate, Duration.infinity)
-19
View File
@@ -176,25 +176,6 @@ describe("ModelsDev Service", () => {
}),
)
it.live("get() returns an empty catalog when the initial fetch fails", () =>
Effect.gen(function* () {
const state = yield* Ref.make({ ...initialState, status: 503 })
const context = yield* Layer.build(buildLayer(state))
const result = yield* Effect.acquireUseRelease(
Effect.sync(() => {
Flag.OPENCODE_DISABLE_MODELS_FETCH = false
}),
() => ModelsDev.Service.use((s) => s.get()).pipe(Effect.provide(context)),
() =>
Effect.sync(() => {
Flag.OPENCODE_DISABLE_MODELS_FETCH = true
}),
)
expect(result).toEqual({})
expect((yield* Ref.get(state)).calls.length).toBe(3)
}),
)
it.live("get() is single-flight under concurrent calls", () =>
Effect.gen(function* () {
yield* writeCache(fixture)
+13 -3
View File
@@ -19,9 +19,19 @@ const daemon = Effect.gen(function* () {
let lastFullDay = ""
const pass = Effect.gen(function* () {
const today = new Date().toISOString().slice(0, 10)
const full = lastFullDay !== today
yield* syncStats({ full })
if (full) lastFullDay = today
if (lastFullDay !== today) {
const completed = yield* syncStats({ full: true }).pipe(
Effect.as(true),
Effect.catchCause((cause) =>
Effect.logWarning(`full stats sync failed; falling back to incremental sync ${Cause.pretty(cause)}`).pipe(
Effect.as(false),
),
),
)
lastFullDay = today
if (completed) return
}
yield* syncStats({ full: false })
}).pipe(
Effect.catchCause((cause) =>
Effect.logWarning(`stats sync failed ${JSON.stringify({ cause: Cause.pretty(cause) })}`),