[Bug]: usage_retrieval_hourly.result_count is always 0 — persisted retrieval audit cannot reproduce the observer's zero-result rate
Issue Origin
Observed or reproduced in a real environment (OpenViking v0.4.21, local deployment, running since 2026-09-15).
Bug Description
The persisted retrieval audit table usage_retrieval_hourly never records results: result_count is 0 in every hourly bucket, while request_count accumulates normally. At the same time the in-memory retrieval observer reports a non-zero Total Results for the same traffic. Because the two surfaces disagree, any dashboard / report / alerting built on the persisted audit either shows a meaningless 100% zero-result rate or cannot compute one at all — while the observer's Zero-Result Rate cannot be cross-checked against any stored data.
This matters because the retrieval zero-result rate is the one signal an operator would use to detect retrieval degradation — and in a persistent store it is currently unusable.
Two further observations on the same surface (may be intended, but they make the metric hard to trust):
Zero-Result Rateis computed over a counter that resets when the server restarts, and is displayed with no window label. On the same deployment the value went from69.6%(over 6274 queries) before a restart to41.9%(over 31 queries) minutes after it, with no change in behavior.- Retrieval can be perfectly healthy while the metric suggests collapse. Direct probes against the same server return results normally:
POST /api/v1/search/search {"query":"<any real query>","session_id":"probe","limit":8}
-> 8 memories, top rerank score 0.851
POST /api/v1/search/find {"query":"<any real query>","limit":8}
-> 5 memories, top score 0.712
Steps to Reproduce
- Start
openviking-server(v0.4.21, local vectordb backend) and drive some retrieval traffic (e.g. an agent harness doing session-scopedsearch+findcalls). - Wait for at least one hourly bucket to be written.
- Inspect the persisted audit:
-- data/_system/usage_audit/usage_audit.sqlite3
SELECT COUNT(*) AS buckets,
SUM(request_count) AS req_total,
SUM(result_count) AS res_total,
MIN(result_count), MAX(result_count)
FROM usage_retrieval_hourly;
-- => buckets=129, req_total=1058, res_total=0, min=0, max=0
SELECT COUNT(*) FROM usage_retrieval_hourly WHERE result_count > 0;
-- => 0
SELECT date_utc, hour_utc, operation, request_count, result_count
FROM usage_retrieval_hourly ORDER BY date_utc DESC, hour_utc DESC LIMIT 4;
-- => ('2026-09-22', 8, 'search', 23, 0)
-- ('2026-09-22', 8, 'find', 4, 0)
-- ('2026-09-22', 7, 'search', 44, 0)
-- ('2026-09-22', 7, 'find', 16, 0)
- Compare with the in-memory observer on the same server:
curl -s http://127.0.0.1:1933/api/v1/observer/retrieval
# Total Queries 31 | Total Results 323 | Avg Results/Query 10.4
# Zero-Result Queries 13 | Zero-Result Rate 41.9% | Rerank Fallback 0
Two surfaces, same period, one says "323 results", the other says "0 results in every bucket".
Expected Behavior
usage_retrieval_hourly.result_countshould be incremented with the number of results returned in that bucket (so that the stored audit can reproduce the rate the observer displays), or the field should be dropped/renamed so nobody builds a metric on it.- The persisted audit and
/api/v1/observer/retrievalshould agree for the same time window. Zero-Result Rateshould be reported together with its window / sample size, and either survive restart (persisted) or be explicitly labelled as since-boot.
Actual Behavior
result_countis0for all 129 buckets (1058 requests recorded), i.e. the column appears to be written but never incremented./api/v1/observer/retrievalreportsTotal Results 323for the current in-memory window.Zero-Result Ratechanges purely as a function of process uptime (69.6%over 6274 queries →41.9%over 31 queries after restart), which makes it unusable as an alerting signal.
Minimal Reproducible Example
-- persisted audit: results are never recorded
SELECT SUM(request_count), SUM(result_count) FROM usage_retrieval_hourly;
-- 1058 | 0
# same server, in-memory observer: results are recorded
curl -s http://127.0.0.1:1933/api/v1/observer/retrieval | grep -E "Total (Queries|Results)|Zero-Result"
# Total Queries 31
# Total Results 323
# Zero-Result Rate 41.9%
Error Logs
No errors are emitted — the table is written and the server reports queue: 0 errors, models available, service healthy. The divergence is silent, which is why this is reported as a bug rather than an observation: there is no way for an operator to notice it without querying the SQLite file directly.
OpenViking Version
0.4.21
Environment / Notes
- macOS (Apple Silicon),
openviking-server --with-bot,auth_mode=dev, local vectordb backend, single process. - Embedding/VLM: Volcengine Ark (doubao). Rerank: OpenAI-compatible endpoint,
threshold=0,max_input_tokens=4096, 0 fallbacks during the sampled window. - Memory/collection size at time of report: 910 memory files, 1 collection, ~2.6k vectors.
- Related but distinct issues already filed, checked before opening this one:
- #4090 — retrieval observer reports 100%
unknowncontext type (same observer surface; classification, not result counting). For reference, our breakdown now readsunknown 15 / resource 7 / skill 6 / memory 3, so it is not 100% on this build. - #4688 — MCP retrieval calls not counted in Studio dashboard metrics (statistical scope).
- #5032 — VLM/abstract-generation failures silently swallowed, retrieval degrades to ~99% zero-result (a cause of high zero-result counts; this report is about the metric itself being unusable).
- #3443 (closed) — Web Studio dashboard misses
/api/v1/search/recalland hides VLM tokens under__unknown__account. Note: we also observe an__unknown__account row inusage_token_hourlyalongside the real one, so this may still be worth revisiting.
- #4090 — retrieval observer reports 100%
The result_count always-zero defect for new successful HTTP find/search requests was fixed by #5294 (merged as e49d6c4). The final response count now flows through the existing http.request event into usage_retrieval_hourly. Regression tests cover list/context responses, zero results, batching, concurrency, and errors; isolated STG verification confirmed nonzero persisted counts for real requests.
Closing this issue for that confirmed defect. Pre-fix hourly buckets cannot be accurately backfilled from the data previously stored. The retrieval observer counts internal queries since process start, while the audit counts public HTTP responses, so their totals and zero-result rates are not directly comparable. Persisting a zero-result rate or changing the observer window/display is outside this bug fix and needs a separate product decision if required.