Mental-model refreshes start all at once; the refresh gate limits parallel calls, not requests per minute
Seen on a self-hosted Hindsight 1.2.1 (API image by digest) and checked against main at 31d5556 (19 Nov 2026).
Paths are under hindsight_api/; line numbers are those of the 1.2.1 image.
Setting: one bank with 14 mental models on the same weekly schedule. One worker with 10 slots, 2 of them reserved
for consolidation, so 8 for everything else. Defaults in force: HINDSIGHT_API_LLM_MAX_RETRIES 3 (four tries),
HINDSIGHT_API_WORKER_MAX_RETRIES 3 with 60 s between task attempts, HINDSIGHT_API_REFLECT_MAX_ITERATIONS 10.
The LLM provider allows 50 requests a minute for the model in use: the headers of an answered request show
x-ratelimit-limit: 50 and x-ratelimit-remaining counting down, back at 49 one minute after the first request.
They carry no reset time. The headers of a refusal were not read.
1. Refreshes are submitted together
Two things queue many refreshes in the same instant:
- A deletion. When a document is deleted and no consolidation is waiting, every scheduled mental model whose
text cites a memory that no longer exists gets a refresh at once (
engine/memory_engine.py21499 to 21579; the log line is "Scheduled 13 refresh(es) in bank ...: their grounding cites memories that no longer exist"). - The schedule. All mental models with the same cron expression become due in the same second. The periodic scan (every 5 minutes) submits every one that is due and stale in one go.
The worker then runs as many as it has free slots: 8 here.
2. Without a cap: every refresh fails (15 Nov)
One deletion queued 13 refreshes. Eight ran at once.
| The burst | The same mental models one at a time, started by hand | |
|---|---|---|
| Refreshed | 0 of 13 | 14 of 14 |
| Time | 6 min | 17 min |
| LLM requests answered per minute | exactly 50 in each of the three busy minutes | 10 to 25 |
| HTTP 429 lines in the log | 630 | 0 |
| Recorded LLM calls that ended as errors | 106 of 699 | 0 |
| Task attempts | 52 (each mental model 4 times, 60 s apart) | 14 |
| Cost at list price | CHF 2.17 (2.65 million input tokens, 2.03 million of them cached) | CHF 2.25 |
- All 13 tasks are retried at the same 60 s step, so each round is the same crowd again.
- The old text of every mental model was kept. Twelve were left failed; one was paused (section 4).
3. With HINDSIGHT_API_MENTAL_MODEL_REFRESH_LLM_MAX_CONCURRENT=1: the gate holds, the rate limit is still hit (16 Nov)
The weekly schedule made all 14 due; the scan submitted them together; 8 ran at once behind one permit.
- The gate does what it says. Of 138 answers in the first seven minutes none came within 200 ms of the one before (smallest gap 0.36 s). In the burst without a cap, 77 of 200 did.
- It does not limit requests per minute. Eight refreshes that search at the same time fill every gap in the single stream: 46 requests went out in the first 46 seconds, and the second minute had 45 refusals (HTTP 429). One refresh alone stays under the limit, because it searches the bank between its calls.
- The tries of a refused call stay inside the provider's window. A refused call is tried 4 times, with about
1, 2 and 4 s between the tries (
engine/remote_retry.py178 to 181: exponential from the initial backoff, plus or minus 20 %). All 45 refusals were logged between 08:10:07.25 and 08:10:15.98. A window of one minute does not reopen in 9 seconds. - A turn that is refused four times costs the refresh one search, and nothing says so. 8 turns ended with
"API error after 4 attempts", one in each of the 8 refreshes. The agent logged "LLM error on iteration 6" (or
7) and went on with the next iteration (
engine/reflect/agent.py1395 to 1423: it continues unless two turns in a row fail). The iteration budget is fixed, so each of these 8 refreshes ended with 10 iterations and 8 tool calls, where the 7 other full-length refreshes of that morning had 10 iterations and 9 tool calls. All 8 completed. Neither the mental model nor the operation shows that it was written with one search fewer. - A call that gets no answer holds the one permit for its whole time limit. Twice a call got its answer only after about 598 s (the refresh LLM timeout was 600 s that day). While it held the permit, five other refreshes stood still; their waiting does not count toward their own wall-clock limit, which is right. The refresh with the silent calls then ran into the 900 s wall-clock limit. (Why those calls got no answer: #6673.)
- Result: 14 of 14 refreshed in 35 minutes, one of them at its second task attempt. Cost CHF 1.03.
4. A rate-limit refusal of the delta-operations call pauses the mental model
A provider failure in the reflect loop does not pause automatic refresh (memory_engine.py 5065 to 5090,
pause_automatic=not is_transient_remote_error(e), #5394). The same failure one step later does:
- Any exception of the delta-operations call is caught and turned into
mode_fallback_reason = "delta_ops_failed"(memory_engine.py19109 to 19114). The exception's type is gone from there on. - The refresh then ends as
refresh_failed_delta_not_applied(19209 to 19217, 19505 to 19516) through_preserve_and_fail, which records the failure with the defaultpause_automatic=True(19483 to 19489, 20102 to 20111) and so writeslast_refresh_failed_at.
Seen in the burst of 15 Nov. The history of the 13 mental models holds 52 failure rows: 51 are
refresh_failed_error with the provider's 429 text and left no stamp; one is refresh_failed_delta_not_applied
with reason delta_ops_failed. That refresh had got through its reflect loop; its mental_model_delta_ops call
ended after 7.6 s as an error with the same 429 (as did its retraction call before it), and the mental model was
stamped in the same second. It was the only one that was paused. The worker's three further attempts of that
task still ran (and were refused); the stamp went with the refresh by hand that followed.
What would help
- Spread the start. A limit on how many refresh tasks run at once, apart from how many LLM calls they make
at once; or submit due mental models a few at a time. Reserved worker slots are a floor for a task type, not a
ceiling (
config.py1103 to 1120), so they cannot do this. - A rate limit for LLM requests next to the concurrency limit: requests per minute per provider, or reading
x-ratelimit-remainingand waiting when it reaches 0. - A backoff on HTTP 429 that can outlast a per-minute window, and task retries that are not all 60 s apart.
- Say so when a turn was lost: count failed turns in the refresh's result, or fail the refresh as a temporary error when a turn is lost to a rate limit.
- Keep the failure's type in the delta leg, so that a rate limit or a time-out of the delta-operations call is recorded without pausing, as it is in the reflect loop.
- Do not let one silent call hold the only permit for minutes: a first-byte timeout for refresh calls, or a watch on the stream (see #6673).
Related
- #6077: showing that a failed refresh has paused automatic refresh.
- #6614 (merged, not released): a failed search inside reflect no longer pauses. The delta leg still does on
mainat 31d5556:engine/memory_engine.py19857 to 19868 calls_preserve_and_failwithoutpause_automatic. - #6673: the replies that never end, which hold the one permit.
Thanks for the detailed report. #6823 fixes the two bugs in it:
- A 429 on the delta-operations call no longer pauses the model (your item 5). A temporary provider error there now ends the refresh the same way it does in the reflect loop. Automatic refresh keeps running, and the worker retries it, or waits for the quota to reset when the provider says when that is.
- A failed turn no longer uses up an iteration (item 4). The turn is retried in place, so a rate-limited refresh still gets its full set of searches.
We're not planning to add the rest (a per-minute request limiter, longer 429 backoff, a cap on refreshes in flight) right now. For refreshes that all come due at once from one shared schedule, giving the mental models different refresh_cron times spreads them out. The silent-call problem is tracked in #6673.