Repository navigation
Conversation
…query (part of #447) The team background loops run every 2 seconds on every API replica and filtered team_runs / team_queue_items by status = 'running' without a usable index, so list_running_team_runs scanned the whole (never pruned) run history. - Migration 0065_team_loop_indexes adds partial indexes that hold only running rows: team_runs (id), team_queue_items (team_run_id), and team_queue_items (updated_at) for items not yet linked to a run. EXPLAIN on 200 000 runs: the running-runs query goes from a parallel seq scan (9.7 ms) to a bitmap scan on team_runs_running_idx (0.05 ms); the other two use the new indexes. - GET /worker/executions/{id}/cancel, polled every second per running execution, now answers with one query (org + bound worker token) instead of ensure_execution plus a flag read (four to five queries). Rows claimed before token binding still take the full check. The worker_tokens last_used_at throttle (finding 2, first half) landed in #471. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #447 (finding 1 and the cancel poll; the worker-token throttle was fixed in #471). All acceptance criteria are now met; pruning archived runs, mentioned in the issue text, is not done.
Summary
The team background loops run every 2 seconds on every API replica and filtered
team_runs / team_queue_items by status = 'running' without a usable index, so
list_running_team_runs scanned the whole (never pruned) run history.
rows: team_runs (id), team_queue_items (team_run_id), and team_queue_items
(updated_at) for items not yet linked to a run. EXPLAIN on 200 000 runs: the
running-runs query goes from a parallel seq scan (9.7 ms) to a bitmap scan on
team_runs_running_idx (0.05 ms); the other two use the new indexes.
execution, now answers with one query (org + bound worker token) instead of
ensure_execution plus a flag read (four to five queries). Rows claimed before
token binding still take the full check.
The worker_tokens last_used_at throttle (finding 2, first half) landed in #471.
Testing
cargo fmt --check,clippy --workspace --all-targets -D warnings: cleancargo test --workspacewith a database: 762 passed, 0 failedworker_cancel_poll_reads_only_the_bound_token_row; the worker-token binding API test checks the claiming worker's cancel polllist_running_team_runsParallel Seq Scan 9.7 ms → Bitmap Index Scan 0.045 ms;list_team_runs_pending_outcome0.97 → 0.083 ms (Index Only Scan);release_stale_team_queue_claims0.12 → 0.022 mspnpm docs:check: passedBehaviour change: a bound token that already claimed an execution reads its cancel flag even if its profile's agent scope changed after the claim (previously 403). Migration
0065.🤖 Generated with Claude Code