Skip to content

Commit f79bf96

Browse files
github-actions[bot]saphid
authored andcommitted
fix(server): address PR bot findings for devin provider
1 parent 8db5582 commit f79bf96

6 files changed

Lines changed: 103 additions & 47 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,17 @@ const permissionRequestCount = Math.max(
7373
);
7474
const sessionId = "mock-session-1";
7575

76+
const devinConfiguredModels = (process.env.T3_ACP_DEVIN_MODELS ?? "")
77+
.split(",")
78+
.map((value) => value.trim())
79+
.filter((value) => value.length > 0);
80+
const devinInitialModel = devinConfiguredModels.find(() => true) ?? "swe-2-high";
81+
7682
let currentModeId = antigravityProfile ? "default" : devinProfile ? "smart" : "ask";
7783
let currentModelId = antigravityProfile
7884
? "gemini-test-low"
7985
: devinProfile
80-
? "swe-2-high"
86+
? devinInitialModel
8187
: "default";
8288
let parameterizedModelPicker = false;
8389
let currentReasoning = "medium";
@@ -125,10 +131,7 @@ process.once("exit", (code) => {
125131

126132
function configOptions(): ReadonlyArray<AcpSchema.SessionConfigOption> {
127133
if (devinProfile) {
128-
const devinModelValues = (process.env.T3_ACP_DEVIN_MODELS ?? "")
129-
.split(",")
130-
.map((value) => value.trim())
131-
.filter((value) => value.length > 0);
134+
const devinModelValues = devinConfiguredModels;
132135
return [
133136
{
134137
id: "model",

‎apps/server/src/provider/Layers/DevinAdapter.ts‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import * as EffectAcpErrors from "effect-acp/errors";
3232
import type * as EffectAcpSchema from "effect-acp/schema";
3333

3434
import { ServerConfig } from "../../config.ts";
35+
import * as McpProviderSession from "../../mcp/McpProviderSession.ts";
3536
import type { DevinAdapterShape } from "../Services/DevinAdapter.ts";
3637
import {
3738
type ProviderAdapterError,
@@ -522,6 +523,7 @@ export const makeDevinAdapter = Effect.fn("makeDevinAdapter")(function* (
522523
);
523524

524525
return yield* Effect.gen(function* () {
526+
const mcpSession = McpProviderSession.readMcpProviderSession(input.threadId);
525527
// The attachments dir grant lets the agent read pasted files at the
526528
// paths ProviderService injects into the turn text. It is a leaf
527529
// directory holding only uploads.
@@ -533,7 +535,23 @@ export const makeDevinAdapter = Effect.fn("makeDevinAdapter")(function* (
533535
// `session/load` replays history without the agent re-running it;
534536
// Devin advertises loadSession but not session/resume.
535537
resumeMethod: "load",
536-
mcpServers: [],
538+
...(mcpSession
539+
? {
540+
mcpServers: [
541+
{
542+
type: "http" as const,
543+
name: "t3-code",
544+
url: mcpSession.endpoint,
545+
headers: [
546+
{
547+
name: "Authorization",
548+
value: mcpSession.authorizationHeader,
549+
},
550+
],
551+
},
552+
],
553+
}
554+
: {}),
537555
...makeNativeLoggers({
538556
nativeEventLogger: options.nativeEventLogger,
539557
provider: PROVIDER,
@@ -778,14 +796,17 @@ export const makeDevinAdapter = Effect.fn("makeDevinAdapter")(function* (
778796
}
779797
const turnId = context.activeTurnId ?? TurnId.make(yield* randomId);
780798
const steering = context.activeTurnId !== undefined;
781-
const turn: TurnIntent = { turnId, generation: ++context.generation, settled: false };
782-
intent = turn;
783-
context.activeTurnId = turnId;
784799
const model = yield* applyDevinAcpModelSelection({
785800
runtime: context.runtime,
786801
model: requestedUnavailable ? undefined : requestedModel,
787802
mapError: (cause) => cause,
788803
});
804+
// Register the intent only after model selection so a selection
805+
// failure cannot emit `turn.completed` for a turn that never
806+
// emitted `turn.started`.
807+
const turn: TurnIntent = { turnId, generation: ++context.generation, settled: false };
808+
intent = turn;
809+
context.activeTurnId = turnId;
789810
// A selection that resolved normally means the thread's saved model
790811
// moved on; remembered stale slugs from a resume no longer apply.
791812
// Turns without an explicit selection leave the memory alone.

‎apps/server/src/provider/Layers/DevinProvider.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ it.layer(
399399
status:
400400
probeAuth.status === "authenticated" ? ("ready" as const) : ("error" as const),
401401
message: undefined,
402+
modelsFetched: false,
402403
models: [],
403404
}),
404405
),

‎apps/server/src/provider/Layers/DevinProvider.ts‎

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ export interface DevinProbeData {
154154
readonly auth: ServerProviderAuth;
155155
readonly status: ServerProviderState;
156156
readonly message: string | undefined;
157+
/**
158+
* Whether `models` is an authoritative probe result. When false (the
159+
* version probe failed, auth is unknown, or `devin models list` errored),
160+
* the snapshot keeps its previous catalog; when true, an empty list means
161+
* the account genuinely has no catalog (sign-out, empty discovery) and the
162+
* snapshot drops its built-in models.
163+
*/
164+
readonly modelsFetched: boolean;
157165
readonly models: ReadonlyArray<ServerProviderModel>;
158166
}
159167

@@ -183,6 +191,7 @@ export const checkDevinProviderStatus = Effect.fn("checkDevinProviderStatus")(fu
183191
message: isCommandMissingCause(error)
184192
? "Devin CLI (`devin`) is not installed or not on PATH."
185193
: "Failed to execute Devin CLI health check.",
194+
modelsFetched: false,
186195
models: [],
187196
};
188197
}
@@ -193,6 +202,7 @@ export const checkDevinProviderStatus = Effect.fn("checkDevinProviderStatus")(fu
193202
auth: { status: "unknown" },
194203
status: "error",
195204
message: "Devin CLI is installed but timed out while running `devin version`.",
205+
modelsFetched: false,
196206
models: [],
197207
};
198208
}
@@ -211,6 +221,7 @@ export const checkDevinProviderStatus = Effect.fn("checkDevinProviderStatus")(fu
211221
auth: { status: "unknown" },
212222
status: "error",
213223
message: "Devin CLI is installed but failed to run.",
224+
modelsFetched: false,
214225
models: [],
215226
};
216227
}
@@ -262,11 +273,13 @@ export const checkDevinProviderStatus = Effect.fn("checkDevinProviderStatus")(fu
262273
auth,
263274
status: "error",
264275
message: "Devin CLI is installed but not logged in. Run `devin auth login`.",
276+
// Sign-out is an authoritative empty catalog.
277+
modelsFetched: true,
265278
models: [],
266279
};
267280
}
268281

269-
const models =
282+
const modelsResult =
270283
auth.status === "authenticated"
271284
? yield* runDevinCliCommand(
272285
devinSettings,
@@ -280,15 +293,16 @@ export const checkDevinProviderStatus = Effect.fn("checkDevinProviderStatus")(fu
280293
),
281294
Effect.timeoutOption(MODELS_PROBE_TIMEOUT_MS),
282295
Effect.result,
283-
Effect.map((result) =>
284-
Result.isSuccess(result) &&
285-
Option.isSome(result.success) &&
286-
result.success.value.code === 0
287-
? parseDevinModelsListJson(result.success.value.stdout)
288-
: [],
289-
),
290296
)
291-
: [];
297+
: undefined;
298+
// A failed or skipped listing keeps the previous catalog; a successful
299+
// listing (even an empty one) replaces it.
300+
const modelsFetched =
301+
modelsResult !== undefined &&
302+
Result.isSuccess(modelsResult) &&
303+
Option.isSome(modelsResult.success) &&
304+
modelsResult.success.value.code === 0;
305+
const models = modelsFetched ? parseDevinModelsListJson(modelsResult.success.value.stdout) : [];
292306

293307
return {
294308
installed: true,
@@ -301,6 +315,7 @@ export const checkDevinProviderStatus = Effect.fn("checkDevinProviderStatus")(fu
301315
auth.status === "unknown"
302316
? "Could not determine Devin sign-in state. Sessions may prompt for login."
303317
: undefined,
318+
modelsFetched,
304319
models,
305320
};
306321
});
@@ -435,10 +450,9 @@ export const makeDevinProvider = Effect.fn("makeDevinProvider")(function* (
435450
const checkedAt = DateTime.formatIso(yield* DateTime.now);
436451
const next = yield* SubscriptionRef.updateAndGet(metadata, (draft) => {
437452
const { message: _previousMessage, ...rest } = draft;
438-
const models =
439-
probe.models.length > 0
440-
? devinModelsFromSettings(settings.customModels, probe.models)
441-
: draft.models;
453+
const models = probe.modelsFetched
454+
? devinModelsFromSettings(settings.customModels, probe.models)
455+
: draft.models;
442456
return {
443457
...rest,
444458
installed: probe.installed,
@@ -481,10 +495,13 @@ export const makeDevinProvider = Effect.fn("makeDevinProvider")(function* (
481495
Array.isArray(started.sessionSetupResult.configOptions)
482496
? started.sessionSetupResult.configOptions
483497
: [];
484-
const sessionModels = devinModelsFromSettings(
485-
settings.customModels,
486-
buildDevinModelsFromSession(configOptions),
487-
);
498+
// A session without a model config option is not an empty catalog —
499+
// keep the probed models instead of collapsing to custom-only.
500+
const sessionBuiltInModels = buildDevinModelsFromSession(configOptions);
501+
const sessionModels =
502+
sessionBuiltInModels.length > 0
503+
? devinModelsFromSettings(settings.customModels, sessionBuiltInModels)
504+
: [];
488505
return {
489506
...rest,
490507
installed: true,
@@ -504,11 +521,9 @@ export const makeDevinProvider = Effect.fn("makeDevinProvider")(function* (
504521
const onConfigOptionsUpdated = Effect.fn("DevinProvider.onConfigOptionsUpdated")(function* (
505522
configOptions: ReadonlyArray<EffectAcpSchema.SessionConfigOption>,
506523
) {
507-
const models = devinModelsFromSettings(
508-
settings.customModels,
509-
buildDevinModelsFromSession(configOptions),
510-
);
511-
if (models.length === 0) return;
524+
const sessionBuiltInModels = buildDevinModelsFromSession(configOptions);
525+
if (sessionBuiltInModels.length === 0) return;
526+
const models = devinModelsFromSettings(settings.customModels, sessionBuiltInModels);
512527
yield* SubscriptionRef.update(metadata, (draft) => {
513528
const heal = adapterFlaggedAuth ? healAdapterFlaggedAuth(draft) : {};
514529
if (heal.auth) adapterFlaggedAuth = false;
@@ -543,6 +558,7 @@ export const makeDevinProvider = Effect.fn("makeDevinProvider")(function* (
543558
...draft,
544559
auth: { status: "unauthenticated" },
545560
status: settings.enabled ? "warning" : "disabled",
561+
supportsTextGeneration: false,
546562
message: "Devin is not signed in. Run `devin auth login`, then start the thread again.",
547563
checkedAt,
548564
}) satisfies ServerProviderDraft,

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,16 @@ it.layer(DevinTextGenerationTestLayer)("DevinTextGeneration", (it) => {
8282
T3_ACP_REQUEST_LOG_PATH: requestLogPath,
8383
T3_ACP_PROMPT_RESPONSE_TEXT: JSON.stringify({ branch: "fix/login-redirect" }),
8484
},
85-
// Signed-out environment: no API key and no credentials file.
86-
{ ...process.env, HOME: fakeHome, WINDSURF_API_KEY: "" },
85+
// Signed-out environment: no API key and no credentials file. The XDG
86+
// and Windows data dirs are redirected too so host credential paths can
87+
// never leak in.
88+
{
89+
...process.env,
90+
HOME: fakeHome,
91+
WINDSURF_API_KEY: "",
92+
XDG_DATA_HOME: NodePath.join(fakeHome, "xdg"),
93+
LOCALAPPDATA: NodePath.join(fakeHome, "localappdata"),
94+
},
8795
(textGeneration) =>
8896
Effect.gen(function* () {
8997
const generated = yield* textGeneration.generateBranchName({

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Option from "effect/Option";
55
import * as Ref from "effect/Ref";
66
import * as Schema from "effect/Schema";
77
import { ChildProcessSpawner } from "effect/unstable/process";
8-
import type * as EffectAcpErrors from "effect-acp/errors";
8+
import * as EffectAcpErrors from "effect-acp/errors";
99

1010
import { type DevinSettings, type ModelSelection, TextGenerationError } from "@t3tools/contracts";
1111
import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/shared/git";
@@ -96,16 +96,20 @@ export const makeDevinTextGeneration = Effect.fn("makeDevinTextGeneration")(func
9696
}).pipe(
9797
// The configured text-generation model may not be in the account's
9898
// catalog; fall back to the model the session already runs on
99-
// rather than failing the operation. `catch` (not `catchCause`) so
100-
// the prompt timeout's interruption is not swallowed.
99+
// rather than failing the operation. Only an invalid-params
100+
// rejection means "model unavailable" — transport/protocol failures
101+
// still propagate. `catch` (not `catchCause`) so the prompt
102+
// timeout's interruption is not swallowed.
101103
Effect.catch((error) =>
102-
Effect.logWarning(
103-
"Devin text-generation model selection failed; using the session model.",
104-
{
105-
errorTag: error._tag,
106-
requestedModel: resolvedModel,
107-
},
108-
),
104+
error._tag === "AcpRequestError" && error.code === -32602
105+
? Effect.logWarning(
106+
"Devin text-generation model selection failed; using the session model.",
107+
{
108+
errorTag: error._tag,
109+
requestedModel: resolvedModel,
110+
},
111+
)
112+
: Effect.fail(error),
109113
),
110114
);
111115

@@ -135,13 +139,16 @@ export const makeDevinTextGeneration = Effect.fn("makeDevinTextGeneration")(func
135139
);
136140

137141
const trimmed = (yield* Ref.get(outputRef)).trim();
142+
if (promptResult.stopReason === "cancelled") {
143+
return yield* new TextGenerationError({
144+
operation,
145+
detail: "Devin ACP request was cancelled.",
146+
});
147+
}
138148
if (!trimmed) {
139149
return yield* new TextGenerationError({
140150
operation,
141-
detail:
142-
promptResult.stopReason === "cancelled"
143-
? "Devin ACP request was cancelled."
144-
: "Devin returned empty output.",
151+
detail: "Devin returned empty output.",
145152
});
146153
}
147154

0 commit comments

Comments
 (0)