Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 85d6a84 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94aca1f665
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| this.stopHookQueue = this.stopHookQueue | ||
| .then(() => this.runStop(facts, stopHookContinuation)) |
There was a problem hiding this comment.
Await Stop hooks before allowing print-mode shutdown
When a kimi -p user configures a Stop hook that does not finish immediately, this private promise is invisible to turn.result, IAgentLoopService.settled(), and quiescence. runNativeTurn therefore returns after the original turn and cleanup can acquire quiescence and dispose the agent while runStop is still executing, aborting the hook or silently discarding its block continuation; the new test's extra timer after loop.settled() demonstrates this lifecycle gap. Make the queued Stop work participate in loop/session settlement before advertising the turn as fully finished.
AGENTS.md reference: AGENTS.md:L122-L124
Useful? React with 👍 / 👎.
| this.stopHookContinuationUsed = true; | ||
| this.loop.notify({ |
There was a problem hiding this comment.
Recheck pending work after the Stop hook returns
If a Stop script is slow and the user submits another prompt after the completed TurnEnded, the pending-work check at scheduling time has already passed. When the old hook later returns a block reason, this unconditional notification inserts that stale continuation into or after the newer turn, despite the stated contract that pending work suppresses Stop. Recheck the loop state after triggerBlock resolves, or keep the loop non-idle for the hook's full lifetime, before enqueueing the continuation.
AGENTS.md reference: AGENTS.md:L122-L124
Useful? React with 👍 / 👎.
| this.stopHookQueue = this.stopHookQueue | ||
| .then(() => this.runStop(facts, stopHookContinuation)) |
There was a problem hiding this comment.
Update the documented Stop-hook timing
This moves Stop execution to after a completed TurnEnded, but both docs/en/customization/hooks.md:117 and docs/zh/customization/hooks.md:117 still tell hook authors that Stop runs when the model is about to end the turn and can stop the current operation. That timing distinction is observable to external scripts, especially now that the current turn is already complete and blocking starts a separate continuation, so update both event references rather than shipping a contradictory public contract.
AGENTS.md reference: AGENTS.md:L122-L124
Useful? React with 👍 / 👎.
) (#4995) * fix(agent-core-v2): run external Stop hooks after turn completion * chore: add changeset for external Stop hooks * docs: clarify post-turn Stop hook timing
* fix: resume sessions with removed default models (#4982) * fix(node-sdk): resume sessions with missing default model * fix(cli): check auth for the resumed session model * chore: add changeset for unavailable model recovery * fix(agent-core-v2): stop rebuilding mismatched session indexes (#4980) * fix(agent-core-v2): reject repeated model responses (#4977) * fix(agent-core-v2): reject repeated model responses * chore: add changeset for repeated model responses --------- Co-authored-by: 7Sageer <[email protected]> * fix(agent-core-v2): inline deferred tools without dynamic loading (#4971) * fix(agent-core-v2): record restored task notifications without model requests (#4949) (#4989) * fix(agent-core-v2): record restored task notifications without model requests - queue restored task notifications as prompt-only turns after loop initialization - preserve interrupted and queued turns during resume and fork - complete reconciliation before initialization and reset return to keep Wire reads ordered - run loop and container cleanup when reconciliation fails - surface restored notification persistence failures * chore: add changeset for restored task notifications * fix(agent-core-v2): restore overflow recovery after LLM retries (#4950) (#4990) * fix(agent-core-v2): restore step state after LLM retries * test(agent-core-v2): scope retry event to overflow regression * fix(config): allow sessions with invalid user config (#4951) (#4991) * fix(agent-core-v2): tolerate config read failures for permission rules * chore: add changeset for permission config recovery * docs: document permission config recovery * docs: qualify permission config recovery scope * fix(config): surface read error diagnostics * fix(config): allow sessions with invalid user config * fix(config): preserve valid values and replay diagnostics * fix(config): remove startup diagnostic replay * fix(agent-core-v2): ignore non-user prompts during Tower wake (#4952) (#4992) * fix(agent-core-v2): ignore non-user prompts during Tower wake * chore: add Tower notification fix changeset * fix(agent-core-v2): preserve slash prompts during Tower wake * fix(agent-core-v2): route foreground shell events by origin (#4954) (#4994) * fix(agent-core-v2): route foreground shell events by origin * test(agent-core-v2): expect tool event origins in snapshots * fix(klient): accept tool events from pre-origin hosts * fix(agent-core-v2): run external Stop hooks after turn completion (#4956) (#4995) * fix(agent-core-v2): run external Stop hooks after turn completion * chore: add changeset for external Stop hooks * docs: clarify post-turn Stop hook timing * fix(agent-core-v2): wait for subagent quiescence (#4953) (#4993) * fix(agent-core-v2): reject incomplete model streams (#5006) * fix(agent-core-v2): preserve choice-level OpenAI token usage (#5017) * fix(capability): confirm stopping WebBridge before Windows updates (#4999) * fix(capability): confirm stopping WebBridge before Windows updates * fix(capability): harden WebBridge update recovery * fix(capability): restore WebBridge after startup failure * fix(capability): wait for WebBridge process exit * fix(capability): handle WebBridge confirmation edge cases --------- Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]> * chore: sync release 2.6.3 back to main * chore: finish release 2.6.3 backsync * chore: sync node-sdk lockfile importer * fix(sdk): preserve main core type dependencies * fix: complete release 2.6.3 backsync --------- Co-authored-by: Haozhe <[email protected]> Co-authored-by: 7Sageer <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]> Co-authored-by: kimi-agent-bot <[email protected]>
Requirement or Bug
External Stop hooks were skipped when an agent finished naturally, so configured scripts did not run and their block/continuation behavior was unavailable. This PR executes Stop after a completed turn and starts a continuation when the hook returns a block reason.
The requirement and reproduction are described directly here; there is no separate issue link.
Bug Reproduction Steps
stopInputs=[]) and only one model request occurs, so no continuation is produced.Root Cause
The loop runtime refactor in #4630 expanded
hasPendingRequeststo include the active turn. Stop was evaluated duringstep.stopping, while that turn was still active, so the guard was always true and the external runner was never called.The same refactor made continuations independent turns, while the continuation-used flag was still reset on every
TurnEnded, breaking reentry protection once the trigger issue was removed.This is a fundamental fix in the external-hook adapter for the explicitly selected post-turn contract. The loop's public busy/settled semantics and the durable
TurnEndedschema remain unchanged.Code Changes
turnId,step,firstStepOfTurn,finishReason, andusagefor the final step instead of retaining the fullAfterStepContextor its signal.stopHookActiveand the existing session facts.TurnEndedis projected.Behavior Changes and Affected Users
step.stoppingand skipped because the active turn counted as pendingTurnEndedwhen no work is pendingstopHookActiveturn_id,step,first_step_of_turn,finish_reason, and final-stepusagestop_hookoriginStopFailureandInterruptAffected modules are limited to the agent external-hook adapter, its integration tests, and the CLI changeset.
Verification:
corepack pnpm vitest run packages/agent-core-v2/test/features/externalHooks/integration.test.ts— 26/26 passed.corepack pnpm --filter @moonshot-ai/agent-core-v2 typecheck— passed.ExternalHooksRunnerServiceand verifies exit-code-2 blocking and continuation.npm run buildindocs/— passed after updating both Stop hook references.Checklist
@moonshot-ai/kimi-code.