Skip to content

Commit f8be63e

Browse files
committed
fix(openai-native): add logging for background resume and polling; classify permanent vs transient errors; chore(task): remove temporary debug log
1 parent 85ddaeb commit f8be63e

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/api/providers/openai-native.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,13 +1355,18 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
13551355
this.resumeCutoffSequence = undefined
13561356
throw e
13571357
}
1358-
} catch (err) {
1358+
} catch (err: any) {
13591359
// If terminal error, don't keep retrying resume; fall back to polling immediately
13601360
const delay = resumeBaseDelayMs * Math.pow(2, attempt)
1361+
const msg = err instanceof Error ? err.message : String(err)
1362+
13611363
if (isTerminalBackgroundError(err)) {
1364+
console.error(`[OpenAiNative][resume] terminal background error on attempt ${attempt + 1}: ${msg}`)
13621365
break
13631366
}
1364-
// Otherwise retry with backoff
1367+
1368+
// Otherwise retry with backoff (transient failure)
1369+
console.warn(`[OpenAiNative][resume] attempt ${attempt + 1} failed; retrying in ${delay}ms: ${msg}`)
13651370
if (delay > 0) {
13661371
await new Promise((r) => setTimeout(r, delay))
13671372
}
@@ -1479,12 +1484,31 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
14791484
const msg = detail ? `Response ${status}: ${detail}` : `Response ${status}: ${respId || responseId}`
14801485
throw createTerminalBackgroundError(msg)
14811486
}
1482-
} catch (err) {
1487+
} catch (err: any) {
14831488
// If we've already emitted a terminal status, propagate to consumer to stop polling.
14841489
if (lastEmittedStatus === "failed" || lastEmittedStatus === "canceled") {
14851490
throw err
14861491
}
1487-
// Otherwise ignore transient poll errors
1492+
1493+
// Classify polling errors and log appropriately
1494+
const statusCode = err?.status ?? err?.response?.status
1495+
const msg = err instanceof Error ? err.message : String(err)
1496+
1497+
// Permanent errors: stop polling
1498+
if (statusCode === 401 || statusCode === 403 || statusCode === 404) {
1499+
console.error(`[OpenAiNative][poll] permanent error (status ${statusCode}); stopping: ${msg}`)
1500+
throw createTerminalBackgroundError(`Polling failed with status ${statusCode}: ${msg}`)
1501+
}
1502+
1503+
// Rate limit: transient, will retry
1504+
if (statusCode === 429) {
1505+
console.warn(`[OpenAiNative][poll] rate limited; will retry: ${msg}`)
1506+
} else {
1507+
// Other transient/network errors
1508+
console.warn(
1509+
`[OpenAiNative][poll] transient error; will retry${statusCode ? ` (status ${statusCode})` : ""}: ${msg}`,
1510+
)
1511+
}
14881512
}
14891513

14901514
// Stop polling immediately on terminal background statuses

src/core/task/Task.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
19141914
// lastMessage.ts = Date.now() DO NOT update ts since it is used as a key for virtuoso list
19151915
lastMessage.partial = false
19161916
// instead of streaming partialMessage events, we do a save and post like normal to persist to disk
1917-
console.log("updating partial message", lastMessage)
19181917
}
19191918

19201919
// Update `api_req_started` to have cancelled and cost, so that

0 commit comments

Comments
 (0)