TurnStarted hook can run after the same turn's Stop hook (fire-and-forget vs awaited)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 85/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- cli
調査の方向性
packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.tsから始め、notifyTurnStarted(TurnStartedのfire-and-forgetディスパッチ)とonDidFinishStep(runner.triggerBlock経由で待機するStopディスパッチ)を確認します。提案された2つの修正のいずれかを実装します。TurnStartedをUserPromptSubmitと同様に待機する経路に通すか、既存のevent.turnIdをrunStopに渡して、ターン終了時のフックペイロードにそのIDが含まれるようにします。external hooksのテストスイートを実行し、単一ターンのイベントが正しく順序付けられ、一致する識別子を持つことを確認します。
索引モデルが issue の本文から書いたものです。
説明
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).
- 主要言語
- TypeScript
- スター
- 7.8k
- フォーク
- 1.3k
- 平均マージ
- 22時間 40分
- マージ済み PR(30日)
- 163
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MoonshotAI/kimi-code のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
MoonshotAI/kimi-code#4177 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
MoonshotAI/kimi-code#4170 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
MoonshotAI/kimi-code#4147 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
MoonshotAI/kimi-code#4146 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
MoonshotAI/kimi-code#4140 ·
メンテナーはふだん 1 日以内に返信
MoonshotAI/kimi-code の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
AvaProtocol/ava-sdk-js#276 ·
メンテナーはふだん 1 日以内に返信
-
useFragment does not require `variables` when the fragment's variables type has required fieldsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
apollographql/apollo-client#13493 ·
メンテナーはふだん 1 日以内に返信
-
Custom hosts written as trailing-dot FQDNs (`host.local.`) aren't detected as local backends対応中かも @roboomp が今日担当しました。 オープンbug prio:p2 providers triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
can1357/oh-my-pi#15798 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
code-yeongyu/oh-my-openagent#10172 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
PDFCraftTool/pdfcraft#189 ·