Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: listSessions queries every historical thread on each call, stalling turn starts and connection setup #8794

Closedwillsheldon(GitHub profile, opens in a new tab) opened this issue 0 comments

Area

apps/server

Steps to reproduce

  1. Use one install for a few weeks so provider_session_runtime accumulates rows. Every thread that has ever run an agent keeps one row; nothing prunes them.
  2. Start a turn in any thread.
  3. Watch server.trace.ndjson, or connect a fresh client while the turn starts.

Expected behavior

Starting a turn costs a bounded number of queries, and connecting a client is not affected by how many threads the install has accumulated.

Actual behavior

ProviderService.listSessions asks the directory for every persisted thread id and then issues one binding lookup per thread:

https://github.com/pingdotgg/t3code/blob/2daff8c25/apps/server/src/provider/Layers/ProviderService.ts#L999-L1016

directory.listThreadIds() already reads the whole table (repository.list()), so the per-thread getBinding calls re-read rows that were just read. Only threads with a live adapter session are used afterwards, so every other read is discarded.

listSessions runs several times per turn start. Parent spans from one burst on my install:

1774x listSessions < resolveSessionRuntimeForThread < resolveCheckpointCwd < ensurePreTurnBaselineFromDomainTurnStart
 887x listSessions < ensureSessionForThread < processTurnStartRequested < processDomainEvent
 887x listSessions < processTurnStartRequested < processDomainEvent
 887x listSessions < resolveSessionRuntimeForThread < resolveCheckpointCwd < ensurePreTurnBaselineFromTurnStart

Measured from server.trace.ndjson on that install (886 rows in provider_session_runtime, 9 of them running):

Windowsql.executePeak ratep95max
Quiet378/s592/s7ms520ms
Turn start643/s over 19s2163/s1298ms1439ms

4,439 statements in that 19s window were the same query, SELECT ... FROM provider_session_runtime WHERE thread_id = ?.

Impact

The server saturates its own event loop on every turn start, so unrelated RPCs queue behind it. server.getConfig is one of them, and it gates connection setup, so clients hit the 15s establishment timeout and show " did not respond during connection setup", then reconnect and repeat. The 15s slow-request toast fires for the same reason. On a local 127.0.0.1 connection with no network involved.

The cost scales with the number of threads the install has ever had, so it gets worse over time.

Version or commit

main at 2daff8c25 (also present in 0.0.35).

Environment

macOS, desktop app hosting its own server, client connected over 127.0.0.1.

Logs or stack traces

uk: Failed to connect. Reconnecting...
uk did not respond during connection setup.

Workaround

None available to a user. Archiving or deleting threads does not remove the rows: ProviderSessionDirectory has no delete method, and nothing calls the repository's deleteByThreadId.

Sign in to join this conversation.