Skip to content

[Feature] Deep Remory Integration: Auto-search and auto-store with graceful fallback #100

Description

@randomm

Summary

Replace the current prompt-driven remory approach with deep system integration. Auto-search before tasks, auto-store after completion, with graceful fallback when remory is unavailable.

Background

Research findings (Jan 29, 2026):

  • Current manual approach produces HIGH quality memories (47 stored, avg 468 chars)
  • Agents store synthesized conclusions, not reasoning noise ✅
  • Gap: Manual process means agents may miss relevant context or forget to store

Requirements

1. Remove Existing Stub Implementation

  • Remove remory_persist_thinking config flag (unused)
  • Clean out any stubbed/unused remory code paths
  • Keep the core memory/remory.ts API

2. Pre-Task Auto-Search

When a task/subagent is dispatched:

const memories = await remory.search(taskDescription, { user_id, limit: 5 })
const relevant = memories.filter(m => m.distance < 0.40) // Confidence threshold
// Inject into task system prompt as context

3. Post-Task Auto-Store

When a task completes successfully:

// Generate one synthesized summary (NOT reasoning dump)
const summary = `Task: ${task.description}\nOutcome: ${task.status}\nApproach: ${task.summary}`
await remory.add(summary, {
  user_id,
  metadata: {
    type: inferType(task), // 'root_cause' | 'investigation' | 'fix' | 'pattern'
    issue: task.issueId,
    agent: task.agentType,
    date: new Date().toISOString()
  }
})

4. Graceful Fallback (CRITICAL)

If remory is not available (not installed, socket unavailable, errors):

  • Log warning once per session, not per operation
  • Continue without memory features — don't block or crash
  • All remory calls must be wrapped in try/catch with fallback
async function safeRemorySearch(query: string): Promise<Memory[]> {
  if (!remoryAvailable) return []
  try {
    return await remory.search(query, { user_id, limit: 5 })
  } catch (e) {
    markRemoryUnavailable()
    log.warn("Remory unavailable, continuing without memory features")
    return []
  }
}

5. Structured Metadata

Add consistent metadata tagging:

interface MemoryMetadata {
  type: 'root_cause' | 'investigation' | 'security' | 'fix' | 'pattern' | 'state'
  issue?: string      // GitHub issue number
  agent?: string      // Agent type that created it
  files?: string[]    // Related file paths
  date: string        // ISO timestamp
}

Files to Modify

  • packages/opencode/src/memory/remory.ts — Add graceful fallback wrapper
  • packages/opencode/src/config/config.ts — Remove remory_persist_thinking stub
  • packages/opencode/src/session/ — Add pre-task search injection
  • packages/opencode/src/task/ — Add post-task auto-store
  • Agent prompt files — Remove manual remory instructions (now automatic)

Acceptance Criteria

  • Stubbed/unused remory code removed
  • Pre-task auto-search injects relevant memories into context
  • Post-task auto-store saves synthesized summary with metadata
  • Graceful fallback when remory unavailable (no crash, warning logged once)
  • Works transparently — agents don't need to call remory manually
  • Existing manual remory search/add tools still available for explicit use

Non-Goals

  • ❌ Storing reasoning blocks (confirmed low value, high noise)
  • ❌ Storing every tool result
  • ❌ Making remory a hard dependency

References

  • Research: Remory value analysis (Jan 29, 2026)
  • Current memories show high quality when synthesized
  • ../remory/ — Remory codebase for reference
  • ~/.remory/remory.db — SQLite database

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions