Skip to content

fix(openai-chat): shrink oversized inline images while retaining source content - #4366

Merged
lidge-jun merged 20 commits into
devfrom
codex/260912-60plus-models-images
Sep 13, 2026
Merged

fix(openai-chat): shrink oversized inline images while retaining source content#4366
lidge-jun merged 20 commits into
devfrom
codex/260912-60plus-models-images

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Summary

Translated OpenAI-compatible Chat requests now shrink oversized inline images before serialization with the existing age-tier image pipeline. The 3.5 MiB base64-image budget is best effort: remote URLs are not fetched, unprocessable/terminal images remain attached, and retained bytes continue to count during demotion. Under-budget request construction stays synchronous; MiMo awaits conditional asynchronous construction.

Carries #4119 at 91835dd. The surgical wrapper preserves current structured-output downgrade behavior and adds regressions for that async path and failed-demotion accounting. Native Chat byte preservation and existing 413 retry scope are retained. Independent dev PR.

Co-authored-by: DamnUi damnui@users.noreply.github.com

Verification

  • Independent source plan audit PASS; Erdos final source review PASS across all 21 files at e5466d1.
  • Static test-layout registration and all 9 required manifest-owner documents verified; git diff --check passed.
  • Local test suites of every size, build, typecheck and install: NOT RUN under explicit maintainer instruction. Regression tests are committed for final-head GitHub-hosted CI.
  • No merge or auto-merge; no dependency, credential destination or service change.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Co-authored-by: Kosta Milovanovic <kosta963@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Sep 12, 2026
@lidge-jun

Copy link
Copy Markdown
Owner Author

리뷰 · 우선순위 61 / 80

이 PR은 OpenAI-compatible Chat 요청을 만들 때, 인라인 data-URL 이미지가 너무 크면 기존 age-tier 이미지 파이프라인으로 줄인 뒤 직렬화합니다. 예산은 약 3.5MiB base64이고, 원격 URL은 가져오지 않으며, 디코드 실패·폭탄 이미지는 드롭하지 않고 원본을 유지합니다. 원본은 #4119이고 src/adapters/openai-chat-images.ts를 새로 두었습니다.

중요한 설계는 retainsBytesOnDrop입니다. openai-chat에는 anthropic처럼 드롭한 이미지를 다시 붙이는 가드가 없어서, drop을 no-op으로 두고도 바이트를 예산에서 빼지 않게 해야 디모션 루프가 일찍 멈추지 않습니다. 그 플래그를 공유 normalizeImageTargets에 넣었습니다. 예산 아래 요청은 동기 buildRequest를 유지하고, 이미지가 예산을 넘을 때만 async 정규화로 갑니다. MiMo free 어댑터는 await base.buildRequest(...)로 맞춰 두었습니다.

현재 dev HEAD 81f6cd591 기준 mergeable은 CONFLICTING입니다. openai-chat.tsbuildRequest 본문이 거의 통째로 들여쓰기·구조 변경되어 충돌 면적이 큽니다. 이미지 정규화 자체는 가치가 높고 테스트도 openai-chat-image-normalization.test.ts에 두껍게 있습니다.

라인 / 심볼 - src/adapters/openai-chat.ts buildRequest - 시그니처가 sync에서 사실상 Promise 가능 경로로 확장됨. ProviderAdapter 계약·다른 호출부가 tip에서 모두 await 가능한지 CONFLICT 해소 후 확인 필요
경로/심볼 - retainsBytesOnDrop in anthropic-image-normalize.ts - 공유 코어 의미 변경. anthropic 기본 경로(retains 없음) 회귀가 깨지지 않았는지 anthropic-image-normalize 테스트만으로 충분한지 검토
경로/심볼 - OPENAI_CHAT_IMAGE_BASE64_BUDGET = 3_670_016 - "본문 전체 upstream limit 보장 아님"은 주석에 있으나, 운영 문서에 best-effort임을 한 줄 더 명시하면 좋음
경로/심볼 - overflowAction: "none" - 320px 바닥까지 줄여도 예산 초과면 원본 유지 → 여전히 413 가능. 의도된 fail-open이면 테스트/가이드에 그 한계를 적어두기
경로/심볼 - structure/ 다수 파일 +2 줄 노이즈 - 기능과 무관, 충돌만 키움

메인테이너의 판단이 필요한 지점

  • CONFLICTING openai-chat.ts를 rebase할지, 충돌이 너무 크면 close 후 이미지 모듈만 다시 올릴지
  • drop-시 바이트 유지(사용자 스크린샷 보존) vs 예산 초과 시 과감히 제거(413 감소) 중 제품 정책
  • types.ts/config.ts 분리와 직접 겹치진 않지만 adapter 계약 변경이 있으면 무효화 시 close-don't-rebase

너의 추천
draft 유지. dev rebase로 충돌 해소 후 image normalization + anthropic + mimo + native-policy 테스트를 tip에서 돌린다. openai-chat.ts 기계적 재들여쓰기 충돌이 반복되면 기능을 openai-chat-images.ts 호출부만 남기고 본문 리팩터는 줄인 새 PR로 갈아탄다.

이 댓글은 grok-bot이 작성했습니다

lidge-jun and others added 2 commits September 12, 2026 14:45
Carry #4119 with current structured-output fields preserved, retained-byte accounting, and conditional-async MiMo delegation.

Co-authored-by: DamnUi <damnui@users.noreply.github.com>
@lidge-jun
lidge-jun force-pushed the codex/260912-60plus-models-images branch from e5466d1 to b110d63 Compare September 12, 2026 05:47
@lidge-jun
lidge-jun merged commit 90667e5 into dev Sep 13, 2026
5 checks passed
@lidge-jun
lidge-jun deleted the codex/260912-60plus-models-images branch September 13, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant