Skip to content

ref(resolvers): inline the trace item table resolver - #8454

Merged
MeredithAnya merged 3 commits into
masterfrom
meredith/convert-resolver-trace-item-table
Sep 17, 2026
Merged

MeredithAnya merged 3 commits into
masterfrom
meredith/convert-resolver-trace-item-table

Conversation

@MeredithAnya

Copy link
Copy Markdown
Member

Stack

  1. ref(resolvers): remove unused resolver declarations #8451 ref(resolvers): remove unused resolver declarations
  2. ref(resolvers): inline the trace item stats resolver #8452 ref(resolvers): inline the trace item stats resolver
  3. ref(resolvers): inline the time series resolver #8453 ref(resolvers): inline the time series resolver
  4. → #this ref(resolvers): inline the trace item table resolver
  5. ref(resolvers): remove the TraceItemDataResolver abstraction

What

Same transformation as #8452 and #8453, applied to EndpointTraceItemTable. ResolverTraceItemTableEAPItems was the last concrete resolver.

Moves the resolver module body into endpoint_trace_item_table.py and turns resolve() into _query_trace_item_table reading self.routing_decision.

This is the biggest of the three — the resolver was 897 lines, so endpoint_trace_item_table.py ends up around 1200. It's a pure move: nothing in the pasted body changed, so the added lines should diff cleanly against the deleted file.

After this, resolvers/__init__.py declares no resolver classes at all. The abstraction itself comes out in the next PR.

Tests

Import/patch-target updates only. pytest tests/web/rpc/v1/test_endpoint_trace_item_table/ test_storage_routing.py test_cross_item_local_join.py → 198 passed. mypy snuba/web/rpc/ clean.

🤖 Generated with Claude Code

) -> PageToken:
num_rows_in_response = len(response[0].results) if response else 0
if time_window is not None:
if num_rows_returned > request.limit:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The pagination logic at _get_page_token incorrectly compares num_rows_returned with request.limit (which can be 0), instead of the effective query limit, causing pagination to fail.
Severity: HIGH

Suggested Fix

The pagination logic should use the effective limit applied to the database query, not the raw request.limit value. When request.limit is 0, the comparison should use the default row limit (e.g., _DEFAULT_ROW_LIMIT) to correctly determine if there are more pages.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: snuba/web/rpc/v1/endpoint_trace_item_table.py#L799

Potential issue: When a flextime-routed query is made without an explicit `limit`, the
`request.limit` defaults to 0. The database query correctly uses a default limit (e.g.,
10,001 rows), but the pagination logic in `_get_page_token` compares the number of rows
returned against the original `request.limit` of 0. This `num_rows_returned > 0`
comparison will always be true if any data is returned, causing the system to
incorrectly issue a next-page token for the same time window. This prevents pagination
from advancing to subsequent time windows or ever finishing, leading to incomplete data
or infinite loops for the client.

Did we get this right? 👍 / 👎 to inform future reviews.

@MeredithAnya
MeredithAnya added this pull request to stack #8456 September 9, 2026 23:52
@MeredithAnya
MeredithAnya force-pushed the meredith/convert-resolver-trace-item-table branch from 39c536a to ea67d2f Compare September 10, 2026 19:50
@MeredithAnya
MeredithAnya force-pushed the meredith/convert-resolver-trace-item-table branch from ea67d2f to e8a4233 Compare September 14, 2026 19:47
Base automatically changed from meredith/convert-resolver-time-series to master September 16, 2026 19:47
ResolverTraceItemTableEAPItems was the last concrete resolver. Move the
resolver module body into endpoint_trace_item_table.py and turn
resolve() into _query_trace_item_table, following 76d1fed.

resolvers/__init__.py now declares no resolver classes; the abstraction
itself is removed in the next change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@MeredithAnya
MeredithAnya force-pushed the meredith/convert-resolver-trace-item-table branch from e8a4233 to 1f385ab Compare September 17, 2026 17:10

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1f385ab. Configure here.

