Skip to content

Commit 8f4d994

Browse files
fix(server): Codex and Pi runs report the model the provider ran
The MCP executedModel reads the provider turn's model, which only the Claude adapter set. Codex now writes the reported or rerouted model it already put in turnTokenUsage.models onto the provider turn's model, and Pi records the provider/model from its assistant message_end on the terminal provider turn. Fixes #34280 AI-assisted; verified with the tests and tools listed above.
1 parent f5d700f commit 8f4d994

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,6 +6393,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
63936393
nativeThreadId != null &&
63946394
(goalsByNativeThread.get(nativeThreadId)?.status === "active" ||
63956395
(activation !== undefined && !activation.stopped));
6396+
const executedModel = reportedTurnModel(nativeThreadId ?? "", input.nativeTurnId);
63966397
const completedTurn: OrchestrationV2ProviderTurn = {
63976398
id: input.context.providerTurnId,
63986399
providerThreadId: input.context.providerThread.id,
@@ -6415,11 +6416,9 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
64156416
),
64166417
input.nativeTurnId,
64176418
input.status === "completed",
6418-
reportedTurnModel(
6419-
input.context.providerThread.nativeThreadRef?.nativeId ?? "",
6420-
input.nativeTurnId,
6421-
),
6419+
executedModel,
64226420
),
6421+
...(executedModel === undefined ? {} : { model: executedModel }),
64236422
};
64246423
if (!holdsForGoal) {
64256424
yield* emitProviderEvent({

‎packages/provider-pi/src/server/adapter.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ interface ActivePiTurn {
378378
/** Steers Pi queued in send order; it reads them at a step boundary, after running tools return. */
379379
readonly unreadSteers: Array<MessageId>;
380380
stopTreeRefs?: PiTurnTreeRefs | null;
381+
/** The provider/model Pi reported on its latest assistant message. */
382+
reportedModel?: string;
381383
}
382384

383385
interface PiTurnTreeRefs {
@@ -1753,6 +1755,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
17531755
status: interrupted ? "interrupted" : failure !== null ? "failed" : "completed",
17541756
completedAt,
17551757
...(tokenUsage === undefined ? {} : { tokenUsage }),
1758+
...(turn.reportedModel === undefined ? {} : { model: turn.reportedModel }),
17561759
},
17571760
});
17581761
yield* updateProviderThread(
@@ -2001,6 +2004,11 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
20012004
const message = event["message"];
20022005
if (recordString(message, "role") !== "assistant") return;
20032006
yield* completeOpenStreamItems(turn);
2007+
const reportedProvider = recordString(message, "provider");
2008+
const reportedModelId = recordString(message, "model");
2009+
if (reportedProvider && reportedModelId) {
2010+
turn.reportedModel = `${reportedProvider}/${reportedModelId}`;
2011+
}
20042012
if (recordString(message, "stopReason") === "error" && turn.failure === null) {
20052013
turn.failure = makeProviderFailure({
20062014
message: recordString(message, "errorMessage") ?? "Pi reported a model error.",

0 commit comments

Comments
 (0)