Skip to content

Feature Request: Pre-compaction memory flush with structured context preservation #6622

@gwthm-in

Description

@gwthm-in

Problem

When context compaction occurs, important information like API keys and credentials can be lost if not explicitly saved to files.

Example scenario:

  1. Agent registers on an external service and receives API key
  2. Agent continues conversation without saving key to file
  3. Context gets compacted
  4. API key is lost forever

Current Behavior

  • OpenClaw sends "Pre-compaction memory flush" message before compaction
  • By this point, the summary may already be generated and details lost
  • Agent has to manually remember to save important data during session

Suggested Improvements

1. Structured pre-compaction hook

Allow agents to define what should always be captured before compaction:

compaction:
  always_save:
    - api_keys
    - credentials
    - project_state

2. Earlier warning

Give agents more notice before compaction, not just at the moment it happens.

3. Automatic credential detection

Detect patterns like api_key, token, secret in conversation and prompt agent to save them.

4. Session state file

Automatically maintain a session state file that persists key context across compactions.

Workarounds Currently Used

  • Save credentials immediately to /data/.config/
  • Symlink ~/.config/ to /data/.config/ for persistence
  • Flush memory during session at trigger points (decisions, completions)
  • Maintain project state files in memory/projects/

Environment

  • OpenClaw: latest
  • Channel: Telegram

Happy to discuss further or help implement!

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