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
4 changes: 4 additions & 0 deletions packages/ai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Fixed `openai-codex-responses` fresh plan execution requests that contained only system/developer guidance by mirroring the final instruction as user input so Codex accepts the first turn. ([#4714](https://github.com/can1357/oh-my-pi/issues/4714))

## [16.3.10] - 2026-07-06

### Fixed
Expand Down
63 changes: 54 additions & 9 deletions packages/ai/src/providers/openai-codex/request-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,61 @@ export async function transformRequestBody(
}
}

if (prompt?.developerMessages && prompt.developerMessages.length > 0 && Array.isArray(body.input)) {
const developerMessages = prompt.developerMessages.map(
text =>
({
if (prompt?.developerMessages && prompt.developerMessages.length > 0) {
const developerMessages: InputItem[] = prompt.developerMessages.map(text => ({
type: "message",
role: "developer",
content: [{ type: "input_text", text }],
}));
const input = Array.isArray(body.input) ? body.input : [];
body.input = [...developerMessages, ...input];
}

let finalInstruction = prompt?.developerMessages.findLast(text => text.trim().length > 0);
if (finalInstruction === undefined && Array.isArray(body.input)) {
for (let itemIndex = body.input.length - 1; itemIndex >= 0; itemIndex -= 1) {
const item = body.input[itemIndex];
if (item.role !== "developer" || !Array.isArray(item.content)) continue;
for (let partIndex = item.content.length - 1; partIndex >= 0; partIndex -= 1) {
const part = item.content[partIndex];
if (
part &&
typeof part === "object" &&
"type" in part &&
part.type === "input_text" &&
"text" in part &&
typeof part.text === "string" &&
part.text.trim().length > 0
) {
finalInstruction = part.text;
break;
}
}
if (finalInstruction !== undefined) break;
}
}
if (finalInstruction === undefined && typeof body.instructions === "string" && body.instructions.trim().length > 0) {
finalInstruction = body.instructions;
}
if (finalInstruction !== undefined) {
const input = Array.isArray(body.input) ? body.input : [];
let hasVisibleInput = false;
for (const item of input) {
if (item.role !== "developer") {
hasVisibleInput = true;
break;
}
}
if (!hasVisibleInput) {
body.input = [
...input,
{
type: "message",
role: "developer",
content: [{ type: "input_text", text }],
}) as InputItem,
);
body.input = [...developerMessages, ...body.input];
role: "user",
content: [{ type: "input_text", text: finalInstruction }],
},
];
}
}

const responsesLite = shouldUseCodexResponsesLite(body, options.responsesLite);
Expand Down
53 changes: 53 additions & 0 deletions packages/ai/test/openai-codex-responses-lite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
transformRequestBody,
} from "@oh-my-pi/pi-ai/providers/openai-codex/request-transformer";
import {
buildTransformedCodexRequestBody,
convertCodexResponsesMessages,
streamOpenAICodexResponses,
} from "@oh-my-pi/pi-ai/providers/openai-codex-responses";
Expand Down Expand Up @@ -269,6 +270,58 @@ describe("openai-codex Responses Lite input shaping", () => {
});
});

describe("openai-codex fresh execution input shaping", () => {
it("adds a user continuation when only instructions would be sent", async () => {
const model = createCodexModel("gpt-5.1-codex");
const body = await buildTransformedCodexRequestBody(
model,
{
systemPrompt: ["You are a helpful assistant.", "Read local://approved-plan.md and execute it."],
messages: [],
},
undefined,
);

expect(body.instructions).toBe("You are a helpful assistant.");
expect(body.input).toEqual([
{
type: "message",
role: "developer",
content: [{ type: "input_text", text: "Read local://approved-plan.md and execute it." }],
},
{
type: "message",
role: "user",
content: [{ type: "input_text", text: "Read local://approved-plan.md and execute it." }],
},
]);
});

it("does not add a continuation when user input is present", async () => {
const model = createCodexModel("gpt-5.1-codex");
const body = await buildTransformedCodexRequestBody(
model,
{
systemPrompt: ["You are a helpful assistant.", "Read local://approved-plan.md and execute it."],
messages: [{ role: "user", content: "Start execution", timestamp: Date.now() }],
},
undefined,
);

expect(body.input).toEqual([
{
type: "message",
role: "developer",
content: [{ type: "input_text", text: "Read local://approved-plan.md and execute it." }],
},
{
role: "user",
content: [{ type: "input_text", text: "Start execution" }],
},
]);
});
});

describe("openai-codex Responses Lite and client metadata wire format", () => {
it("sends the lite header and client_metadata body field over SSE", async () => {
const model = createCodexModel("gpt-5.1-codex");
Expand Down
Loading