Skip to content

feat(hooks): include final assistant message in Stop payload - #2443

Open
ousamabenyounes wants to merge 2 commits into
MoonshotAI:mainfrom
ousamabenyounes:feat/issue-2123
Open

feat(hooks): include final assistant message in Stop payload#2443
ousamabenyounes wants to merge 2 commits into
MoonshotAI:mainfrom
ousamabenyounes:feat/issue-2123

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Jul 31, 2026

Copy link
Copy Markdown

Related Issue

Resolve #2123

Problem

Stop hooks cannot inspect the assistant response that is about to end the turn, so they cannot validate or conditionally reject that response.

What changed

  • include the last assistant message's text in Stop hook input as last_assistant_message
  • preserve the exact concatenated text while excluding non-text content
  • cover the real hook subprocess/JSON boundary with an integration test
  • document the field in the English and Chinese hook references
  • add a patch changeset

Test verification (RED → GREEN)

RED on unmodified upstream origin/main (17dfd4976) with only the regression test:

AssertionError: expected history to contain the final assistant text
Actual Stop continuation reason: "Blocked by Stop hook"

GREEN with this patch:

Test Files  1 passed (1)
Tests       1 passed | 82 skipped (83)

Full local suite proof

The complete agent-core suite is iso-or-better against an exact clean-main baseline:

clean main: 4053 passed, 63 failed, 3 expected failures, 30 skipped, 1 todo
patched:    4054 passed, 63 failed, 3 expected failures, 30 skipped, 1 todo

The same 63 pre-existing failures occur in both runs and come from missing local workspace/profile fixtures (workspace.additional_dir and the reviewer profile); this patch adds one passing test and no failure or skip.

Additional validation:

pnpm --filter agent-core typecheck
pnpm --filter agent-core build
pnpm exec oxlint --type-aware <changed TypeScript files>  # 0 errors
pnpm exec sherif
pnpm exec changeset status
pnpm --filter kimi-code-docs build
git diff --check

Independent PR review: PASS. Final read-only Codex review: PASS.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Follow-up review fix

The v2 agent path now sends the same last_assistant_message field as the legacy Stop-hook path, sourced from the latest assistant entry in v2 context memory. The generated v2 state manifest was refreshed after the import change.

  • RED: the v2 integration test received { stopHookActive: false } without the documented assistant field.
  • GREEN: v2 external-hook + manifest tests pass 22/22; the full repository run reached 16,852 passing tests with one unrelated Kap Server timeout that passed immediately in focused replay.
  • Typecheck, lint (0 errors), Sherif, changeset, docs build, independent review, OCR/Codex review, and explicit revert proof pass.

@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ee99610

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ad8691842

ℹ️ 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".

Comment thread packages/agent-core/src/agent/turn/index.ts
@ousamabenyounes

Copy link
Copy Markdown
Author

Addressed the v2 Stop-hook payload gap in ee99610ba: last_assistant_message is now populated from the latest v2 assistant context, matching the documented legacy contract. RED reproduced the missing field; GREEN: v2 hook/manifest tests 22/22, full suite 16,852 passed with one unrelated Kap timeout green on focused retry. Typecheck, lint, Sherif, changeset, docs, independent review, OCR/Codex, and revert proof pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(hooks): include the final assistant message in Stop payload

1 participant