reflect: low-budget reflect spends its time prefilling 30–90k tokens of tool results, so the coding-agents hook reflect can't fit a hook window even with no other work queued
Area: hindsight-api reflect agent (affects hindsight-integrations/coding-agents)
Why a new issue
#4343 was closed as a capacity problem, with an invitation to open a fresh issue "if you … still see first-prompt reflects capping out with nothing else running … with recall timings for that bank". This is that report. #4401 made the hook cap configurable, which helps, but hosts still bound the hook (30 s as installed for Claude Code), and the numbers below show where the time goes: recall is a small part of it, and the reflects were sent one at a time to a server that started each run idle.
Setup
- Self-hosted Docker image, server 0.9.2 and then 0.10.0;
@vectorize-io/hindsight-coding-agents0.6.1; Claude Code 2.1.278 - LLM:
openai-codex,gpt-5.6-luna,HINDSIGHT_API_LLM_REASONING_EFFORT=low;HINDSIGHT_API_RERANKER_MAX_CANDIDATES=100 - Benchmark: the hook's exact
buildReflectQuery()template,budget: "low", sent one at a time toPOST /reflectafter waiting for every bank to report zero pending operations/consolidation. 5 prompts × 2 reps per bank per configuration. Scripts: https://gist.github.com/feniix/44a3c76c6dedb86c897fdde12fbfe338
Two per-repo coding-agent::* banks:
| bank S | bank L | |
|---|---|---|
| documents | 106 | 492 |
| memory nodes (world / experience / observation) | 1,646 (412 / 463 / 771) | 7,834 (1,774 / 2,215 / 3,845) |
| links | 62,371 | 292,481 |
| mental models (5 seeded pages + captured initiatives) | 24 | 12 |
| mental-model text, total / largest | 546,295 / 77,669 chars | 192,757 / 21,848 chars |
Production picture from the plugin's diag.jsonl, 2026-09-14 to 2026-09-20, server 0.9.2, 9 banks: reflect_ok 11 (median 17.8 s, max 19.4 s), reflect_failed 144 (143 of them at the 20 s cap), fallback to pages ≈ 116 ms.
Results
| configuration | bank S median | bank L median | under 20 s | errors |
|---|---|---|---|---|
| 0.9.2 baseline | 49.9 s | 29.3 s | 2 / 20 | 0 |
0.9.2, RERANKER_MAX_CANDIDATES=50 |
49.5 s | 27.6 s | 3 / 20 | 0 |
0.9.2, REFLECT_LLM_REASONING_EFFORT=none |
72.8 s | 59.7 s | 1 / 20 | 0 |
0.9.2, request max_tokens: 250 |
51.6 s | 33.5 s | 1 / 20 | 0 |
0.9.2, request max_tokens: 500 |
41.0 s | 43.5 s | 3 / 20 | 0 |
0.10.0, REFLECT_LLM_TIMEOUT=180 |
30.0 s | 34.6 s | 2 / 20 | 0 |
(Every run started on an idle server — zero pending operations and consolidation on every bank — but the server was not isolated: other agent sessions could still write to it during a run. The 0.9.2 baseline partly overlapped knowledge-page refreshes on bank S, so its absolute numbers are somewhat inflated. During the 0.10.0 run, and the first minutes of the 0.9.2 baseline, the agent session driving the benchmark also retained its own transcript about every 30 s, queueing one short consolidation each time on a third bank; the other 0.9.2 rows had that every ~5 min. I expect the effect to be small next to the differences shown, but it is not zero.)
Where the time goes
0.9.2, per the reflect log lines I read for this template (about a dozen; iterations=4, 3 tool calls): three sequential tool-calling turns ≈ 8–12 s, the tools themselves ≈ 4 s, the final synthesis call 5–48 s — and it must run longer in the slowest benchmark reflects (up to 116 s end to end on the baseline). From /llm-requests, one reflect from the max_tokens: 250 configuration:
| call | input tokens | output tokens | duration |
|---|---|---|---|
| final synthesis | 62,711 | 433 | 18.5 s |
length-target rewrite (max_tokens: 250) |
1,081 | 359 | 7.5 s |
The largest traced final call on bank S during the benchmark (in the effort=none window) received 88,373 input tokens (_original_chars: 363898) and took 37.7 s. Tool-result sizes seen in reflect log lines on this server — across banks, and including knowledge-page refresh reflects, not only this template: search_mental_models up to ~68k chars, search_observations ~34–113k chars (98k and 113k of those with max_tokens=6000 and 8000), recall ~25–51k chars. The 0.9.2 container logs are gone, so I can't tie sizes to individual benchmark reflects.
So recall/reranking is ~4 s of the total; 433 output tokens still cost 18.5 s because of the prompt. That is why none of the knobs help: the reranker cap is irrelevant, effort none doubles answer length, and a smaller max_tokens adds the rewrite call. Bank L has ~5× the memories of bank S and was faster on 0.9.2. Bank S has ~2.8× the mental-model text, and whole models go into the prompt, which may be why; I did not isolate it.
0.10.0 confirms it from the other side. With the new "fresh mental models sufficient" short-circuit, none of the 20 reflects called search_observations or recall — only search_mental_models (one to three calls each), returning 52–163k chars per call — and the median is still 30–35 s. Three traced final calls: 28.6k–36.9k input tokens, ~800 output tokens, 26.5 s median.
Notes
- A tool's
max_tokensdoes not bound what reaches the prompt:search_observationscalled withmax_tokens=6000returned ~98k chars in one logged reflect (113k withmax_tokens=8000in another);tool_search_observationsserializes each result withmodel_dump(), andsearch_mental_modelsreturns whole documents (up to 163k chars in one call on 0.10.0). - On 0.9.2 the three retrieval calls ran as three sequential LLM turns of 2–5 s each (~8–12 s per reflect) before synthesis started.
- The coding-agents hook already injects the page roster and falls back to page search, so on that path the mental-model text is the part of the prompt the agent can already reach another way. (Related: #4422.)
I can re-run this benchmark against a candidate change, or put up a PR if there is a direction you would prefer.
Related: #3443, #4343, #4398 / #4401, #4422.
I ran a controlled, read-only replay on a self-hosted Hindsight v0.10.1 bank using one real Recall query captured from a Reflect tool call.
This is single-query evidence from one self-hosted v0.10.1 bank. The same query and bank were held constant while varying the facts/chunks budgets:
| facts/chunks budget | serialized chars | rough tokens | reduction vs 12K/4K |
|---|---|---|---|
| 12K / 4K | 92,616 | 23,154 | baseline |
| 8K / 3K | 67,563 | 16,891 | 27.050% |
| 4K / 1K | 32,245 | 8,062 | 65.184% |
| 2048 / 1K | 19,805 | 4,952 | 78.616% |
Using the 12K/4K run as the reference set, 4K/1K retained 5/5 of the reference Top-5 IDs and 9/10 of the Top-10 IDs. 2048/1K retained 4/5 and 5/10 respectively.
I am not using the 8K/3K run for rank-retention claims because its saved audit has an unresolved result-count/order provenance issue.
The original Reflect tool call explicitly requested:
- max_tokens=12000
- max_chunk_tokens=4000
A v0.10.1 source audit shows that configured Recall values from env/tenant/Bank/mental-model settings are resolved defaults for omitted tool arguments, not operator-configurable hard ceilings for explicit model-supplied values. Explicit model values are instead bounded by the fixed 1000..16000 tool-argument safety range and the remaining-context ceiling. With two concurrent calls, remaining_context_tokens must fall to 8000 or below for the per-call share to fall to 4000 or below. Configured defaults use a separate path and are not model-supplied arguments; this does not make the fixed model-argument ceiling exceedable by the model.
Replay fidelity note: the replay used the public Recall API with the captured Reflect-generated query. Query and explicit budget fidelity were high, while scope/enrichment fidelity was medium because several omitted internal defaults were reconstructed from the v0.10.1 source. This is a payload/retention comparison, not a Reflect latency benchmark.
This is not a universal recommended default. For this captured query, 4K/1K was a promising operating point: it reduced serialized payload by 65.184% while retaining all reference Top-5 IDs and 90% of the reference Top-10 IDs.
This may be useful context when considering whether Reflect should eventually have an optional operator ceiling for raw Recall facts and chunks, separate from the existing defaults and global context-safety budget.
0.10.1 rerun — full original configuration matrix
Re-ran the original first-prompt Reflect benchmark on September 22 against the official ghcr.io/vectorize-io/hindsight:0.10.1 image, not a candidate PR build. 100 unique attempts, 99 successful responses, one HTTP 504. The hook-window problem still reproduces in this setup.
The exact original buildReflectQuery() template and original five prompts per bank were recovered from the original local benchmark script and reused unchanged: budget: "low", two repetitions, one request at a time, same prompt/bank ordering. This is an end-to-end Reflect latency benchmark, not the Recall payload replay in the preceding comment.
Results
Medians below are for successful requests. Each configuration has 20 attempts (10 per bank); deadline counts include only successful responses, with all 20 attempts in the denominator.
| 0.10.1 configuration | bank S median | bank L median | under 20 s | under 30 s | errors |
|---|---|---|---|---|---|
| Baseline: reranker 100, effort low | 63.0 s | 40.3 s | 1/20 | 3/20 | 0 |
| Reranker 50 | 51.8 s | 33.7 s | 0/20 | 3/20 | 0 |
| Reflect reasoning effort none | 53.9 s* | 47.8 s | 1/20 | 3/20 | 1 |
Request max_tokens: 250 |
57.9 s | 35.7 s | 0/20 | 2/20 | 0 |
Request max_tokens: 500 |
68.5 s | 45.1 s | 1/20 | 3/20 | 0 |
Across the matrix, 3/100 attempts succeeded under 20 seconds and 14/100 under 30 seconds.
The effort-none bank-S median uses nine successful requests. The tenth returned HTTP 504: Gateway Timeout after 300.04 s (fourth prompt, second repetition). Including its elapsed time gives an all-attempt median of 57.9 s for that bank/configuration. The failure was retained, not retried or replaced by a successful result.
For context, the original 0.9.2 baseline medians were 49.9 / 29.3 s (S/L); the previous 0.10.0 REFLECT_LLM_TIMEOUT=180 run was 30.0 / 34.6 s. These are historical comparisons, not a controlled version-regression claim, for the reasons below.
Setup and comparability limits
-
Same provider/model:
openai-codex,gpt-5.6-luna; reasoning effortlowexcept the explicit Reflectnonerow.REFLECT_LLM_TIMEOUT=180throughout this rerun, matching the earlier 0.10.0 timeout180 row; HTTP client timeout 320 seconds. -
New isolated container/API on localhost port 18890, with separate database and credential volumes. The live server and previous PR-test containers were left untouched.
-
Both banks were copied in one read-only, repeatable-read database snapshot. The same archive was restored between configurations. These were September 22 bank contents, not the original September 20 snapshot:
snapshot bank S bank L documents 116 494 memory nodes 1,714 7,795 links 69,280 291,793 -
Background workers were disabled in the isolated container, so ingestion/consolidation/page-refresh jobs could not compete there. Maintenance could still enqueue automatic page refreshes; those stayed pending and did not execute. This is not identical to the original live-server idle/drain protocol.
-
Isolation was at the container/database level, not dedicated host hardware or exclusive upstream model quota. Other containers remained running.
-
Execution was interrupted and resumed. Two initial runner readiness-check problems occurred before any measured reranker-50 request. The real 504 later stopped the effort-none run; it was resumed after restarting/restoring the isolated container. Existing measurements, including that failure, were preserved and skipped. This introduces a time gap and a cold restart within the effort-none configuration.
-
Final validation checked exactly 100 unique
(configuration, bank, prompt, repetition)combinations, unchanged prompts/template, and independently recomputed the summary. Raw answers, snapshots, logs and credentials remain private.
Conclusion: none of the tested configurations made this workload reliably fit either a 20-second or a 30-second hook window on 0.10.1. This rerun establishes end-to-end latency, not a fresh attribution of time to prefill versus retrieval, and should not be read as proving that 0.10.1 itself caused the difference from the earlier runs.
Adding measurements from a self-hosted 0.10.1 deployment (coding-agents 0.6.1, Claude Code, reflect on zai/glm-5.3-flashx, thinking off), since they point at the same cause and at what fixed it for us.
Where the time went (reflect log lines, automatic <goal> reflect, budget low): tools 0.5-2.5 s in total; search_mental_models returned 52-110k chars per call (whole pages, uncapped - #4533); final synthesis read 33-46k input tokens and took 11-19 s; end to end 27-40 s against Claude Code's 30 s hook. Like you, we found a max_tokens target made it worse, not better: overshoots trigger final_rewrite (+5-6 s).
Two engine details that surprised us:
- Any trimming applied to
messagesdoes not reach_forced_final_synthesis: it re-readscontext_history, which keeps the raw tool dict. Evidence has to be reduced where the tool output lands, before both. - A text-only turn after tool calls is discarded and re-synthesized by design (the "No tool calls this turn" branch). With GLM this happened on most reflects at iteration 3, so two answer-writing calls (4-6 s + 3-5 s).
What got us under 20 s (all in a derived image, flag-gated, fail-open):
- At the tool-result gather point, split mental-model pages into heading sections and score every section / observation / memory against the
<goal>with a small relevance model (one batched call per iteration, ~0.4 s), keeping only relevant units within ~8k chars per output. - The same call asks whether the best evidence kept so far already covers the goal; above a calibrated floor, or when a round from iteration 3 adds at most one new relevant unit, go straight to synthesis instead of another retrieval round (avoids the recall-recall walk to the 5-iteration cap and the discarded prose turn).
- Automatic-reflect template: one added rule asking for a report under 250 words, most goal-relevant facts first (the agent-called tool keeps full depth).
Result over 20 real first-prompt hook runs across three coding-agent::* banks: from 2/20 inside the 20 s bound to 19/20; p50 12 s, p90 15.7 s; zero hook kills; answers 1.6-2.4k chars.
Two upstream changes would let others get most of this without patches: a token bound on search_mental_models (#4533), and a configurable automatic-reflect query template (or length rule) in coding-agents, so a local tweak survives auto-update.
Thanks all for the detailed measurements — they pointed straight at the cause. This is fixed on main and ships in 0.10.2. The fixes:
search_mental_modelsno longer returns whole pages (#4716, closes #4533). It returns the top-ranked page in full only if it fits 4,000 tokens; every other hit is a snippet plus its size. A newread_mental_modelstool fetches full pages on request, capped at 6,000 tokens per call. This was the 52–163k-char call in the 0.10.x runs above. Measured −39% input per reflect on our refresh eval.- Tool results are written for the model, not the record (#4656). Short per-reflect aliases instead of UUIDs, dates to the minute, no repeated
fact_type/chunk bookkeeping, and items already shown are referenced instead of re-sent. −26% to −43% per knowledge-page refresh. - Finish through
donein the conversation (#4656). A text-only stop after tool calls now asks fordoneon the prefix the provider already holds, instead of always re-rendering every tool result into a second standalone synthesis prompt. - Tool results are bounded before they reach the prompt. Observation budgets are configurable per bank (
reflect_search_observations_max_tokens, #4521), and oversized fields are packed once instead of copied into every split piece (#4771). Model-supplied budgets were already clamped to 1,000–16,000 tokens and to the remaining context (#4290).
Closing. If first-prompt reflects still overrun the hook window on 0.10.2, please reopen with the same benchmark — it would be very useful to see the new numbers.