MENTAL_MODEL_REFRESH_LLM_MAX_CONCURRENT does not cap the refresh's reflect-agent calls
Bug Description
HINDSIGHT_API_MENTAL_MODEL_REFRESH_LLM_MAX_CONCURRENT does not cap the mental-model refresh's main LLM traffic.
_scope_to_operation in engine/llm_wrapper.py picks the per-operation bucket from the call scope alone. The refresh runs the reflect agent (_llm_for_reflect_operation("refresh_mental_model")), and that agent's calls are scoped reflect, reflect_tool_call, reflect_structured and final_rewrite. None of those scopes starts with refresh_mental_model or dry_run_refresh_mental_model, so these calls fall into the interactive reflect bucket. As a result:
- The refresh cap only gates
mental_model_delta_ops. mental_model_retraction_opsmatches no bucket and runs under the global cap only.- Split synthesis (
final_map_*, run withasyncio.gather) fans out with no refresh cap at all. - The only setting that does throttle refresh is
REFLECT_LLM_MAX_CONCURRENT, which also throttles interactive reflect. A user's reflect then waits behind background refreshes, which is the starvation #4463 split the buckets to prevent.
On a self-hosted instance, three days of llm_requests with operation = 'refresh_mental_model' (about 3,800 calls) were all reflect / reflect_tool_call scopes, so all of them were outside the refresh cap.
Steps to Reproduce
- Start a server with
HINDSIGHT_API_MENTAL_MODEL_REFRESH_LLM_MAX_CONCURRENT=1. Point the LLM at a stub (ashindsight-system-testsdoes) that parks the firstreflectturn. - Retain one fact into each of three banks, then create one mental model per bank so three refreshes run in the worker.
- While the first reflect turn is parked (holding its permits), count the refresh calls that reach the provider.
Control: with HINDSIGHT_API_REFLECT_LLM_MAX_CONCURRENT=1 instead, parking a refresh's reflect turn keeps an interactive reflect on another bank from reaching the provider.
Expected Behavior
With the refresh cap at 1, at most one refresh LLM call is in flight. Interactive reflect is unaffected by background refreshes.
Actual Behavior
| Setting | v0.10.2 | main @ ec39e1090 |
|---|---|---|
MENTAL_MODEL_REFRESH_LLM_MAX_CONCURRENT=1: refresh calls in flight at once |
3 | 3 |
REFLECT_LLM_MAX_CONCURRENT=1: interactive reflect calls reaching the provider while a refresh is parked |
0 | 0 |
Version
v0.10.2 (5fc4ce20); also reproduced on main at ec39e1090.
LLM Provider
Any. Reproduced with the openai-compatible stub; observed in production with xai-oauth. Both are attempt-gated providers.
Source: vectorize-io/hindsight