Context Recovery
by @jdrhyne
Automatically recover working context after session compaction or when continuation is implied but context is missing. Works across Discord, Slack, Telegram,...
clawhub install context-recoveryπ About This Skill
name: context-recovery description: Automatically recover working context after session compaction or when continuation is implied but context is missing. Works across Discord, Slack, Telegram, Signal, and other supported channels. homepage: https://github.com/PSPDFKit-labs/agent-skills repository: https://github.com/PSPDFKit-labs/agent-skills metadata: { "openclaw": { "emoji": "π", }, }
Context Recovery
Automatically recover working context after session compaction or when continuation is implied but context is missing. Works across Discord, Slack, Telegram, Signal, and other supported channels.
Use when: Session starts with truncated context, user references prior work without specifying details, or compaction indicators appear.
Safety Boundaries
Triggers
Automatic Triggers
tag (compaction detected)Manual Triggers
Execution Protocol
Step 1: Detect Active Channel
Extract from runtime context:
channel β discord | slack | telegram | signal | etc.channelId β the specific channel/conversation IDthreadId β for threaded conversations (Slack, Discord threads)Step 2: Fetch Channel History (Adaptive Depth)
Initial fetch:
message:read
channel:
channelId:
limit: 50
Adaptive expansion logic:
1. Parse timestamps from returned messages
2. Calculate time span: newest_timestamp - oldest_timestamp
3. If time span < 2 hours AND message count == limit:
- Fetch additional 50 messages (using before parameter if supported)
- Repeat until time span β₯ 2 hours OR total messages β₯ 100
4. Hard cap: 100 messages maximum (token budget constraint)
Thread-aware recovery (Slack/Discord):
# If threadId is present, fetch thread messages first
message:read
channel:
threadId:
limit: 50Then fetch parent channel for broader context
message:read
channel:
channelId:
limit: 30
Parse for:
Step 3: Fetch Session Context (safe mode)
Use platform/session APIs only (no shell filesystem scans):
# List recent sessions (if tool exists)
sessions_list:
limit: 5Pull last messages from likely matching session
sessions_history:
sessionKey:
limit: 80
includeTools: true
If session APIs are unavailable, skip this step and proceed with channel-only evidence.
Step 4: Optional Memory Check (explicitly scoped)
Only inspect memory if the agent runtime already provides a scoped memory tool/path. Do not run shell glob scans across home directories.
Step 5: Synthesize Context
Compile a structured summary:
## Recovered ContextChannel: # ()
Time Range: to
Messages Analyzed:
Active Project/Task
Repository:
Branch:
PR: # β Recent Work Timeline
1. []
2. []
3. [] Pending/Incomplete Actions
β³ ""
β³ "" Last User Request
> ""
Step 6: Optional Persistence (consent-first)
Do not write to disk by default. If persistence is useful, ask first:
> "I can cache this recovered context to memory for later continuity. Should I save it?"
Step 7: Respond with Context
Present the recovered context, then prompt:
> "Context recovered. Your last request was [X]. This action [completed/did not complete]. Shall I [continue/retry/clarify]?"
Channel-Specific Notes
Discord
channelId from the incoming message metadatathreadId in message metadataSlack
channel parameter with Slack channel IDthreadId β always check for thread context firstTelegram / Signal / Others
message:read interfaceConstraints
Auto-Trigger Detection
At session start, scan for compaction indicators:
# Pseudocode for trigger detection
if message contains "":
trigger_context_recovery()
elif message contains any of ["Summary unavailable", "context limits", "truncated", "compacted"]:
trigger_context_recovery()
elif message matches continuation_patterns:
# "continue", "where were we", "did this happen", etc.
trigger_context_recovery()
Do not wait for user to ask β if compaction is detected, proactively recover and present context.
Example
Scenario: Session starts with compaction summary
User message: "Summary unavailable due to context limits... "
User message: "did this happen?"
Agent executes:
1. Detects compaction via tag
2. message:read channel=discord channelId=1460342116516364533 limit=50
3. Calculates time span: 2.5 hours β sufficient, no expansion needed
4. Parses messages, finds last action: "Now let me extract the key orchestration decisions..."
5. Checks session context APIs β extracts recent user requests
6. Responds:
> "Context recovered. Your last request was to extract orchestration decisions from Nexus archived sessions for PR #137 (Skills & Agents System). This action did not complete before context was truncated.
>
> Recovered state:
> - PR #137: 15,053 additions, 91 files, CONFLICTING merge state
> - Spec location: content/spec-skills-agents-system.md (2,067 lines)
>
> Shall I proceed with the extraction?"
π‘ Examples
Scenario: Session starts with compaction summary
User message: "Summary unavailable due to context limits... "
User message: "did this happen?"
Agent executes:
1. Detects compaction via tag
2. message:read channel=discord channelId=1460342116516364533 limit=50
3. Calculates time span: 2.5 hours β sufficient, no expansion needed
4. Parses messages, finds last action: "Now let me extract the key orchestration decisions..."
5. Checks session context APIs β extracts recent user requests
6. Responds:
> "Context recovered. Your last request was to extract orchestration decisions from Nexus archived sessions for PR #137 (Skills & Agents System). This action did not complete before context was truncated.
>
> Recovered state:
> - PR #137: 15,053 additions, 91 files, CONFLICTING merge state
> - Spec location: content/spec-skills-agents-system.md (2,067 lines)
>
> Shall I proceed with the extraction?"