jackwener/OpenCLI · error · CommandExecutionError

Midjourney reference upload fallback lost its transfer buffe

Error message

Midjourney reference upload fallback lost its transfer buffer

What it means

While streaming the file to the in-page transfer buffer in base64 chunks, each append is verified: the page-side code re-reads window[uploadKey][fileIndex] and pushes the chunk. If any append returns false — the buffer entry vanished or its chunks array is gone — this CommandExecutionError is thrown, since the partial upload would be corrupt.

Source

Thrown at clis/midjourney/utils.js:1016

        const files = window[key];
        if (!Array.isArray(files)) return -1;
        files.push({ ...item, chunks: [] });
        return files.length - 1;
      }, uploadKey, descriptor));
      if (!Number.isInteger(fileIndex) || fileIndex < 0) {
        throw new CommandExecutionError('Midjourney reference upload fallback could not initialize its transfer buffer');
      }
      const base64 = (await fs.readFile(localPath)).toString('base64');
      const chunkSize = 96 * 1024;
      for (let offset = 0; offset < base64.length; offset += chunkSize) {
        const chunk = base64.slice(offset, offset + chunkSize);
        const appended = unwrapEvaluateResult(await page.evaluate((key, index, value) => {
          const file = window[key]?.[index];
          if (!file || !Array.isArray(file.chunks)) return false;
          file.chunks.push(value);
          return true;
        }, uploadKey, fileIndex, chunk));
        if (!appended) throw new CommandExecutionError('Midjourney reference upload fallback lost its transfer buffer');
      }
    }
    const result = unwrapEvaluateResult(await page.evaluate((key) => {
    const input = document.querySelector('[data-opencli-image-input="1"]');
    if (!(input instanceof HTMLInputElement)) return { ok: false, reason: 'image file input not found' };
    const transfer = new DataTransfer();
    for (const item of window[key] || []) {
      const binary = atob(item.chunks.join(''));
      const bytes = new Uint8Array(binary.length);
      for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
      transfer.items.add(new File([bytes], item.name, { type: item.mime }));
    }
    input.files = transfer.files;
    const nativeEvent = new Event('change', { bubbles: true });
    const propsKey = Object.keys(input).find((key) => key.startsWith('__reactProps$'));
    if (propsKey && typeof input[propsKey]?.onChange === 'function') {
      input[propsKey].onChange({ target: input, currentTarget: input, nativeEvent });
    } else {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the upload; ensure no navigation or reload happens during the transfer
  2. Avoid triggering other actions in the page while the upload is streaming
  3. Use smaller images (fewer chunks, shorter transfer window) to reduce exposure
  4. Update the CLI if the page environment changed how window state persists

Example fix

// before
uploadPromise = uploadReferences(page, refs);
await page.reload(); // wipes window buffer mid-transfer
// after
await uploadReferences(page, refs); // wait for transfer to finish first
await page.reload();
Defensive patterns

Strategy: retry

Validate before calling

// before starting, ensure the buffer exists and will not be disturbed
const ready = await page.evaluate((k) => Array.isArray(window[k]) && window[k].length > 0, uploadKey);
if (!ready) throw new Error('Transfer buffer missing before chunked upload');

Type guard

null

Try / catch

try {
  await uploadLocalReference(page, localPath, descriptor);
} catch (e) {
  if (String(e.message).includes('lost its transfer buffer')) {
    await page.reload();
    await uploadLocalReference(page, localPath, descriptor); // restart transfer cleanly
  } else throw e;
}

Prevention

When it happens

Trigger: The page navigated or the execution context was destroyed mid-transfer, another script cleared window[uploadKey] between chunks, or the file entry was replaced with an object lacking a chunks array.

Common situations: Large files taking many chunks while the SPA re-renders or the user clicks something that reloads state, HMR/dev reloads clearing window state, or concurrent upload attempts overwriting the same key.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/49db24ef4424c9e1. Report an issue: GitHub.