compressor_v2 sends unbounded prompts to the VLM (52k+ tokens observed) — no prompt budget on the session-compression/memory-extraction path
Environment
- OpenViking v0.4.5; observed in production 2026-07-13 against an OpenAI-compatible vLLM backend
Bug
Directory overview generation respects semantic.max_overview_prompt_chars, but the session compression / trajectory memory extraction path (session/compressor_v2.py and friends) has no equivalent budget: it sends the accumulated session trajectory to the VLM however large it is.
Observed in production:
- a single compression request with prompt_token_ids_len=52,794 (from the serving engine's input dump);
- sustained bursts of such requests (avg prompt ~8.7k tokens, spikes far higher) that saturated the serving backend (32 running / 56 queued), pushing unrelated requests to 150–190s latency;
- on a backend configured with
max-num-batched-tokens=max-model-len(single-step prefill), the 52k-token request caused a CUDA OOM that killed the engine (transient prefill activations exceeded the remaining headroom). That serving configuration is arguably too aggressive, but the client sending unbounded prompts is what made it lethal — and on providers with per-request token limits these requests would simply fail permanently.
Additionally, when many compressions run concurrently they contend on memory locks with unlimited retries (Failed to acquire memory locks, retrying (attempt=N, max=unlimited)), amplifying the burst.
Reproduction
- Produce a session with a long trajectory (large tool outputs / many turns).
- Trigger archive/compression.
- Observe the VLM request size — it scales with the trajectory with no cap.
Expected behavior
- Cap the compression prompt (chars or tokens) the same way overview generation is capped, chunking or windowing the trajectory when it exceeds the budget (map-reduce over segments would preserve fidelity better than truncation).
- Consider a retry cap / backoff on the memory-lock acquisition path instead of
max=unlimited.
@zhoujh01 will support automatic session commit.
Adding independent field data from another deployment that hits the same pattern as this issue (+ #3274, + #1581 which fixed the config semantics).
Environment
- OpenViking
v0.4.7(docker-single-node, 24-core class host, Volcengine Doubao embedding + VLM backends). - Workload is agent-driven memory extraction (Hermes Agent → OV memory provider). Bursty rather than steady; a few sessions/minute with occasional bursts of ~5/sec.
memory.v2_lock_max_retriesleft at default (i.e. the pre-#1581 unlimited-retry semantics).
Observed symptoms (matches #3274 exactly)
openviking-serverprocess pinned around ~60% CPU baseline, with sustained bursts higher during memory extraction.- Swap grew slowly (~tens of MB / hour) while RSS climbed correspondingly; no leak stabilization within a normal working day.
- Log stream dominated by two repeating patterns during the CPU spikes:
compressor_v2 - Failed to acquire memory locks, retrying (attempt=N, max=unlimited) path_lock - Removing stale lock: /.../memories/{events,tools}/.path.ovlockattemptcounter climbs into the tens of thousands on a bad hour, exactly matching the "unbounded retries" behavior described in this issue and in #1581.
Cross-issue read
- #1581 (now closed) fixed the config surface —
0no longer means "unlimited". Deployments that never explicitly setmemory.v2_lock_max_retriesinherit the historical unlimited semantics until they upgrade + set a bounded value. - This issue (#3274) is the runtime half: even with a finite retry count, the hardcoded 0.2 s poll interval is what turns any legitimate contention into CPU pressure and log flood.
- #3226 explains why compressor_v2 stays inside a lock section long enough to matter — the unbounded-prompt path can send 52k+ token payloads to the VLM, which is exactly the kind of tail latency that lets a compressor session hold
.path.ovlocklong enough for the next N sessions to pile into the retry loop.
Reading the three together, this looks less like "three separate bugs" and more like one failure mode with three surface expressions: unbounded retries × short poll × unbounded per-attempt work = a stable log-flood/CPU-saturation attractor whenever memory extraction fans out.
What worked as a workaround here
- Configuring
memory.v2_lock_max_retries=30(post-#1581) cut the log flood immediately — extraction now fails fast with a real error instead of spinning. - Rate-limiting extraction concurrency at the agent layer (fewer parallel session commits) kept the still-hardcoded 0.2 s poll from stacking up.
- Neither of those addresses the root cause; both just push the failure mode below the threshold where the system self-DoSes.
Happy to run additional reproduction against v0.4.9 / v0.4.10 if the maintainers want confirmation that the fix in #3274's suggested direction (configurable poll interval + bounded retry) lands cleanly on top of #1581.
Most commercial model APIs offer context windows of up to 1M tokens, while self-hosted deployments often use smaller, operator-configured limits. Given that this constraint is deployment-specific, I feel short-context Phase 2 extraction in OV should be treated as a known limitation. Long context (1M) is the trend and major.
A separate minimal fail-closed request guard may still be considered, as proposed in (https://github.com/volcengine/OpenViking/pull/3342).
REPRO: Long-session memory extraction still sends unbounded prompts to the VLM - zero memories, silent "completed" (v0.4.12, local 32k backend)
Reproduced in a local rootless Podman deployment of OpenViking v0.4.12 with a local OpenAI-compatible llama-server (CUDA13) VLM at an effective 32,768-token context. The issue from #3226 is still present in the current image.
Observed behavior:
After session.commit(), the Phase-2 memory extractor sends the full archived session trajectory - including hydrated tool outputs and prefetch/read content - to the VLM in one prompt. One 144-message research session produced extraction requests of ~37k, ~62k, ~82k, and ~104k tokens across commits. The VLM rejected them with HTTP 400: request (...) exceeds the available context size (32768). The session task is still reported completed, memories_extracted.total stays 0, and memory_diff.json is empty - the failure is silent from the API perspective. Raw session archives were preserved correctly; only long-term memory extraction failed. Because commit returns accepted and the task shows completed, this is easy to mistake for "extraction found nothing."
Environment:
OpenViking v0.4.12 (image 2026-08-03), rootless Podman, single RTX 4060 Ti 16GB VLM: Qwen3-VL-4B via llama.cpp server-cuda13, n_ctx 32768 Session compressor: compressor_v2 Client: Hermes agent integration, commits with keep_recent_count: 0 (whole session archived and extracted in one batch) On PR #3595: I have been testing #3595 (fix(compressor): enforce prompt token budget in memory-extraction VLM calls) as a local backport. It does prevent the oversized requests, and I can confirm the truncation fires on large tool-output/prefetch blobs. Two concerns to raise:
The hard-coded 32,000-token budget leaves almost no completion headroom on a 32,768-token backend - please make the budget configurable and default it below the model limit. Truncation is lossy. For long research sessions a windowed/map-reduce approach over whole logical turns (as suggested in the issue) would preserve much more fidelity. Suggested acceptance criteria:
Final VLM prompt is bounded after tool-output hydration and prefetch expansion. The bound is configurable and leaves headroom below the model context limit. Oversized sessions are processed in resumable windows or another loss-aware strategy rather than truncated/discarded. Task status distinguishes successful memory extraction from archive-only completion. Extraction failures are visible in task metadata, not reported as success with zero memories. Large tool outputs are summarized or referenced, not hydrated verbatim into the prompt.
Follow-up to #3226: Phase 2 rehydrates externalized tool results, bypassing context budgeting
Summary
OpenViking's tool-output externalization reduces the size of the archived/live message representation, but Phase 2 session compaction restores the complete externalized tool results before constructing the Working Memory and long-term memory extraction prompts.
This bypasses the purpose of externalization and can make a session's extraction request substantially larger than the session context reported before compaction. In our case, a session that OpenClaw reported as approximately 500–600k tokens produced a provider request of 1,118,311 input tokens and exceeded the model's 1,048,576-token context limit.
Environment
- OpenViking: 0.4.17
- OpenViking OpenClaw plugin: @openviking/openclaw-plugin 2026.8.13
- Python: 3.12
- OS: Linux
- Deployment: self-hosted OpenViking server
- VLM: OpenAI-compatible endpoint
- VLM model: deepseek-v4-flash
Steps to reproduce
- Enable the OpenClaw OpenViking context engine with default tool-output externalization.
- Create a long session containing many tool calls and large tool results.
- Allow the tool results to be externalized into the session tool-result store.
- Trigger
/compact, causingcommit(wait=true). - Inspect the OpenViking server log and the VLM request size.
Expected behavior
Externalized tool results should remain available for explicit, on-demand tools
such as openviking_tool_result_read and
openviking_tool_result_search.
Working Memory and normal user-memory extraction should not automatically restore all raw externalized tool-result bodies into the VLM prompt. They should use user/assistant conversation text plus bounded tool-result previews or explicitly budgeted evidence.
The extraction path should also enforce a final token budget before making the VLM request, reserving space for the completion.
Actual behavior
Before Phase 2, OpenViking reported:
messages=84, tokens=312677
The archive contained:
- 339 tool parts
- 107 externalized tool results
- approximately 991,529 characters of inline tool output
- approximately 3,067,757 characters restored from externalized originals
After hydration, the formatted extraction input contained approximately 3,904,842 characters, corresponding to roughly 1.1M tokens for the configured provider.
The provider rejected the Working Memory request:
The input (1118311 tokens) is longer than the model's context length
(1048576 tokens)
The server then logged:
WM update tool_call failed ... input ... longer than the model's context length
WM creation fallback failed ... input ... longer than the model's context length
The later long-term extraction request remained in flight until the configured 300-second VLM timeout:
Phase 2 step long_term failed: Request timed out.
Memory extraction failed for session ...
Task ... failed.
Relevant implementation path
The installed OpenViking 0.4.17 code contains:
Session._hydrate_tool_outputs_for_extraction()
This reads externalized results with an effectively unlimited read:
limit = -1
The Working Memory path then formats each hydrated ToolPart using the complete
tool_output value in:
Session._format_message_for_wm()
This means externalized output is replaced by a preview during normal storage, then restored and inserted in full into the Phase 2 model prompt.
Impact
- Compaction can fail even though the pre-compaction context estimate is below the model limit.
- Large tool results can unexpectedly consume most or all of the VLM context.
- The failure may occur after Phase 1 has already archived and cleared the live session.
- Memory extraction fails or times out, creating a second recovery problem related to the failed archive state.
- Providers with smaller context windows fail more frequently.
- Large raw outputs may also cause avoidable token cost and latency.
Suggested fix
- Keep full tool results in the tool-result store for explicit retrieval.
- Do not hydrate complete externalized tool results for Working Memory.
- Use bounded previews or a separate token-budgeted evidence-selection path for long-term extraction.
- Add a final token-budget guard before every Phase 2 VLM request.
- Reserve completion tokens and account for prompt-template overhead.
- Emit a clear
input_too_largetask failure instead of allowing the request to run until an HTTP timeout. - Add regression tests where a session has small externalized previews but oversized original tool results.
This appears related to #3226 and is the general text-output counterpart to #4455, which documents the same rehydration problem for inline Base64 images.