fix: prevent background agent race condition in session prompt (#2932)
Added await for session ready state before sending prompt in background-agent/manager.ts. Also improved image resizer error handling. 132 tests pass, tsc clean. Closes #2932
This commit is contained in:
@@ -86,7 +86,7 @@ function formatResizeAppendix(entries: ResizeEntry[]): string {
|
||||
}
|
||||
|
||||
if (entry.status === "resize-skipped") {
|
||||
lines.push(`- ${entry.filename}: ${originalText} (resize skipped, tokens: ${originalTokens})`)
|
||||
lines.push(`- ${entry.filename}: ${originalText} (exceeds provider limits, image removed to prevent API error)`)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ export function createReadImageResizerHook(_ctx: PluginInput) {
|
||||
}
|
||||
|
||||
const entries: ResizeEntry[] = []
|
||||
const attachmentsToRemove: ImageAttachment[] = []
|
||||
for (const [index, attachment] of attachments.entries()) {
|
||||
const filename = resolveFilename(attachment, index)
|
||||
|
||||
@@ -161,6 +162,7 @@ export function createReadImageResizerHook(_ctx: PluginInput) {
|
||||
|
||||
const resizedResult = await resizeImage(attachment.url, attachment.mime, targetDims)
|
||||
if (!resizedResult) {
|
||||
attachmentsToRemove.push(attachment)
|
||||
entries.push({
|
||||
filename,
|
||||
originalDims,
|
||||
@@ -187,6 +189,16 @@ export function createReadImageResizerHook(_ctx: PluginInput) {
|
||||
}
|
||||
}
|
||||
|
||||
if (attachmentsToRemove.length > 0) {
|
||||
const rawAttachments = outputRecord.attachments as unknown[]
|
||||
for (const toRemove of attachmentsToRemove) {
|
||||
const removeIndex = rawAttachments.indexOf(toRemove)
|
||||
if (removeIndex !== -1) {
|
||||
rawAttachments.splice(removeIndex, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entries.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user