Commit Graph
2 Commits
Author SHA1 Message Date
nesquena-hermes ca175beca7 docs(changelog): v0.51.458 — O(D²) context-backfill, prevents server hang (#4314) 2026-06-16 16:56:11 +00:00
nesquena-hermesandpsanger 50a290e419 perf(streaming): O(D²·C)→O(D²) context-backfill loop, prevents server hang (#4314)
The backfill inner loop in _merge_display_messages_after_agent_result
re-ran _message_identity (json.dumps) for every future display row on
every outer iteration and used an O(N) list-slice membership test
(in context_keys[_cursor:]), making it O(D²·C). On long tool-call
sessions this pegged a core, held the GIL, and stalled /api/sessions
5-11s — the WebUI appeared hung. Precompute display keys once and keep
a multiset (count-keyed dict) mirror of context_keys[_cursor:] for O(1)
membership → O(D²).

Salvaged from #4314 (the original PR bundled an unrelated, undescribed
HermesWebUIContext feature). Reimplemented the membership mirror as a
count-keyed dict instead of the PR's set: _message_identity returns
DUPLICATE keys for identical-content turns and None for empty rows, so
a plain set diverges from the original list-slice semantics (verified
over 3M adversarial trials); a multiset including None is exact. Added
a differential regression test guarding the equivalence.

Co-authored-by: psanger <psanger@users.noreply.github.com>
2026-06-16 16:55:42 +00:00