diff --git a/cli/src/codex/codexLocalLauncher.ts b/cli/src/codex/codexLocalLauncher.ts index f1e30772..28e92563 100644 --- a/cli/src/codex/codexLocalLauncher.ts +++ b/cli/src/codex/codexLocalLauncher.ts @@ -11,6 +11,7 @@ export async function codexLocalLauncher(session: CodexSession): Promise<'switch let exitReason: 'switch' | 'exit' | null = null; const processAbortController = new AbortController(); const exitFuture = new Future(); + const resumeSessionId = session.sessionId; // Start hapi server for MCP bridge (same as remote mode) const { server: happyServer, mcpServers } = await buildHapiMcpBridge(session.client); @@ -28,7 +29,7 @@ export async function codexLocalLauncher(session: CodexSession): Promise<'switch }; const scanner = await createCodexSessionScanner({ - sessionId: session.sessionId, + sessionId: resumeSessionId, cwd: session.path, startupTimestampMs: Date.now(), onSessionMatchFailed: handleSessionMatchFailed, @@ -102,7 +103,7 @@ export async function codexLocalLauncher(session: CodexSession): Promise<'switch try { await codexLocal({ path: session.path, - sessionId: session.sessionId, + sessionId: resumeSessionId, onSessionFound: handleSessionFound, abort: processAbortController.signal, codexArgs: session.codexArgs, diff --git a/cli/src/codex/utils/codexSessionScanner.test.ts b/cli/src/codex/utils/codexSessionScanner.test.ts index 739bc658..f83342ec 100644 --- a/cli/src/codex/utils/codexSessionScanner.test.ts +++ b/cli/src/codex/utils/codexSessionScanner.test.ts @@ -75,7 +75,7 @@ describe('codexSessionScanner', () => { }); it('limits session scan to dates within the start window', async () => { - const referenceTimestampMs = Date.parse('2025-12-22T00:00:30.000Z'); + const referenceTimestampMs = Date.parse('2025-12-22T00:00:00.000Z'); const windowMs = 2 * 60 * 1000; const matchingSessionId = 'session-222'; const outsideSessionId = 'session-999'; @@ -85,7 +85,7 @@ describe('codexSessionScanner', () => { await mkdir(outsideDir, { recursive: true }); const baseLines = [ - JSON.stringify({ type: 'session_meta', payload: { id: matchingSessionId, cwd: '/data/github/happy/hapi', timestamp: '2025-12-22T00:00:00.000Z' } }), + JSON.stringify({ type: 'session_meta', payload: { id: matchingSessionId, cwd: '/data/github/happy/hapi', timestamp: '2025-12-22T00:00:30.000Z' } }), JSON.stringify({ type: 'event_msg', payload: { type: 'agent_message', message: 'hello' } }) ]; await writeFile(matchingFile, baseLines.join('\n') + '\n'); diff --git a/cli/src/codex/utils/codexSessionScanner.ts b/cli/src/codex/utils/codexSessionScanner.ts index 579c6792..e3c92b65 100644 --- a/cli/src/codex/utils/codexSessionScanner.ts +++ b/cli/src/codex/utils/codexSessionScanner.ts @@ -336,7 +336,11 @@ class CodexSessionScannerImpl extends BaseSessionScanner { return null; } - const diff = Math.abs(sessionTimestamp - this.referenceTimestampMs); + if (sessionTimestamp < this.referenceTimestampMs) { + return null; + } + + const diff = sessionTimestamp - this.referenceTimestampMs; if (diff > this.sessionStartWindowMs) { return null; }