GeezerVison is showing github.com — fix(claude): include provider notices in fallback completion · pingdotgg/t3code@0a4c3a7
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2 packages/provider-core/src/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/SubagentProjection.test.ts +61-5Lines changed: 61 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | EventId, | 9 | 9 | TurnItemId, | 10 | 10 | type OrchestrationV2Run, | | 11 | + type OrchestrationV2TurnItem, | 11 | 12 | type OrchestrationV2AppThread, | 12 | 13 | ProjectId, | 13 | 14 | ProviderInstanceId, | @@ -357,27 +358,42 @@ it("exposes the provider failure rather than a progress message from the failed | 357 | 358 | }); | 358 | 359 |
| 359 | 360 | it.each([ | 360 | | - { requestedModel: "claude-opus-4-1", observedModel: undefined, provenance: "" }, | 361 | | - { requestedModel: "claude-opus-4-1", observedModel: "claude-opus-4-1", provenance: "" }, | | 361 | + { | | 362 | + requestedModel: "claude-opus-4-1", | | 363 | + observedModel: undefined, | | 364 | + fallbackNotice: null, | | 365 | + provenance: "", | | 366 | + }, | | 367 | + { | | 368 | + requestedModel: "claude-opus-4-1", | | 369 | + observedModel: "claude-opus-4-1", | | 370 | + fallbackNotice: null, | | 371 | + provenance: "", | | 372 | + }, | 362 | 373 | { | 363 | 374 | requestedModel: "claude-opus-5-5", | 364 | 375 | observedModel: "claude-sonnet-5-5", | 365 | | - provenance: "Requested model: claude-opus-5-5. Provider-reported model: claude-sonnet-5-5.\n\n", | | 376 | + fallbackNotice: | | 377 | + 'Model "claude-opus-5-5" is restricted by your organization\'s settings. Using claude-sonnet-5-5 instead.', | | 378 | + provenance: | | 379 | + 'Requested model: claude-opus-5-5. Provider-reported model: claude-sonnet-5-5.\nProvider notice: Model "claude-opus-5-5" is restricted by your organization\'s settings. Using claude-sonnet-5-5 instead.\n\n', | 366 | 380 | }, | 367 | 381 | { | 368 | 382 | requestedModel: "opus", | 369 | 383 | observedModel: "claude-opus-4-1", | | 384 | + fallbackNotice: null, | 370 | 385 | provenance: "Requested model: opus. Provider-reported model: claude-opus-4-1.\n\n", | 371 | 386 | }, | 372 | 387 | { | 373 | 388 | requestedModel: "claude-opus-4-1", | 374 | 389 | observedModel: "claude-opus-4-1[1m]", | | 390 | + fallbackNotice: null, | 375 | 391 | provenance: | 376 | 392 | "Requested model: claude-opus-4-1. Provider-reported model: claude-opus-4-1[1m].\n\n", | 377 | 393 | }, | 378 | 394 | ])( | 379 | 395 | "orders assistant messages and reports $requestedModel / $observedModel provenance", | 380 | | - ({ requestedModel, observedModel, provenance }) => { | | 396 | + ({ requestedModel, observedModel, fallbackNotice, provenance }) => { | 381 | 397 | const { projection, run } = taskFixture(); | 382 | 398 | const at = DateTime.makeUnsafe("2026-07-24T10:05:00.000Z"); | 383 | 399 | const message = (id: string, text: string, ordinal: number) => { | @@ -401,11 +417,51 @@ it.each([ | 401 | 417 | }; | 402 | 418 | const progress = message("progress", "Starting step 0.", 1); | 403 | 419 | const report = message("report", "All steps passed.", 2); | | 420 | + | | 421 | + const notice = { | | 422 | + id: TurnItemId.make("fallback-notice"), | | 423 | + threadId: run.threadId, | | 424 | + runId: run.id, | | 425 | + nodeId: run.rootNodeId, | | 426 | + providerThreadId: null, | | 427 | + providerTurnId: null, | | 428 | + nativeItemRef: null, | | 429 | + parentItemId: null, | | 430 | + ordinal: 0, | | 431 | + type: "system_notice", | | 432 | + status: "completed", | | 433 | + title: null, | | 434 | + message: fallbackNotice ?? "", | | 435 | + startedAt: at, | | 436 | + completedAt: at, | | 437 | + updatedAt: at, | | 438 | + } satisfies OrchestrationV2TurnItem; | | 439 | + const notices = [ | | 440 | + { | | 441 | + ...notice, | | 442 | + id: TurnItemId.make("other-run"), | | 443 | + runId: RunId.make("other"), | | 444 | + message: "Other run notice", | | 445 | + }, | | 446 | + { | | 447 | + ...notice, | | 448 | + id: TurnItemId.make("other-root"), | | 449 | + nodeId: NodeId.make("previous-root"), | | 450 | + message: "Previous attempt notice", | | 451 | + }, | | 452 | + { | | 453 | + ...notice, | | 454 | + id: TurnItemId.make("native-child"), | | 455 | + parentItemId: TurnItemId.make("native-task"), | | 456 | + message: "Native child notice", | | 457 | + }, | | 458 | + notice, | | 459 | + ]; | 404 | 460 | const result = subagentResultForRun( | 405 | 461 | { | 406 | 462 | ...projection, | 407 | 463 | messages: [progress.message, report.message], | 408 | | - turnItems: [report.turnItem, progress.turnItem], | | 464 | + turnItems: [report.turnItem, ...notices, progress.turnItem], | 409 | 465 | }, | 410 | 466 | { ...run, modelSelection: { ...run.modelSelection, model: requestedModel }, observedModel }, | 411 | 467 | ); | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-core/src/server/subagentProjection.ts +25-4Lines changed: 25 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -214,11 +214,32 @@ export function subagentResultForRun( | 214 | 214 | (run.status === "completed" | 215 | 215 | ? "Child task completed without an assistant result." | 216 | 216 | : `Child task ended with status ${run.status}.`); | | 217 | + | | 218 | + const hasModelMismatch = | | 219 | + run.observedModel != null && run.observedModel !== run.modelSelection.model; | | 220 | + const providerNotices = hasModelMismatch | | 221 | + ? projection.turnItems | | 222 | + .filter( | | 223 | + (item): item is Extract<OrchestrationV2TurnItem, { readonly type: "system_notice" }> => | | 224 | + item.type === "system_notice" && | | 225 | + item.runId === run.id && | | 226 | + run.rootNodeId !== null && | | 227 | + item.nodeId === run.rootNodeId && | | 228 | + item.parentItemId === null && | | 229 | + item.message.trim().length > 0, | | 230 | + ) | | 231 | + .toSorted((left, right) => left.ordinal - right.ordinal) | | 232 | + .map((item) => `Provider notice: ${item.message.trim()}`) | | 233 | + : []; | | 234 | + const provenance = hasModelMismatch | | 235 | + ? [ | | 236 | + `Requested model: ${run.modelSelection.model}. Provider-reported model: ${run.observedModel}.`, | | 237 | + ...providerNotices, | | 238 | + ].join("\n") + "\n\n" | | 239 | + : ""; | | 240 | + | 217 | 241 | return { | 218 | | - text: | 219 | | - run.observedModel !== undefined && run.observedModel !== run.modelSelection.model | 220 | | - ? `Requested model: ${run.modelSelection.model}. Provider-reported model: ${run.observedModel}.\n\n${text}` | 221 | | - : text, | | 242 | + text: `${provenance}${text}`, | 222 | 243 | messageId: failure === undefined ? (message?.id ?? turnItem?.messageId ?? null) : null, | 223 | 244 | turnItemId: failure?.id ?? turnItem?.id ?? null, | 224 | 245 | }; | |
|