fix(FN-000): harden terminal session startup
This commit is contained in:
5
.changeset/fix-setup-browse-and-terminal.md
Normal file
5
.changeset/fix-setup-browse-and-terminal.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@runfusion/fusion": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix the setup wizard directory browser and make terminal session startup more resilient.
|
||||||
@@ -493,11 +493,48 @@ export class TerminalService extends EventEmitter {
|
|||||||
(ptyOptions as IWindowsPtyForkOptions).useConpty = false;
|
(ptyOptions as IWindowsPtyForkOptions).useConpty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ptyProcess: IPty;
|
const attemptedSpawns = new Set<string>();
|
||||||
try {
|
const spawnAttempts: Array<{ shell: string; args: string[]; reason: string }> = [];
|
||||||
ptyProcess = pty.spawn(shell, shellArgs, ptyOptions);
|
const addSpawnAttempt = (shellPath: string, args: string[], reason: string): void => {
|
||||||
} catch (spawnError) {
|
const key = `${shellPath}\0${args.join("\0")}`;
|
||||||
console.error(`[createSession] PTY spawn failed:`, spawnError);
|
if (attemptedSpawns.has(key)) return;
|
||||||
|
attemptedSpawns.add(key);
|
||||||
|
spawnAttempts.push({ shell: shellPath, args, reason });
|
||||||
|
};
|
||||||
|
|
||||||
|
addSpawnAttempt(shell, shellArgs, "primary");
|
||||||
|
|
||||||
|
if (shellArgs.length > 0) {
|
||||||
|
addSpawnAttempt(shell, [], "retry-without-login");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const allowedShell of this.getAllowedShells()) {
|
||||||
|
if (allowedShell === shell || !existsSync(allowedShell)) continue;
|
||||||
|
const shellName = path.basename(allowedShell).toLowerCase().replace(".exe", "");
|
||||||
|
const fallbackArgs = shellName === "bash" || shellName === "zsh" ? [] : [];
|
||||||
|
addSpawnAttempt(allowedShell, fallbackArgs, "allowed-fallback");
|
||||||
|
}
|
||||||
|
|
||||||
|
let ptyProcess: IPty | undefined;
|
||||||
|
let lastSpawnError: unknown;
|
||||||
|
for (const attempt of spawnAttempts) {
|
||||||
|
try {
|
||||||
|
console.info(
|
||||||
|
`[createSession] Spawning terminal via ${attempt.reason}: ${attempt.shell} ${attempt.args.join(" ")} in ${cwd}`,
|
||||||
|
);
|
||||||
|
ptyProcess = pty.spawn(attempt.shell, attempt.args, ptyOptions);
|
||||||
|
break;
|
||||||
|
} catch (spawnError) {
|
||||||
|
lastSpawnError = spawnError;
|
||||||
|
console.error(
|
||||||
|
`[createSession] PTY spawn failed (${attempt.reason}) for ${attempt.shell} ${attempt.args.join(" ")}:`,
|
||||||
|
spawnError,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ptyProcess) {
|
||||||
|
console.error(`[createSession] All PTY spawn attempts failed`, lastSpawnError);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
code: "pty_spawn_failed",
|
code: "pty_spawn_failed",
|
||||||
|
|||||||
Reference in New Issue
Block a user