Skip to content

Commit 5f29f86

Browse files
committed
Throw on new session init failure instead of swallowing
1 parent 677580a commit 5f29f86

3 files changed

Lines changed: 30 additions & 31 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
641641
sessionId: existingSessionId,
642642
systemPrompt,
643643
...(permissionMode && { permissionMode }),
644-
...(model && { model }),
644+
...(model != null && { model }),
645645
claudeCode: {
646646
options: {
647647
...(additionalDirectories?.length && {
@@ -673,7 +673,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
673673
taskRunId,
674674
systemPrompt,
675675
...(permissionMode && { permissionMode }),
676-
...(model && { model }),
676+
...(model != null && { model }),
677677
claudeCode: {
678678
options: {
679679
...(additionalDirectories?.length && { additionalDirectories }),

apps/code/src/renderer/features/sessions/service/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ export class SessionService {
549549
effort: effortLevelSchema.safeParse(reasoningLevel).success
550550
? (reasoningLevel as EffortLevel)
551551
: undefined,
552-
model: preferredModel || undefined,
552+
model: preferredModel,
553553
});
554554

555555
const session = this.createBaseSession(taskRun.id, taskId, taskTitle);

packages/agent/src/adapters/claude/claude-agent.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -910,38 +910,16 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
910910
}
911911
}
912912

913-
// Fetch model config in parallel with SDK initialization for new sessions.
914-
// The gateway REST call doesn't depend on the SDK being ready.
913+
// Kick off SDK initialization for new sessions so it runs concurrently
914+
// with the model config fetch below (the gateway REST call is independent).
915+
const initPromise = !isResume
916+
? withTimeout(q.initializationResult(), SESSION_VALIDATION_TIMEOUT_MS)
917+
: undefined;
918+
915919
const [modelOptions] = await Promise.all([
916920
this.getModelConfigOptions(
917921
settingsManager.getSettings().model || meta?.model || undefined,
918922
),
919-
// For new sessions, await initialization concurrently with model fetch.
920-
// SDK starts in the background via query() — we just need it ready
921-
// before the first prompt, not before returning configOptions.
922-
...(!isResume
923-
? [
924-
withTimeout(q.initializationResult(), SESSION_VALIDATION_TIMEOUT_MS)
925-
.then((result) => {
926-
if (result.result === "timeout") {
927-
this.logger.error("Session initialization timed out", {
928-
sessionId,
929-
taskId,
930-
taskRunId: meta?.taskRunId,
931-
});
932-
}
933-
})
934-
.catch((err) => {
935-
this.logger.error("Session initialization failed", {
936-
sessionId,
937-
taskId,
938-
taskRunId: meta?.taskRunId,
939-
error: err instanceof Error ? err.message : String(err),
940-
});
941-
}),
942-
]
943-
: []),
944-
// Fire notification in parallel too
945923
...(meta?.taskRunId
946924
? [
947925
this.client.extNotification("_posthog/sdk_session", {
@@ -953,6 +931,27 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
953931
: []),
954932
]);
955933

934+
if (initPromise) {
935+
try {
936+
const initResult = await initPromise;
937+
if (initResult.result === "timeout") {
938+
settingsManager.dispose();
939+
throw new Error(
940+
`Session initialization timed out for sessionId=${sessionId}`,
941+
);
942+
}
943+
} catch (err) {
944+
settingsManager.dispose();
945+
this.logger.error("Session initialization failed", {
946+
sessionId,
947+
taskId,
948+
taskRunId: meta?.taskRunId,
949+
error: err instanceof Error ? err.message : String(err),
950+
});
951+
throw err;
952+
}
953+
}
954+
956955
const settingsModel = settingsManager.getSettings().model;
957956
const metaModel = meta?.model;
958957
const resolvedModelId =

0 commit comments

Comments
 (0)