Skip to content

Commit 1ebc92f

Browse files
authored
refactor(config): use cachedInvalidateWithTTL, bump effect to beta.37 (#19322)
1 parent 9f94bdb commit 1ebc92f

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

bun.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"packages/slack"
2626
],
2727
"catalog": {
28-
"@effect/platform-node": "4.0.0-beta.35",
28+
"@effect/platform-node": "4.0.0-beta.37",
2929
"@types/bun": "1.3.11",
3030
"@octokit/rest": "22.0.0",
3131
"@hono/zod-validator": "0.4.2",
@@ -45,7 +45,7 @@
4545
"dompurify": "3.3.1",
4646
"drizzle-kit": "1.0.0-beta.19-d95b7a4",
4747
"drizzle-orm": "1.0.0-beta.19-d95b7a4",
48-
"effect": "4.0.0-beta.35",
48+
"effect": "4.0.0-beta.37",
4949
"ai": "5.0.124",
5050
"hono": "4.10.7",
5151
"hono-openapi": "1.1.2",

packages/opencode/src/config/config.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { Lock } from "@/util/lock"
4040
import { AppFileSystem } from "@/filesystem"
4141
import { InstanceState } from "@/effect/instance-state"
4242
import { makeRuntime } from "@/effect/run-service"
43-
import { Effect, Layer, ServiceMap } from "effect"
43+
import { Duration, Effect, Layer, ServiceMap } from "effect"
4444

4545
export namespace Config {
4646
const ModelId = z.string().meta({ $ref: "https://models.dev/model-schema.json#/$defs/Model" })
@@ -1241,7 +1241,15 @@ export namespace Config {
12411241
return result
12421242
})
12431243

1244-
let cachedGlobal = yield* Effect.cached(loadGlobal().pipe(Effect.orElseSucceed(() => ({}) as Info)))
1244+
const [cachedGlobal, invalidateGlobal] = yield* Effect.cachedInvalidateWithTTL(
1245+
loadGlobal().pipe(
1246+
Effect.tapError((error) =>
1247+
Effect.sync(() => log.error("failed to load global config, using defaults", { error: String(error) })),
1248+
),
1249+
Effect.orElseSucceed((): Info => ({})),
1250+
),
1251+
Duration.infinity,
1252+
)
12451253

12461254
const getGlobal = Effect.fn("Config.getGlobal")(function* () {
12471255
return yield* cachedGlobal
@@ -1446,7 +1454,7 @@ export namespace Config {
14461454
})
14471455

14481456
const invalidate = Effect.fn("Config.invalidate")(function* (wait?: boolean) {
1449-
cachedGlobal = yield* Effect.cached(loadGlobal().pipe(Effect.orElseSucceed(() => ({}) as Info)))
1457+
yield* invalidateGlobal
14501458
const task = Instance.disposeAll()
14511459
.catch(() => undefined)
14521460
.finally(() =>

0 commit comments

Comments
 (0)