Comment thread snuba/web/rpc/v1/endpoint_trace_item_table.py
Comment thread snuba/web/rpc/v1/endpoint_trace_item_table.py
Comment on lines +1160 to +1161
effective_limit = in_msg.limit
if effective_limit <= 0 and in_msg.HasField("limit_by"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: When a request omits the limit and limit_by fields, the logic fails to trim the extra sentinel row used for pagination, causing it to leak into the response.
Severity: MEDIUM

Suggested Fix

Modify the logic that sets effective_limit. When in_msg.limit is 0 and limit_by is not set, effective_limit should be set to _DEFAULT_ROW_LIMIT. This will ensure the subsequent check correctly identifies that the result set needs to be trimmed by one row, preventing the sentinel row from being included in the final response.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: snuba/web/rpc/v1/endpoint_trace_item_table.py#L1160-L1161

Potential issue: When a request is made without an explicit `limit` and without a
`limit_by` clause, the logic to trim the extra sentinel row used for pagination fails.
The `effective_limit` variable remains 0, causing the condition `if effective_limit > 0
...` to be false. As a result, `islice` is never called to remove the extra row fetched
for pagination detection. This leads to the API returning up to `_DEFAULT_ROW_LIMIT + 1`
rows (e.g., 10,001) instead of the expected maximum of `_DEFAULT_ROW_LIMIT` (10,000).

@MeredithAnya
MeredithAnya merged commit 384cd1e into master Sep 17, 2026
66 checks passed
@MeredithAnya
MeredithAnya deleted the meredith/convert-resolver-trace-item-table branch September 17, 2026 18:51
MeredithAnya added a commit that referenced this pull request Sep 18, 2026
## Stack
1. #8451 `ref(resolvers): remove unused resolver declarations`
2. #8452 `ref(resolvers): inline the trace item stats resolver`
3. #8453 `ref(resolvers): inline the time series resolver`
4. #8454 `ref(resolvers): inline the trace item table resolver`
5. **→ #this** `ref(resolvers): remove the TraceItemDataResolver
abstraction`

## What

No endpoint dispatches through a resolver anymore, so this deletes:

- `TraceItemDataResolver` and `RPCEndpoint.get_resolver` in
`snuba/web/rpc/__init__.py`
- the whole `snuba/web/rpc/v1/resolvers/` package, including the
`_TO_IMPORT` directory scan that populated the registry as an import
side effect

## Re-homing the non-resolvers

`resolvers/` also held modules that were never resolvers and are
imported by already-converted endpoints
(`endpoint_trace_item_attribute_names.py`,
`trace_item_attribute_values.py`, `endpoint_get_traces.py`), so they
move somewhere that describes them — following `eefb13118`:

| From | To |
|---|---|
|
`resolvers/common/{aggregation,trace_item_table,cross_item_queries,formula_reliability}.py`
| `snuba/web/rpc/common/` |
| `resolvers/R_eap_items/heatmap_builder.py` | `snuba/web/rpc/v1/` |
| `resolvers/R_eap_items/co_occurring_attrs/` | `snuba/web/rpc/v1/` |
| `tests/web/rpc/v1/resolvers/.../co_occurring_attrs/` |
`tests/web/rpc/v1/co_occurring_attrs/` |

All `git mv`, so they should show as renames.

## Verification

- `pytest tests/web/rpc/` → **826 passed, 2 skipped, 2 xfailed**
- `mypy snuba/` → clean across 816 files
- `grep -rn 'resolver' snuba/web/rpc/` returns only the unrelated
`snuba/query/allocation_policies/resolver.py` import

Worth a second look: deleting the `_TO_IMPORT` scan removes an import
side effect. The passing suite dispatches these endpoints by name over
HTTP, which covers registration, but I couldn't run a standalone import
smoke check — a bare `python -c 'from snuba.web.rpc import RPCEndpoint'`
fails with `AttributeError: METRICS_COUNTERS` on `master` too, so that's
a pre-existing settings-profile thing rather than something introduced
here.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants