Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"@ff-labs/fff-bun@0.10.5": "patches/@ff-labs%2Ffff-bun@0.10.5.patch",
"ghostty-web@github:anomalyco/ghostty-web#83c0a07": "patches/ghostty-web@0.3.0.patch",
"vite@8.2.2": "patches/vite@8.2.2.patch",
"@modelcontextprotocol/client@2.0.0": "patches/@modelcontextprotocol%2Fclient@2.0.0.patch"
"@modelcontextprotocol/client@2.0.0": "patches/@modelcontextprotocol%2Fclient@2.0.0.patch",
"effect@4.0.0-rc.112": "patches/effect@4.0.0-rc.112.patch"
}
}
46 changes: 46 additions & 0 deletions packages/core/test/location-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,52 @@ const itWithActivity = testEffect(
)

describe("LocationServiceMap", () => {
testEffect(Layer.empty).live("releases a reloaded graph after its last borrower without evicting its replacement", () =>
Effect.gen(function* () {
const builds = { started: 0 }
const finalized: number[] = []
const layer = AppNodeBuilder.build(LayerNode.group([Database.node, Bus.node, LocationServiceMap.node]), [
Global.node.replace(tempGlobalLayer),
offlineModels,
LocationWatcher.node.replace(
LocationWatcher.node.mapLayer((layer) =>
layer.pipe(
Layer.tap(() =>
Effect.gen(function* () {
const build = ++builds.started
yield* Effect.addFinalizer(() => Effect.sync(() => finalized.push(build)))
}),
),
),
),
),
])
yield* Effect.gen(function* () {
const dir = yield* tmpdirScoped()
const ref = Location.Ref.make({ directory: AbsolutePath.make(dir.path) })
const locations = yield* LocationServiceMap.Service
const first = yield* Scope.make()
const second = yield* Scope.make()
yield* Effect.addFinalizer(() => Scope.close(first, Exit.void))
yield* Effect.addFinalizer(() => Scope.close(second, Exit.void))
yield* locations.contextEffect(ref).pipe(Scope.provide(first))
yield* locations.contextEffect(ref).pipe(Scope.provide(second))
yield* LocationServiceMap.reload()
const replacement = yield* locations.contextEffect(ref)
expect(builds.started).toBe(2)
expect(finalized).toEqual([])
yield* Scope.close(first, Exit.void)
expect(finalized).toEqual([])
yield* Scope.close(second, Exit.void)
expect(finalized).toEqual([1])
expect(yield* locations.contextEffect(ref)).toBe(replacement)
expect(builds.started).toBe(2)
}).pipe(Effect.provide(layer))
expect(finalized).toEqual([1, 2])
}),
60000,
)

for (const failure of ["file", "permissions", "config reference"] as const) {
for (const invalidate of [false, true]) {
// The file-path fixture boots on Windows rather than failing during
Expand Down
42 changes: 42 additions & 0 deletions patches/effect@4.0.0-rc.112.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/dist/RcMap.js b/dist/RcMap.js
index 6e9a9ad04ec2c0fef0852cc0e6b3b1dba530a6f4..25941ed96695ef0272c2920fd6369848cdc03b0e 100644
--- a/dist/RcMap.js
+++ b/dist/RcMap.js
@@ -252,10 +252,12 @@ export const getOption = /*#__PURE__*/dual(2, (self, key) => Effect.uninterrupti
}));
const release = (self, key, entry) => Effect.withFiber(fiber => {
entry.refCount--;
+ const current = self.state._tag === "Open" ? MutableHashMap.get(self.state.map, key) : undefined;
+ const retained = current?._tag === "Some" && current.value === entry;
if (entry.refCount > 0) {
return Effect.void;
- } else if (self.state._tag === "Closed" || !MutableHashMap.has(self.state.map, key) || Duration.isZero(entry.idleTimeToLive)) {
- if (self.state._tag === "Open") {
+ } else if (self.state._tag === "Closed" || !retained || Duration.isZero(entry.idleTimeToLive)) {
+ if (self.state._tag === "Open" && retained) {
MutableHashMap.remove(self.state.map, key);
}
return Scope.close(entry.scope, Exit.void);
diff --git a/src/RcMap.ts b/src/RcMap.ts
index 67dcc147389a8fd0e8aae21b69ef58f44c295958..9c66319ddd58b0db3f84d7e5026210061e541013 100644
--- a/src/RcMap.ts
+++ b/src/RcMap.ts
@@ -736,14 +736,16 @@ export const getOption: {
const release = <K, A, E>(self: RcMap<K, A, E>, key: K, entry: State.Entry<A, E>) =>
Effect.withFiber((fiber) => {
entry.refCount--
+ const current = self.state._tag === "Open" ? MutableHashMap.get(self.state.map, key) : undefined
+ const retained = current?._tag === "Some" && current.value === entry
if (entry.refCount > 0) {
return Effect.void
} else if (
self.state._tag === "Closed"
- || !MutableHashMap.has(self.state.map, key)
+ || !retained
|| Duration.isZero(entry.idleTimeToLive)
) {
- if (self.state._tag === "Open") {
+ if (self.state._tag === "Open" && retained) {
MutableHashMap.remove(self.state.map, key)
}
return Scope.close(entry.scope, Exit.void)
Loading