MoonshotAI / MoonshotAI/kimi-code

UserPromptSubmit hooks never fire on goal-continuation turns (origin kind guard)

Open
#3,692 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

Component: agent-core-v2 external hooks + goal feature

Observed (verified on latest main 7f5debf, also present in released 0.41.0):

  • packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.ts:341:
    if ((ctx.promptMessage.origin ?? USER_PROMPT_ORIGIN).kind !== 'user') return false;
    so the UserPromptSubmit hook runs ONLY when the prompt origin kind is user.
  • Goal continuations are submitted with a different origin —
    packages/agent-core-v2/src/features/goal/goalService.ts:101:
    { kind: 'system_trigger', name: 'goal_continuation' }.
  • Therefore during goal mode every auto-continuation turn skips the UserPromptSubmit hook
    entirely, however long the goal runs.

Impact: hooks configured on UserPromptSubmit (mailbox sweeps, session-facts injection,
input gating, metrics) silently never fire for the whole duration of a goal session, which is
exactly the mode where the machine is meant to work unattended. There is no other hook event
that fires per goal turn (PreToolUse/PostToolUse fire only when tools run; Stop/
PreCompact are turn/compaction-adjacent and do not carry prompt input).

Suggested fix (any of):

  1. Fire UserPromptSubmit for system_trigger origins whose name is goal_continuation
    (and document the matcher value), or
  2. Add a dedicated GoalContinuation hook event so consumers opt in explicitly, or
  3. Document this exclusion in the hooks reference so consumers can choose PostToolUse
    instead.

Test seam exists: the hook service already subscribes to PromptQueued and TurnStarted;
a RED test asserting the hook runs on a goal-continuation-shaped prompt would cover it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.ts around line 341 and packages/agent-core-v2/src/features/goal/goalService.ts around line 101. Use the existing PromptQueued and TurnStarted hook subscriptions to add a RED regression test for a goal-continuation-shaped prompt. Done means the expected hook behavior is chosen, covered by the test, and any matcher or exclusion is documented as needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.