Skip to content

Commit c9094be

Browse files
MarcoDotIOclaude
andcommitted
feat: failed commit and PR generation names the model and opens its setting
Text generation errors now carry the provider instance and model that ran, including a usage-limit fallback, and commit and pull request generation say which setting picked that model. The web failure toast gains a Settings button that opens that setting for the acting project and environment. Mobile shows the model name through the shared message. Refs #17995 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 935818e commit c9094be

9 files changed

Lines changed: 389 additions & 42 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type {
2828
GitActionProgressEvent,
2929
GitPreparePullRequestThreadInput,
3030
ModelSelection,
31+
ServerProvider,
3132
} from "@t3tools/contracts";
3233

3334
import {
@@ -597,6 +598,7 @@ function makeManager(input?: {
597598
sourceControlProvider?: SourceControlProvider["Service"];
598599
textGeneration?: Partial<FakeGitTextGeneration>;
599600
serverSettings?: Parameters<typeof ServerSettings.layerTest>[0];
601+
providers?: ReadonlyArray<ServerProvider>;
600602
setupScriptRunner?: ProjectSetupScriptRunner.ProjectSetupScriptRunner["Service"];
601603
gitConfigReads?: string[];
602604
gitCommands?: string[];
@@ -703,7 +705,7 @@ function makeManager(input?: {
703705
const layerManager = Layer.mergeAll(
704706
Layer.succeed(TextGeneration.TextGeneration, textGeneration),
705707
Layer.mock(ProviderRegistry.ProviderRegistry)({
706-
getProviders: Effect.succeed([]),
708+
getProviders: Effect.succeed(input?.providers ?? []),
707709
}),
708710
Layer.succeed(
709711
ProjectSetupScriptRunner.ProjectSetupScriptRunner,
@@ -742,6 +744,22 @@ const layerGitManagerTest = GitVcsDriver.layer.pipe(
742744
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
743745
);
744746

747+
const WRITER_INSTANCE_ID = ProviderInstanceId.make("claudeAgent");
748+
const WRITER = { instanceId: WRITER_INSTANCE_ID, model: "claude-sonnet-4-5" };
749+
const WRITER_SNAPSHOT: ServerProvider = {
750+
instanceId: WRITER_INSTANCE_ID,
751+
driver: ProviderDriverKind.make("claudeAgent"),
752+
enabled: true,
753+
installed: true,
754+
status: "ready",
755+
auth: { status: "authenticated" },
756+
version: null,
757+
checkedAt: "1970-01-01T00:00:00Z",
758+
models: [],
759+
slashCommands: [],
760+
skills: [],
761+
};
762+
745763
it.layer(layerGitManagerTest)("GitManager", (it) => {
746764
it.effect(
747765
"publishes local Git changes during a held PR lookup without caching its old branch",
@@ -2956,6 +2974,85 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
29562974
}),
29572975
);
29582976

2977+
it.effect.each([
2978+
{ name: "no writer", writer: null, providers: [], expected: "textGeneration" },
2979+
{
2980+
name: "an available writer",
2981+
writer: WRITER,
2982+
providers: [WRITER_SNAPSHOT],
2983+
expected: "sourceControlWriter",
2984+
},
2985+
{
2986+
name: "an unavailable writer",
2987+
writer: WRITER,
2988+
providers: [{ ...WRITER_SNAPSHOT, availability: "unavailable" }],
2989+
expected: "textGeneration",
2990+
},
2991+
] as const)(
2992+
"a failed commit message names the setting that picked its model with $name",
2993+
({ writer, providers, expected }) =>
2994+
Effect.gen(function* () {
2995+
const repoDir = yield* makeTempDir("t3code-git-manager-");
2996+
yield* initRepo(repoDir);
2997+
NodeFS.writeFileSync(NodePath.join(repoDir, "README.md"), "hello\nwriter\n");
2998+
const { manager } = yield* makeManager({
2999+
serverSettings: { sourceControlWriterModelSelection: writer },
3000+
providers,
3001+
textGeneration: {
3002+
generateCommitMessage: () =>
3003+
Effect.fail(
3004+
new TextGenerationError({
3005+
operation: "generateCommitMessage",
3006+
detail: "model rejected",
3007+
}),
3008+
),
3009+
},
3010+
});
3011+
3012+
const error = yield* runStackedAction(manager, { cwd: repoDir, action: "commit" }).pipe(
3013+
Effect.flip,
3014+
);
3015+
3016+
expect(error).toBeInstanceOf(TextGenerationError);
3017+
expect(error).toMatchObject({ modelSetting: expected });
3018+
}),
3019+
);
3020+
3021+
it.effect("failed pull request content names the writer setting that picked its model", () =>
3022+
Effect.gen(function* () {
3023+
const repoDir = yield* makeTempDir("t3code-git-manager-");
3024+
yield* initRepo(repoDir);
3025+
yield* runGit(repoDir, ["checkout", "-b", "feature/writer-failure"]);
3026+
const remoteDir = yield* createBareRemote();
3027+
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
3028+
NodeFS.writeFileSync(NodePath.join(repoDir, "writer.txt"), "writer\n");
3029+
yield* runGit(repoDir, ["add", "writer.txt"]);
3030+
yield* runGit(repoDir, ["commit", "-m", "Writer failure"]);
3031+
yield* runGit(repoDir, ["push", "-u", "origin", "feature/writer-failure"]);
3032+
const { manager, providerCalls } = yield* makeManager({
3033+
serverSettings: { sourceControlWriterModelSelection: WRITER },
3034+
providers: [WRITER_SNAPSHOT],
3035+
textGeneration: {
3036+
generatePrContent: () =>
3037+
Effect.fail(
3038+
new TextGenerationError({
3039+
operation: "generatePrContent",
3040+
detail: "model rejected",
3041+
}),
3042+
),
3043+
},
3044+
});
3045+
3046+
const error = yield* runStackedAction(manager, { cwd: repoDir, action: "create_pr" }).pipe(
3047+
Effect.flip,
3048+
);
3049+
3050+
expect(error).toBeInstanceOf(TextGenerationError);
3051+
expect(error).toMatchObject({ modelSetting: "sourceControlWriter" });
3052+
expect(created(providerCalls)).toHaveLength(0);
3053+
}),
3054+
);
3055+
29593056
it.effect("uses an explicit project's provider settings for generated commit text", () =>
29603057
Effect.gen(function* () {
29613058
const repoDir = yield* makeTempDir("t3code-git-manager-");

‎apps/server/src/git/GitManager.ts‎

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
type ProjectId,
3939
SourceControlProviderError,
4040
type SourceControlWritingStyleSettings,
41+
type TextGenerationModelSetting,
4142
type ThreadId,
4243
type ThreadPullRequestKey,
4344
type VcsCreateWorktreeInput,
@@ -64,7 +65,11 @@ import {
6465
} from "../sourceControl/threadPullRequests.ts";
6566
import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
6667

67-
import { GitManagerError, GitPullRequestMaterializationError } from "@t3tools/contracts";
68+
import {
69+
GitManagerError,
70+
GitPullRequestMaterializationError,
71+
TextGenerationError,
72+
} from "@t3tools/contracts";
6873
import {
6974
historicalMessage,
7075
renderHistory,
@@ -113,9 +118,20 @@ export type GitBranchPullRequest = NonNullable<VcsStatusResult["pr"]> & {
113118

114119
interface SourceControlTextGenerationSettings {
115120
readonly modelSelection: ModelSelection;
121+
readonly modelSetting: TextGenerationModelSetting;
116122
readonly style: SourceControlWritingStyleSettings;
117123
}
118124

125+
const withModelSetting = (error: TextGenerationError, modelSetting: TextGenerationModelSetting) =>
126+
new TextGenerationError({
127+
operation: error.operation,
128+
detail: error.detail,
129+
...(error.instanceId === undefined ? {} : { instanceId: error.instanceId }),
130+
...(error.model === undefined ? {} : { model: error.model }),
131+
modelSetting,
132+
...(error.cause === undefined ? {} : { cause: error.cause }),
133+
});
134+
119135
export class GitManager extends Context.Service<
120136
GitManager,
121137
{
@@ -2135,7 +2151,10 @@ export const make = Effect.gen(function* () {
21352151
...(policy ? { policy } : {}),
21362152
modelSelection: input.settings.modelSelection,
21372153
})
2138-
.pipe(Effect.map((result) => sanitizeCommitMessage(result)));
2154+
.pipe(
2155+
Effect.map((result) => sanitizeCommitMessage(result)),
2156+
Effect.mapError((error) => withModelSetting(error, input.settings.modelSetting)),
2157+
);
21392158

21402159
return {
21412160
subject: generated.subject,
@@ -2325,18 +2344,20 @@ export const make = Effect.gen(function* () {
23252344
: undefined;
23262345
const threadContext = yield* readThreadContext(threadId);
23272346

2328-
const generated = yield* textGeneration.generatePrContent({
2329-
cwd,
2330-
baseBranch,
2331-
headBranch: headContext.headBranch,
2332-
commitSummary: limitContext(rangeContext.commitSummary, 20_000),
2333-
diffSummary: limitContext(rangeContext.diffSummary, 20_000),
2334-
diffPatch: limitContext(rangeContext.diffPatch, 60_000),
2335-
...(changeRequestTemplate ? { changeRequestTemplate } : {}),
2336-
...(threadContext ? { threadContext } : {}),
2337-
...(policy ? { policy } : {}),
2338-
modelSelection: settings.modelSelection,
2339-
});
2347+
const generated = yield* textGeneration
2348+
.generatePrContent({
2349+
cwd,
2350+
baseBranch,
2351+
headBranch: headContext.headBranch,
2352+
commitSummary: limitContext(rangeContext.commitSummary, 20_000),
2353+
diffSummary: limitContext(rangeContext.diffSummary, 20_000),
2354+
diffPatch: limitContext(rangeContext.diffPatch, 60_000),
2355+
...(changeRequestTemplate ? { changeRequestTemplate } : {}),
2356+
...(threadContext ? { threadContext } : {}),
2357+
...(policy ? { policy } : {}),
2358+
modelSelection: settings.modelSelection,
2359+
})
2360+
.pipe(Effect.mapError((error) => withModelSetting(error, settings.modelSetting)));
23402361

23412362
const bodyFile = path.join(
23422363
tempDir,
@@ -3177,19 +3198,29 @@ export const make = Effect.gen(function* () {
31773198
const textGenerationSettings = yield* projectSettingsFor(input).pipe(
31783199
Effect.flatMap(({ settings, projectId }) =>
31793200
settings.sourceControlWriterModelSelection === null
3180-
? Effect.succeed({
3201+
? Effect.succeed<SourceControlTextGenerationSettings>({
31813202
modelSelection: settings.textGenerationModelSelection,
3203+
modelSetting: "textGeneration",
31823204
style: settings.sourceControlWritingStyle,
31833205
})
31843206
: providerRegistry.getProviders.pipe(
3185-
Effect.map((providers) => ({
3186-
modelSelection: ServerSettings.resolveSourceControlWriterModelSelection(
3207+
Effect.map((providers): SourceControlTextGenerationSettings => {
3208+
const modelSelection = ServerSettings.resolveSourceControlWriterModelSelection(
31873209
settings,
31883210
providers,
31893211
projectId,
3190-
),
3191-
style: settings.sourceControlWritingStyle,
3192-
})),
3212+
);
3213+
return {
3214+
modelSelection,
3215+
// The resolver returns the writer's own selection or falls back to the
3216+
// general one; a fallback is fixed in the general setting.
3217+
modelSetting:
3218+
modelSelection === settings.sourceControlWriterModelSelection
3219+
? "sourceControlWriter"
3220+
: "textGeneration",
3221+
style: settings.sourceControlWritingStyle,
3222+
};
3223+
}),
31933224
),
31943225
),
31953226
Effect.mapError(

‎apps/server/src/textGeneration/CodexTextGeneration.test.ts‎

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import * as Scope from "effect/Scope";
2222
import { createModelSelection } from "@t3tools/shared/model";
2323
import { expect } from "vite-plus/test";
2424

25-
import { CodexSettings, ProviderInstanceId } from "@t3tools/contracts";
25+
import { CodexSettings, ProviderInstanceId, TextGenerationError } from "@t3tools/contracts";
2626

2727
import * as ServerConfig from "../config.ts";
2828
import { makeProcessProbe, processProbeSource } from "../testUtils/processProbe.ts";
@@ -444,16 +444,13 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
444444
);
445445
});
446446

447-
it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhausted) =>
447+
const makePreflightTextGeneration = (
448+
exhausted: boolean,
449+
generateThreadTitle: TextGeneration.TextGeneration["Service"]["generateThreadTitle"],
450+
) =>
448451
Effect.gen(function* () {
449452
const primary = ProviderInstanceId.make("codex");
450453
const fallback = ProviderInstanceId.make("claude_work");
451-
const selection = {
452-
instanceId: primary,
453-
model: "chat-model",
454-
options: [{ id: "effort", value: "high" }],
455-
};
456-
const calls: ModelSelection[] = [];
457454
const instances: ProviderInstance[] = [primary, fallback].map((instanceId) => {
458455
const driver = ProviderDriverKind.make(instanceId === primary ? "codex" : "claudeAgent");
459456
const snapshot: ServerProvider = {
@@ -490,11 +487,7 @@ it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhaus
490487
generatePrContent: () => Effect.die("unused"),
491488
generateBranchName: () => Effect.die("unused"),
492489
generateReviewGuide: () => Effect.die("unused"),
493-
generateThreadTitle: (input) =>
494-
Effect.sync(() => {
495-
calls.push(input.modelSelection);
496-
return { title: "Generated title" };
497-
}),
490+
generateThreadTitle,
498491
}),
499492
};
500493
});
@@ -517,6 +510,23 @@ it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhaus
517510
),
518511
),
519512
);
513+
return { service, primary, fallback };
514+
});
515+
516+
it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhausted) =>
517+
Effect.gen(function* () {
518+
const selection = {
519+
instanceId: ProviderInstanceId.make("codex"),
520+
model: "chat-model",
521+
options: [{ id: "effort", value: "high" }],
522+
};
523+
const calls: ModelSelection[] = [];
524+
const { service, fallback } = yield* makePreflightTextGeneration(exhausted, (input) =>
525+
Effect.sync(() => {
526+
calls.push(input.modelSelection);
527+
return { title: "Generated title" };
528+
}),
529+
);
520530
expect(
521531
yield* service.generateThreadTitle({
522532
cwd: "/tmp",
@@ -536,3 +546,31 @@ it.effect.each([false, true])("text generation preflight: exhausted=%s", (exhaus
536546
]);
537547
}),
538548
);
549+
550+
it.effect.each([false, true])(
551+
"a text generation failure names the model that ran: exhausted=%s",
552+
(exhausted) =>
553+
Effect.gen(function* () {
554+
const { service, primary, fallback } = yield* makePreflightTextGeneration(exhausted, () =>
555+
Effect.fail(
556+
new TextGenerationError({ operation: "generateThreadTitle", detail: "model rejected" }),
557+
),
558+
);
559+
const error = yield* service
560+
.generateThreadTitle({
561+
cwd: "/tmp",
562+
message: "hello",
563+
linkedContext: "",
564+
modelSelection: { instanceId: primary, model: "chat-model" },
565+
})
566+
.pipe(Effect.flip);
567+
const fallbackModel =
568+
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")];
569+
570+
expect(error.message).toBe(
571+
exhausted
572+
? `Text generation failed in generateThreadTitle using ${fallbackModel} (${fallback}): model rejected`
573+
: `Text generation failed in generateThreadTitle using chat-model (${primary}): model rejected`,
574+
);
575+
}),
576+
);

‎apps/server/src/textGeneration/TextGeneration.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ export const make = Effect.gen(function* () {
124124
}
125125
return yield* resolveInstance(registry, operation, selection.instanceId).pipe(
126126
Effect.flatMap((service) => invoke(service, selection)),
127+
// Drivers report what went wrong, not which model ran; after a usage-limit fallback only
128+
// this layer knows.
129+
Effect.mapError(
130+
(error) =>
131+
new TextGenerationError({
132+
operation: error.operation,
133+
detail: error.detail,
134+
instanceId: selection.instanceId,
135+
model: selection.model,
136+
...(error.modelSetting === undefined ? {} : { modelSetting: error.modelSetting }),
137+
...(error.cause === undefined ? {} : { cause: error.cause }),
138+
}),
139+
),
127140
);
128141
});
129142
return TextGeneration.of({

0 commit comments

Comments
 (0)