openclaw - ✅(Solved) Fix Session reset hooks: idle/daily reset do not trigger session-memory save [5 pull requests, 5 comments, 4 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#50891Fetched 2026-04-08 01:06:53
View on GitHub
Comments
5
Participants
4
Timeline
19
Reactions
0
Timeline (top)
referenced ×6commented ×5cross-referenced ×5subscribed ×3

Fix Action

Workaround

Currently no workaround — users lose session context when idle timeout or daily reset fires.

PR fix notes

PR #50902: fix: trigger session-memory hook on idle and daily session resets

Description (problem / solution / changelog)

Summary

Fixes #50891

  • The session-memory hook previously only triggered on manual /new and /reset commands (command:new, command:reset events), but not when sessions were automatically reset via idle timeout or daily reset
  • Added session:reset event emission in initSessionState when an automatic reset is detected (isNewSession && !resetTriggered && previousSessionEntry)
  • Updated the session-memory handler to also respond to session:reset events alongside the existing command:new/command:reset events
  • Updated HOOK.md metadata to declare session:reset in its events list

Test plan

  • Existing session-memory/handler.test.ts tests pass (17/17)
  • Existing session.test.ts tests pass (54/54)
  • Existing internal-hooks.test.ts tests pass (30/30)
  • Existing get-reply.reset-hooks-fallback.test.ts tests pass (2/2)
  • TypeScript type-check passes
  • Lint and format checks pass
  • Manual test: configure idle timeout, wait for expiry, verify memory file is created
  • Manual test: configure daily reset, cross the reset hour boundary, verify memory file is created

Changed files

  • src/auto-reply/reply/session.ts (modified, +17/-1)
  • src/hooks/bundled/session-memory/HOOK.md (modified, +4/-4)
  • src/hooks/bundled/session-memory/handler.ts (modified, +14/-7)

PR #50918: fix: trigger session-memory hook on idle and daily session resets

Description (problem / solution / changelog)

Summary

  • Add session:reset event emission for idle timeout and daily session resets
  • Update session-memory hook handler to respond to session:reset events
  • Fire hook before transcript archival so handler can access the transcript
  • Add debug logging for hook errors instead of silent swallowing

Closes #50891

Changed files

  • src/auto-reply/reply/session.ts (modified, +22/-1)
  • src/hooks/bundled/session-memory/HOOK.md (modified, +4/-4)
  • src/hooks/bundled/session-memory/handler.ts (modified, +14/-7)

PR #50933: Fix session-memory hooks for automatic session resets

Description (problem / solution / changelog)

Summary

  • emit internal session:idle_reset and session:daily_reset hook events when stale sessions rotate automatically
  • let the bundled session-memory hook persist context for those automatic resets, not just /new and /reset
  • add coverage and docs for the new session reset hook behavior

Testing

  • pnpm exec vitest run src/hooks/bundled/session-memory/handler.test.ts --config vitest.unit.config.ts
  • pnpm exec vitest run src/auto-reply/reply/session.test.ts --config vitest.config.ts

Fixes #50891.

Changed files

  • src/auto-reply/reply/session.test.ts (modified, +867/-16)
  • src/auto-reply/reply/session.ts (modified, +140/-25)
  • src/hooks/bundled/session-memory/HOOK.md (modified, +5/-4)
  • src/hooks/bundled/session-memory/handler.test.ts (modified, +43/-17)
  • src/hooks/bundled/session-memory/handler.ts (modified, +17/-6)

PR #51293: fix(session-memory): emit session:idle_reset and session:daily_reset events for automatic resets

Description (problem / solution / changelog)

Summary

Fixes #50891

The session-memory hook only subscribed to command:new and command:reset events. Idle timeout and daily reset bypass the hook system entirely, so session context was never saved on automatic resets.

Problem

When a session becomes stale due to idle timeout or daily reset policy (not an explicit /new or /reset command), no command:new or command:reset event is emitted. The session-memory hook never fires, so conversation context is lost without being saved to memory.

Solution

  • Emit new events: In session.ts, after detecting a stale session (non-command reset), emit session:idle_reset or session:daily_reset via triggerInternalHook. The choice between the two is determined by whether idleExpiresAt has elapsed (idle) or the daily reset threshold was crossed (daily).
  • Handler update: Updated session-memory/handler.ts to accept both session:idle_reset and session:daily_reset event types in addition to the existing command:new / command:reset.
  • HOOK.md metadata: Added session:idle_reset and session:daily_reset to the events list so the hook loader registers these subscriptions at gateway startup.

Changes

FileChange
src/auto-reply/reply/session.tsCapture full SessionFreshness result; emit session:idle_reset or session:daily_reset on stale non-command resets
src/hooks/bundled/session-memory/handler.tsAccept session:idle_reset and session:daily_reset alongside command events
src/hooks/bundled/session-memory/HOOK.mdRegister new event keys in metadata

Testing

  • Build passes: pnpm exec tsdown
  • Existing tests unaffected (new events fire only on stale non-command resets)

Checklist

  • Follows existing code patterns
  • TypeScript compiles without errors
  • No breaking changes to existing hook API
  • Both idle and daily reset cases are covered

Changed files

  • src/auto-reply/reply/session.ts (modified, +22/-4)
  • src/hooks/bundled/session-memory/HOOK.md (modified, +2/-2)
  • src/hooks/bundled/session-memory/handler.ts (modified, +8/-5)

PR #61675: feat: fire session reset hooks for daily and idle resets

Description (problem / solution / changelog)

Summary

  • Problem: Internal hooks and before_reset plugin hook only fire for manual /new and /reset commands, not for daily (4AM) or idle-timeout session resets. This means session-memory never saves on daily/idle resets.
  • Why it matters: 4 community issues report lost session memory on daily/idle resets (#10142, #31266, #50891, #43524)
  • What changed: Wire both hook types into the lazy staleness path in initSessionState(), update session-memory registration and filter
  • What did NOT change (scope boundary): No new hook event names, no changes to plugin SDK API, no extraction/refactor — only export added to existing functions

Change Type (select all)

  • Bug fix
  • Feature

Scope (select all touched areas)

  • Memory / storage

Linked Issue/PR

  • Closes #10142
  • Closes #31266
  • Closes #50891
  • Closes #43524
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: initSessionState() fires session_end/session_start plugin hooks for lazy resets but never fires triggerInternalHook or hookRunner.runBeforeReset. These only fire via emitResetCommandHooks() in commands-core.ts, which is only called for manual /new and /reset commands.
  • Missing detection / guardrail: No test asserted that internal hooks fire for lazy resets
  • Contributing context (if known): The lazy evaluation design means sessions aren't proactively killed — staleness is checked on next message arrival, a code path separate from manual commands

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
  • Target test or file: src/auto-reply/reply/session.stale-hooks.test.ts (new), src/hooks/bundled/session-memory/handler.test.ts (extended)
  • Scenario the test should lock in: Internal hook fires with action: "daily" / "idle" when session is stale; before_reset plugin hook fires for lazy resets; no double-fire on manual reset
  • Why this is the smallest reliable guardrail: Mocks triggerInternalHook and hookRunner to assert dispatch without side-effects
  • Existing test that already covers this (if any): session-hooks-context.test.ts covers session_end/session_start but not internal hooks or before_reset

User-visible / Behavior Changes

session-memory now saves session summaries on daily (4AM) and idle-timeout resets, not just manual /new and /reset. Plugin before_reset hook now fires for lazy resets, giving plugins pre-archive transcript access.

Diagram (if applicable)

Before:
[lazy reset] -> session_end + session_start hooks only

After:
[lazy reset] -> internal hook (command:daily/idle) + before_reset + session_end + session_start

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Any
  • Runtime/container: Node.js 24
  • Integration/channel (if any): Any channel with daily or idle reset configured

Steps

  1. Configure a session with daily reset (default 4AM)
  2. Have an active session with messages before 4AM
  3. Send a message after 4AM (triggering lazy staleness detection)

Expected

  • session-memory saves a summary of the previous session
  • before_reset plugin hook fires with reason: "daily" and transcript messages

Actual (before this PR)

  • session-memory does not fire — no summary saved
  • before_reset plugin hook does not fire

Evidence

  • Failing test/log before + passing after

Human Verification (required)

  • Verified scenarios: Daily reset with stale session triggers session-memory save; idle reset triggers save; manual /new does not double-fire
  • Edge cases checked: First-ever session (no previous entry), system events (heartbeat), fresh session
  • What you did not verify: End-to-end with real LLM slug generation (mocked in tests)

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: before_reset receives the post-archive sessionFile path (after renameSync), not the original path. loadBeforeResetTranscript handles ENOENT by scanning for the latest .reset.* archived sibling.
    • Mitigation: This matches the manual reset path behavior. The stable post-archive path is intentional — it avoids racing transcript reads against the archive rename.

AI Disclosure

  • Mark as AI-assisted in the PR title or description
  • Note the degree of testing: fully tested — 10 unit tests (7 new + 3 extended) + manual daily/idle reset verification
  • Confirm: I understand what this code does and have verified the hook dispatch logic, guard conditions, and fire-and-forget patterns

🤖 AI-assisted with Claude Code

cc @vincentkoc (hooks/plugins CODEOWNER)

Changed files

  • src/auto-reply/reply/commands-reset-hooks.ts (modified, +3/-3)
  • src/auto-reply/reply/session.stale-hooks.test.ts (added, +295/-0)
  • src/auto-reply/reply/session.ts (modified, +55/-2)
  • src/hooks/bundled/session-memory/HOOK.md (modified, +1/-1)
  • src/hooks/bundled/session-memory/handler.test.ts (modified, +74/-0)
  • src/hooks/bundled/session-memory/handler.ts (modified, +5/-1)
RAW_BUFFERClick to expand / collapse

Problem

There are three ways to reset a session in OpenClaw:

  1. Manual: /new or /reset command — triggers session-memory hook ✅
  2. Idle timeout: session.reset.idleMinutes — does NOT trigger session-memory
  3. Daily reset: default 4:00 AM — does NOT trigger session-memory

The hooks system only listens for command:new and command:reset events, but idle timeout and daily reset are gateway-internal mechanisms that don't fire these events.

Expected Behavior

When a session is automatically reset (idle or daily), the session-memory hook should save the session context to memory, just as it does for manual /new//reset.

Suggested Fix

  1. Add session:idle_reset and session:daily_reset events to the hooks system
  2. Have session-memory hook respond to these events as well, OR
  3. Document clearly that automatic resets do not preserve context

Workaround

Currently no workaround — users lose session context when idle timeout or daily reset fires.

Additional Context

  • OpenClaw version: 2026.3.13
  • Hooks documentation: docs/automation/hooks.md

extent analysis

Fix Plan

To fix the issue, we will add two new events to the hooks system: session:idle_reset and session:daily_reset. We will then modify the session-memory hook to listen for these events.

Step-by-Step Solution

  • Add the following events to the hooks system:
    • session:idle_reset
    • session:daily_reset
  • Modify the session-memory hook to respond to the new events:
// session-memory hook
module.exports = async function(session) {
  // Existing code for command:new and command:reset events
  // ...

  // New code for session:idle_reset and session:daily_reset events
  if (session.event === 'session:idle_reset' || session.event === 'session:daily_reset') {
    // Save session context to memory
    await saveSessionContext(session);
  }
};
  • Update the idle timeout and daily reset mechanisms to fire the new events:
// Idle timeout mechanism
if (session.idleMinutes > 0 && session.lastActivity < Date.now() - session.idleMinutes * 60 * 1000) {
  // Fire session:idle_reset event
  await hooks.emit('session:idle_reset', session);
  // Reset session
  session.reset();
}

// Daily reset mechanism
if (dailyResetTime === new Date().getHours()) {
  // Fire session:daily_reset event
  await hooks.emit('session:daily_reset', session);
  // Reset session
  session.reset();
}

Verification

To verify that the fix worked, test the following scenarios:

  • Idle timeout: let the session idle for the specified time and verify that the session context is saved to memory.
  • Daily reset: wait for the daily reset time and verify that the session context is saved to memory.
  • Manual reset: verify that the session context is still saved to memory when the /new or /reset command is used.

Extra Tips

  • Make sure to update the hooks documentation to include the new events.
  • Consider adding logging to track when the new events are fired and when the session context is saved to memory.

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