fix: remove premature session/end call from stop hook#746
Conversation
The agentStop hook (src/hooks/stop.ts) was calling /agentmemory/session/end on every assistant turn completion. In Claude Code CLI this fires after every response, causing sessions to be marked completed mid-conversation. Claude Code has a dedicated sessionEnd hook for true session exit; Codex does not. The session/end call was originally added as a Codex workaround (rohitg00#579) but cannot be safely retained because we lack a reliable Codex identifier in the hook payload, and a blacklist guard would still incorrectly fire for Hermes and other agents without SessionEnd. Remove the call with a TODO comment documenting the Codex regression. Re-add once a reliable agent identifier is available. Fixes rohitg00#745 Signed-off-by: Fu <1340468261@qq.com>
|
@LeonemFu is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThe agentStop hook is refactored to call only the ChangesStop Hook Endpoint Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Removes the premature
/agentmemory/session/endcall from thestop.mjshook script that was causing Claude Code sessions to be markedcompletedmid-conversation.Problem
src/hooks/stop.tsfired/agentmemory/session/endon everyagentStopevent. In Claude Code CLI,agentStopfires after every assistant turn — not just at session exit — because Claude Code has a dedicatedsessionEndhook for true exit. This caused:completedwhile the user was still actively chatting.session-end.mjslifecycle events (slot-reflect, graph-extract, consolidation) firing prematurely or against an already-completed session.event::session::stopped trigger failed.Root Cause
The
/session/endcall was intentionally added in commit35512414(#579) as a workaround for Codex, which does not fire a separateSessionEndevent. At the time it was assumed to be "harmless idempotent" for Claude Code, but that assumption was incorrect — Claude Code firesagentStopafter every assistant turn.Why not guard by agent type?
We cannot reliably detect Codex from the hook payload (no confirmed
entrypointvalue or other identifier). A black-list guard (entrypoint !== "cli") would still incorrectly firesession/endfor Hermes and other agents that also lack a dedicatedSessionEndhook. A white-list guard is not possible without a known Codex identifier.Changes
src/hooks/stop.ts: Commented out thesession/endfetch with aTODO(codex-session-end)explaining the regression.test/copilot-plugin.test.ts: Added a test verifyingstop.mjscalls/summarizebut not/session/end.plugin/scripts/stop.mjs: Rebuilt from source.Verification
All 17 tests in
copilot-plugin.test.tspass, including the new stop-hook behavior test.Regression Note
Codex sessions will no longer be auto-closed on the
Stophook. This is a known regression that can be reverted once a reliable Codex identifier is available in the hook payload.Related
Fixes #745
35512414— originally addedsession/endtostop.mjsas a Codex workaround (fix(hooks): stop also closes session for Codex (closes #493) #579, fixes Codex Stop hook does not mark sessions ended #493).Summary by CodeRabbit
Bug Fixes
Tests