Skip to content

Commit 4ee49cf

Browse files
committed
fix(effect): propagate InstanceRef into ScopedCache lookups in InstanceState.get
When InstanceState.make runs during app initialization, InstanceRef is not yet in scope. ScopedCache captures the Effect context at construction time, so all subsequent lookups via ScopedCache.get use stale context without InstanceRef. This caused downstream issues like project-level skills (.opencode/skills/) being unavailable in REST API sessions, because Skill.state uses InstanceState (backed by ScopedCache) and the lookup fell back to Instance.current (Node ALS), which is empty after the REST middleware returns. Fix: eagerly resolve InstanceRef from the calling fiber's context (where it IS available) and explicitly pipe Effect.provideService(InstanceRef, ctx) onto the ScopedCache.get call, overriding the stale captured context. Upstream issue: anomalyco/opencode#25686 Closes #419
1 parent 8e29f84 commit 4ee49cf

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎packages/teamcode/src/effect/instance-state.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export const make = <A, E = never, R = never>(
5151

5252
export const get = <A, E, R>(self: InstanceState<A, E, R>) =>
5353
Effect.gen(function* () {
54-
return yield* ScopedCache.get(self.cache, yield* directory)
54+
const ctx = yield* context
55+
return yield* ScopedCache.get(self.cache, ctx.directory).pipe(
56+
Effect.provideService(InstanceRef, ctx),
57+
)
5558
})
5659

5760
export const use = <A, E, R, B>(self: InstanceState<A, E, R>, select: (value: A) => B) => Effect.map(get(self), select)

0 commit comments

Comments
 (0)