Skip to content

Commit 6062167

Browse files
committed
Overlay branch overlay/opencode-textgen on top of origin/main via Merge
# Conflicts: # packages/provider-opencode/src/server/textGeneration.test.ts * packages/provider-opencode/src/server/textGeneration.test.ts * packages/provider-opencode/src/server/textGeneration.ts • b244cd8691 Overlay branch overlay/opencode-textgen on top of origin/main via Merge |\ | • c6a0ac0 Overlay branch overlay/opencode-textgen on top of origin/main via Merge | |\ | | • d5e383b fix(textGeneration): delete opencode helper sessions after one-shot calls | |/ • | 19108aa feat(auth): pairing grants access and T3 Connect management by default (pingdotgg#20432) • | 6a326af perf(web): connections settings compile with the React Compiler (pingdotgg#20515) • | 3448e01 perf(web): SnapShot settings compile with the React Compiler (pingdotgg#20514) • | 5422872 fix(web): an abandoned machine switch still clears its busy state (pingdotgg#20519) • | 6a71716 perf(web): theme import dialog compile with the React Compiler (pingdotgg#20513)
2 parents 19108aa + c6a0ac0 commit 6062167

2 files changed

Lines changed: 98 additions & 33 deletions

File tree

‎packages/provider-opencode/src/server/textGeneration.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const runtimeMock = {
2424
authHeaders: [] as Array<string | null>,
2525
closeCalls: [] as string[],
2626
sessionCreateCalls: 0,
27+
sessionDeleteCalls: [] as string[],
2728
connectionError: undefined as Error | undefined,
2829
sessionCreateError: undefined as unknown,
2930
sessionResult: undefined as { data?: { id: string } } | undefined,
@@ -39,6 +40,7 @@ const runtimeMock = {
3940
this.state.authHeaders.length = 0;
4041
this.state.closeCalls.length = 0;
4142
this.state.sessionCreateCalls = 0;
43+
this.state.sessionDeleteCalls.length = 0;
4244
this.state.connectionError = undefined;
4345
this.state.sessionCreateError = undefined;
4446
this.state.sessionResult = undefined;
@@ -125,6 +127,10 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntime.OpenCodeRuntime["Service"] = {
125127
}
126128
);
127129
},
130+
delete: async (input: { readonly sessionID: string }) => {
131+
runtimeMock.state.sessionDeleteCalls.push(input.sessionID);
132+
return { data: true };
133+
},
128134
},
129135
}) as unknown as ReturnType<
130136
OpenCodeRuntime.OpenCodeRuntime["Service"]["createOpenCodeSdkClient"]
@@ -228,6 +234,47 @@ const advanceIdleClock = Effect.gen(function* () {
228234
});
229235

