EverOS icon indicating copy to clipboard operation
EverOS copied to clipboard

[Bug]: extract_user_profile loops forever on truncated LLM output: unbounded prompt (116K -> 216K tokens), cursor never advances, re-fires on every memcell

Open vzkqct7wmp-oss opened this issue 3 weeks ago • 1 comments

Area: src/everos

What happened?

extract_user_profile can enter a self-sustaining failure loop that burns the LLM endpoint indefinitely and whose prompt only ever grows. On a long single-owner session the strategy has been re-sending a 116K -> 216K-token prompt to the LLM, every ~2 minutes, for ~2.5 days. Every call ends with finish_reason=length, no profile is written, and nothing ever stops it.

Observed on 1.4.2 (single owner, local OpenAI-compatible Qwen3.8-flash-next, [llm.extra] max_tokens = 8192, enable_thinking = false). I compared src/everos/memory/strategies/extract_user_profile.py on current main (blob 2379072) and the constants and selection logic that cause this are unchanged; I have not run 1.5.1 itself.

Mechanism (from the code):

  1. PROFILE_EXTRACTION_INTERVAL = 1 -> every new memcell fires extract_user_profile (max_retries=2, so up to 3 LLM calls per trigger).
  2. Memcell selection is "everything in the owner's selected clusters with last_ts > last_profile_ts" (_select_via_cluster), and all of them are rendered into ONE prompt (_render_conversation(memcells) in everalgo's ProfileExtractor). There is no token budget, no cap on memcell count and no chunking.
  3. last_profile_ts only advances when _persist_profile succeeds. If the response is truncated (finish_reason=length) the strategy raises/retries and persists nothing, so the cursor never moves.
  4. Therefore the next trigger selects a strict superset of the previous memcells -> a larger prompt -> another truncated response (I cannot see inside the model, but that is what the logs show). A new memcell arrives, repeat. It cannot recover on its own.
  5. LLMClient only logs llm_non_stop_finish as a warning and returns the truncated response as if it were valid; there is no typed error, circuit breaker or backoff for repeated failures of the same owner.

Steps to reproduce

  1. Run a long, chatty single-owner session so the owner accumulates many memcells.
  2. Use any model/config where one profile UPDATE call can hit the output cap (we have [llm.extra] max_tokens = 8192; a long input makes a non-thinking model ramble until the cap).
  3. Once a single run ends with finish_reason=length, watch extract_user_profile re-fire on every subsequent memcell with an ever-larger prompt. user.md stops changing.

Environment

OS: Windows 11
Python: 3.12
everos: 1.4.2 (main compared: extract_user_profile.py blob 2379072)
LLM: local OpenAI-compatible endpoint, qwen3.8-flash-next, max_tokens=8192, thinking off

Logs or screenshots

All "llm_non_stop_finish" warnings in the server log: 242, every one
strategy_name=extract_user_profile, model=qwen3.8-flash-next, finish_reason=length
(content_len 34K-54K chars). Last successful write: user_profile_extracted
memcell_count=33 mode=UPDATE at 2026-11-06T12:46Z; user.md unchanged since.

Prompt size per day (gateway log of the LLM endpoint; >50K-token calls only):
  2026-11-06  171 calls   50,388 - 163,096 tokens
  2026-11-07   40 calls  163,096 - 180,841 tokens
  2026-11-08   65 calls  180,841 - 215,645 tokens   (still firing; ~115 s each, completion always 8192)
Totals: 276 calls, 39.7M prompt tokens, 10.7 hours of endpoint time (shared inference server).

Suggested fixes (any one of 1+3 would stop the bleeding)

  1. Bound the input: a token (or memcell-count) budget per extraction; process the backlog in chronological chunks and advance last_profile_ts after each successful chunk so a large backlog converges instead of growing.
  2. Make truncation a hard failure at the client: raise a typed error on finish_reason == "length" instead of returning the partial text, so callers can distinguish "model finished" from "cut off".
  3. Circuit breaker / backoff per owner: after N consecutive failed extractions, stop re-triggering on every memcell (exponential backoff or pause until a config change) and emit one clear error rather than a stream of warnings.
  4. Make the interval tunable: the docstring on PROFILE_EXTRACTION_INTERVAL says to "tune via Settings", but it is a module constant; exposing it (and a PROFILE_MIN_MEMCELLS/budget) in config would let operators throttle this without patching.

vzkqct7wmp-oss avatar Nov 08 '26 22:11 vzkqct7wmp-oss

Thanks for the detailed report and the numbers. This is fixed as of v1.7.0 (#595, which rebuilt the profile strategy on episodes):

  • Input is bounded. One call folds at most [profile] max_episodes_per_call episodes (default 10), the triggering one included, instead of every memcell since the last profile.
  • A cut-off reply is a failure, not a profile. finish_reason=length now raises LLMCallError(reason="cut_short") in the OpenAI provider.
  • Both knobs are configurable. EVEROS_PROFILE__MAX_EPISODES_PER_CALL, and the profile's model, including max_tokens, can be set separately under [llm.profile].

I checked this on current main (ed88c21) with a fake extractor that always fails with cut_short. 40 consecutive episodes produced 120 calls (3 attempts each), and no call carried more than 10 episodes: the batch stops growing at the cap.

What remains: if the same batch keeps getting cut off, the profile stays unchanged, and each new episode still costs up to 3 bounded calls. There is no per-owner backoff yet. Lowering max_episodes_per_call or raising [llm.profile] max_tokens should get it out of that state.

1.7.0 includes breaking changes; please read the release notes before upgrading. Closing as fixed in 1.7.0. Please reopen if you still see the prompt grow after upgrading.

gloryfromca avatar Nov 19 '26 09:11 gloryfromca