core: boundImages spends its image-budget cut on remote images that carry no payload

Aberta Para iniciantes
#61,391 2 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@jimmyallinai já está trabalhando nisso.

Desde 3/11/2026.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
typescript
Domínio
backend

Direção de pesquisa

Comece em packages/core/src/session/model-request.ts: mediaBytes, por volta das linhas 153-154, retorna 0 para mídias remotas e de referência, e boundImages, por volta das linhas 208-221, escolhe o corte a partir de sizes, mas o aplica pela posição no documento. Faça a fila de remoção pular imagens de custo zero para que nunca sejam substituídas. Execute bun run script/test.ts test/session-model-request.test.ts -t "spends the image budget" a partir de packages/core; está pronto quando apenas uma imagem inline é removida e as duas imagens remotas são mantidas.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

reproduced
Description

boundImages sizes the inline image budget with mediaBytes, which returns 0 for url and ref sources — the comment at packages/core/src/session/model-request.ts:153-154 states that "Remote and provider-referenced media carry no local payload and never count toward the inline budget".

The cut is then chosen by walking sizes in order (:208-214) but applied by document position (:217-221), so zero-cost media occupies slots in the removal queue. When the loop reaches a remote image it subtracts 0 from kept and still advances cut, spending a removal that frees nothing. Remote images are therefore replaced with IMAGE_REMOVED even though deleting them cannot help the budget, and the session loses content that was free to keep.

Steps to reproduce

Two remote images followed by two 13 MiB inline images (26 MiB passes the 25 MiB trigger; one inline image returns it under the 15 MiB target):

expect(removed(boundImages([remote("a.png"), remote("b.png"), inline("c.png"), inline("d.png")]))).toBe(1)
// Expected: 1, Received: 3
cd packages/core && bun run script/test.ts test/session-model-request.test.ts -t "spends the image budget"

Three images are replaced — both remote ones plus one inline — where only the inline one costs anything.

Plugins

none

OpenCode version

dev

Screenshot

No response

Linguagem predominante
TypeScript
Estrelas
224k
Forks
30k
Merge médio
6h 12min
PRs com merge (30d)
445

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de anomalyco/opencode

Todas as issues de anomalyco/opencode

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.