Skip to content

[Question]: threads search N+1 checkpoint queries #36

Description

@TBice123123

Description

Problem

POST /threads/search calls _enrich_thread_state for each thread row individually when values or interrupts fields
are needed. Each call triggers a separate list_checkpoints(thread_id) database query.

File: src/agentseek_api/api/threads.py:354-360

states = await asyncio.gather(*[_enrich_thread_state(row.thread_id) for row in rows])

This is acceptable at limit=10, but at limit=1000 it fires 1000 concurrent checkpoint queries, which could overwhelm the
checkpoint store.

Possible solutions

  1. Batch loading — Fetch checkpoints for multiple threads in a single query
  2. Opt-in enrichment — Only query checkpoints when select explicitly includes values/interrupts (partially implemented,
    but select=None still triggers full enrichment)
  3. Cap limit — Reduce max limit for state-enriched requests

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions