TurnStarted hook can run after the same turn's Stop hook (fire-and-forget vs awaited)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- cli
Hướng nghiên cứu
Bắt đầu tại packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.ts: xem xét notifyTurnStarted (dispatch TurnStarted không chờ hoàn tất) và onDidFinishStep (dispatch Stop có chờ thông qua runner.triggerBlock). Triển khai một trong hai cách khắc phục được đề xuất: định tuyến TurnStarted qua luồng có chờ như UserPromptSubmit, hoặc truyền event.turnId hiện có cho runStop để payload của hook cuối lượt bao gồm ID này. Chạy bộ kiểm thử external hooks để xác nhận các sự kiện trong một lượt được sắp xếp đúng và mang các mã định danh khớp nhau.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What version of Kimi Code is running?
2.1.1 (npm @moonshot-ai/kimi-code). The code path is unchanged on main at 21406fb.
Which open platform/subscription were you using?
A local OpenAI-compatible test server (custom provider)
Which model were you using?
A scripted test model that answers immediately
What platform is your computer?
Windows 10 (10.0.19045), x64
What issue are you seeing?
External hook events for one turn can reach hook commands in the wrong order. On a fast turn, the TurnStarted hook runs after the Stop hook of the same turn.
In packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.ts, TurnStarted goes through fireAndForget (notifyTurnStarted), while Stop is awaited (runner.triggerBlock in onDidFinishStep). Both start a separate process, and nothing orders the fire-and-forget one before the awaited one. When the model answers in well under a second, the Stop process often finishes first.
A consumer that tracks turns from hooks then sees "turn ended" followed by "turn started" and is left thinking a turn is still running. Stop carries no turnId, so the consumer can't tell that the late TurnStarted belongs to the turn that already ended.
What steps can reproduce the bug?
- In
config.toml, add two[[hooks]]entries,TurnStartedandStop. Each runs a command that appends the event name and a high-resolution timestamp to the same file (for example, an HTTP POST to a local listener that logs arrival order). - Use a provider that answers immediately (a local stub or a trivial prompt on a fast model).
- Send several short prompts in the interactive TUI.
- Check the log. For some turns,
Stopis logged beforeTurnStarted.
We saw this with hooks that POST to a loopback HTTP listener (curl, cmd.exe on Windows). On sub-second turns, the late TurnStarted regularly arrived after Stop.
What is the expected behavior?
For a given turn, TurnStarted is delivered before Stop/StopFailure/Interrupt. If keeping it fire-and-forget matters, then Stop, StopFailure and Interrupt should carry the same turnId that TurnStarted has, so consumers can match the events and drop a stale start.
Additional information
Context: we run Kimi Code in a desktop app (NeuroSquad) and show each session's status from its hooks. For turns the user types, we rely on UserPromptSubmit (awaited). TurnStarted is the only start signal for turns nobody typed (background task notifications, schedules), and that's where the reordering leaves a session stuck at "working".
Two possible fixes: dispatch TurnStarted through the awaited path like UserPromptSubmit (it doesn't block), or add turnId to the end-of-turn payloads (notifyTurnEnded already has event.turnId; runStop doesn't pass it).
- Ngôn ngữ chính
- TypeScript
- Star
- 7.8k
- Fork
- 1.3k
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 137
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MoonshotAI/kimi-code
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
MoonshotAI/kimi-code#4225 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
MoonshotAI/kimi-code#4177 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
MoonshotAI/kimi-code#4170 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
MoonshotAI/kimi-code#4147 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
MoonshotAI/kimi-code#4146 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của MoonshotAI/kimi-code
Issue tương tự
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
lingdojo/kana-dojo#32590 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bastani-inc/atomic#3703 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend bug difficulty: medium priority: medium reliability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
trustflow-protocol/trustflow-backend#730 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
firecrawl/firecrawl-mcp-server#548 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày