From 732b936fb626eda42fa05037a42641f19bdd7ecd Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Wed, 25 Nov 2026 20:00:15 +0700 Subject: [PATCH] fix(codex): keep configured developer instructions when Paseo adds instructions (#10792) Codex uses a thread's developerInstructions in place of the developer_instructions in its config. Paseo now reads the configured value through config/read and sends it ahead of the agent, daemon, and plugin instructions on thread/start, thread/resume, and rewind forks. Closes #10644 --- .../providers/codex-app-server-agent.test.ts | 25 ++++++++++++++++ .../agent/providers/codex-app-server-agent.ts | 29 ++++++++++++++----- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/packages/server/src/server/agent/providers/codex-app-server-agent.test.ts b/packages/server/src/server/agent/providers/codex-app-server-agent.test.ts index 975ea8c8e9..90cdd1cbc6 100644 --- a/packages/server/src/server/agent/providers/codex-app-server-agent.test.ts +++ b/packages/server/src/server/agent/providers/codex-app-server-agent.test.ts @@ -1470,6 +1470,31 @@ describe("Codex app-server provider", () => { } }); + test.each(["thread/start", "thread/resume"] as const)( + "%s appends plugin instructions to the developer instructions configured in Codex", + async (method) => { + const appServer = createFakeCodexAppServer({ + "config/read": () => ({ config: { developer_instructions: "Configured role" } }), + }); + const provider = createProviderWithFakeAppServer(appServer); + const config = { pluginAppendSystemPrompt: ["Plugin instructions"] }; + const session = + method === "thread/start" + ? await provider.createSession(createConfig(config)) + : await provider.resumeSession({ sessionId: "saved-thread" }, config); + try { + await session.startTurn("hello"); + await appServer.waitForTurnStart(); + expect( + appServer.requests().find((request) => request.method === method)?.params, + ).toMatchObject({ developerInstructions: "Configured role\n\nPlugin instructions" }); + appServer.assertNoErrors(); + } finally { + await session.close(); + } + }, + ); + test("reopen injects current instructions once, including an explicit empty snapshot", async () => { const handlers = { initialize: () => ({ userAgent: "codex/0.165.0" }), diff --git a/packages/server/src/server/agent/providers/codex-app-server-agent.ts b/packages/server/src/server/agent/providers/codex-app-server-agent.ts index 1974de11c5..2e9b3ee558 100644 --- a/packages/server/src/server/agent/providers/codex-app-server-agent.ts +++ b/packages/server/src/server/agent/providers/codex-app-server-agent.ts @@ -57,7 +57,7 @@ import path from "node:path"; import { isDeepStrictEqual } from "node:util"; import { z } from "zod"; import { renderPromptAttachmentAsText } from "../prompt-attachments.js"; -import { composeAgentSystemPrompt } from "../system-prompt.js"; +import { composeAgentSystemPrompt, composeSystemPromptParts } from "../system-prompt.js"; import { CodexInstructionSnapshot } from "./codex/instruction-snapshot.js"; import { CodexAsyncQuestions, codexAsyncQuestionToTimeline } from "./codex/async-questions.js"; import { @@ -3797,6 +3797,7 @@ export class CodexAppServerAgentSession implements AgentSession { private resolvedWorkspaceWrite: NonNullable< CodexProviderOptions["sandbox_workspace_write"] > | null = null; + private configuredDeveloperInstructions: string | undefined; private resolvedSandboxPolicy: Record | null = null; private currentThreadId: string | null = null; // Codex writes a new thread's rollout at its first turn. Until then the thread exists only @@ -4062,7 +4063,7 @@ export class CodexAppServerAgentSession implements AgentSession { this.speedModels = CodexModelListResponseSchema.parse(await client.request("model/list", {})).data ?? []; this.normalizeSpeed(); - await this.loadResolvedWorkspaceWrite(); + await this.loadResolvedConfig(); await this.loadCollaborationModes(); await this.loadSkills(); @@ -4093,7 +4094,7 @@ export class CodexAppServerAgentSession implements AgentSession { } } - private async loadResolvedWorkspaceWrite(): Promise { + private async loadResolvedConfig(): Promise { if (!this.client) return; try { const response = toObjectRecord( @@ -4101,11 +4102,25 @@ export class CodexAppServerAgentSession implements AgentSession { ); const config = toObjectRecord(response?.config); this.resolvedWorkspaceWrite = readSandboxWorkspaceWrite(config?.sandbox_workspace_write); + this.configuredDeveloperInstructions = + typeof config?.developer_instructions === "string" + ? config.developer_instructions + : undefined; } catch (error) { - this.logger.debug({ error }, "Failed to read resolved Codex workspace-write config"); + this.logger.debug({ error }, "Failed to read resolved Codex config"); } } + /** + * Codex uses a thread's developerInstructions in place of the developer_instructions in its + * config, so Paseo's instructions carry the configured ones ahead of them. + */ + private threadDeveloperInstructions(): string | undefined { + const paseoInstructions = composeAgentSystemPrompt(this.config); + if (!paseoInstructions) return undefined; + return composeSystemPromptParts(this.configuredDeveloperInstructions, paseoInstructions); + } + private rememberResolvedSandboxPolicy(response: unknown): void { const sandbox = toObjectRecord(toObjectRecord(response)?.sandbox); this.resolvedSandboxPolicy = sandbox ?? null; @@ -4561,7 +4576,7 @@ export class CodexAppServerAgentSession implements AgentSession { // the unnamespaced key emitted by earlier Paseo versions. params.modelProvider = this.deps.customCodexConfig.model_provider; } - const developerInstructions = composeAgentSystemPrompt(this.config); + const developerInstructions = this.threadDeveloperInstructions(); if (developerInstructions) { params.developerInstructions = developerInstructions; } @@ -5526,7 +5541,7 @@ export class CodexAppServerAgentSession implements AgentSession { model: this.config.model ?? null, serviceTier: this.serviceTier, config: this.buildCodexInnerConfig(), - developerInstructions: composeAgentSystemPrompt(this.config), + developerInstructions: this.threadDeveloperInstructions(), userMessageTurns: this.codexUserMessageTurns(), threadRollbackAvailable: this.threadRollbackAvailable, setThreadId: async (threadId) => { @@ -6082,7 +6097,7 @@ export class CodexAppServerAgentSession implements AgentSession { const approvalPolicy = this.hasWorkflowModeOverride ? preset.approvalPolicy : undefined; const sandbox = this.hasWorkflowModeOverride ? preset.sandbox : undefined; const innerConfig = this.buildCodexInnerConfig(); - const developerInstructions = composeAgentSystemPrompt(this.config); + const developerInstructions = this.threadDeveloperInstructions(); const params: Record = { model, cwd: this.config.cwd ?? null,