OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Feature]: Compaction should still work for bypassed sessions (delegate to runtime or summarize without storage)

Open hhspiny opened this issue 3 months ago • 3 comments

Problem Statement

bypassSessionPatterns lets the OpenClaw plugin exclude sessions (e.g. subagent sessions agent::subagent:) from OpenViking entirely — no capture, no recall, no commit, no session-history storage, no memory extraction. That works for storage, but it breaks context compaction for those sessions:

Because the plugin declares ownsCompaction: true, OpenClaw delegates compaction to the plugin's compact(). For a bypassed session, compactOpenVikingSession() returns:

{ ok: true, compacted: false, reason: "session_bypassed" } OpenClaw does not treat session_bypassed as a benign skip (benign = below_threshold / already_compacted / no_compactable_entries, see compact-reasons.ts). Consequence:

Preflight compaction (auto, near context limit): throws "Preflight compaction required but failed: session_bypassed" — the turn hard-fails instead of compacting. Manual /compact: reports "Compaction skipped" — nothing is compacted. So a bypassed session can never be compacted: it grows until it errors, or must be manually reset.

Proposed Solution

For bypassed sessions, compaction should still happen without persisting history or extracting memory:

Delegate to OpenClaw runtime — compact() signals delegation (e.g. reason: "delegated_to_runtime" or a delegateToRuntime field); OpenClaw falls back to its native compactor (summarize older turns, keep recent tail in host transcript store), zero OV writes. OpenClaw already has the concept (DEFERRED_CONTEXT_ENGINE_COMPACTION_REASON in compact-reasons.ts). OV-side compaction without storage — for bypassed sessions, compress the in-memory session and return a summary assemble() can inject, but skip writing history/archive_NNN/, .abstract.md/.overview.md, and skip memory extraction. Minimal acceptable mitigation: classify session_bypassed as benign skip so it stops hard-failing (no real compaction, but no turn failure).

Alternatives Considered

Don't bypass subagent sessions — works, but defeats the purpose (OV DB bloat + memory pollution). Manual retirement via DELETE /api/v1/sessions/{id} — cleanup only, doesn't solve live context growth. Benign-skip classification only — avoids failure, still no compaction.

Feature Area

Session Management

Use Case

OpenClaw + OpenViking context engine. Subagent sessions (agent::subagent:, high volume, mostly short-lived) should not be stored in OV or feed memory extraction, but occasional long-running subagent tasks still need context compaction. With the feature: bypassSessionPatterns: ["agent::subagent:"] keeps OV clean while subagent sessions stay functional at any length.

Example API (Optional)

{
  plugins: { entries: { openviking: { config: {
    bypassSessionPatterns: ["agent:*:subagent:*"],
    // "delegate-runtime" (default) | "ov-memory-only" | "none"
    bypassSessionCompaction: "delegate-runtime"
  } } } }
}

Additional Context

Plugin refs: config.ts (bypassSessionPatterns, default []), text-utils.ts (glob→regex, *=one segment/**=multi, matched against sessionKey then sessionId), context-lifecycle-service.ts:1027 (bypass return), context-engine.ts (ownsCompaction: true). Host refs (OpenClaw): compact-reasons.ts (benign bucket), agent-runner-memory.ts:945-963 (preflight throw), commands-compact.ts:317 (manual skip label). Latest release v0.4.13 (2026-08-06): "Session Auto Commit v2" adds per-session auto_commit_policy (token/message/idle triggers) — controls when stored sessions commit, not whether a session is stored. The gap remains. Today's only mitigation is manual cleanup — the plugin never calls deleteSession().

Contribution

  • [ ] I am willing to contribute to implementing this feature

hhspiny avatar Aug 08 '26 19:08 hhspiny

I verified this remains open and unclaimed, but the safe implementation depends on the host contract rather than an OpenViking-only behavior change.

Proposed narrow scope for maintainer confirmation:

  • For a matched bypassSessionPatterns session, return the same deferred/delegation reason already recognized by the supported OpenClaw runtime (DEFERRED_CONTEXT_ENGINE_COMPACTION_REASON) instead of introducing another benign skip.
  • Keep ownsCompaction: true for normal sessions and keep all capture/recall/commit/history writes bypassed for matched sessions.
  • Add a contract test proving a bypassed session requests host compaction and performs zero OpenViking writes; preserve existing compaction tests for normal sessions.
  • Gate the behavior on the minimum OpenClaw version that recognizes the deferred reason, or retain the current result for older hosts if runtime version detection already exists.

Could maintainers confirm (1) the exact wire reason/field OpenViking should return and (2) the minimum supported OpenClaw version? Without those two decisions, an OpenViking-only PR could either keep hard-failing older hosts or silently skip real compaction.

AaronZ345 avatar Aug 10 '26 10:08 AaronZ345

Confirming the shape of option (a) before implementing it on the plugin side: the OV-side fix is small — compactOpenVikingSession's bypass branch (context-lifecycle-service.ts, returns {ok: true, compacted: false, reason: "session_bypassed"}) would instead return whatever signal OpenClaw's runtime maps to "fall back to the native compactor". The blocker is that the contract literal lives in OpenClaw's compact-reasons.ts (DEFERRED_CONTEXT_ENGINE_COMPACTION_REASON), which isn't mirrored in this repo.

Two questions to pin the contract:

  1. What exact value does DEFERRED_CONTEXT_ENGINE_COMPACTION_REASON expect — a specific reason string, a delegateToRuntime boolean, or a member of the benign-skip set (below_threshold / already_compacted / no_compactable_entries)? If it's just "add session_bypassed to the benign set", that's a one-line OpenClaw-side change and the OV plugin needs nothing.
  2. Is emitting the delegation signal conditional on an OpenClaw version (older runtimes would treat an unknown reason as failure again)? If so the plugin should gate on a capability probe rather than assume.

With the literal confirmed, the plugin-side diff is ~5 lines in the bypass branch plus a test; happy to land it immediately.

now-ing avatar Sep 03 '26 18:09 now-ing

got it, need a fix.

probably should fallback to normal openclaw compact when it's excluded.

ZaynJarvis avatar Sep 04 '26 11:09 ZaynJarvis