makecindy / makecindy/cindy

bug: MCP/ghost 工具结果过大时全文直通对话上下文,缺少统一的「落盘+指针」护栏,导致下一轮必现 Prompt exceeds max length 400

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

Description

## 环境

Windows 桌面版;模型经 litellm → Z.ai GLM;通过 ghost/MCP 工具获取远程大对象。

## 问题

单个工具结果过大时,宿主将**全文原样注入对话上下文**,无任何拦截。实测一次调用返回 641,694 字节(JSON 转义后约 133 万字符):

1. 调用本身成功——通道实测可送达 ~150 万字符,说明数据能回来;
2. 全文进上下文后,**下一轮请求** prompt 超过模型窗口上限,后端直接 400:

```
400: {"message":"litellm.BadRequestError: ZaiException - Prompt exceeds max length"}
```

3. 自动压缩后对话恢复,但工具结果原文被有损丢弃——数据“取回来了”却“用不上”。

## 关键观测:护栏已部分存在,但未统一

实测发现同类场景行为不一致:有的工具返回几十 KB 就会自动落盘(只返回 `saved_to` 文件名 + 字节数 + 预览 hint,模型拿指针按需读文件);而另一些工具返回 60 万+ 字节却全文直通。说明落盘护栏目前依赖各工具/插件自行实现,宿主层没有统一约束,模型也无法预判哪个工具会直通。

## 建议行为

1. 单个工具结果超过阈值(建议 ~50–100KB,可配置)→ 写入会话工作目录(如 `tool-results/-.json`);
2. 注入上下文的替换为 `{saved_to, bytes, truncated, 开头 ≤1KB 预览}`;
3. 模型按需用文件工具读取所需片段(对大 JSON 尤其有效)。

## 影响

- agent 无法消费接近上下文窗口量级的大对象(远程附件、日志包、数据导出)——恰是排障最常见的数据;
- 爆上下文后整轮 400 不可用,只能等自动压缩,且原文有损丢失。

---

关联:#1429 #1865 #2354 报告的是超限后压缩机制的表现,本 issue 聚焦源头(工具结果注入上下文之前的护栏)。

Contributor guide

Open the contributing guide

Research direction

Start by tracing the host path where MCP/ghost tool results are inserted into the conversation context, then compare it with tools that already save large results and return a pointer. Verify the behavior with a result larger than the proposed configurable threshold. Done means oversized results are saved in the session work directory, the context receives metadata and a preview, and smaller results retain their existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.