Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Oct 10, 2025

Summary

Adds GPT-5 Pro model with OpenAI Responses API background mode support. Background requests can take several minutes, so this implements resilient streaming with automatic recovery.

Why

GPT-5 Pro is a slow, reasoning-focused model that can take several minutes to respond. The standard streaming approach times out or appears stuck. OpenAI's Responses API background mode is designed for these long-running requests.

What Changed

Model Addition

  • Added gpt-5-pro-2025-10-06 with backgroundMode: true flag in model metadata

Background Mode Implementation

  • Auto-enables background: true, stream: true, store: true for flagged models
  • Emits status events: queuedin_progresscompleted/failed
  • Shows status labels in UI spinner ("background mode (queued)…", etc.)

Resilient Streaming

  • Auto-resume: If stream drops, resumes from last sequence number using GET /v1/responses/{id}?starting_after={seq}
  • Poll fallback: If resume fails after 3 retries, polls every 2s until completion (up to 20 minutes)
  • Synthesizes final output and usage data when polling completes

Files Changed

  • packages/types/src/providers/openai.ts - Model metadata
  • src/api/providers/openai-native.ts - Background mode logic, auto-resume, polling
  • src/core/task/Task.ts - Status event handling
  • webview-ui/src/utils/backgroundStatus.ts - Status label mapping
  • webview-ui/src/components/chat/* - UI status display

Testing

  • Background mode status emission and lifecycle
  • Auto-resume on stream drop with exponential backoff
  • Poll fallback when resume exhausts retries
  • Usage tracking parity with non-background requests
  • UI status label mapping
image

Important

Adds GPT-5 Pro model with background mode, implementing resilient streaming and UI updates for status tracking.

  • Behavior:
    • Adds gpt-5-pro-2025-10-06 model with backgroundMode: true in openai.ts.
    • Implements background mode with auto-resume and polling in openai-native.ts.
    • UI updates in ChatRow.tsx and ChatView.tsx for background status display.
  • Resilient Streaming:
    • Auto-resume from last sequence number on stream drop.
    • Polls every 2s for up to 20 minutes if resume fails.
  • UI:
    • Displays background mode status in chat UI with labels like "queued", "in_progress", etc.
    • Updates ChatRow.tsx and ChatView.tsx to handle new status labels.
  • Testing:
    • Adds tests in backgroundStatus.spec.ts for status label mapping.
    • Tests for auto-resume and polling in openai-native.spec.ts.

This description was created by Ellipsis for 706138e. You can customize this summary. It will automatically update as commits are pushed.

Copilot AI review requested due to automatic review settings October 10, 2025 20:02
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Enhancement New feature or request labels Oct 10, 2025

This comment was marked as outdated.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 10, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 10, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Oct 10, 2025
@hannesrudolph hannesrudolph moved this from PR [Needs Review] to PR [Needs Prelim Review] in Roo Code Roadmap Oct 10, 2025
@hannesrudolph hannesrudolph moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Oct 10, 2025
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Oct 10, 2025
@hannesrudolph hannesrudolph added PR - Draft / In Progress and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Oct 10, 2025
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 12, 2025
@hannesrudolph
Copy link
Collaborator Author

Any update? When will the pr merged?

Not sure yet. Will look at it after we get Native Tool Calling out later this week. Sorry for the delay.

…for long-running models (e.g., gpt-5-pro)

- Introduce ModelInfo.disableTimeout to opt out of request timeouts on a per-model basis
- Apply in OpenAI-compatible, Ollama, and LM Studio providers (timeout=0 when flag is true)
- Preserve global “API Request Timeout” behavior (0 still disables globally); per-model flag takes precedence for that model
- Motivation: gpt-5-pro often requires longer runtimes; per-model override avoids forcing a global setting that impacts all models
- Add/extend unit tests to validate provider behavior
…nd non‑streaming notice

- Add GPT‑5 Pro to model registry with:
  - contextWindow: 400k, maxTokens: 272k
  - supportsImages: true, supportsPromptCache: true, supportsVerbosity: true, supportsTemperature: false
  - reasoningEffort: high (Responses API only)
  - pricing: $15/1M input tokens, $120/1M output tokens
- Set disableTimeout: true to avoid requiring a global timeout override
- Description clarifies: this is a slow, reasoning‑focused model designed for tough problems; requests may take several minutes; it does not stream (UI may appear idle until completion)
…-5-pro model entry (server-side timeouts). Prep for background mode approach.
Enable OpenAI Responses background mode with resilient streaming for GPT‑5 Pro and any model flagged via metadata.

Key changes:

- Background mode enablement

  • Auto-enable for models with info.backgroundMode === true (e.g., gpt-5-pro-2025-10-06) defined in [packages/types/src/providers/openai.ts](packages/types/src/providers/openai.ts).

  • Also respects manual override (openAiNativeBackgroundMode) from ProviderSettings/ApiHandlerOptions.

- Request shape (Responses API)

  • background:true, stream:true, store:true set in [OpenAiNativeHandler.buildRequestBody()](src/api/providers/openai-native.ts:224).

- Streaming UX and status events

  • New ApiStreamStatusChunk in [src/api/transform/stream.ts](src/api/transform/stream.ts) with statuses: queued, in_progress, completed, failed, canceled, reconnecting, polling.

  • Provider emits status chunks in SDK + SSE paths via [OpenAiNativeHandler.processEvent()](src/api/providers/openai-native.ts:1100) and [OpenAiNativeHandler.handleStreamResponse()](src/api/providers/openai-native.ts:651).

  • UI spinner shows background lifecycle labels in [webview-ui/src/components/chat/ChatRow.tsx](webview-ui/src/components/chat/ChatRow.tsx) using [webview-ui/src/utils/backgroundStatus.ts](webview-ui/src/utils/backgroundStatus.ts).

- Resilience: auto-resume + poll fallback

  • On stream drop for background tasks, attempt SSE resume using response.id and last sequence_number with exponential backoff in [OpenAiNativeHandler.attemptResumeOrPoll()](src/api/providers/openai-native.ts:1215).

  • If resume fails, poll GET /v1/responses/{id} every 2s until terminal and synthesize final output/usage.

  • Deduplicate resumed events via resumeCutoffSequence in [handleStreamResponse()](src/api/providers/openai-native.ts:737).

- Settings (no new UI switch)

  • Added optional provider settings and ApiHandlerOptions: autoResume, resumeMaxRetries, resumeBaseDelayMs, pollIntervalMs, pollMaxMinutes in [packages/types/src/provider-settings.ts](packages/types/src/provider-settings.ts) and [src/shared/api.ts](src/shared/api.ts).

- Cleanup

  • Removed VS Code contributes toggle for background mode; behavior now model-driven + programmatic override.

- Tests

  • Provider: coverage for background status emission, auto-resume success, resume→poll fallback, non-background negative in [src/api/providers/__tests__/openai-native.spec.ts](src/api/providers/__tests__/openai-native.spec.ts).

  • Usage parity unchanged validated in [src/api/providers/__tests__/openai-native-usage.spec.ts](src/api/providers/__tests__/openai-native-usage.spec.ts).

  • UI: label mapping tests for background statuses in [webview-ui/src/utils/__tests__/backgroundStatus.spec.ts](webview-ui/src/utils/__tests__/backgroundStatus.spec.ts).

Notes:

- Aligns with TEMP_OPENAI_BACKGROUND_TASK_DOCS.DM: background requires store=true; supports streaming resume via response.id + sequence_number.

- Default behavior unchanged for non-background models; no breaking changes.
…description, remove duplicate test, revert gitignore
…ded dep to useMemo; test: remove duplicate GPT-5 Pro background-mode test; chore(core): remove temp debug log
…background labels; fix deps warning in ChatRow useMemo
…assify permanent vs transient errors; chore(task): remove temporary debug log
…core/task): avoid full-state refresh on each background status chunk to reduce re-renders
@Lagyu
Copy link

Lagyu commented Dec 10, 2025

Not sure yet. Will look at it after we get Native Tool Calling out later this week. Sorry for the delay.

@hannesrudolph Thank you so much for your effort. I am looking forward to use this feature soon in production :)

@hannesrudolph
Copy link
Collaborator Author

Not sure yet. Will look at it after we get Native Tool Calling out later this week. Sorry for the delay.

@hannesrudolph Thank you so much for your effort. I am looking forward to use this feature soon in production :)

Feel free to give it a try in its current form. I have not tested it since I just updated it and have to run out! BBL

@Lagyu
Copy link

Lagyu commented Dec 11, 2025

@hannesrudolph Hi, I’ve been testing the gpt-5-pro branch with Azure OpenAI (Responses API, gpt-5-pro-2025-10-06 model and the same deployment name) and ran into an issue with background mode when openAiNativeBaseUrl already includes /v1 (e.g. https://<resource>.openai.azure.com/openai/v1/).

For long-running background responses, the initial responses.create call works, but when the stream is terminated and Roo tries to resume or poll, the URL becomes:

https://<resource>.openai.azure.com/openai/v1//v1/responses/{responseId}...

That extra /v1 causes Azure to return 404, so resume and polling both fail.

I tested the following change on src/api/providers/openai-native.ts locally and it fixes the issue for me with Azure while preserving the current behavior for https://api.openai.com:

@@
-	private normalizeUsage(usage: any, model: OpenAiNativeModel): ApiStreamUsageChunk | undefined {
+	private buildResponsesUrl(path: string): string {
+		const rawBase = this.options.openAiNativeBaseUrl || "https://api.openai.com"
+		// Normalize base by trimming trailing slashes
+		const normalizedBase = rawBase.replace(/\/+$/, "")
+		// If the base already ends with a version segment (e.g. /v1), do not append another
+		const hasVersion = /\/v\d+(?:\.\d+)?$/.test(normalizedBase)
+		const baseWithVersion = hasVersion ? normalizedBase : `${normalizedBase}/v1`
+		const normalizedPath = path.startsWith("/") ? path : `/${path}`
+		return `${baseWithVersion}${normalizedPath}`
+	}
+
+	private normalizeUsage(usage: any, model: OpenAiNativeModel): ApiStreamUsageChunk | undefined {
@@
-		const apiKey = this.options.openAiNativeApiKey ?? "not-provided"
-		const baseUrl = this.options.openAiNativeBaseUrl || "https://api.openai.com"
-		const url = `${baseUrl}/v1/responses`
+		const apiKey = this.options.openAiNativeApiKey ?? "not-provided"
+		const url = this.buildResponsesUrl("responses")
@@
-		const apiKey = this.options.openAiNativeApiKey ?? "not-provided"
-		const baseUrl = this.options.openAiNativeBaseUrl || "https://api.openai.com"
+		const apiKey = this.options.openAiNativeApiKey ?? "not-provided"
 		const resumeMaxRetries = this.options.openAiNativeBackgroundResumeMaxRetries ?? 3
 		const resumeBaseDelayMs = this.options.openAiNativeBackgroundResumeBaseDelayMs ?? 1000
@@
-				const resumeUrl = `${baseUrl}/v1/responses/${responseId}?stream=true&starting_after=${lastSeq}`
+				const resumeUrl = this.buildResponsesUrl(
+					`responses/${responseId}?stream=true&starting_after=${lastSeq}`,
+				)
@@
-				const pollRes = await fetch(`${baseUrl}/v1/responses/${responseId}`, {
+				const pollRes = await fetch(this.buildResponsesUrl(`responses/${responseId}`), {
 					method: "GET",
 					headers: {
 						Authorization: `Bearer ${apiKey}`,
 					},

Behavior-wise:

  • openAiNativeBaseUrl = "https://api.openai.com" → URLs become https://api.openai.com/v1/responses/... (same as today).
  • openAiNativeBaseUrl = "https://<resource>.openai.azure.com/openai/v1" → URLs become https://<resource>.openai.azure.com/openai/v1/responses/... (fixes the 404s).

If you’d prefer, I can also open a small PR from my fork targeting the gpt-5-pro branch with this change.


After applying the change above, everything has been working great with Azure OpenAI.
Thank you very much for the awesome implementation!

@hannesrudolph hannesrudolph marked this pull request as draft December 12, 2025 22:59
@hannesrudolph hannesrudolph moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Dec 12, 2025
@hannesrudolph
Copy link
Collaborator Author

Closing for now as it is way off from the current codebase.

@github-project-automation github-project-automation bot moved this from PR [Draft / In Progress] to Done in Roo Code Roadmap Jan 6, 2026
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Draft / In Progress size:XXL This PR changes 1000+ lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants