Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-app): keep running effects when onTransition throws (R1-L3)

Diego Zacarias214d68960cb7
diff --git a/desktop-app/ui/src/lib/__tests__/embedOwnershipMachine.test.ts b/desktop-app/ui/src/lib/__tests__/embedOwnershipMachine.test.ts
index 0a6a4b973..b2433b5a3 100644
--- a/desktop-app/ui/src/lib/__tests__/embedOwnershipMachine.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/embedOwnershipMachine.test.ts
@@ -363,6 +363,38 @@ describe('embed ownership machine — tab store writes', () => {
})
})
+describe('embed ownership machine — transition observer', () => {
+ it('still opens, notifies and settles a launch when onTransition throws', async () => {
+ const h = harness({
+ onTransition: () => {
+ throw new Error('observer broke')
+ },
+ })
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {})
+ const listener = vi.fn()
+ h.machine.subscribe(listener)
+ // A caller that survives the throw must still see the launch go through.
+ const survive = (dispatch: () => void) => {
+ try {
+ dispatch()
+ } catch {
+ // asserted through the observable outcome below
+ }
+ }
+ h.machine.registerMeasurer(measured)
+ survive(() => h.machine.projected(TAB_A))
+ const settled = h.machine.registerWhenSettled('l-1')
+ survive(() => h.machine.intent(launch('l-1')))
+ await flush()
+
+ expect(h.bridge.open).toHaveBeenCalledWith(expect.objectContaining({ launchId: 'l-1' }))
+ expect(listener).toHaveBeenCalled()
+ h.opens.get('l-1')!.resolve()
+ await expect(settled).resolves.toBe('mounted')
+ error.mockRestore()
+ })
+})
+
describe('embed ownership machine — notifications', () => {
it("reports only the owner's refresh failures", async () => {
const onOwnerRefreshError = vi.fn()
diff --git a/desktop-app/ui/src/lib/embedOwnershipMachine.ts b/desktop-app/ui/src/lib/embedOwnershipMachine.ts
index 3349e25bc..4cd3d665d 100644
--- a/desktop-app/ui/src/lib/embedOwnershipMachine.ts
+++ b/desktop-app/ui/src/lib/embedOwnershipMachine.ts
@@ -58,12 +58,17 @@ export function createEmbedOwnershipMachine(
const previous = state
const transition = reduceEmbedOwnership(previous, next)
state = transition.state
- deps.onTransition?.({
- event: next,
- previous,
- next: transition.state,
- effects: transition.effects,
- })
+ // An observer failing must not keep this transition's effects from running.
+ try {
+ deps.onTransition?.({
+ event: next,
+ previous,
+ next: transition.state,
+ effects: transition.effects,
+ })
+ } catch (error) {
+ console.error('[embedOwnership] onTransition failed:', next.type, error)
+ }
for (const effect of transition.effects) runEffect(effect)
}
} finally {