Repository navigation
Conversation
Add a partial agent_id index matching ListAgentsByUser's all-time outbound pending_review count. Build it concurrently through the existing non-transactional migration runner. Verify index validity and idempotent reapplication, plus per-agent and per-owner counts across directions, statuses and resolved holds. Refs tokencanopy#129 (pending-count index; DNS handling is covered by tokencanopy#1032). Co-authored-by: Codex <noreply@openai.com> Signed-off-by: Raul Ernesto Guillen Hernandez <37725305+RauPro@users.noreply.github.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.
Summary
Addresses item 1 of #129: add a partial
messages(agent_id)index forstatus = 'pending_review' AND direction = 'outbound', matchingListAgentsByUser's existing all-timepending_countsubquery. DNS error visibility is handled separately in #1032; this PR does not close the whole issue.The expiry index leads with
approval_expires_at, so it cannot directly seek to one agent's holds. The new index supports that lookup without adding a cached counter or changing the query's results. It intentionally adds neither an age cutoff nor adeleted_atpredicate absent from the query.Measurement
Measured the actual SQL emitted by
ListAgentsByUseron PostgreSQL 16.15, usingEXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)and default planner settings. Synthetic fixture: 100 agents across 5 owners, 160,000 historical sent messages, 2,000 outbound holds and 2,000 inbound holds; the selected owner has 20 agents. Rows are 14 days old and carry a 512-byte synthetic raw body.Both sides used the same rows after
VACUUM (ANALYZE); timings are medians of five warm executions after one warm-up.The pending subplan changed from a bitmap intersection of the agent/history and global review indexes to an index-only scan on
idx_messages_agent_pending, with zero heap fetches in this vacuumed fixture. The new index occupied 40 KB. These are local synthetic results, not a production latency guarantee.Operational risk
Migration 132 uses
CREATE INDEX CONCURRENTLYand the existinge2a:no-transactionrunner, avoiding a write-blocking index build. Building still consumes I/O and can wait for existing transactions; matching holds incur index-maintenance cost. The migration documents invalid-index recovery, and the runner already refuses to record an invalid build as applied.No public API or SDK changes.
Test plan
New DB-backed tests verify the embedded migration and idempotent reapplication, index validity/readiness and definition, and pending counts across agents, owners, directions, terminal states, old holds and a transition to
sent. Timing and planner-choice assertions are deliberately kept out of CI.Verified locally with Go 1.26.9 and PostgreSQL 16.15:
go test -tags integration ./internal/identity -count=1 -timeout=11mgo test ./...make fmt-checkscripts/check-repository-text-integrity.shscripts/check-no-committed-credentials.shgit diff --check