fix: end Codex sessions on Stop hook#495
Conversation
Signed-off-by: Nanami <Rex57@users.noreply.github.com>
|
@Rex57 is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe Stop hook in ChangesStop Hook Session Lifecycle
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/codex-plugin.test.ts`:
- Around line 101-105: The test currently only checks that both stop scripts
exist in stopCommands (from hooks.hooks.Stop) but not their order; update the
assertions to verify sequence explicitly by locating the two command strings
(from stopCommands) and asserting that "node
${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs" appears before "node
${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs" (e.g., compare their indices or
assert the slice/sequence matches the expected order) so regressions that invert
these handlers fail the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5efbe79c-ac8f-47cc-9919-53c825dbede8
📒 Files selected for processing (2)
plugin/hooks/hooks.codex.jsontest/codex-plugin.test.ts
| const stopCommands = hooks.hooks.Stop.flatMap((entry) => | ||
| entry.hooks.map((handler) => handler.command), | ||
| ); | ||
| expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs"); | ||
| expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs"); |
There was a problem hiding this comment.
Assert command order, not just presence.
Line 101 flattens commands and Lines 104-105 only check containment. This misses regressions where session-end.mjs runs before stop.mjs. Please assert sequence explicitly.
Suggested test tightening
- expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs");
- expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs");
+ const stopIdx = stopCommands.indexOf("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs");
+ const endIdx = stopCommands.indexOf("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs");
+ expect(stopIdx).toBeGreaterThanOrEqual(0);
+ expect(endIdx).toBeGreaterThanOrEqual(0);
+ expect(stopIdx).toBeLessThan(endIdx);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const stopCommands = hooks.hooks.Stop.flatMap((entry) => | |
| entry.hooks.map((handler) => handler.command), | |
| ); | |
| expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs"); | |
| expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs"); | |
| const stopCommands = hooks.hooks.Stop.flatMap((entry) => | |
| entry.hooks.map((handler) => handler.command), | |
| ); | |
| const stopIdx = stopCommands.indexOf("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs"); | |
| const endIdx = stopCommands.indexOf("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs"); | |
| expect(stopIdx).toBeGreaterThanOrEqual(0); | |
| expect(endIdx).toBeGreaterThanOrEqual(0); | |
| expect(stopIdx).toBeLessThan(endIdx); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/codex-plugin.test.ts` around lines 101 - 105, The test currently only
checks that both stop scripts exist in stopCommands (from hooks.hooks.Stop) but
not their order; update the assertions to verify sequence explicitly by locating
the two command strings (from stopCommands) and asserting that "node
${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs" appears before "node
${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs" (e.g., compare their indices or
assert the slice/sequence matches the expected order) so regressions that invert
these handlers fail the test.
|
Merged + shipped in v0.9.19 — https://github.com/rohitg00/agentmemory/releases/tag/v0.9.19 Thanks @Rex57 for the surface-level fix + the regression test on the Stop chain. Closed both #493 and the related #308 thread. |
v0.9.19 shipped #495 which chained session-end.mjs after stop.mjs on the Codex Stop hook. Field-testing surfaced the underlying issue: Codex fires Stop multiple times within a single conversation (once per assistant turn), so chaining session-end marked sessions as completed while later observations were still arriving. #501 reverts the chain. Stop returns to summarize-only behavior. The SessionEnd-shaped solution (a dedicated terminate event the agent sends only once on real session end) tracks at #493. Files bumped (9): - package.json, packages/mcp/package.json - plugin/.claude-plugin/plugin.json, plugin/.codex-plugin/plugin.json - src/version.ts, src/types.ts - src/functions/export-import.ts - test/export-import.test.ts - CHANGELOG.md 1034/1034 tests pass.
Summary
Stopto run the existingsession-end.mjshook afterstop.mjs.SessionEndentry inhooks.codex.json.Fixes #493.
Related: #308.
Verification
npx tsdownpassed in isolated fork clone.node -e "JSON.parse(require('fs').readFileSync('plugin/hooks/hooks.codex.json','utf8')); console.log('hooks.codex.json OK')"passed.npm testintentionally skipped to avoid any accidental interaction with the live AgentMemory setup.Summary by CodeRabbit
Chores
Tests