Skip to content

fix(experiments): enable server sorting for list columns#6

Open
lordspline wants to merge 2 commits into
masterfrom
capy/fix-experiments-list-sorting
Open

fix(experiments): enable server sorting for list columns#6
lordspline wants to merge 2 commits into
masterfrom
capy/fix-experiments-list-sorting

Conversation

@lordspline

@lordspline lordspline commented Jun 17, 2026

Copy link
Copy Markdown

Problem

The Experiments list exposed sortable Result and Created by columns, but clicking them sent order=conclusion and order=created_by to the list API. Those order values were not both handled safely server-side, so users saw API errors instead of global sorting.

Fixes PostHog#63621

Changes

  • Make the Experiments table use controlled, URL-backed server sorting for sortable columns instead of page-local sort functions.
  • Add null-safe server ordering for created_by and a deterministic conclusion sort key matching the displayed result order.
  • Preserve the existing valid server order fields and document the expanded allowlist in the DRF schema.
  • Add focused backend and frontend regression tests for ascending/descending ordering, null creators/conclusions, pagination, URL hydration, and unaffected order fields.
  • Regenerate the generated API files affected by the schema help text change.

How did you test this code?

As an agent, I tested this with:

  • SANDBOX_PROVIDER= TEST=1 DEBUG=1 POSTHOG_TELEMETRY_OPT_OUT=1 pytest -s products/experiments/backend/test/test_experiment_service.py products/experiments/backend/test/test_presentation_api.py -k "orders_by_conclusion or orders_by_created_by or order_by_valid_fields_works or can_order_experiments_by"
  • pnpm --filter=@posthog/frontend exec jest frontend/src/scenes/experiments/experimentsLogic.test.ts --runInBand --forceExit
  • ruff format --check products/experiments/backend/experiment_service.py products/experiments/backend/presentation/views.py products/experiments/backend/test/test_experiment_service.py products/experiments/backend/test/test_presentation_api.py && ruff check products/experiments/backend/experiment_service.py products/experiments/backend/presentation/views.py products/experiments/backend/test/test_experiment_service.py products/experiments/backend/test/test_presentation_api.py
  • pnpm exec oxfmt --check frontend/src/scenes/experiments/Experiments.tsx frontend/src/scenes/experiments/experimentsLogic.test.ts products/experiments/frontend/generated/api.schemas.ts services/mcp/src/api/generated.ts services/mcp/src/generated/experiments/api.ts && pnpm exec oxlint --quiet frontend/src/scenes/experiments/Experiments.tsx frontend/src/scenes/experiments/experimentsLogic.test.ts products/experiments/frontend/generated/api.schemas.ts services/mcp/src/api/generated.ts services/mcp/src/generated/experiments/api.ts
  • pnpm --filter=@posthog/frontend typescript:check
  • Local browser verification against http://localhost:8010: seeded six Experiments rows, clicked Result ascending/descending and Created by ascending/descending, and confirmed the four API requests returned HTTP 200 with no experiment-list API errors.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

No docs update needed; this fixes existing Experiments list sorting behavior.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented by Capy after a human request to fix the Experiments list sorting issue end to end. I kept Result and Created by globally server-sorted instead of disabling them or sorting only the current page, because LemonTable was already emitting those order keys and the list API owns pagination. The main backend choice was to map conclusion to the same deterministic display order the old client-side sorter used, and to make created_by sort through a typed display-name expression so null creators and mixed name/email field types do not error.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@lordspline lordspline added the capy Generated by capy.ai label Jun 17, 2026 — with Capy AI

@capy-ai capy-ai 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.

Added 1 comment

Comment thread services/mcp/src/generated/experiments/api.ts
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capy Generated by capy.ai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Filtering the experiment list by Result or Created By causes the sort to break.

1 participant