Repository navigation
Conversation
Every API connection sets statement_timeout to 120 seconds, the same bound at which useSearchTask stops polling. A search still running past it has no client waiting for the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| ), | ||
| ) | ||
| options = ( | ||
| f"-c search_path=public,ord -c statement_timeout={STATEMENT_TIMEOUT_SECONDS}s" |
There was a problem hiding this comment.
Search outlives polling deadline A similarity search can run a filter query followed by a separate ranking query. This timeout gives each statement its own 120 seconds, while the browser allows 120 seconds for the whole task from submission. If the filter query uses most of that time, ranking can keep the database busy after the browser stops polling, leaving the work this change is meant to prevent. Bound the total task time rather than only each statement.
Knowledge Base Used:
| options = ( | ||
| f"-c search_path=public,ord -c statement_timeout={STATEMENT_TIMEOUT_SECONDS}s" | ||
| ) | ||
| async with await psycopg.AsyncConnection[dict[str, Any]].connect( | ||
| dsn, row_factory=dict_row, options="-c search_path=public,ord" | ||
| dsn, row_factory=dict_row, options=options |
There was a problem hiding this comment.
Canceled tasks remain pending When this timeout cancels a background search, the task exits before writing a result or a failure state. The result endpoint then returns “pending” until the query key expires an hour later. This makes a canceled task look like one that is still running and prevents callers from handling the failure promptly. Record a terminal failure state for canceled tasks.
Knowledge Base Used:
Summary
statement_timeoutto 120 s, the client's polling bound.Changes
get_cursorpasses-c statement_timeout=120salongside the existingsearch_path, from a newSTATEMENT_TIMEOUT_SECONDSconstant insearch.py.STATEMENT_TIMEOUT_SECONDSandPOLL_TIMEOUT_MS(useSearchTask.ts) point at each other, since nothing else keeps the two in step.Testing
test_statement_timeout_cancels_slow_query: with the constant set to 1 s,pg_sleep(2)raisesQueryCanceled. It fails with the option removed.SHOW statement_timeouton aget_cursorconnection reads2min.pytest: 92 passed. pre-commit hooks pass.Notes
🤖 Generated with Claude Code
The PR should not merge until server-side search work is bounded to the client’s total wait.
Findings
Summary
The PR sets a 120-second PostgreSQL statement timeout on API connections and documents its relationship to the browser’s search-poll deadline. A new test verifies cancellation of one slow statement.
Reviews (1) · Last reviewed commit: "Cancel database statements that outlive ..."