Skip to content

fix(devin-connect): merge consecutive same-role text turns before wire encoding - #270

Merged
dwgx merged 1 commit into
dwgx:masterfrom
lovedxc:fix/merge-consecutive-text
Sep 14, 2026
Merged

dwgx merged 1 commit into
dwgx:masterfrom
lovedxc:fix/merge-consecutive-text

Conversation

@lovedxc

@lovedxc lovedxc commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary / 摘要

EN: Split off from #267 per review — this is only the mergedMessages half, with the requested assertions. Clients that persist streamed output per-part can store one logical turn as several consecutive same-role entries. Encoded verbatim, those runs produce back-to-back same-source ChatMessages, and the upstream request validator rejects a same-source run of length >= 3 with invalid_argument ("an internal error occurred").

中文: 按 #267 评审意见拆分——本 PR 只含 mergedMessages 那一半,并补上要求的断言。客户端把一个回合按 part 拆存时,历史里会出现连续同 role 的纯文本消息;原样编码后 wire 上出现连续同源 ChatMessage,run 长度 ≥ 3 时上游校验器返回 invalid_argument("an internal error occurred")。

Changes / 修改

EN:

  • Coalesce runs of consecutive same-role text-only messages before the wire loop. Entries carrying tool_calls / tool_call_id / reasoning / non-text content are never merged (they encode to distinct wire types); system turns are skipped for adjacency (they hoist to 大佬,这个非常厉害,calude code 不支持好像 #2); merge produces fresh objects — the caller array is reused by retry/failover and is never mutated.

中文:

  • wire 循环前合并连续同 role 的纯文本消息。携带 tool_calls / tool_call_id / reasoning / 非文本内容的条目不参与合并(编码为不同 wire 类型);system 不参与相邻判断(会提升到 大佬,这个非常厉害,calude code 不支持好像 #2);合并生成新对象,不改调用方数组(重试/failover 会复用同一 messages)。

Tests / 测试

EN: Four wire-level assertions in devin-connect.test.js:

devin-connect.test.js: 185/185 pass.

中文: devin-connect.test.js 新增四条 wire 级断言:

devin-connect.test.js:185/185 通过。

…e encoding

Clients that persist streamed output per-part can store one logical turn as
several consecutive same-role entries. Encoded verbatim, those runs produce
back-to-back same-source ChatMessages, and the upstream request validator
rejects a same-source run of length >= 3 with invalid_argument ("an internal
error occurred") — the request decodes and begins processing, then the
trailer fails.

Coalesce runs of consecutive same-role text-only messages before the wire
loop. Entries carrying tool_calls / tool_call_id / reasoning / non-text
content are never merged (they encode to distinct wire types); system turns
are skipped for adjacency since they hoist to field dwgx#2; the merge produces
fresh objects so the caller array stays intact for retry/failover.

Pins the merge contract with wire-level assertions: a [user,assistant x3,
user x2] history collapses to sources [1,2,1] with joined text, while
tool_call / tool_result / reasoning entries are never absorbed into a merge.
dwgx added a commit that referenced this pull request Sep 14, 2026
@dwgx
dwgx merged commit aa3db79 into dwgx:master Sep 14, 2026
7 checks passed
dwgx added a commit that referenced this pull request Sep 14, 2026
@dwgx

dwgx commented Sep 14, 2026

Copy link
Copy Markdown
Owner

评审:mergedMessages 那半按上次说的收了,已经进 master(aa3db79)。

四条 wire 断言实测 185/185。对抗:image_url 数组不合并、CJK/ZWJ 码点保留、空+文本不被 empty-drop 吃掉、调用方数组不改。Linux CI 34799913540 6/6。

两件合并后我这边补的,不是你的疏漏:

  1. credit-cost-top-level / reasoning-continuity 跑 devin-connect.test.js,你加了 4 条测试,不刷 expectBaselinePass 的话 Linux 突变扫会在第一次 mutation 前 die。已经按实测刷了。
  2. DEVIN_CONNECT_COLLAPSE_SYSTEM=1 时 system 不会消失到 #2,look-past 会把夹心 system 挤出注入位。7386481 修了,并加了一条 wire 断言。默认路径你原来的 look-past 仍对。

#267 还是 8d155cf,另说。

dwgx added a commit that referenced this pull request Sep 14, 2026
User-visible: consecutive same-role Connect text no longer trips run>=3 invalid_argument (#270); Responses tool-output images reach Connect tag 10 and docker nginx is 32m/900s with the real cap still MAX_BODY_SIZE=10MB (#265); local import finds Devin desktop userData and a 160KB windsurfAuthStatus is no longer silently skipped (#264); swe-2 is in the Connect catalog and gpt-5.6 Local is opt-in (#266).

No API breakage. ACU ^22 still default off. FREE_TIER_SELECTOR still swe-1-6-slow. Mutation specs stay 49/588; baselines were remeasured at merge.
dwgx added a commit that referenced this pull request Sep 15, 2026
The #270 negative test sat a tool_calls turn next to role:tool, so deleting isMergeableText's tool_calls/image checks stayed green. Same-role tool_calls+text and two image_url users now fail if those guards vanish. credit-cost-top-level 186->188, reasoning-continuity 313->315. README 三套->四套 and lists SWE-2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants