Skip to content

Commit 2b755fe

Browse files
authored
feat: clean up session reloadin (#1481)
simplify agent reconnection ## Problem The agent service had separate code paths for handling session reconnection between Codex and Claude adapters, leading to code duplication and inconsistent handling. ## Changes - Consolidated the reconnection logic for both Codex and Claude adapters into a single code path - Moved PostHog JSONL hydration to be Claude-specific (non-Codex adapters) while keeping it within the unified flow - Both adapters now use `unstable_resumeSession` method, with Claude delegating to SDK's resumeSession and Codex delegating to codex-acp's loadSession internally - Added clarifying comments explaining the different internal implementations for each adapter
1 parent de21189 commit 2b755fe

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

apps/code/src/main/services/agent/service.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -692,36 +692,34 @@ When creating pull requests, add the following footer at the end of the PR descr
692692
let configOptions: SessionConfigOption[] | undefined;
693693
let agentSessionId: string;
694694

695-
if (isReconnect && adapter === "codex" && config.sessionId) {
696-
const existingSessionId = config.sessionId;
697-
const loadResponse = await connection.loadSession({
698-
sessionId: existingSessionId,
699-
cwd: repoPath,
700-
mcpServers,
701-
});
702-
configOptions = loadResponse.configOptions ?? undefined;
703-
agentSessionId = existingSessionId;
704-
} else if (isReconnect && adapter === "claude" && config.sessionId) {
695+
if (isReconnect && config.sessionId) {
705696
const existingSessionId = config.sessionId;
706697

707-
const posthogAPI = agent.getPosthogAPI();
708-
if (posthogAPI) {
709-
await hydrateSessionJsonl({
710-
sessionId: existingSessionId,
711-
cwd: repoPath,
712-
taskId,
713-
runId: taskRunId,
714-
permissionMode: config.permissionMode,
715-
posthogAPI,
716-
log,
717-
});
698+
// Claude-specific: hydrate session JSONL from PostHog before resuming
699+
if (adapter !== "codex") {
700+
const posthogAPI = agent.getPosthogAPI();
701+
if (posthogAPI) {
702+
await hydrateSessionJsonl({
703+
sessionId: existingSessionId,
704+
cwd: repoPath,
705+
taskId,
706+
runId: taskRunId,
707+
permissionMode: config.permissionMode,
708+
posthogAPI,
709+
log,
710+
});
711+
}
718712
}
719713

720714
const systemPrompt = this.buildSystemPrompt(
721715
credentials,
722716
taskId,
723717
customInstructions,
724718
);
719+
720+
// Both adapters implement unstable_resumeSession:
721+
// - Claude: delegates to SDK's resumeSession with JSONL hydration
722+
// - Codex: delegates to codex-acp's loadSession internally
725723
const resumeResponse = await connection.unstable_resumeSession({
726724
sessionId: existingSessionId,
727725
cwd: repoPath,

0 commit comments

Comments
 (0)