-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: avoid resending web uploads after restart #2288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
he-yufeng
wants to merge
1
commit into
MoonshotAI:main
Choose a base branch
from
he-yufeng:fix/web-upload-sent-marker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """Tests for web runner upload handling.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from types import SimpleNamespace | ||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
| from kosong.message import TextPart | ||
|
|
||
| from kimi_cli.web.runner import process as process_module | ||
| from kimi_cli.web.runner.process import SessionProcess | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_uploaded_files_marker_survives_process_restart( | ||
| tmp_path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| session_dir = tmp_path / "session" | ||
| uploads = session_dir / "uploads" | ||
| uploads.mkdir(parents=True) | ||
| (uploads / "note.txt").write_text("hello", encoding="utf-8") | ||
|
|
||
| session = SimpleNamespace(kimi_cli_session=SimpleNamespace(dir=session_dir)) | ||
| monkeypatch.setattr(process_module, "load_session_by_id", lambda _session_id: session) | ||
|
|
||
| first_process = SessionProcess(uuid4()) | ||
| first_parts = [part async for part in first_process._encode_uploaded_files()] | ||
|
|
||
| assert any(isinstance(part, TextPart) and "note.txt" in part.text for part in first_parts) | ||
| assert json.loads((uploads / ".sent").read_text(encoding="utf-8")) == ["note.txt"] | ||
|
|
||
| restarted_process = SessionProcess(uuid4()) | ||
| restarted_parts = [part async for part in restarted_process._encode_uploaded_files()] | ||
|
|
||
| assert restarted_parts == [] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Writing
.senthere commits uploads as delivered beforesend_message()actually forwards the prompt to the worker (stdin.write/drainhappens later). If the worker exits or the pipe write fails in that window, the prompt never reaches the model, but the persisted marker survives restart and causes those files to be skipped on retry, silently dropping user uploads. This regression is specific to restart/error paths introduced by persisting the marker in_encode_uploaded_files.Useful? React with 👍 / 👎.