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

未关闭 适合新手
#61,391 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
backend

调研方向

从 packages/core/src/session/model-request.ts 开始:mediaBytes(约第 153-154 行)对远程和引用媒体返回 0,boundImages(约第 208-221 行)从 sizes 中选择截断点,但却按文档位置来应用。让移除队列跳过零成本图片,使它们永远不会被替换。在 packages/core 目录下运行 bun run script/test.ts test/session-model-request.test.ts -t "spends the image budget";当只移除一张内联图片且保留两张远程图片时即完成。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
TypeScript
星标
224k
派生
30k
平均合并
6 小时 51 分钟
30 天内合并 PR
475

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

anomalyco/opencode 的其他 Issue

查看 anomalyco/opencode 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。