fix(coding): preserve runtime model and failure contracts

This commit is contained in:
2026-08-23 21:21:02 +08:00
parent 52b2467d5d
commit 195979d30f
11 changed files with 427 additions and 112 deletions

View File

@@ -339,11 +339,24 @@ export class CodingConversationService {
}
async setModel(conversationId: string, model: ProductModelRef): Promise<ConversationModelState> {
const { project } = await this.projects.findActiveConversation(conversationId);
const { project, conversation } = await this.projects.findActiveConversation(conversationId);
let selected: ProductModelRef;
try {
selected = await this.runtime.validateModel(model);
} catch (error) { runtimeError(error); }
if (conversation.modelResolution === 'resolved' && conversation.model) {
await this.ensurePrepared(conversationId);
let state: ConversationModelState;
try {
state = await this.runtime.setModel({
conversationId,
accountId: selected.accountId,
modelId: selected.modelId,
});
} catch (error) { runtimeError(error); }
await persist(() => this.projects.conversationStore(project.path).setModelState(conversationId, state));
return state;
}
const state: ConversationModelState = {
model: selected,
modelResolution: 'resolved',
@@ -364,7 +377,7 @@ export class CodingConversationService {
const { project } = await this.projects.findActiveConversation(conversationId);
try {
const state = await this.runtime.setThinking({ conversationId, thinkingLevel });
await this.projects.conversationStore(project.path).setModelState(conversationId, state);
await persist(() => this.projects.conversationStore(project.path).setModelState(conversationId, state));
return state;
} catch (error) { runtimeError(error); }
}