@devries-cameron20 / t3code-1 / commits / 04be2b365f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): Codex and Pi runs report the model the provider ran (#34489)

Julius Marminge committed Nov 11, 2026 at 15:54 UTC 04be2b365fbddac76f48f81490660018b947d322
4 files changed +114 -4
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+68
@@ -2266,6 +2266,74 @@ describe("CodexAdapterV2 post-settle continuation", () => {
2266 ),
2267 );
2268
2269 + it.effect("records the model Codex reports on the root provider turn", () =>
2270 + Effect.scoped(
2271 + Effect.gen(function* () {
2272 + const nativeThreadId = "reported-model-thread";
2273 + const nativeTurnId = "reported-model-turn";
2274 + const transcript = makeCodexReplayTranscript({
2275 + scenario: "codex-reported-model",
2276 + entries: [
2277 + ...codexReplayPreamble({ nativeThreadId, nativeTurnId, prompt: "say hi" }),
2278 + {
2279 + type: "emit_inbound",
2280 + label: "rerouted",
2281 + frame: {
2282 + method: "model/rerouted",
2283 + params: {
2284 + threadId: nativeThreadId,
2285 + turnId: nativeTurnId,
2286 + fromModel: "gpt-6-astra",
2287 + toModel: "gpt-5.6-sol",
2288 + reason: "highRiskCyberActivity",
2289 + },
2290 + },
2291 + },
2292 + {
2293 + type: "emit_inbound",
2294 + label: "complete",
2295 + frame: {
2296 + method: "turn/completed",
2297 + params: {
2298 + threadId: nativeThreadId,
2299 + turn: makeCodexReplayTurn({ id: nativeTurnId, status: "completed" }),
2300 + },
2301 + },
2302 + },
2303 + ],
2304 + });
2305 + const harness = yield* makeCodexReplayHarness(transcript);
2306 + yield* harness.runtime.startTurn(
2307 + makeCodexTestTurnInput({
2308 + threadId: harness.threadId,
2309 + providerThread: harness.providerThread,
2310 + now: yield* DateTime.now,
2311 + attemptId: RunAttemptId.make("reported-model-attempt"),
2312 + text: "say hi",
2313 + }),
2314 + );
2315 + yield* harness.firstTerminal;
2316 + const completed = harness.events.find(
2317 + (event) =>
2318 + event.type === "provider_turn.updated" && event.providerTurn.status === "completed",
2319 + );
2320 + assert.equal(completed?.type, "provider_turn.updated");
2321 + if (completed?.type !== "provider_turn.updated") return;
2322 + assert.deepEqual(completed.providerTurn.turnTokenUsage?.models, ["gpt-5.6-sol"]);
2323 + assert.equal(completed.providerTurn.model, "gpt-5.6-sol");
2324 + }).pipe(
2325 + Effect.provide(
2326 + Layer.mergeAll(
2327 + IdAllocator.layer,
2328 + McpProviderSessions.layer,
2329 + NodeServices.layer,
2330 + NodeCrypto.layer,
2331 + ),
2332 + ),
2333 + ),
2334 + ),
2335 + );
2336 +
2337 it.effect("stops asking for commands the user allowed for the session", () =>
2338 Effect.scoped(
2339 Effect.gen(function* () {
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+3 -4
@@ -6451,6 +6451,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
6451 nativeThreadId != null &&
6452 (goalsByNativeThread.get(nativeThreadId)?.status === "active" ||
6453 (activation !== undefined && !activation.stopped));
6454 + const executedModel = reportedTurnModel(nativeThreadId ?? "", input.nativeTurnId);
6455 const completedTurn: OrchestrationV2ProviderTurn = {
6456 id: input.context.providerTurnId,
6457 providerThreadId: input.context.providerThread.id,
@@ -6473,11 +6474,9 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
6474 ),
6475 input.nativeTurnId,
6476 input.status === "completed",
6476 - reportedTurnModel(
6477 - input.context.providerThread.nativeThreadRef?.nativeId ?? "",
6478 - input.nativeTurnId,
6479 - ),
6477 + executedModel,
6478 ),
6479 + ...(executedModel === undefined ? {} : { model: executedModel }),
6480 };
6481 if (!holdsForGoal) {
6482 yield* emitProviderEvent({
packages/provider-pi/src/server/adapter.test.ts
+35
@@ -3384,6 +3384,41 @@ describe("PiAdapterV2", () => {
3384 }).pipe(Effect.scoped, Effect.provide(layerTest)),
3385 );
3386
3387 + it.effect("records the model Pi reports on the completed provider turn", () =>
3388 + Effect.gen(function* () {
3389 + const fake = yield* makeFakePi;
3390 + const { runtime, takeEvent } = yield* openRuntime(fake);
3391 + const providerThread = yield* runtime.ensureThread({
3392 + threadId: THREAD_ID,
3393 + modelSelection: modelSelection("default"),
3394 + runtimePolicy,
3395 + });
3396 + yield* startTurn(runtime, providerThread);
3397 + yield* fake.takeRequest("prompt");
3398 + yield* fake.emit({ type: "response", command: "prompt", success: true });
3399 + yield* fake.emit({ type: "agent_start" });
3400 + yield* fake.emit({
3401 + type: "message_end",
3402 + message: {
3403 + role: "assistant",
3404 + provider: "anthropic",
3405 + model: "model-b",
3406 + content: [{ type: "text", text: "done" }],
3407 + stopReason: "stop",
3408 + },
3409 + });
3410 + yield* fake.emit({ type: "agent_settled" });
3411 + const turn = yield* takeEvent(
3412 + (event) =>
3413 + event.type === "provider_turn.updated" && event.providerTurn.status === "completed",
3414 + );
3415 + assert.equal(
3416 + turn.type === "provider_turn.updated" ? turn.providerTurn.model : null,
3417 + "anthropic/model-b",
3418 + );
3419 + }).pipe(Effect.scoped, Effect.provide(layerTest)),
3420 + );
3421 +
3422 it.effect.each(["turn window", "full tree"] as const)(
3423 "finishes a turn whose %s has a parentId cycle",
3424 (cycleIn) =>
packages/provider-pi/src/server/adapter.ts
+8
@@ -378,6 +378,8 @@ interface ActivePiTurn {
378 /** Steers Pi queued in send order; it reads them at a step boundary, after running tools return. */
379 readonly unreadSteers: Array<MessageId>;
380 stopTreeRefs?: PiTurnTreeRefs | null;
381 + /** The provider/model Pi reported on its latest assistant message. */
382 + reportedModel?: string;
383 }
384
385 interface PiTurnTreeRefs {
@@ -1753,6 +1755,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
1755 status: interrupted ? "interrupted" : failure !== null ? "failed" : "completed",
1756 completedAt,
1757 ...(tokenUsage === undefined ? {} : { tokenUsage }),
1758 + ...(turn.reportedModel === undefined ? {} : { model: turn.reportedModel }),
1759 },
1760 });
1761 yield* updateProviderThread(
@@ -2007,6 +2010,11 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
2010 const message = event["message"];
2011 if (recordString(message, "role") !== "assistant") return;
2012 yield* completeOpenStreamItems(turn);
2013 + const reportedProvider = recordString(message, "provider");
2014 + const reportedModelId = recordString(message, "model");
2015 + if (reportedProvider && reportedModelId) {
2016 + turn.reportedModel = `${reportedProvider}/${reportedModelId}`;
2017 + }
2018 if (recordString(message, "stopReason") === "error" && turn.failure === null) {
2019 turn.failure = makeProviderFailure({
2020 message: recordString(message, "errorMessage") ?? "Pi reported a model error.",