






















@@ -3255,9 +3255,11 @@ export async function runCodexAppServerAttempt(
32553255abort: () => runAbortController.abort("aborted"),
32563256};
32573257setActiveEmbeddedRun(params.sessionId, handle, params.sessionKey);
3258+const notifyUserMessagePersisted = createCodexAppServerUserMessagePersistenceNotifier(params);
32583259void mirrorPromptAtTurnStartBestEffort({
32593260 params,
32603261agentId: sessionAgentId,
3262+ notifyUserMessagePersisted,
32613263sessionKey: sandboxSessionKey,
32623264threadId: thread.threadId,
32633265turnId: activeTurnId,
@@ -3372,6 +3374,7 @@ export async function runCodexAppServerAttempt(
33723374await mirrorTranscriptBestEffort({
33733375 params,
33743376agentId: sessionAgentId,
3377+ notifyUserMessagePersisted,
33753378 result,
33763379sessionKey: contextSessionKey,
33773380threadId: thread.threadId,
@@ -6083,13 +6086,14 @@ function getCodexContextFileBasename(filePath: string): string {
60836086async function mirrorTranscriptBestEffort(params: {
60846087params: EmbeddedRunAttemptParams;
60856088agentId?: string;
6089+notifyUserMessagePersisted: (message: Extract<AgentMessage, { role: "user" }>) => void;
60866090result: EmbeddedRunAttemptResult;
60876091sessionKey?: string;
60886092threadId: string;
60896093turnId: string;
60906094}): Promise<void> {
60916095try {
6092-await mirrorCodexAppServerTranscript({
6096+const mirrorResult = await mirrorCodexAppServerTranscript({
60936097sessionFile: params.params.sessionFile,
60946098agentId: params.agentId,
60956099sessionKey: params.sessionKey,
@@ -6104,27 +6108,38 @@ async function mirrorTranscriptBestEffort(params: {
61046108idempotencyScope: `codex-app-server:${params.threadId}`,
61056109config: params.params.config,
61066110});
6111+for (const message of mirrorResult.userMessagesPresent) {
6112+params.notifyUserMessagePersisted(message);
6113+}
61076114} catch (error) {
61086115embeddedAgentLog.warn("failed to mirror codex app-server transcript", { error });
61096116}
61106117}
611161186112-function notifyCodexAppServerUserMessagePersisted(params: {
6113-message: Extract<AgentMessage, { role: "user" }>;
6114-runParams: EmbeddedRunAttemptParams;
6115-}) {
6116-try {
6117-params.runParams.onUserMessagePersisted?.(params.message);
6118-} catch (error) {
6119-embeddedAgentLog.warn("codex app-server user persistence notification failed", {
6120-error: formatErrorMessage(error),
6121-});
6122-}
6119+function createCodexAppServerUserMessagePersistenceNotifier(
6120+runParams: EmbeddedRunAttemptParams,
6121+): (message: Extract<AgentMessage, { role: "user" }>) => void {
6122+let notified = false;
6123+return (message) => {
6124+if (notified) {
6125+return;
6126+}
6127+notified = true;
6128+runParams.userTurnTranscriptRecorder?.markRuntimePersisted(message);
6129+try {
6130+runParams.onUserMessagePersisted?.(message);
6131+} catch (error) {
6132+embeddedAgentLog.warn("codex app-server user persistence notification failed", {
6133+error: formatErrorMessage(error),
6134+});
6135+}
6136+};
61236137}
6124613861256139async function mirrorPromptAtTurnStartBestEffort(params: {
61266140params: EmbeddedRunAttemptParams;
61276141agentId?: string;
6142+notifyUserMessagePersisted: (message: Extract<AgentMessage, { role: "user" }>) => void;
61286143sessionKey?: string;
61296144threadId: string;
61306145turnId: string;
@@ -6147,10 +6162,7 @@ async function mirrorPromptAtTurnStartBestEffort(params: {
61476162config: params.params.config,
61486163});
61496164for (const message of mirrorResult.userMessagesPresent) {
6150-notifyCodexAppServerUserMessagePersisted({
6151-runParams: params.params,
6152- message,
6153-});
6165+params.notifyUserMessagePersisted(message);
61546166}
61556167})();
61566168params.params.userTurnTranscriptRecorder?.markRuntimePersistencePending(mirrorPromise);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。