Stop hook never fires in 2.6.0 (regression from 2.5.3)
Bug: Stop hook never fires in 2.6.0 (regression from 2.5.3)
Summary
In @moonshot-ai/[email protected] the Stop external hook is never executed. The same configuration works in 2.5.2 and 2.5.3. Other hook events (e.g. SessionStart) still fire in 2.6.0, so this is specific to the Stop code path.
Reproduction
- Configure a hook in
config.toml:
[[hooks]]
event = "Stop"
command = "echo STOP_HOOK_FIRED >> /tmp/kimi-stop.log"
[[hooks]]
event = "SessionStart"
command = "echo SESSION_START_FIRED >> /tmp/kimi-stop.log"
- Run headless:
kimi -p "Reply with exactly: OK"
- Check
/tmp/kimi-stop.log:
| Version | SessionStart | Stop |
|---|---|---|
| 2.5.2 | ✅ fires | ✅ fires |
| 2.5.3 | ✅ fires | ✅ fires |
| 2.6.0 | ✅ fires | ❌ never fires |
This also means the Stop-hook continuation flow (stopHookContinuationUsed, blocking the stop and injecting the reason as a user message) is dead code in 2.6.0.
Root cause
AgentExternalHooksService.registerLoopHooks guards the Stop trigger with:
this._register(loop.hooks.onDidFinishStep.register("externalHooks", async (ctx, next) => {
await next();
if (ctx.finishReason === "tool_calls" || ctx.finishReason === "filtered" || loop.snapshot().hasPendingRequests) return;
const reason = await this.runStop(ctx);
...
In 2.6.0, AgentLoopService.hasPendingRequests() (agent-core-v2 loop) gained a new clause:
hasPendingRequests() {
if (this.disposing) return false;
return this.pendingSubmissions.length > 0
|| this.pendingNotifications.length > 0
|| (this.loop?.state.inbox.normal.length ?? 0) > 0
|| (this.loop?.state.inbox.notify.length ?? 0) > 0
|| (this.loop?.state.completionPending ?? false)
|| (this.loop?.state.resetting ?? false)
|| this.loop !== void 0 && this.loop.state.status !== "idle"; // <-- new in 2.6.0
}
But onDidFinishStep handlers run inside the still-running turn (from AgentTurnProjection.stepStopping, before the loop transitions back to idle). So at the moment the guard is evaluated, loop.state.status !== "idle" is always true → hasPendingRequests() is always true → runStop() is never called.
Instrumented run of the published 2.6.0 bundle confirming this:
[TRACE] onDidFinishStep finishReason=completed snapshot={"state":"running","activeTurnId":0,"activePromptId":"msg_...","queue":[],"notificationCount":0,"paused":false,"hasPendingRequests":true,"turn":{"turnId":0,"phase":"running","step":1,...}}
Queue is empty, nothing is pending — hasPendingRequests is true solely because the turn is still running while the hook executes. In 2.5.3 hasPendingRequests() did not include the loop-status clause, so the guard passed and the Stop hook fired.
Suggested fix
Either drop the loop.state.status !== "idle" clause from hasPendingRequests() (or exclude it from what the Stop guard consults), or run the Stop hook trigger after the loop has settled to idle. A regression test that a configured Stop hook fires once per completed turn would cover this.
Environment
@moonshot-ai/kimi-code2.6.0 (npm tarball, also reproduced against the release published 2026-11-12T10:11Z)- macOS (Darwin 25.6.0), Node 24/26
- Reproduced in headless
-pmode; the guard is shared by the interactive TUI path, so it should be affected identically.
Title: Corroboration: 2.6.0 native Linux — StopFailure still fires on failed turns (turn-level dispatch alive, only normal-completion Stop is dead)
Body:
Corroborating this regression with controlled reproductions on 2.6.0 (Linux x86_64, native install, WezTerm terminal):
- Armed print-mode probes (
AXIOM_KIMI_COMPLETION_GATE=1, isolatedKIMI_CODE_HOME): PreToolUse/PostToolUse hooks fire normally, the turn ends cleanly (turn.ended+prompt.completed), zero Stop events, zerostop_hooksystem-trigger injections, TodoList item left open. - Disarmed isolated probes: identical — no Stop.
- Live observation across 8 sessions on 2026-11-13: 59 PreToolUse / 59 PostToolUse / 51 SubagentStart / 43 SubagentStop, zero Stop. The last Stop event we ever observed (2026-11-12T13:35:52Z) came from a long-running process still executing pre-2.6.0 code in memory (2.6.0 was installed 2026-11-12T11:46Z).
- A detail not on this issue's record yet (PR #4902's test prose mentions
filteredendings still triggering StopFailure, but as a test expectation): StopFailure still fires on failed turns — a TUI turn failing on an upstream HTTP 404 dispatched StopFailure normally. So turn-level dispatch wiring is alive; only the normal-completion Stop path is dead. That is consistent with thehasPendingRequests()counting the in-flight turn, as PR #4902 describes. - Control: the same headless
-pprobe design on 2.2.0 produced the fullstop_hooksystem-trigger injection with the exit-2 continuation flow (stopHookContinuationUsed) — so this is a 2.6.0 regression, not a probe artifact. - One more localization datum: the TUI's own turn-completion notification (a separate code path in the TUI streaming layer) still fires normally on 2.6.0 — turn lifecycle events reach the TUI while Stop never reaches external hooks, which also matches the dispatch-side root cause in #4902.
The probe harness is small (a pty/print driver plus hook observers); happy to share details if useful. Watching #4902 closely — thanks for the fix work.
Stop hook regression: confirmation on Kimi Code 2.6.1 and 2.6.2
This is additional evidence for #4884, rather than a new issue.
A successful main turn records turn.ended with reason: "completed", but its configured Stop hook never runs. Other hooks execute through the same script. This also prevents a terminal wrapper that registers hooks from observing completion.
Environment
- Official Kimi Code CLI binaries, automatic updates disabled for each test copy.
- 2.5.3: Stop fires; tested on Linux x86_64 and macOS arm64.
- 2.6.0: Stop absent; tested on Linux x86_64 and macOS arm64.
- 2.6.1 and 2.6.2: Stop absent; tested on Arch Linux x86_64, tmux 3.8, interactive TUI.
- Each reproduction used private configuration/state. No hooks intentionally blocked the turn.
Minimal reproduction
-
Create
/tmp/kimi-hook-repro/log-event.py:import json import sys event = json.load(sys.stdin) with open('/tmp/kimi-hook-repro/events.jsonl', 'a') as log: log.write(json.dumps({'event': event.get('hook_event_name')}) + '\n') # No stdout and a successful exit: this hook does not request continuation. -
Add these rules to the test copy's
config.toml:[[hooks]] event = "SessionStart" command = "python3 /tmp/kimi-hook-repro/log-event.py" [[hooks]] event = "UserPromptSubmit" command = "python3 /tmp/kimi-hook-repro/log-event.py" [[hooks]] event = "TurnStarted" command = "python3 /tmp/kimi-hook-repro/log-event.py" [[hooks]] event = "Stop" command = "python3 /tmp/kimi-hook-repro/log-event.py" -
Start a new interactive session with a working model configuration. Submit:
Reply with OK only. Do not call tools.Let the response finish without submitting another message. -
Compare the event log with the main agent's
wire.jsonl.
Expected
The logger receives Stop when the main turn successfully finishes, as it does on 2.5.3.
Actual
The logger receives SessionStart, UserPromptSubmit and TurnStarted, but no Stop. The main wire contains a completed terminal event. A reduced example, with unrelated fields omitted, is:
{"type":"turn.prompt","agentId":"main","turnId":0}
{"type":"turn.ended","agentId":"main","turnId":0,"reason":"completed"}
The answer is already visible and the native TUI has returned to its composer. There is no hook execution error in the diagnostic log. The same executable hook command works for the other events.
The relevant bundled dispatch path is registerLoopHooks → onDidFinishStep → runStop. This reproduction confirms the completion-without-Stop symptom reported in #4884 on later 2.6.x releases; it does not require inferring completion from reply text.
Still reproduces on 2.6.2 (Homebrew, macOS arm64) — and not only in -p mode.
A debug hook that just logs the event name was registered for SessionStart, UserPromptSubmit, TurnStarted, Stop, StopFailure, SessionEnd, Notification, Interrupt:
| Run | plan mode | MCP servers | Fired | Stop |
|---|---|---|---|---|
kimi -p "say ok" |
on | configured | SessionStart, UserPromptSubmit | never |
| interactive TUI (launched by an orchestrator) | on | configured | SessionStart, UserPromptSubmit | never |
kimi -p |
off | configured | SessionStart, UserPromptSubmit | never |
kimi -p |
off | none (mcp.json removed) |
SessionStart, UserPromptSubmit | never |
| interactive TUI | off | configured | SessionStart, UserPromptSubmit | never |
kimi -p + extra hooks |
off | configured | SessionStart, UserPromptSubmit, TurnStarted | never; SessionEnd and Notification never either |
So plan mode and failing MCP servers (pending notifications) are ruled out. wire.jsonl records turn.ended normally, but the external Stop hook never runs; SessionEnd does not run on -p exit either.
Impact: orchestrators that rely on Stop to detect turn completion (e.g. Orca) show Kimi as "working" forever after it finishes.
Closing this as fixed by #4956 / #4995 (fix(agent-core-v2): run external Stop hooks after turn completion), which shipped in v2.6.3+.
Stop hooks are now triggered from notifyTurnEnded after the loop settles back to idle, instead of being blocked by hasPendingRequests always evaluating to true inside onDidFinishStep.
(Note: a separate print-mode-specific race where kimi -p exits before a queued blocking Stop hook finishes is tracked in #5032.)