230236
it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
237+
it.effect("deletes the helper session after a successful title generation", () =>
238+
withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
239+
Effect.gen(function* () {
240+
runtimeMock.state.sessionResult = { data: { id: "ses_helper_1" } };
241+
runtimeMock.state.promptResult = {
242+
data: {
243+
parts: [{ type: "text", text: '{"title":"Review uploaded report"}' }],
244+
},
245+
};
246+
247+
const title = yield* textGeneration.generateThreadTitle({
248+
cwd: process.cwd(),
249+
message: "Review these attachments.",
250+
modelSelection: DEFAULT_TEST_MODEL_SELECTION,
251+
});
252+
253+
expect(title.title).toBe("Review uploaded report");
254+
expect(runtimeMock.state.sessionDeleteCalls).toEqual(["ses_helper_1"]);
255+
}),
256+
),
257+
);
258+
259+
it.effect("deletes the helper session when the prompt fails", () =>
260+
withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
261+
Effect.gen(function* () {
262+
runtimeMock.state.sessionResult = { data: { id: "ses_helper_2" } };
263+
runtimeMock.state.promptRequestError = new Error("provider exploded");
264+
265+
yield* textGeneration
266+
.generateThreadTitle({
267+
cwd: process.cwd(),
268+
message: "Review these attachments.",
269+
modelSelection: DEFAULT_TEST_MODEL_SELECTION,
270+
})
271+
.pipe(Effect.flip);
272+
273+
expect(runtimeMock.state.sessionDeleteCalls).toEqual(["ses_helper_2"]);
274+
}),
275+
),
276+
);
277+
231278
it.effect("excludes generic files from thread title generation", () =>
232279
withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
233280
Effect.gen(function* () {

‎packages/provider-opencode/src/server/textGeneration.ts‎

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -204,49 +204,67 @@ export const makeOpenCodeTextGeneration = Effect.fn("makeOpenCodeTextGeneration"
204204
cwd: input.cwd,
205205
});
206206
}
207+
const sessionId = session.data.id;
207208
const selectedAgent = getModelSelectionStringOptionValue(input.modelSelection, "agent");
208209
const selectedVariant = getModelSelectionStringOptionValue(input.modelSelection, "variant");
209210
const promptContext = {
210211
operation: input.operation,
211212
cwd: input.cwd,
212-
sessionId: session.data.id,
213+
sessionId,
213214
providerId: parsedModel.providerID,
214215
modelId: parsedModel.modelID,
215216
};
216217

217-
const result = yield* Effect.tryPromise({
218-
try: () =>
219-
client.session.prompt({
220-
sessionID: session.data.id,
221-
model: parsedModel,
222-
...(selectedAgent ? { agent: selectedAgent } : {}),
223-
...(selectedVariant ? { variant: selectedVariant } : {}),
224-
parts: [{ type: "text", text: input.prompt }, ...fileParts],
225-
}),
226-
catch: (cause) =>
227-
new OpenCodeTextGenerationPromptRequestError({
228-
...promptContext,
229-
cause,
230-
}),
231-
});
232-
const promptFailure = getOpenCodePromptFailure(result.data?.info?.error);
233-
if (promptFailure) {
234-
return yield* new OpenCodeTextGenerationPromptResponseError({
235-
...promptContext,
236-
...(promptFailure.name ? { providerErrorName: promptFailure.name } : {}),
237-
providerMessage: promptFailure.message,
218+
// The helper session exists only to satisfy session.prompt; opencode
219+
// persists it in the user's session store, so delete it on every exit
220+
// path (prime's --no-session is the parity point).
221+
return yield* Effect.gen(function* () {
222+
const result = yield* Effect.tryPromise({
223+
try: () =>
224+
client.session.prompt({
225+
sessionID: sessionId,
226+
model: parsedModel,
227+
...(selectedAgent ? { agent: selectedAgent } : {}),
228+
...(selectedVariant ? { variant: selectedVariant } : {}),
229+
parts: [{ type: "text", text: input.prompt }, ...fileParts],
230+
}),
231+
catch: (cause) =>
232+
new OpenCodeTextGenerationPromptRequestError({
233+
...promptContext,
234+
cause,
235+
}),
238236
});
239-
}
240-
const responseParts = result.data?.parts ?? [];
241-
const rawText = getOpenCodeTextResponse(responseParts);
242-
if (rawText.length === 0) {
243-
return yield* new OpenCodeTextGenerationEmptyOutputError({
244-
...promptContext,
245-
responsePartCount: responseParts.length,
246-
textPartCount: responseParts.filter(isOpenCodeTextPart).length,
247-
});
248-
}
249-
return rawText;
237+
const promptFailure = getOpenCodePromptFailure(result.data?.info?.error);
238+
if (promptFailure) {
239+
return yield* new OpenCodeTextGenerationPromptResponseError({
240+
...promptContext,
241+
...(promptFailure.name ? { providerErrorName: promptFailure.name } : {}),
242+
providerMessage: promptFailure.message,
243+
});
244+
}
245+
const responseParts = result.data?.parts ?? [];
246+
const rawText = getOpenCodeTextResponse(responseParts);
247+
if (rawText.length === 0) {
248+
return yield* new OpenCodeTextGenerationEmptyOutputError({
249+
...promptContext,
250+
responsePartCount: responseParts.length,
251+
textPartCount: responseParts.filter(isOpenCodeTextPart).length,
252+
});
253+
}
254+
return rawText;
255+
}).pipe(
256+
Effect.ensuring(
257+
Effect.tryPromise({
258+
try: () => client.session.delete({ sessionID: sessionId }),
259+
catch: (cause) =>
260+
new OpenCodeTextGenerationSessionRequestError({
261+
operation: input.operation,
262+
cwd: input.cwd,
263+
cause,
264+
}),
265+
}).pipe(Effect.ignore),
266+
),
267+
);
250268
},
251269
Effect.catchTags({
252270
OpenCodeTextGenerationSessionRequestError: (cause) =>

0 commit comments

Comments
 (0)