makecindy / makecindy/cindy

【Bug + 需求】长对话贴图导致请求体超 32MB 代理上限:413 静默卡死、无预警、无自助恢复入口

Open
#4,241 3 comments 0 reactions 0 assignees View on GitHub
bug pi
Dominant language
TypeScript
Stars
2.7k
Forks
395
Avg merge
21h 48m
Merged PRs (30d)
776

Description

**环境**:Windows 11 专业版 (26200) / Cindy 0.1.57 / pi 引擎(pi 0.84.4 运行时)/ 模型 z-ai/glm-5.3-flash(1M 窗口)/ 经宿主代理转发

## 现象

1. 一个长期使用、贴图较多的对话(上下文约 82 万 / 100 万 tokens)从某次请求起全部返回:

```
413 {"type":"proxy_error","reason":"request_body_too_large",
"message":"request body too large: 68201786 bytes exceeds proxy limit of 33554432 bytes"}
```

2. 宿主自动恢复机制重试约 10 次全部 413;此后用户发送任何内容(包括纯文本 `1`、`/compact`)都立即 413,对话彻底无法使用。
3. UI 上表现为"发消息没反应 / 报错横幅",没有解释原因,也没有可操作的指引。

## 根因

- 用户贴的图片以 base64 内联保存在 pi 会话文件(`{"type":"image","data":"..."}`),每次请求全量重发。
- 该对话文字部分仅 ~3MB,其余 ~65MB 全是历史贴图的 base64。
- token 维度只用了 82%,pi 的 auto-compaction(按 token 阈值触发)不会启动;**请求体字节数是独立维度,宿主与运行时都没有检测**,直到撞上代理 32MiB 硬上限。
- 撞上限后每次重试还会把错误文本追加进历史,请求体继续增大,形成死循环。

## 影响面

所有「贴图密集 + 长期沿用同一对话」的使用方式都会撞上(图证核对、素材确认、截图排障等场景很常见)。当前表现为对话静默卡死且无法自救,用户只能整条弃用。

## 已验证的自救(供参考)

离线备份会话 JSONL 后移除历史图片的 base64(该案例:58 张图,65.76MB → 3.55MB),对话立即恢复可用——说明请求体降下来后 session 本身没有损坏,可救。

## 建议(按优先级)

1. **接近上限时主动预警**:宿主发送前已知请求体大小,≥70% 时横幅提醒"贴图过多,建议清理旧图或新开会话",≥85% 强提醒。
2. **413 给可操作的错误提示**:明确告知"请求体超 32MB 上限 + 已停止自动重试 + 建议清理旧图 / 新开会话";413 时不要自动重试(只会越滚越大)。
3. **UI 提供 `/compact`(手动压缩上下文)入口**:pi 运行时本身支持 compaction,且其总结请求是文本序列化(工具结果截断 2000 字符),可绕过体积上限。目前在 Cindy 输入框输入 `/compact` 会被当成普通消息发出(同样 413)。这个入口能同时缓解 token 与请求体两个维度的膨胀。
4. **官方"清理历史图片"能力**:保留 UI 展示与本地 blob,仅从发给模型的请求副本中移除或降采样历史贴图(目前用户只能脚本改文件,建议产品化)。
5. 顺带一个小 bug:powershell/bash 守卫误报。正常命令(如 `python xxx.py`、rclone lsf、含 `$env:` 或 `$变量` 的命令)偶发被拦,报 "Direct Pi extension changes are unavailable through bash. Use cindy_pi_extension...";同一命令去掉 `$` 变量后即可执行,疑似守卫正则误匹配,值得排查。

Contributor guide

Open the contributing guide

Research direction

Start with the host request path, the UI message input, and the pi session JSONL handling described in the report; verify how oversized requests, 413 responses, retries, and `/compact` are currently routed. Done means the affected flow has a clear size warning, actionable 413 handling without runaway retries, and a recovery path for image-heavy sessions, with the scope of the PowerShell/bash guard bug decided separately.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
full-stack
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.