fix(chat): stop send-time OOM crash from references reactive infinite loop#1416
Merged
Conversation
… loop
Sending any chat message (even a bare "hi", any account) froze and OOM-crashed
the tab. Console proved it: one send logged `references changed` 107,725 times —
an infinite reactive loop between Composer and Conversation:
1. send → Conversation `this.references = []` (fresh array)
2. Composer `references` watcher → `this.fileList = []` (unconditional, fresh array)
3. fileList change → `refs` computed → new `[]`
4. `refs` watcher → `$emit('update:references', [])` — PR #1398 removed its
prior `if (val.length > 0)` guard, so it now echoes empty values
5. parent `@update:references="references = $event"` → `references = []` → step 2 → ∞
Fix: guard the back-edge in the Composer `references` watcher — only reset
`fileList` when there is something to clear AND nothing is mid-upload:
`if (val.length === 0 && this.fileList.length > 0 && !this.uploading)`.
The `!uploading` clause prevents clobbering an in-flight upload (fileList is
non-empty but `refs` is still [] until the response arrives, so the parent
momentarily holds []). Send is gated on `!uploading`, so the post-send reset
we DO want to clear always passes. Also removed two stray debug logs
(`references changed`, `References:`) that amplified the loop's cost.
Regression tests (Composer.loop.test.ts): (a) parent back-edge wired — emit
count stays bounded, must settle; (b) completed upload clears on empty reset;
(c) in-flight upload is preserved. Each fails if its guard clause is reverted.
Note: this is the actual send-crash cause. The earlier persist-summaries change
(#1415) fixed a separate real perf issue (heavy persisted history) but not this.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
nexior | 889c271 | Commit Preview URL Branch Preview URL |
Jul 23 2026, 07:15 AM |
Germey
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
P0 — 发消息卡死/OOM 的真正原因
发任何一条消息(哪怕只是 `hi`,任何账号)都会冻结并 OOM 崩溃标签页。Console 是铁证:一次发送打印了 107,725 条 `references changed` —— Composer ↔ Conversation 之间的响应式无限循环:
第 4 步守卫的移除就是"昨天还行今天崩"的真正回归点(#1398 于 7/23 01:33 凌晨合并),且与账号轻重无关,人人发消息都崩。
修复
在 Composer 的 `references` watcher 上给回边加守卫 —— 仅当有内容可清 且没有上传进行中 时才重置 `fileList`:
```js
if (val.length === 0 && this.fileList.length > 0 && !this.uploading) {
this.fileList = [];
}
```
同时删掉两处放大损害的 debug 日志(`references changed`、`References:`)。
回归测试 `Composer.loop.test.ts`(3 个,每个都验证过"改回 bug 就挂")
验证
🤖 对抗评审
Codex (`gpt-5.5`, `codex exec --sandbox read-only`) 复核。发现一个真实 RISK(已采纳修复):初版守卫 `if(val.length===0 && fileList.length>0)` 会在文件上传进行中误删附件 —— 因为此时 `fileList` 非空但 `refs` 为空,父组件短暂持有 `[]` 触发清空。据此加了 `!uploading` 守卫,并补了上传保护回归测试 (c)。Codex 同时确认:单独恢复 `refs` watcher 的 `if(val.length>0)` 会破坏"用户删掉最后一个附件、父组件需被告知"的合法场景 —— 故不采用该方案。收敛后无残留 RISK。
与 #1415 的关系
本 PR 是发消息崩溃的真正修复。先前 #1415(持久化只存 summary)修的是另一个真实但独立的性能问题(重账号持久化全量历史,序列化 158ms),不是本次崩溃主因,保留无害。
🤖 Generated with Claude Code