[Bug] Overview batching gate counts only file summaries — many-subdirectory dirs still send single oversized prompts and burn VLM tokens (0.4.7 prod incident, #3153 still unfixed)
Issue Origin
Observed or reproduced in a real production environment.
Environment
- OpenViking v0.4.7 (self-hosted, uv venv)
- VLM backend:
openaiprovider against an OpenAI-compatible endpoint (SenseNovasensenova-6.8-flash-lite), thinking disabled, timeout 600s - Embedding: Qwen3-Embedding-4B via llama.cpp, input token cap tuned below ctx
Summary
#3153 (closed 2026-07-14, no merged fix) still reproduces on 0.4.7 — and at scale it is expensive. The batching decision in _generate_overview counts only file summaries; directories with many subdirectories and few/no direct files always take the single-prompt path with all children abstracts concatenated, untruncated. During a bulk ingest into viking://user/default/resources/ (directories up to 3201 direct children), every child-summary completion re-triggered the parent directory's overview rebuild, producing guaranteed-oversized prompts that fail with HTTP 400 yet still burn the input tokens. Net effect on 2026-09-19: ~37M tokens in 3 hours (~5x the previous day) and 1957 Error code: 400 overview failures in a single day, while the affected directories ended up with the failure placeholder anyway.
The bug (0.4.7 code)
openviking/storage/queuefs/semantic_processor.py, _generate_overview:
estimated_size = len(file_summaries_str) + len(children_abstracts_str)
over_budget = estimated_size > semantic.max_overview_prompt_chars
many_files = len(file_summaries) > semantic.overview_batch_size
if over_budget and many_files: # <-- batching requires MANY FILES
... # batched path
elif over_budget:
... # truncate FILE summaries only
Three gaps:
- Batching gate counts only files (
many_files), exactly as #3153 described. A directory with 300 subdirectories and 0 direct files isover_budgetbut notmany_files→ single-prompt path with all 300 children abstracts concatenated. We observed rendered prompts of 0.5–2 MB this way (single-request input up to ~100k+ tokens). - The truncation path never truncates children abstracts:
budget -= len(children_abstracts_str); per_file = max(100, budget // max(len(files), 1)). With more children than budget, the per-file budget goes negative and clamps to 100 chars per file, butchildren_abstracts_strstill passes through in full — so the "truncated" request can still be oversized. - The batched path also injects the full
children_abstracts_strinto batch 0, untruncated (children_str = children_abstracts_str if batch_idx == 0 else "None").
Combined with the placeholder-on-failure behavior (#3151 / #3609 / #3191 — the failure-semantics fix is still unmerged), each failure permanently writes [Directory overview is not generated], and the next child completion triggers the same doomed rebuild → a repeat-burn loop for the lifetime of the ingest.
Related from the topology side: #2959 and #4577 cover the recursive/full-store refresh amplification; this issue is the prompt-construction side of the same cost explosion. We're flagging all of these as one root-cause family.
Production incident (2026-09-19)
- Bulk ingestion into
viking://user/default/resources/...with directories of 200–3201 direct children. - Server log for that day: 1957 ×
Failed to generate overview ... Error code: 400 - {'message': 'inference request is invalid'}, plus a handful ofConnection error/Request timed out. - Tracebacks land at
_single_generate_overview→vlm.get_completion_async(prompt)— the single-prompt path, not the batched one (no "Splitting into batches" log lines for these directories). - VLM spend: ~37M tokens in 3 morning hours, ~5x the previous day's total with less usable output. Normal per-item summary cost is 2–3k tokens; effective per-item spend during the incident exceeded 100k tokens once parent-rebuild overhead amortized in — i.e. each completed child paid ~9x overhead for a rebuild that was guaranteed to fail.
Controlled experiment (22-file sample, same directory shape, local guard on vs off):
| tokens per item | throughput | overview failures | |
|---|---|---|---|
| before guard | 102k | 152 items/h | 13% |
| after guard | 11k (-89%) | 220 items/h (+45%) | 0 |
Workaround we run locally (validated)
A guard at the top of _generate_overview: if the directory has more than 200 direct children on disk, skip the rebuild and return the placeholder immediately — before any VLM call. Covers both the queue path and the ov reindex subprocess path. Effect measured in the table above.
Two operational lessons for anyone hitting this:
- A silent
except:around such a guard can swallow aNameError(ours ran broken for 20h due to a missingimport osbefore we noticed); log guard failures. - The guard is a site patch — reinstall/upgrade silently reverts it, so re-apply and re-verify after every upgrade.
Suggested fix directions
- Count
len(children_abstracts)toward the batching gate, or letover_budgetalone trigger batching (this is exactly #3153's proposal — it just never landed). - Truncate
children_abstracts_strin all three paths (single, truncate, batch-0), not only file summaries. - Pre-check the rendered prompt size before sending: if still over budget after truncation, skip the VLM call entirely (cheap string-length check) instead of paying input tokens for a request that is guaranteed to 400.
- Optionally: a config switch to disable automatic parent-directory overview rebuilds above a child-count threshold, for ingestion-heavy workflows that generate their own hierarchical summaries afterwards.
Happy to provide more log excerpts or the guard diff if useful.
Update: I found that #5250 is already addressing the remaining child-abstract truncation problem, so I will defer to that PR and will not start a separate implementation.
I checked current main at 9f21385993b2f27625eeee869ad9f074b955ebff. #3154 was merged and is present: _generate_overview counts both files and child directories, _batched_generate_overview splits both kinds of entries, and the final merge does not repeat the raw child abstracts. I will preserve that behavior rather than duplicate #3154. This check is against current main; it does not establish which code was installed in the reported production environment.
#5250 addresses child-abstract truncation in the few-entry path. Its description explicitly retains an approximate budget (100-character floors and uncounted line prefixes), and it leaves batching unchanged.
The remaining strict-budget gap is broader: the gate measures summary strings rather than the rendered prompt, count-based batches can still be oversized, and the final merge of partial overviews has no character-budget check.
Leaving these current-code findings here for the existing PR discussion; this comment is not a claim of a parallel fix.
Thanks for the detailed report.
I checked the release history and confirmed that v0.4.7 does not include #3154, so the reported behavior is valid for that release: child directory abstracts were not included in the batching decision and could be sent in one oversized prompt.
Current main, and releases from v0.4.10 onward, include #3154. The overview batching logic now counts both file summaries and child directory abstracts, and batches both kinds of entries together, so the original many-subdirectory single-prompt issue is already fixed in newer versions.
Closing this as fixed by #3154 for current versions.