fix(host): roll back the surviving deferral when flow-registration setup fails halfway

A declared-but-occupied second hole registers synchronously, so the pair
construction can throw after the first deferral installed its subscription;
that orphan then fires against the failed fiber's inactive context. The
effect now disposes already-created deferrals before rethrowing
(ds-review-bot on the browse twin; same shape here).
This commit is contained in:
creatixchu
2026-07-29 01:29:08 +08:00
parent 6a78bf4dd0
commit b6762d20a2
2 changed files with 38 additions and 6 deletions
@@ -62,12 +62,19 @@ export const inject = ['slots', 'workspaces']
export function apply(ctx: ClientContext): void {
const injected = (): NativeFlowInjected => ({ pick: () => ctx.workspaces.pickDirectory() })
ctx.effect(() => {
const deferred = [
deferRegistration(ctx.slots, 'conversation.hero.workspace.directoryFlow', NativeDirectoryFlow, () =>
ctx.slots.register({ name: 'conversation.hero.workspace.directoryFlow', inject: injected }, NativeDirectoryFlow)),
deferRegistration(ctx.slots, 'sidebar.workspaces.directoryFlow', NativeDirectoryFlow, () =>
ctx.slots.register({ name: 'sidebar.workspaces.directoryFlow', inject: injected }, NativeDirectoryFlow)),
]
// Constructing the pair can throw halfway (a declared hole already
// occupied registers synchronously): roll the earlier deferral back so
// no live subscription outlives the failed fiber.
const deferred: ReturnType<typeof deferRegistration>[] = []
try {
deferred.push(deferRegistration(ctx.slots, 'conversation.hero.workspace.directoryFlow', NativeDirectoryFlow, () =>
ctx.slots.register({ name: 'conversation.hero.workspace.directoryFlow', inject: injected }, NativeDirectoryFlow)))
deferred.push(deferRegistration(ctx.slots, 'sidebar.workspaces.directoryFlow', NativeDirectoryFlow, () =>
ctx.slots.register({ name: 'sidebar.workspaces.directoryFlow', inject: injected }, NativeDirectoryFlow)))
} catch (error) {
for (const entry of deferred) entry.dispose()
throw error
}
return () => { for (const entry of deferred) entry.dispose() }
}, 'directory-picker-native: flow registrations')
}