openclaw - 💡(How to fix) Fix Feature: session:end hook event for session summary automation [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#56842Fetched 2026-04-08 01:47:05
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Add a session:end lifecycle hook event that fires when a session is ending or being reset.

Root Cause

Add a session:end lifecycle hook event that fires when a session is ending or being reset.

Fix Action

Fix / Workaround

Workaround in use

RAW_BUFFERClick to expand / collapse

Summary

Add a session:end lifecycle hook event that fires when a session is ending or being reset.

Motivation

Currently, the hooks system lists session:end as a planned future event (per docs). This is a real blocker for automating session memory/summary workflows.

Use case: When a session ends (via /new, idle timeout, or daily reset), automatically write a structured summary of that session to a memory file in the agent workspace. This enables long-running agents to maintain a running log of activity across sessions without requiring the user to manually trigger a summary.

The existing session-memory bundled hook partially covers this (triggers on command:new), but it misses:

  • Sessions that end via daily/idle timeout (no /new issued)
  • Graceful shutdowns
  • Any programmatic session termination

Proposed Event

\\ ypescript // session:end event context { type: 'session', action: 'end', sessionKey: string, sessionId: string, timestamp: Date, messages: string[], context: { reason: 'reset' | 'idle' | 'daily' | 'shutdown' | 'manual', workspaceDir?: string, sessionFile?: string, cfg?: OpenClawConfig, } } \\

Requested alongside

  • session:start (also listed as planned) — useful for bootstrapping session context on resume

Environment

  • OpenClaw version: 2026.3.2
  • Platform: Windows 10 / Node 24
  • Multi-agent setup: 12+ agents across workspaces

Workaround in use

Heartbeat-based periodic summaries + session-memory hook on command:new. Works but incomplete.

extent analysis

Fix Plan

To implement the session:end lifecycle hook event, follow these steps:

  • Step 1: Define the event context Create a new TypeScript interface for the session:end event context:

interface SessionEndEvent { type: 'session'; action: 'end'; sessionKey: string; sessionId: string; timestamp: Date; messages: string[]; context: { reason: 'reset' | 'idle' | 'daily' | 'shutdown' | 'manual'; workspaceDir?: string; sessionFile?: string; cfg?: OpenClawConfig; }; }

* **Step 2: Create the event emitter**
  Modify the existing session management code to emit the `session:end` event when a session is ending or being reset:
  ```typescript
import { EventEmitter } from 'events';

const sessionEmitter = new EventEmitter();

// Example usage:
sessionEmitter.emit('session:end', {
  type: 'session',
  action: 'end',
  sessionKey: 'example-session-key',
  sessionId: 'example-session-id',
  timestamp: new Date(),
  messages: [],
  context: {
    reason: 'reset',
  },
});
  • Step 3: Implement the event listener Create a new hook that listens for the session:end event and writes a structured summary of the session to a memory file:

import { writeFile } from 'fs/promises';

sessionEmitter.on('session:end', (event: SessionEndEvent) => { const summary = { sessionKey: event.sessionKey, sessionId: event.sessionId, timestamp: event.timestamp, messages: event.messages, context: event.context, };

const workspaceDir = event.context.workspaceDir; const sessionFile = event.context.sessionFile;

if (workspaceDir && sessionFile) { const filePath = ${workspaceDir}/${sessionFile}; writeFile(filePath, JSON.stringify(summary, null, 2)); } });

### Verification
To verify that the fix worked, test the `session:end` event by triggering a session end event and checking if the summary is written to the memory file.

### Extra Tips
* Make sure to handle errors and edge cases when writing to the memory file.
* Consider adding additional logging or monitoring to track the `session:end` event and any issues that may arise.
* Review the existing `session-memory` hook and update it to work in conjunction with the new `session:end` event.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING