Skip to content

Commit 37dac88

Browse files
github-actions[bot]saphid
authored andcommitted
fix(server): gate devin browser auth to interactive starts and harden model probe
1 parent f79bf96 commit 37dac88

4 files changed

Lines changed: 55 additions & 18 deletions

File tree

‎apps/server/src/provider/Drivers/DevinDriver.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,14 @@ export const DevinDriver: ProviderDriver<DevinSettings, DevinDriverEnv> = {
123123
(snapshot) => snapshot.models.find((model) => model.isDefault)?.slug,
124124
),
125125
makeRuntime: (input) =>
126+
// The adapter decides `browserAuth`: interactive starts may fall
127+
// back to `devin-browser` when no credentials exist, while resumes
128+
// and sessions with stored credentials never open a browser.
126129
makeDevinAcpRuntime({
127130
...input,
128131
devinSettings: effectiveConfig,
129132
environment: processEnv,
130133
childProcessSpawner: spawner,
131-
// User-initiated sessions may fall back to `devin-browser` when no
132-
// credentials exist at all; sessions with stored credentials skip
133-
// `authenticate` entirely.
134-
browserAuth: true,
135134
}).pipe(
136135
Effect.provideService(Crypto.Crypto, crypto),
137136
Effect.provideService(FileSystem.FileSystem, fileSystem),

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ const makeTestAdapter = (
110110
...input,
111111
devinSettings: { binaryPath },
112112
environment,
113-
browserAuth: true,
114113
childProcessSpawner,
115114
}).pipe(
116115
Effect.provideService(Crypto.Crypto, crypto),
@@ -216,6 +215,36 @@ it.layer(devinAdapterTestLayer)("DevinAdapterLive", (it) => {
216215
}),
217216
);
218217

218+
it.effect("never requests browser authentication when resuming while signed out", () =>
219+
Effect.gen(function* () {
220+
const threadId = ThreadId.make("devin-resume-signed-out");
221+
const tempDir = yield* Effect.promise(() =>
222+
NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "devin-resume-signed-out-")),
223+
);
224+
const requestLogPath = NodePath.join(tempDir, "requests.ndjson");
225+
const wrapperPath = yield* Effect.promise(() =>
226+
makeMockDevinWrapper({ T3_ACP_REQUEST_LOG_PATH: requestLogPath }),
227+
);
228+
const adapter = yield* makeTestAdapter(wrapperPath, signedOutEnvironment(tempDir));
229+
230+
// Recovery during server restart resumes with a cursor; popping a
231+
// browser there would surprise nobody at the keyboard.
232+
yield* adapter.startSession({
233+
threadId,
234+
cwd: process.cwd(),
235+
runtimeMode: "auto",
236+
resumeCursor: { schemaVersion: 1, sessionId: "previous-devin-session" },
237+
});
238+
yield* adapter.stopSession(threadId);
239+
240+
const requests = yield* Effect.promise(() => readJsonLines(requestLogPath));
241+
const methods = requests.map((request) => request.method);
242+
assert.notInclude(methods, "authenticate");
243+
assert.include(methods, "session/load");
244+
assert.notInclude(methods, "session/new");
245+
}),
246+
);
247+
219248
it.effect("maps the mock ACP prompt flow to runtime events", () =>
220249
Effect.gen(function* () {
221250
const threadId = ThreadId.make("devin-mock-thread");

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ function devinApprovalOptions(request: NativePermission): ReadonlyArray<Provider
168168
export interface DevinAdapterOptions {
169169
readonly instanceId: ProviderInstanceId;
170170
readonly makeRuntime: (
171-
input: Omit<
172-
DevinAcpRuntimeInput,
173-
"childProcessSpawner" | "devinSettings" | "environment" | "browserAuth"
174-
>,
171+
input: Omit<DevinAcpRuntimeInput, "childProcessSpawner" | "devinSettings" | "environment">,
175172
) => Effect.Effect<
176173
AcpSessionRuntime.AcpSessionRuntime["Service"],
177174
EffectAcpErrors.AcpError,
@@ -535,6 +532,10 @@ export const makeDevinAdapter = Effect.fn("makeDevinAdapter")(function* (
535532
// `session/load` replays history without the agent re-running it;
536533
// Devin advertises loadSession but not session/resume.
537534
resumeMethod: "load",
535+
// A resume can run during server-restart recovery where nobody is
536+
// watching; only an interactive fresh start may fall back to
537+
// `devin-browser` when credentials are missing.
538+
browserAuth: Option.isNone(cursor),
538539
...(mcpSession
539540
? {
540541
mcpServers: [

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ const DevinModelsListJson = Schema.Struct({
7575

7676
const decodeDevinModelsListJson = Schema.decodeResult(Schema.fromJsonString(DevinModelsListJson));
7777

78-
export function parseDevinModelsListJson(output: string): ReadonlyArray<ServerProviderModel> {
79-
const decoded = decodeDevinModelsListJson(output);
80-
if (Result.isFailure(decoded)) return [];
78+
function devinModelsFromDecodedList(
79+
decoded: typeof DevinModelsListJson.Type,
80+
): ServerProviderModel[] {
8181
const seen = new Set<string>();
8282
const models: ServerProviderModel[] = [];
83-
for (const family of decoded.success.families ?? []) {
83+
for (const family of decoded.families ?? []) {
8484
for (const variant of family.variants ?? []) {
8585
const slug = variant.model_uid.trim();
8686
if (!slug || seen.has(slug)) continue;
@@ -102,6 +102,11 @@ export function parseDevinModelsListJson(output: string): ReadonlyArray<ServerPr
102102
return models;
103103
}
104104

105+
export function parseDevinModelsListJson(output: string): ReadonlyArray<ServerProviderModel> {
106+
const decoded = decodeDevinModelsListJson(output);
107+
return Result.isFailure(decoded) ? [] : devinModelsFromDecodedList(decoded.success);
108+
}
109+
105110
export interface DevinAuthStatus {
106111
/** True or false when the CLI printed a verdict, null when unparseable. */
107112
readonly authenticated: boolean | null;
@@ -295,14 +300,17 @@ export const checkDevinProviderStatus = Effect.fn("checkDevinProviderStatus")(fu
295300
Effect.result,
296301
)
297302
: undefined;
298-
// A failed or skipped listing keeps the previous catalog; a successful
299-
// listing (even an empty one) replaces it.
300-
const modelsFetched =
303+
// A failed, skipped, or undecodable listing keeps the previous catalog; a
304+
// decoded listing (even an empty one) replaces it.
305+
const decodedModels =
301306
modelsResult !== undefined &&
302307
Result.isSuccess(modelsResult) &&
303308
Option.isSome(modelsResult.success) &&
304-
modelsResult.success.value.code === 0;
305-
const models = modelsFetched ? parseDevinModelsListJson(modelsResult.success.value.stdout) : [];
309+
modelsResult.success.value.code === 0
310+
? decodeDevinModelsListJson(modelsResult.success.value.stdout)
311+
: undefined;
312+
const modelsFetched = decodedModels !== undefined && Result.isSuccess(decodedModels);
313+
const models = modelsFetched ? devinModelsFromDecodedList(decodedModels.success) : [];
306314

307315
return {
308316
installed: true,

0 commit comments

Comments
 (0)