From d14bebc154c8c7fdb1afcc001147fabced683d41 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Sun, 15 Nov 2026 15:51:59 +0100 Subject: [PATCH] fix(codex): retain instructions after rewinding A rewind forks the native thread, which does not inherit its parent launch instructions. Pass the current instructions to the fork. --- .../providers/codex-app-server-agent.test.ts | 7 +++++++ .../agent/providers/codex-app-server-agent.ts | 21 +++++-------------- .../server/agent/providers/codex/rewind.ts | 2 ++ 3 files changed, 14 insertions(+), 16 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 10ffc7bde7..fbed0a4005 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 @@ -2939,6 +2939,9 @@ describe("Codex app-server provider", () => { const session = new CodexAppServerAgentSession( createConfig({ cwd: "/workspace/project", + systemPrompt: "Agent instructions", + daemonAppendSystemPrompt: "Daemon instructions", + pluginAppendSystemPrompt: ["Plugin instructions"], mcpServers: { paseo: { type: "http", url: "http://127.0.0.1:6767/mcp/agents?callerAgentId=agent-1" }, }, @@ -2970,6 +2973,10 @@ describe("Codex app-server provider", () => { await session.revertConversation({ messageId: "codex-first" }); + const forkRequest = appServer.requests().find((request) => request.method === "thread/fork"); + expect(forkRequest?.params).toMatchObject({ + developerInstructions: "Agent instructions\n\nDaemon instructions\n\nPlugin instructions", + }); const forkConfigs = appServer .requests() .filter((request) => request.method === "thread/fork") 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 738dbd3120..4708dda1e7 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 @@ -55,7 +55,7 @@ import path from "node:path"; import { isDeepStrictEqual } from "node:util"; import { z } from "zod"; import { renderPromptAttachmentAsText } from "../prompt-attachments.js"; -import { composeSystemPromptParts } from "../system-prompt.js"; +import { composeAgentSystemPrompt } from "../system-prompt.js"; import { CodexAsyncQuestions, codexAsyncQuestionToTimeline } from "./codex/async-questions.js"; import { fileChangesToPreview, @@ -4314,11 +4314,7 @@ export class CodexAppServerAgentSession implements AgentSession { // the unnamespaced key emitted by earlier Paseo versions. params.modelProvider = this.deps.customCodexConfig.model_provider; } - const developerInstructions = composeSystemPromptParts( - this.config.systemPrompt, - this.config.daemonAppendSystemPrompt, - ...(this.config.pluginAppendSystemPrompt ?? []), - ); + const developerInstructions = composeAgentSystemPrompt(this.config); if (developerInstructions) { params.developerInstructions = developerInstructions; } @@ -4486,11 +4482,7 @@ export class CodexAppServerAgentSession implements AgentSession { if (options?.outputSchema) { params.outputSchema = normalizeCodexOutputSchema(options.outputSchema); } - const developerInstructions = composeSystemPromptParts( - this.config.systemPrompt, - this.config.daemonAppendSystemPrompt, - ...(this.config.pluginAppendSystemPrompt ?? []), - ); + const developerInstructions = composeAgentSystemPrompt(this.config); if (developerInstructions) { params.developerInstructions = developerInstructions; } @@ -5282,6 +5274,7 @@ export class CodexAppServerAgentSession implements AgentSession { model: this.config.model ?? null, serviceTier: this.serviceTier, config: this.buildCodexInnerConfig(), + developerInstructions: composeAgentSystemPrompt(this.config), userMessageTurns: this.codexUserMessageTurns(), threadRollbackAvailable: this.threadRollbackAvailable, setThreadId: async (threadId) => { @@ -5829,11 +5822,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 = composeSystemPromptParts( - this.config.systemPrompt, - this.config.daemonAppendSystemPrompt, - ...(this.config.pluginAppendSystemPrompt ?? []), - ); + const developerInstructions = composeAgentSystemPrompt(this.config); const params: Record = { model, cwd: this.config.cwd ?? null, diff --git a/packages/server/src/server/agent/providers/codex/rewind.ts b/packages/server/src/server/agent/providers/codex/rewind.ts index a22931b92b..bdff3c0c5d 100644 --- a/packages/server/src/server/agent/providers/codex/rewind.ts +++ b/packages/server/src/server/agent/providers/codex/rewind.ts @@ -49,6 +49,7 @@ export async function revertCodexConversation(input: { model?: string | null; serviceTier?: string | null; config?: Record | null; + developerInstructions?: string; userMessageTurns: CodexUserMessageTurnIndex; threadRollbackAvailable: boolean; setThreadId: (threadId: string) => void | Promise; @@ -76,6 +77,7 @@ export async function revertCodexConversation(input: { model: input.model ?? null, serviceTier: input.serviceTier ?? null, ...(input.config ? { config: input.config } : {}), + ...(input.developerInstructions ? { developerInstructions: input.developerInstructions } : {}), // Paseo re-reads the rewound thread through paged history, not the fork reply. excludeTurns: true, persistExtendedHistory: true,