fix(hooks): stop also closes session for Codex (closes #493)#579
Conversation
Codex does not fire a separate SessionEnd event, so its Stop hook is the only signal we get when a Codex session terminates. The current stop hook only POSTs /agentmemory/summarize, leaving the session row stuck on status:"active" in the viewer for Codex users (#493). Stop now ALSO POSTs /agentmemory/session/end, best-effort with a short 5s timeout. For Claude Code this is a harmless idempotent second call (session-end.mjs runs on the dedicated SessionEnd hook and sets the same endedAt + status fields). For Codex it's the only path that closes the lifecycle. Tests (1081) + build pass. plugin/scripts/stop.mjs regenerated by tsdown.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
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 (2)
📝 WalkthroughWalkthroughThe PR adds session cleanup requests to both the plugin stop script and TypeScript stop hook. After each sends a summarize request to agentmemory, they now issue a best-effort POST to ChangesSession cleanup on stop
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
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 docstrings
🧪 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 |
|
@rohitg00 However, there is another issue. Each time the conversation ends, the codex automatically triggers sessionend by calling stop, which prevents the subsequent conversations within the same session from being remembered. This is because the current session has already been marked as completed after the last conversation. |
Summary
Closes #493.
Codex sessions stayed
status: "active"in the viewer forever because Codex doesn't fire a separateSessionEndhook and the existingStophandler only called/agentmemory/summarize.session-end.mjsalready POSTs/agentmemory/session/end, but it's only wired to Claude Code'sSessionEndevent. Codex has no equivalent.Fix
src/hooks/stop.tsnow also POSTs/agentmemory/session/endafter the summarize call, best-effort with a 5s timeout. For Claude Code this is a harmless idempotent second call (the dedicatedSessionEndhook still runs and sets the sameendedAt+statusfields). For Codex it's the only path that closes the lifecycle.Diff
src/hooks/stop.ts—+18adds the second fetchplugin/scripts/stop.mjs—+8regenerated by tsdownValidation
npm test→ 97/97 test files, 1081/1081 tests passnpm run build→ bundle cleanNotes on idempotency
POST /agentmemory/session/endis akv.updatewith two{type: "set"}ops onendedAtandstatus. Repeating it is safe and overwrites with the current time +"completed"— desired behavior since Stop fires after the user-visible session is over.If a follow-up sets a stricter "don't overwrite endedAt if already set" guard at the server side, that's orthogonal and won't regress this fix.
Summary by CodeRabbit