openclaw - 💡(How to fix) Fix [Bug]: /compact rotates session ID before plugins flush, causing silent data loss on external sync [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#59296Fetched 2026-04-08 02:26:19
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

The /compact command rotates the local session ID to a new UUID before the compact handler fires for plugins. Plugins that need to sync the pre-compaction history (e.g. OpenViking) receive the new session ID, attempt to commit against it, and fail silently because the new ID does not yet exist in the remote store.

Root Cause

The /compact command rotates the local session ID to a new UUID before the compact handler fires for plugins. Plugins that need to sync the pre-compaction history (e.g. OpenViking) receive the new session ID, attempt to commit against it, and fail silently because the new ID does not yet exist in the remote store.

Code Example

# Successful compact (session existed in OV before compact):
2026-03-30T17:33:46.886-04:00 [plugins] openviking: compact committing session=e5137499-5b32-451d-b50c-8934976f6bc4 (wait=true, tokenBudget=1000000)
2026-03-30T17:33:47.415-04:00 [plugins] openviking: compact committed session=e5137499-5b32-451d-b50c-8934976f6bc4, archived=true, memories=0, task_id=2dde14b6-22ac-462c-a571-2e3274c23be1

# Failed compact (new rotated ID, never existed in OV):
2026-04-01T12:04:32.985-04:00 [plugins] openviking: compact committing session=3d94b36f-4a83-452d-ab6d-fdf42c147020 (wait=true, tokenBudget=1000000)
# No "compact committed" line follows. Lane task ends immediately:
2026-04-01T12:04:32.988-04:00 [diagnostic] lane task done: lane=main durationMs=30

---

$ ov session list | grep "3d94b36f"
(no results)
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

The /compact command rotates the local session ID to a new UUID before the compact handler fires for plugins. Plugins that need to sync the pre-compaction history (e.g. OpenViking) receive the new session ID, attempt to commit against it, and fail silently because the new ID does not yet exist in the remote store.

Steps to reproduce

  1. Run an OpenClaw session with the OpenViking memory plugin enabled.
  2. Accumulate conversation history in the session.
  3. Run /compact.
  4. Observe that the plugin's compact handler receives the new (rotated) session ID.
  5. The plugin attempts to commit session history to the new ID.
  6. The commit silently fails because the new ID has no corresponding entry in the remote store.

Expected behavior

Plugins receiving the compact handler should be able to flush or commit history for the session that was just compacted. The pre-compaction session ID should be available to the handler, either as the primary ID or as an explicit previousSessionId field.

Actual behavior

The session ID is rotated before the handler fires. The plugin receives only the new ID. The commit produces a "compact committing" log line but never produces a "compact committed" confirmation, and the session is missing from the external store.

Evidence from gateway log:

# Successful compact (session existed in OV before compact):
2026-03-30T17:33:46.886-04:00 [plugins] openviking: compact committing session=e5137499-5b32-451d-b50c-8934976f6bc4 (wait=true, tokenBudget=1000000)
2026-03-30T17:33:47.415-04:00 [plugins] openviking: compact committed session=e5137499-5b32-451d-b50c-8934976f6bc4, archived=true, memories=0, task_id=2dde14b6-22ac-462c-a571-2e3274c23be1

# Failed compact (new rotated ID, never existed in OV):
2026-04-01T12:04:32.985-04:00 [plugins] openviking: compact committing session=3d94b36f-4a83-452d-ab6d-fdf42c147020 (wait=true, tokenBudget=1000000)
# No "compact committed" line follows. Lane task ends immediately:
2026-04-01T12:04:32.988-04:00 [diagnostic] lane task done: lane=main durationMs=30

OpenViking session store confirms the rotated ID never made it in:

$ ov session list | grep "3d94b36f"
(no results)

OpenClaw version

v2026.4.1

Operating system

macOS 15.4 (arm64)

Install method

npm global

Model

anthropic/claude-opus-4-6

Provider / routing chain

openclaw -> anthropic

Additional provider/model setup details

OpenViking plugin is configured as the memory slot. The plugin's compact handler attempts to commit the session transcript to OpenViking's store using the session ID provided by the hook context.

Logs, screenshots, and evidence

See log excerpts above showing the successful vs. failed compact commit pattern. The failed case shows "compact committing" with no subsequent "compact committed", and the session ID is absent from the OV session store.

Impact and severity

  • Affected: Any plugin that uses the compact handler to flush session data to an external store
  • Severity: High (session history is silently lost from the external store on every compaction)
  • Frequency: Every /compact invocation with an affected plugin
  • Consequence: Session history that should be persisted to OpenViking is dropped, creating gaps in long-term memory

Additional information

Root cause is an ordering issue in the session lifecycle: the ID rotation and the plugin flush happen in the wrong sequence. Two potential fixes:

  1. Immediate: Snapshot the original session ID before rotation and pass it to the compact handler as previousSessionId, so plugins can target the correct store entry.
  2. Systemic: Implement two-phase rotation where plugins complete their flush against the old ID before the session identity changes.

The immediate fix is backward-compatible (additive field). Happy to pick this up and PR if wanted.

extent analysis

TL;DR

Pass the original session ID to the compact handler as previousSessionId to allow plugins to commit against the correct store entry.

Guidance

  • Identify the point where the session ID is rotated and snapshot the original ID before rotation.
  • Modify the compact handler to accept an additional previousSessionId field.
  • Pass the snapshotted original session ID to the compact handler as previousSessionId.
  • Update plugins (e.g., OpenViking) to use the previousSessionId for committing session history.

Example

// Pseudo-code example of passing previousSessionId to compact handler
const originalSessionId = session.id;
const newSessionId = generateNewId();
session.id = newSessionId;
compactHandler({ session: session, previousSessionId: originalSessionId });

Notes

The immediate fix is backward-compatible, but the systemic fix (two-phase rotation) may require more significant changes to the session lifecycle.

Recommendation

Apply the immediate fix by passing the original session ID as previousSessionId to the compact handler, as it is backward-compatible and addresses the issue directly.

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…

FAQ

Expected behavior

Plugins receiving the compact handler should be able to flush or commit history for the session that was just compacted. The pre-compaction session ID should be available to the handler, either as the primary ID or as an explicit previousSessionId field.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING