Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: abort the in-flight hosted turn before the loom read in switchHostedEpisode

[._.]/ Adam Eivyda406828e643
diff --git a/server/services/fableLoom/hostedSession.js b/server/services/fableLoom/hostedSession.js
index 847cf7c94c..4cb2389e2a 100644
--- a/server/services/fableLoom/hostedSession.js
+++ b/server/services/fableLoom/hostedSession.js
@@ -441,17 +441,20 @@ export async function switchHostedEpisode(sessionId, episodeId, { io } = {}) {
throw new ServerError('Hosted session not found or ended', { status: 404, code: 'SESSION_NOT_FOUND' });
}
+ // Abort BEFORE the first await: a turn already in flight against the OLD
+ // episode must not be able to resolve and commit narration/a transition
+ // while this function is off awaiting the loom read below.
+ if (session.activeTurn?.abortController) {
+ session.activeTurn.abortController.abort('episode_switch');
+ session.activeTurn = null;
+ }
+
const loom = await getLoom(session.loomId);
if (!loom) {
throw new ServerError('Loom not found', { status: 404, code: 'NOT_FOUND' });
}
const episode = findEpisode(loom, episodeId);
- if (session.activeTurn?.abortController) {
- session.activeTurn.abortController.abort('episode_switch');
- session.activeTurn = null;
- }
-
const preflight = await checkHostedSessionReadiness({ loomId: session.loomId, episodeId, loom, episode });
const startNode = preflight.ready
? episode.nodes?.find((n) => n.id === episode.startNodeId) || null