Skip to content

UI 'Compact Session Log' should use smart LLM-based compaction instead of raw file truncation #14606

@yanfeatherai

Description

@yanfeatherai

Problem

The "Compact Session Log" button in the OpenClaw UI (macOS app / web control panel) performs a raw JSONL file truncation — it simply keeps the last N lines and discards the rest. This results in complete context loss after compaction.

Meanwhile, the /compact text command uses the Pi Coding Agent SDK's intelligent compaction, which:

  • Generates a structured LLM summary (Goal, Progress, Key Decisions, Next Steps, Critical Context)
  • Keeps recent messages (keepRecentTokens: 20000)
  • Tracks file operations (read/modified files)
  • Supports iterative summarization (merges with previous summaries)

This is the same compaction mechanism used by Claude Code, and it produces seamless context continuity.

Root Cause

The UI button calls sessions.compact in src/gateway/server-methods/sessions.ts, which does:

const keptLines = lines.slice(-maxLines);
fs.writeFileSync(filePath, keptLines.join("\n") + "\n", "utf-8");

No LLM call, no summarization — just file truncation.

The /compact text command (src/auto-reply/reply/commands-compact.ts) calls compactEmbeddedPiSession(), which uses the full Pi SDK session.compact() with structured summarization prompts.

Additional Issue: /compact unreachable on Slack

The /compact command has scope: "text" and textAlias: "/compact", but on Slack, all /-prefixed messages are intercepted by Slack as native slash commands and never reach OpenClaw. This means there is no way for Slack users to trigger smart compaction manually.

Suggested Fix

  1. UI button: Change sessions.compact to call compactEmbeddedPiSession() instead of raw file truncation
  2. Slack accessibility: Either register /compact as a Slack slash command, or support a non-/ prefix alternative (e.g., !compact)

Environment

  • OpenClaw with Slack channel
  • Pi Coding Agent SDK (shared with Claude Code)
  • Discovered by source code analysis comparing sessions.compact vs commands-compact.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions