Skip to content

Commit 9d27ffc

Browse files
committed
fix: correct GPT-5 response ID persistence and usage
- Renamed metadata field from 'previous_response_id' to 'response_id' for clarity - Fixed logic to correctly use the response_id from the previous message as previous_response_id for the next request - This resolves the 'Previous response with id not found' errors that occurred after multiple turns in the same session
1 parent f749d35 commit 9d27ffc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/core/task/Task.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
17511751
presentAssistantMessage(this)
17521752
}
17531753

1754-
// Persist GPT‑5 per-turn metadata (previous_response_id, instructions)
1754+
// Persist GPT‑5 per-turn metadata (response_id, instructions)
17551755
try {
17561756
const modelId = this.api.getModel().id
17571757
if (modelId && modelId.startsWith("gpt-5")) {
@@ -1765,7 +1765,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
17651765
msg.metadata = msg.metadata ?? {}
17661766
msg.metadata.gpt5 = {
17671767
...(msg.metadata.gpt5 ?? {}),
1768-
previous_response_id: lastResponseId,
1768+
response_id: lastResponseId, // This is the response ID generated by THIS turn
17691769
instructions: this.lastUsedInstructions,
17701770
reasoning_summary: (reasoningMessage ?? "").trim() || undefined,
17711771
}
@@ -2074,16 +2074,16 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
20742074
try {
20752075
const modelId = this.api.getModel().id
20762076
if (modelId && modelId.startsWith("gpt-5") && !this.skipPrevResponseIdOnce) {
2077+
// Find the last assistant message that has a response_id stored
20772078
const idx = findLastIndex(
20782079
this.clineMessages,
2079-
(m) =>
2080-
m.type === "say" &&
2081-
(m as any).say === "text" &&
2082-
(m as any).metadata?.gpt5?.previous_response_id,
2080+
(m) => m.type === "say" && (m as any).say === "text" && (m as any).metadata?.gpt5?.response_id,
20832081
)
20842082
if (idx !== -1) {
2085-
previousResponseId = ((this.clineMessages[idx] as any).metadata.gpt5.previous_response_id ||
2086-
undefined) as string | undefined
2083+
// Use the response_id from the last assistant message as the previous_response_id for this request
2084+
previousResponseId = ((this.clineMessages[idx] as any).metadata.gpt5.response_id || undefined) as
2085+
| string
2086+
| undefined
20872087
}
20882088
}
20892089
} catch {

0 commit comments

Comments
 (0)