Skip to content

Commit f91fa30

Browse files
committed
🤖 fix: surface pre-stream errors and persist model on workspace creation
Two issues fixed: 1. Pre-stream error surfacing: - When sendMessage fails before streaming starts (e.g., API key not configured), the error was silently ignored - Modified StreamingMessageAggregator.handleStreamError to create a synthetic error message when no active stream exists - Added logging in workspaceService.completeWorkspaceCreation 2. Model persistence on workspace creation: - Model selected for creation was persisted at project scope but not synced to workspace scope - On restart, getSendOptionsFromStorage would fall back to default model - Added model sync in syncCreationPreferences alongside mode/thinking _Generated with mux_
1 parent 2b16543 commit f91fa30

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/browser/components/ChatInput/useCreationWorkspace.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { readPersistedState, updatePersistedState } from "@/browser/hooks/usePer
99
import { useSendMessageOptions } from "@/browser/hooks/useSendMessageOptions";
1010
import {
1111
getInputKey,
12+
getModelKey,
1213
getModeKey,
1314
getPendingScopeId,
1415
getProjectScopeId,
@@ -27,6 +28,13 @@ interface UseCreationWorkspaceOptions {
2728
function syncCreationPreferences(projectPath: string, workspaceId: string): void {
2829
const projectScopeId = getProjectScopeId(projectPath);
2930

31+
// Sync model from project scope to workspace scope
32+
// This ensures the model used for creation is persisted for future resumes
33+
const projectModel = readPersistedState<string | null>(getModelKey(projectScopeId), null);
34+
if (projectModel) {
35+
updatePersistedState(getModelKey(workspaceId), projectModel);
36+
}
37+
3038
const projectMode = readPersistedState<UIMode | null>(getModeKey(projectScopeId), null);
3139
if (projectMode) {
3240
updatePersistedState(getModeKey(workspaceId), projectMode);

src/browser/utils/messages/StreamingMessageAggregator.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,28 @@ export class StreamingMessageAggregator {
564564
// Clean up stream-scoped state (active stream tracking, TODOs)
565565
this.cleanupStreamState(data.messageId);
566566
this.invalidateCache();
567+
} else {
568+
// Pre-stream error (e.g., API key not configured before streaming starts)
569+
// Create a synthetic error message since there's no active stream to attach to
570+
// Get the highest historySequence from existing messages so this appears at the end
571+
const maxSequence = Math.max(
572+
0,
573+
...Array.from(this.messages.values()).map((m) => m.metadata?.historySequence ?? 0)
574+
);
575+
const errorMessage: MuxMessage = {
576+
id: data.messageId,
577+
role: "assistant",
578+
parts: [],
579+
metadata: {
580+
partial: true,
581+
error: data.error,
582+
errorType: data.errorType,
583+
timestamp: Date.now(),
584+
historySequence: maxSequence + 1,
585+
},
586+
};
587+
this.messages.set(data.messageId, errorMessage);
588+
this.invalidateCache();
567589
}
568590
}
569591

src/node/services/workspaceService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ export class WorkspaceService extends EventEmitter {
610610
// Send the first message, surfacing errors to the chat UI
611611
void session.sendMessage(message, options).then((result) => {
612612
if (!result.success) {
613+
log.error("sendMessage failed during workspace creation", {
614+
workspaceId,
615+
errorType: result.error.type,
616+
error: result.error,
617+
});
613618
const { message: errorMessage, errorType } = formatSendMessageError(result.error);
614619
const streamError: StreamErrorMessage = {
615620
type: "stream-error",

0 commit comments

Comments
 (0)