Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions README.md

This file was deleted.

32 changes: 32 additions & 0 deletions apps/server/src/provider/Layers/CodexProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@ it("maps current Codex model capability fields", () => {
]);
});

it("falls back to high when the catalog reasoning default is unavailable", () => {
const capabilities = mapCodexModelCapabilities({
additionalSpeedTiers: [],
defaultReasoningEffort: "unavailable",
defaultServiceTier: null,
description: "Test model",
displayName: "GPT Test",
hidden: false,
id: "gpt-test",
isDefault: true,
model: "gpt-test",
serviceTiers: [],
supportedReasoningEfforts: [
{ description: "Low reasoning", reasoningEffort: "low" },
{ description: "High reasoning", reasoningEffort: "high" },
],
});

assert.deepStrictEqual(capabilities.optionDescriptors, [
{
id: "reasoningEffort",
label: "Reasoning",
type: "select",
options: [
{ id: "low", label: "Low" },
{ id: "high", label: "High", isDefault: true },
],
currentValue: "high",
},
]);
});

it("uses standard routing when the catalog has no default service tier", () => {
const capabilities = mapCodexModelCapabilities({
additionalSpeedTiers: ["fast"],
Expand Down
13 changes: 10 additions & 3 deletions apps/server/src/provider/Layers/CodexProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,16 @@ function codexAccountEmail(account: CodexSchema.V2GetAccountResponse["account"])
export function mapCodexModelCapabilities(
model: CodexSchema.V2ModelListResponse__Model,
): ModelCapabilities {
const reasoningOptions = model.supportedReasoningEfforts.map(({ reasoningEffort }) =>
reasoningEffort === model.defaultReasoningEffort
const supportedReasoningEfforts = model.supportedReasoningEfforts.map(
({ reasoningEffort }) => reasoningEffort,
);
const defaultReasoning = supportedReasoningEfforts.includes(model.defaultReasoningEffort)
? model.defaultReasoningEffort
: supportedReasoningEfforts.includes("high")
? "high"
: undefined;
const reasoningOptions = supportedReasoningEfforts.map((reasoningEffort) =>
reasoningEffort === defaultReasoning
? {
id: reasoningEffort,
label: reasoningEffortLabel(reasoningEffort),
Expand All @@ -121,7 +129,6 @@ export function mapCodexModelCapabilities(
label: reasoningEffortLabel(reasoningEffort),
},
);
const defaultReasoning = reasoningOptions.find((option) => option.isDefault)?.id;
const serviceTiers =
model.serviceTiers && model.serviceTiers.length > 0
? model.serviceTiers
Expand Down
88 changes: 83 additions & 5 deletions apps/server/src/provider/Layers/PiAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface FakePi {

const makeFakePi = Effect.fn("makeFakePi")(function* (input?: {
readonly subagentsCommand?: boolean;
readonly contextCommand?: boolean;
readonly fastCommand?: boolean;
}) {
const stdoutQueue = yield* Queue.unbounded<Uint8Array>();
Expand Down Expand Up @@ -100,6 +101,9 @@ const makeFakePi = Effect.fn("makeFakePi")(function* (input?: {
...(input?.subagentsCommand === false
? []
: [{ name: "subagents-rpc", source: "extension" }]),
...(input?.contextCommand === true
? [{ name: "context", source: "extension" }]
: []),
...(input?.fastCommand === true
? [{ name: "fast", source: "extension" }]
: []),
Expand Down Expand Up @@ -253,18 +257,19 @@ describe("makePiAdapter", () => {
}).pipe(Effect.scoped, Effect.provide(TestEnv)),
);

it.effect("synchronizes Codex Fast service before the user prompt", () =>
it.effect("synchronizes Pi context and Codex Fast service before the user prompt", () =>
Effect.gen(function* () {
const fake = yield* makeFakePi({ fastCommand: true });
const fake = yield* makeFakePi({ contextCommand: true, fastCommand: true });
const adapter = yield* makePiAdapter(settings, { instanceId: INSTANCE }).pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, fake.spawner),
);
const threadId = ThreadId.make("88888888-8888-4888-8888-888888888888");
const fastSelection: ModelSelection = {
instanceId: INSTANCE,
model: "openai-codex/gpt-5.5",
model: "openai-codex/gpt-5.6-sol",
options: [
{ id: "reasoning", value: "off" },
{ id: "contextWindow", value: "372k" },
{ id: "serviceTier", value: "priority" },
],
};
Expand All @@ -283,12 +288,16 @@ describe("makePiAdapter", () => {
const thinkingIndex = fake.written.findIndex(
(command) => command.type === "set_thinking_level" && command.level === "off",
);
const contextIndex = fake.written.findIndex(
(command) => command.type === "prompt" && command.message === "/context 372k",
);
const fastIndex = fake.written.findIndex(
(command) => command.type === "prompt" && command.message === "/fast on",
);
expect(modelIndex).toBeGreaterThanOrEqual(0);
expect(thinkingIndex).toBeGreaterThan(modelIndex);
expect(fastIndex).toBeGreaterThan(thinkingIndex);
expect(contextIndex).toBeGreaterThan(thinkingIndex);
expect(fastIndex).toBeGreaterThan(contextIndex);

yield* adapter.sendTurn({
threadId,
Expand All @@ -297,6 +306,7 @@ describe("makePiAdapter", () => {
...fastSelection,
options: [
{ id: "reasoning", value: "off" },
{ id: "contextWindow", value: "auto" },
{ id: "serviceTier", value: "default" },
],
},
Expand All @@ -305,13 +315,80 @@ describe("makePiAdapter", () => {
(command) => command.type === "prompt" && command.message === "/fast off",
);
expect(disabled.message).toBe("/fast off");
const resetContextIndex = fake.written.findIndex(
(command) => command.type === "prompt" && command.message === "/context auto",
);
const disableFastIndex = fake.written.findIndex(
(command) => command.type === "prompt" && command.message === "/fast off",
);
expect(resetContextIndex).toBeGreaterThan(fastIndex);
expect(disableFastIndex).toBeGreaterThan(resetContextIndex);
const userPrompt = yield* fake.takeStdinUntil(
(command) => command.type === "prompt" && command.message === "Use the standard tier now",
);
expect(userPrompt.message).toBe("Use the standard tier now");
}).pipe(Effect.scoped, Effect.provide(TestEnv)),
);

it.effect("drops stale profile options when the live Pi profile lacks their commands", () =>
Effect.gen(function* () {
const fake = yield* makeFakePi();
const adapter = yield* makePiAdapter(settings, { instanceId: INSTANCE }).pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, fake.spawner),
);
const events = yield* Queue.unbounded<ProviderRuntimeEvent>();
yield* Stream.runForEach(adapter.streamEvents, (event) => Queue.offer(events, event)).pipe(
Effect.forkScoped,
);
const threadId = ThreadId.make("77777777-7777-4777-8777-777777777777");
const staleSelection: ModelSelection = {
instanceId: INSTANCE,
model: "openai-codex/gpt-5.6-sol",
options: [
{ id: "reasoning", value: "high" },
{ id: "contextWindow", value: "372k" },
{ id: "serviceTier", value: "priority" },
{ id: "profile", value: "without-effort-commands" },
],
};

yield* adapter.startSession({
threadId,
cwd: process.cwd(),
runtimeMode: "full-access",
modelSelection: staleSelection,
});

expect(fake.captured.args).toContain("without-effort-commands");
const contextWarning = yield* takeEventOfType(events, "runtime.warning");
const fastWarning = yield* takeEventOfType(events, "runtime.warning");
expect(
contextWarning.type === "runtime.warning" ? contextWarning.payload.message : "",
).toContain("does not provide /context");
expect(fastWarning.type === "runtime.warning" ? fastWarning.payload.message : "").toContain(
"does not provide /fast",
);
expect(fake.written).not.toContainEqual(
expect.objectContaining({ type: "prompt", message: "/context 372k" }),
);
expect(fake.written).not.toContainEqual(
expect.objectContaining({ type: "prompt", message: "/fast on" }),
);

yield* adapter.sendTurn({
threadId,
input: "Continue without profile-specific options",
modelSelection: staleSelection,
});
const prompt = yield* fake.takeStdinUntil(
(command) =>
command.type === "prompt" &&
command.message === "Continue without profile-specific options",
);
expect(prompt.message).toBe("Continue without profile-specific options");
}).pipe(Effect.scoped, Effect.provide(TestEnv)),
);

it.effect("keeps opposite Fast tiers atomic with concurrent sends", () =>
Effect.gen(function* () {
const fake = yield* makeFakePi({ fastCommand: true });
Expand Down Expand Up @@ -361,7 +438,8 @@ describe("makePiAdapter", () => {
(command) => command.type === "prompt" && command.message === "first-fast-prompt",
);
const fastOffIndex = fake.written.findIndex(
(command) => command.type === "prompt" && command.message === "/fast off",
(command, index) =>
index > firstPromptIndex && command.type === "prompt" && command.message === "/fast off",
);
const secondPromptIndex = fake.written.findIndex(
(command) => command.type === "steer" && command.message === "second-standard-steer",
Expand Down
Loading
Loading