OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Feature]: Add bounded cross-session archive fallback to Codex and Claude Code auto-recall

Open sunhuaian2026 opened this issue 4 months ago • 1 comments

Feature Description

Add a bounded, read-only cross-session archive fallback to the official Codex and Claude Code memory plugins.

Today their automatic recall searches user memories and skills. Historical sessions can already be stored under viking://user/<user>/sessions, but they do not automatically participate when a user asks a clearly historical question and semantic recall has no useful result.

Motivation

This creates a gap for users who have already migrated older sessions: the archive is durable, shared across devices, and searchable, but it is effectively invisible to normal assistant recall unless the user manually invokes a grep/read tool.

This is especially painful for old coding sessions, where the sought fact is often an exact command, file path, error message, or prior decision. Promoting all raw historical chats into profile/tool/persona memory is unsafe; a read-only archive fallback is the safer architecture.

The OpenClaw example integration already treats archive search as a separate layer when memory recall or archive summary lacks exact detail.

Proposed Solution

In the Codex and Claude Code auto-recall hooks:

  1. Run the existing memory/skill recall unchanged.
  2. Only when the prompt has clear history intent (for example: "previously", "last time", "earlier", "history") and recall is empty or below a relevance threshold, issue a bounded archive search:
POST /api/v1/search/grep
uri: viking://user/<user>/sessions
pattern: safely derived literal/regex anchors
node_limit: 12
level_limit: 10
  1. Inject at most a small, fixed character budget of matches, with each item carrying its source URI and archive id.
  2. Treat archive contents as quoted reference data, not instructions. Exclude or strongly delimit tool-output payloads.
  3. Do not create a session, commit messages, invoke extraction, or write memories in this path.

Acceptance Criteria

  • Normal non-historical prompts do not call archive search.
  • A history-oriented prompt with no useful semantic recall can surface a matching prior-session URI and bounded excerpt.
  • A zero-match fallback injects nothing and does not fail the user prompt.
  • The fallback creates no memory files, extraction tasks, or session writes.
  • Search scope is restricted to the requesting user and has explicit result/depth/character budgets.
  • Behavior is covered for both Codex and Claude Code plugins.

Alternatives Considered

  • Bulk-extract all historical sessions into long-term memory: unsafe. Historical developer chats can produce low-confidence or hallucinated tool/persona facts.
  • Local source patch or custom global prompt rule: not update-safe and shifts a plugin capability gap onto every user.
  • Manual archive grep: works but defeats automatic recall.

Scope / Effort Estimate

Medium. The server-side grep API already exists and returns bounded URI/line matches. The main work is plugin trigger policy, safe term selection, result shaping, and integration tests.

Additional Context

A read-only spike against a shared remote server succeeded with the official API: searching viking://user/default/sessions with node_limit=12 returned matching history/archive_001/messages.jsonl and .overview.md URIs; a unique no-match sentinel returned an empty result. No source changes or historical re-extraction were required.

sunhuaian2026 avatar Jul 16 '26 09:07 sunhuaian2026

This is a well-reasoned enhancement that addresses a real architectural gap between durable archives and live recall. A few thoughts on the bounded fallback design:

Trigger policy refinement: The "clear history intent" heuristic (keywords like "previously," "last time") is a good start, but consider also:

  • Temporal phrasing: "3 weeks ago," "in June," "during the sprint"
  • Negative recall signals: when semantic search returns zero results or scores below a threshold (you mentioned this), explicitly log it to tune the trigger over time
  • User-facing affordance: if archive fallback fires, surface a small visual hint ("also searched historical sessions") so users understand the broader scope

Result shaping & citation hygiene: Your proposal to "strongly delimit tool-output payloads" is critical. I'd recommend:

  • Prefix each archive excerpt with metadata: [Session: {date}, Archive: {uri}]
  • Apply aggressive output-filtering: strip tool_result blocks, base64 blobs, and large inline payloads before injecting context
  • Render the archive match as quoted reference with a light disclaimer: "This is from a prior session; verify current state before acting."

Bounded search parameters: node_limit: 12 and level_limit: 10 seem reasonable for a grep-style fallback. I'd add:

  • max_result_chars: 2000 (or similar) to cap total injected context
  • Explicit timeout (e.g., 500ms) to prevent archive search from delaying prompt response
  • Structured failure handling: if archive search errors or times out, log it but let the prompt continue with standard recall results

Non-instrumentation side effect: You correctly call out that this path must not create sessions, trigger extraction, or write memories. Enforce this at the integration boundary: have the fallback use a read-only API key or a clearly scoped /search/grep-no-session endpoint.

Testing & observability: Integration tests should cover:

  • Zero-match case (empty result, no injection)
  • Multi-match case (respects node/char limits)
  • Non-history prompt (no archive search triggered)
  • Archive search timeout or error (degrades gracefully)

Also, emit telemetry: archive_fallback_triggered, archive_fallback_matched, archive_fallback_injected_chars. This will help tune the trigger policy and justify the feature investment.

Why bounded read-only beats bulk extraction: You nailed it — historical chats carry stale commands, hallucinated reasoning, and outdated context. Promoting them wholesale into profile/tool/persona memory would pollute the working set. A fallback that cites the archive without trusting it is the right boundary.

Would you also consider a complementary user-facing command (e.g., /archive-search "pattern") for explicit manual queries? That would cover the gap when the trigger heuristic doesn't fire but the user knows they want historical results.


I'm building memory systems for AI coding agents with SwarmAI. Discussion: T-MEM: Memory, Context, Recall

xg-gh-25 avatar Jul 16 '26 09:07 xg-gh-25