fix(opencode): preserve effect logging during cleanup

This commit is contained in:
opencode-agent[bot] 2026-06-05 15:12:26 +00:00
parent 45f257da73
commit b1927969e8
2 changed files with 36 additions and 13 deletions

View file

@ -125,9 +125,7 @@ export const layer = Layer.effect(
const ps = yield* getOrCreate(s, def)
const subscription = yield* PubSub.subscribe(ps)
yield* Effect.addFinalizer(() =>
Effect.sync(() =>
Effect.logInfo("unsubscribing").pipe(Effect.annotateLogs({ service: "bus", ...{ type: def.type } })),
),
Effect.logInfo("unsubscribing").pipe(Effect.annotateLogs({ service: "bus", ...{ type: def.type } })),
)
return Stream.fromSubscription(subscription)
})
@ -138,9 +136,7 @@ export const layer = Layer.effect(
const s = yield* InstanceState.get(state)
const subscription = yield* PubSub.subscribe(s.wildcard)
yield* Effect.addFinalizer(() =>
Effect.sync(() =>
Effect.logInfo("unsubscribing").pipe(Effect.annotateLogs({ service: "bus", ...{ type: "*" } })),
),
Effect.logInfo("unsubscribing").pipe(Effect.annotateLogs({ service: "bus", ...{ type: "*" } })),
)
return Stream.fromSubscription(subscription)
})
@ -157,15 +153,25 @@ export const layer = Layer.effect(
Stream.runForEach((msg) =>
Effect.tryPromise({
try: () => Promise.resolve().then(() => callback(msg)),
catch: (cause) => {},
}).pipe(Effect.ignore),
catch: (cause) => cause,
}).pipe(
Effect.tapError((cause) =>
Effect.logError("subscriber failed").pipe(Effect.annotateLogs({ service: "bus", ...{ type, cause } })),
),
Effect.ignore,
),
),
Effect.forkScoped,
),
)
return () => {
bridge.fork(Scope.close(scope, Exit.void))
bridge.fork(
Effect.logInfo("unsubscribing").pipe(
Effect.annotateLogs({ service: "bus", ...{ type } }),
Effect.andThen(Scope.close(scope, Exit.void)),
),
)
}
})
}

View file

@ -153,8 +153,15 @@ export const layer = Layer.effect(
)
const init = yield* Effect.tryPromise({
try: () => plugin(input),
catch: (err) => {},
}).pipe(Effect.option)
catch: (error) => error,
}).pipe(
Effect.tapError((error) =>
Effect.logError("failed to load internal plugin").pipe(
Effect.annotateLogs({ service: "plugin", ...{ name: plugin.name, error } }),
),
),
Effect.option,
)
if (init._tag === "Some") hooks.push(init.value)
}
@ -210,6 +217,11 @@ export const layer = Layer.effect(
return message
},
}).pipe(
Effect.tapError((error) =>
Effect.logError("failed to load plugin").pipe(
Effect.annotateLogs({ service: "plugin", ...{ path: load.spec, error } }),
),
),
Effect.catch(() => {
// TODO: make proper events for this
// bus.publish(Session.Event.Error, {
@ -226,8 +238,13 @@ export const layer = Layer.effect(
for (const hook of hooks) {
yield* Effect.tryPromise({
try: () => Promise.resolve((hook as any).config?.(cfg)),
catch: (err) => {},
}).pipe(Effect.ignore)
catch: (error) => error,
}).pipe(
Effect.tapError((error) =>
Effect.logError("plugin config hook failed").pipe(Effect.annotateLogs({ service: "plugin", ...{ error } })),
),
Effect.ignore,
)
}
// Subscribe to bus events, fiber interrupted when scope closes