#4594·hindsight

session_end transcript fallback never loads with SQLite-backed OpenClaw transcripts - un-retained turns silently lost at session end

Author: PaulClawitzkiCreated Sep 21, 2026Updated Oct 1, 2026
Labelsintegration:openclaw

Bug Description

Plugin 0.13.0 fixed #4341 by adding sessionEndMessagesFromTranscript(), which loads the transcript from event.sessionFile when a session_end event carries no messages. With OpenClaw 2026.9.4 this fallback never yields messages, so every session_end (via /new, /reset, gateway restart/stop, daily reset) still bails out with:

[Hindsight Hook] session_end triggered - bank: <bank>
[Hindsight Hook] No messages in event, skipping retention

Root cause: OpenClaw 2026.9.4 persists session transcripts in SQLite (<state>/agents/<agent>/agent/openclaw-agent.sqlite, table transcript_events). There is no .jsonl transcript file on disk for new sessions (verified: <sessionId>.jsonl absent, no .reset.* variant either — the sessions directory only contains legacy files from older OpenClaw versions). The fallback in dist/session-file.js reads the transcript with readFileSync(filePath, "utf8") and parses JSONL — on a non-existent path this throws, is swallowed by the catch, and returns undefined, producing the "No messages in event" bail-out.

Source path (dist/index.js):

typescript
const sessionFile = typeof payload.sessionFile === "string" ? payload.sessionFile : undefined;
if (!sessionFile) return undefined;
const messages = read(sessionFile, agentId).messages; // parseSessionFile -> readFileSync(JSONL)
return messages.length > 0 ? messages : undefined;

Reproduction

  1. Configure retainEveryNTurns: 3, retainOverlapTurns: 1 against OpenClaw 2026.9.4.
  2. Start a new session, send 2 user turns (fewer than the cadence).
  3. Run /reset.
  4. Observe the plugin debug log: session_end triggered → No messages in event, skipping retention.
  5. Check the Hindsight bank: no document was created — the 2 un-retained turns are silently lost.

With debug: true in the plugin config the agent_end cadence itself is healthy:

agent_end triggered - bank: <bank>
Turn 1/3, skipping retain (next at turn 3)
agent_end triggered - bank: <bank>
Turn 2/3, skipping retain (next at turn 3)

Gateway shutdown behaves the same (session_end × 2 → same bail), and cadence retains themselves arrive correctly once turn 3 is reached (verified via server-side logs).

Expected Behavior

session_end (any variant: /new, /reset, gateway restart/stop, daily/idle reset) flushes the un-retained tail — including sessions with fewer than retainEveryNTurns un-retained turns.

Actual Behavior

session_end bails with "No messages in event, skipping retention" because the transcript fallback cannot read event.sessionFile (SQLite-backed transcripts, no JSONL file on disk). Sessions ending with fewer than retainEveryNTurns un-retained turns lose them silently.

Version

  • @vectorize-io/hindsight-openclaw 0.13.0
  • OpenClaw 2026.9.4
  • Hindsight API 0.10.0
  • Config: retainEveryNTurns: 3, retainOverlapTurns: 1, retainToolCalls: false, retainExtractionMode: "concise", debug: true

Suggested fix options

  1. Plugin: load the transcript via OpenClaw's runtime API / session store (SQLite) instead of the legacy JSONL path.
  2. OpenClaw: include the final messages directly in the session_end hook payload.
  3. OpenClaw: guarantee sessionFile points to a readable transcript at hook time (e.g., materialize it on session end).

Related: #4341, #4229