fix(api): bound internal route workloads#2712
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b83671a91
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| """List comments grouped by top-level thread.""" | ||
| await self._require_replies_entitlement() | ||
| rows = await self._list_comment_rows(case_id=case.id) | ||
| rows = await self._list_comment_rows(case_id=case.id, limit=limit) |
There was a problem hiding this comment.
Preserve complete comment threads when limiting rows
When the internal /comments/threads endpoint is called for a case with more than the default 100 comments (or more than the requested limit), this passes the cap into the raw chronological comment query before grouping, so replies or even root comments past that prefix are dropped and reply_count/last_activity_at are computed from incomplete data. The internal SDK calls this endpoint without any cursor or pagination parameter, so workflow users can receive silently truncated thread data; limit/paginate top-level threads first or fetch/count complete threads after selecting the roots.
Useful? React with 👍 / 👎.
|
✅ No security or compliance issues detected. Reviewed everything up to 2b83671. Security Overview
Detected Code Changes
|
|
Found 1 test failure on Blacksmith runners: Failure
|
Summary
/internaltable lookup, case comments, and case metrics routes.Tests
uv run pytest tests/unit/api/test_api_internal_cases.py tests/unit/api/test_api_internal_tables.py -quv run pytest tests/unit/test_case_comments_service.py::TestCaseCommentsService::test_list_comments tests/unit/test_tables_service.py::TestTableRows::test_lookup_rows_applies_default_limit tests/unit/test_tables_service.py::TestTableRows::test_lookup_row_multiple tests/unit/test_case_attachments_service.py::test_create_list_download_delete_attachment -quv run ruff check tracecat/config.py tracecat/tables/internal_router.py tracecat/tables/service.py tracecat/cases/internal_router.py tracecat/cases/service.py tracecat/cases/dropdowns/service.py tracecat/cases/attachments/internal_router.py tracecat/cases/attachments/service.py tests/unit/api/test_api_internal_tables.py tests/unit/api/test_api_internal_cases.py tests/unit/test_case_comments_service.py tests/unit/test_tables_service.pyuv run ruff format --check tracecat/config.py tracecat/tables/internal_router.py tracecat/tables/service.py tracecat/cases/internal_router.py tracecat/cases/service.py tracecat/cases/dropdowns/service.py tracecat/cases/attachments/internal_router.py tracecat/cases/attachments/service.py tests/unit/api/test_api_internal_tables.py tests/unit/api/test_api_internal_cases.py tests/unit/test_case_comments_service.py tests/unit/test_tables_service.pyuv run basedpyright tracecat/config.py tracecat/tables/internal_router.py tracecat/tables/service.py tracecat/cases/internal_router.py tracecat/cases/service.py tracecat/cases/dropdowns/service.py tracecat/cases/attachments/internal_router.py tracecat/cases/attachments/service.py tests/unit/api/test_api_internal_tables.py tests/unit/api/test_api_internal_cases.py tests/unit/test_case_comments_service.py tests/unit/test_tables_service.pySummary by cubic
Bound internal API workloads with sane defaults and max limits, batched case metrics context loading, and moved blocking attachment work off the event loop to improve stability and latency. Internal case reads no longer record case-view events.
Refactors
tracecat.configand applied them to table lookup, case comments, and case metrics.CasesService.get_cases,fields.batch_get_fields, and dropdown batch loading to remove N+1 DB calls.asyncio.to_thread.get_casenow setstrack_view=Falseto avoid view-side effects.Bug Fixes
Written for commit 2b83671. Summary will update on new commits. Review in cubic