deerflow2/backend/packages/harness/deerflow
ly-wang19 0d3bfe0a76
perf(runtime): index runs by thread_id to avoid O(n) scans in RunManager (#3499)
* perf(runtime): index runs by thread_id to avoid O(n) scans in RunManager

RunManager.list_by_thread, create_or_reject (inflight check), and has_inflight each filtered every in-memory run by thread_id — an O(total in-memory runs) scan that grows with overall gateway traffic rather than the queried thread's depth.

Add a thread_id -> run_ids secondary index (an insertion-ordered dict used as an ordered set) maintained in lockstep with _runs under the existing lock at every add/remove site (create, create_or_reject, both rollbacks, cleanup). The three per-thread queries now run in O(runs-in-thread); insertion order is preserved so list_by_thread keeps stable tie-breaking. Behavior unchanged. Adds 6 regression tests; full RunManager suite 146 passed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(runtime): cover create_or_reject rollback + clarify thread-index guard docstrings

Address review on #3499 (fancyboi999):
- Reword _thread_records_locked docstring: lockstep under self._lock is the
  correctness guarantee; self._runs.get is one-directional defense-in-depth
  (drops stale ids, cannot recover index-missing ids), not reconciliation.
- Add test_failed_create_or_reject_unindexes_run covering the create_or_reject
  rollback/unindex mutation site (the last untested mutation path).
- Fix _FailingPutRunStore docstring ("initial put" -> "every put").

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: ly-wang19 <ly-wang19@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-12 16:48:47 +08:00
..
agents feat(memory): add memory.token_counting config to avoid tiktoken network dependency (#3429) (#3465) 2026-06-10 23:26:15 +08:00
community feat(community): add SearXNG and Browserless web search/fetch tools (#3451) 2026-06-12 09:45:26 +08:00
config feat(im): Add user-owned IM channel connections (#3487) 2026-06-12 15:24:58 +08:00
guardrails feat(guardrails): add pre-tool-call authorization middleware with pluggable providers (#1240) 2026-03-23 18:07:33 +08:00
mcp fix(mcp): close stdio sessions on their owning loop to avoid cross-task cancel-scope error (#3379) (#3392) 2026-06-07 21:37:30 +08:00
models feat(models): add StepFun reasoning model adapter (#3461) 2026-06-09 18:01:43 +08:00
persistence feat(im): Add user-owned IM channel connections (#3487) 2026-06-12 15:24:58 +08:00
reflection refactor: split backend into harness (deerflow.*) and app (app.*) (#1131) 2026-03-14 22:55:52 +08:00
runtime perf(runtime): index runs by thread_id to avoid O(n) scans in RunManager (#3499) 2026-06-12 16:48:47 +08:00
sandbox fix(sandbox): persist lazily-acquired sandbox state via Command (#3464) 2026-06-11 17:50:36 +08:00
skills fix(skills): keep skill archive installation off the event loop (#3505) 2026-06-12 15:17:40 +08:00
subagents feat(subagents): extend deferred MCP tool loading to subagents (#3432) 2026-06-08 23:17:22 +08:00
tools feat(subagents): extend deferred MCP tool loading to subagents (#3432) 2026-06-08 23:17:22 +08:00
tracing fix(tracing): propagate session_id and user_id into Langfuse traces (#2944) 2026-05-21 16:49:31 +08:00
uploads fix upload file size contract (#3408) 2026-06-06 15:12:17 +08:00
utils fix(skills): harden slash skill activation across chat channels (#3466) 2026-06-09 23:07:17 +08:00
__init__.py refactor: split backend into harness (deerflow.*) and app (app.*) (#1131) 2026-03-14 22:55:52 +08:00
client.py feat(memory): add memory.token_counting config to avoid tiktoken network dependency (#3429) (#3465) 2026-06-10 23:26:15 +08:00