fix: codex session selection

This commit is contained in:
weishu
2025-12-27 22:24:18 +08:00
parent 7c1baa28ee
commit 007721bdc8
3 changed files with 185 additions and 77 deletions
+19 -4
View File
@@ -7,10 +7,26 @@ import { convertCodexEvent } from './utils/codexEventConverter';
import { getLocalLaunchExitReason } from '@/agent/localLaunchPolicy';
export async function codexLocalLauncher(session: CodexSession): Promise<'switch' | 'exit'> {
let exitReason: 'switch' | 'exit' | null = null;
const processAbortController = new AbortController();
const exitFuture = new Future<void>();
const handleSessionMatchFailed = (message: string) => {
logger.warn(`[codex-local]: ${message}`);
session.sendSessionEvent({ type: 'message', message });
if (!exitReason) {
exitReason = 'exit';
}
if (!processAbortController.signal.aborted) {
processAbortController.abort();
}
};
const scanner = await createCodexSessionScanner({
sessionId: session.sessionId,
cwd: session.path,
startupTimestampMs: Date.now(),
onSessionMatchFailed: handleSessionMatchFailed,
onSessionFound: (sessionId) => {
session.onSessionFound(sessionId);
},
@@ -29,10 +45,6 @@ export async function codexLocalLauncher(session: CodexSession): Promise<'switch
}
});
let exitReason: 'switch' | 'exit' | null = null;
const processAbortController = new AbortController();
const exitFuture = new Future<void>();
try {
async function abortProcess() {
if (!processAbortController.signal.aborted) {
@@ -64,6 +76,9 @@ export async function codexLocalLauncher(session: CodexSession): Promise<'switch
void doSwitch();
});
if (exitReason) {
return exitReason;
}
if (session.queue.size() > 0) {
return 'switch';
}