Skip to content

Commit f1a30bb

Browse files
committed
chore(openai-native,task): guard debug logs behind flag and extract GPT-5 model prefix constant; no behavior change
1 parent c2ec3d9 commit f1a30bb

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/api/providers/openai-native.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
4141
private responseIdPromise: Promise<string | undefined> | undefined
4242
private responseIdResolver: ((value: string | undefined) => void) | undefined
4343

44+
// Internal debug logger for conditional diagnostics
45+
private logDebug(...args: any[]): void {
46+
if (DEBUG_RESPONSES_API) {
47+
console.debug(...args)
48+
}
49+
}
50+
4451
// Event types handled by the shared event processor to avoid duplication
4552
private readonly coreHandledEventTypes = new Set<string>([
4653
"response.text.delta",
@@ -268,11 +275,9 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
268275

269276
if (is400Error && requestBody.previous_response_id && isPreviousResponseError) {
270277
// Log the error and retry without the previous_response_id
271-
if (DEBUG_RESPONSES_API) {
272-
console.debug(
273-
`[Responses API] Previous response ID not found (${requestBody.previous_response_id}), retrying without it`,
274-
)
275-
}
278+
this.logDebug(
279+
`[Responses API] Previous response ID not found (${requestBody.previous_response_id}), retrying without it`,
280+
)
276281

277282
// Remove the problematic previous_response_id and retry
278283
const retryRequestBody = { ...requestBody }
@@ -442,11 +447,9 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
442447

443448
if (response.status === 400 && requestBody.previous_response_id && isPreviousResponseError) {
444449
// Log the error and retry without the previous_response_id
445-
if (DEBUG_RESPONSES_API) {
446-
console.debug(
447-
`[Responses API] Previous response ID not found (${requestBody.previous_response_id}), retrying without it`,
448-
)
449-
}
450+
this.logDebug(
451+
`[Responses API] Previous response ID not found (${requestBody.previous_response_id}), retrying without it`,
452+
)
450453

451454
// Remove the problematic previous_response_id and retry
452455
const retryRequestBody = { ...requestBody }

src/core/task/Task.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ import { Gpt5Metadata, ClineMessageWithMetadata } from "./types"
106106

107107
const MAX_EXPONENTIAL_BACKOFF_SECONDS = 600 // 10 minutes
108108
const DEFAULT_USAGE_COLLECTION_TIMEOUT_MS = 5000 // 5 seconds
109+
// Centralized GPT‑5 model prefix to avoid magic strings
110+
const GPT5_MODEL_PREFIX = "gpt-5"
109111

110112
export type TaskOptions = {
111113
provider: ClineProvider
@@ -2394,7 +2396,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
23942396
let previousResponseId: string | undefined = undefined
23952397
try {
23962398
const modelId = this.api.getModel().id
2397-
if (modelId && modelId.startsWith("gpt-5") && !this.skipPrevResponseIdOnce) {
2399+
if (modelId && modelId.startsWith(GPT5_MODEL_PREFIX) && !this.skipPrevResponseIdOnce) {
23982400
// Find the last assistant message that has a previous_response_id stored
23992401
const idx = findLastIndex(
24002402
this.clineMessages,
@@ -2580,7 +2582,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25802582
private async persistGpt5Metadata(reasoningMessage?: string): Promise<void> {
25812583
try {
25822584
const modelId = this.api.getModel().id
2583-
if (!modelId || !modelId.startsWith("gpt-5")) return
2585+
if (!modelId || !modelId.startsWith(GPT5_MODEL_PREFIX)) return
25842586

25852587
// Check if the API handler has a getLastResponseId method (OpenAiNativeHandler specific)
25862588
const handler = this.api as ApiHandler & { getLastResponseId?: () => string | undefined }
@@ -2633,4 +2635,4 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
26332635
public get taskAsk(): ClineMessage | undefined {
26342636
return this.idleAsk || this.resumableAsk || this.interactiveAsk
26352637
}
2636-
}
2638+
}

0 commit comments

Comments
 (0)