MoonshotAI / MoonshotAI/kimi-cli
Web 模式:恢复会话后历史图片被重复发送给 LLM || Web mode: historical images are repeatedly sent to LLM after restoring the session
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
What version of Kimi Code CLI is running?
kimi, version 1.43.0
Which open platform/subscription were you using?
kimi-code
Which model were you using?
kimi-for-coding(Kimi-k2.6)
What platform is your computer?
Windows 11 x64
What issue are you seeing?
在 Web 界面中上传图片并完成一轮对话后,如果之后重启kimi并重新进入web模式恢复该会话并发送一条纯文本消息,这条新消息会 unexpectedly 携带所有之前上传过的图片。这导致 LLM 收到重复的图片内容,并误以为是用户新提交的图而开始分析。
通过对源码的分析,发现这是 SessionProcess.encode_uploaded_files()(kimi_cli/web/runner/process.py:386)中的状态持久化缺陷导致的:
_sent_files 是一个内存中的 set[str](第101行),用于记录 uploads/ 目录中哪些文件已经被编码并发送过。
每次用户提交 prompt 时,_encode_uploaded_files() 都会扫描 uploads/ 目录,跳过已在 _sent_files 中的文件。
关键问题:_sent_files 在正常 Web 会话流程中从未被持久化到磁盘。.sent 标记文件仅在 fork_session 时被创建(session_fork.py:325)。
会话恢复时进程会重启,sent_files 被重置为空集合,导致 uploads/ 目录中的所有历史图片都被重新编码并附加到新消息中。
相关源码:
process.py:101
self._sent_files: set[str] = set()
process.py:386-505
async def _encode_uploaded_files(self):
uploads_dir = session.kimi_cli_session.dir / "uploads"
sent_marker = uploads_dir / ".sent"
if sent_marker.exists():
already_sent = json.loads(sent_marker.read_text())
self._sent_files.update(already_sent) # 仅对 fork 的会话有效
files = [f for f in all_files if f.name not in self._sent_files]
# ... 所有历史图片在这里被重新编码
What steps can reproduce the bug?
启动 Web 模式:kimi web
打开 Web UI 并创建一个会话
通过聊天输入框粘贴/上传一张或多张图片,发送消息(例如:"描述这张图片")
等待 LLM 回复完成
在控制台ctrl+c退出kimi
重新启动kimi web并打开该会话(恢复会话)
发送一条新的纯文本消息,不上传任何新图片(例如:"你好")
Bug 现象:LLM 收到这条文本消息的同时,还收到了所有之前上传过的图片,并重新开始分析这些图片,就好像用户又发了一遍图一样
What is the expected behavior?
在 Web 模式下恢复会话后,用户新发送的消息应该是一个全新的 prompt,之前已经上传并发送过的图片不应该被自动附加到新消息中,除非用户显式重新上传。
Additional information
CLI 模式不受此影响 — 该 bug 是 Web 模式特有的。CLI 模式使用 AttachmentCache 和占位符([image:xxx])机制,恢复会话时不会自动携带历史图片。
What version of Kimi Code CLI is running?
kimi, version 1.43.0
Which open platform/subscription were you using?
kimi-code
Which model were you using?
kimi-for-coding (Kimi-k2.6)
What platform is your computer?
Windows 11 x64
What issue are you seeing?
After uploading pictures in the web interface and completing a round of conversation, if you then restart kimi and re-enter web mode to resume the session and send a plain text message, this new message will unexpectedly carry all previously uploaded pictures. This causes LLM to receive duplicate image content and mistakenly think it is a newly submitted image by the user and start analysis.
Through analysis of the source code, it is found that this is caused by the state persistence defect in SessionProcess._encode_uploaded_files() (kimi_cli/web/runner/process.py:386): _
_sent_files is an in-memory set[str] (line 101) used to record which files in the uploads/ directory have been encoded and sent.
Each time the user submits a prompt, _encode_uploaded_files() scans the uploads/ directory, skipping files already in _sent_files.
Key issue: _sent_files are never persisted to disk during the normal flow of a web session. .sent tag files are only created when fork_session (session_fork.py:325).
When the session is restored, the process is restarted and _sent_files is reset to an empty collection, causing all historical images in the uploads/ directory to be re-encoded and appended to the new message. _
Related source code:
process.py:101
self._sent_files: set[str] = set()
process.py:386-505
async def _encode_uploaded_files(self):
uploads_dir = session.kimi_cli_session.dir / "uploads"
sent_marker = uploads_dir / ".sent"
if sent_marker.exists():
already_sent = json.loads(sent_marker.read_text())
self._sent_files.update(already_sent) # Only valid for fork sessions
files = [f for f in all_files if f.name not in self._sent_files]
# ...all historical images are recoded here
What steps can reproduce the bug?
Start web mode: kimi web
Open the Web UI and create a session
Paste/upload one or more pictures through the chat input box and send a message (for example: "Describe this picture")
Wait for LLM reply to complete
Exit kimi in the console ctrl+c
Restart kimi web and open the session (restore session)
Send a new text-only message without uploading any new images (eg: "Hello")
Bug Phenomenon: When LLM received this text message, it also received all previously uploaded images, and started analyzing these images again, as if the user had sent the image again.
What is the expected behavior?
After resuming a session in web mode, new messages sent by the user should have a completely new prompt, and images that have been uploaded and sent before should not be automatically attached to the new message unless the user explicitly re-uploads them.
Additional information
CLI mode is not affected by this - this bug is specific to web mode. CLI mode uses AttachmentCache and placeholder ([image:xxx]) mechanism, and historical images will not be automatically carried when restoring the session.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in kimi_cli/web/runner/process.py at SessionProcess._sent_files and _encode_uploaded_files(), then compare the marker handling in session_fork.py around line 325. Reproduce the restore-and-send-text scenario and trace which uploads are selected after restart. Done means previously sent images are not attached to a restored session's new text message, while newly uploaded images still are.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100