Skip to content

feat: move runs grouping and filtering server-side - #570

Closed
Cedric Vidal (cedricvidal) wants to merge 29 commits into
mainfrom
feat/server-side-grouping
Closed

Cedric Vidal (cedricvidal) wants to merge 29 commits into
mainfrom
feat/server-side-grouping

Conversation

@cedricvidal

Copy link
Copy Markdown
Collaborator

Original author: Cedric Vidal (@cedricvidal)

Closes #568

Summary

Move runs grouping, filtering, and aggregation from the portal client to the API server. The GET /api/v1/requests endpoint now supports a groupBy query parameter that returns RunGroup[] via a MongoDB aggregation pipeline, plus status, outcome, and taskPromptId query parameters for server-side filtering. Includes database indexes for filtered/grouped queries and documentation.

What changed

Server-side grouping (aggregation pipeline)

  • New buildGroupingPipeline() in apps/api/src/grouping.ts — 4-stage MongoDB aggregation ($addFields → $group → $project → $sort)
  • groupBy=task groups by taskPromptId, groupBy=submissionId groups by submissionId
  • Per-group aggregates: count, turns/duration/tokens stats (min/max/mean/stdDev), status/outcome distribution counts
  • Uniform-value detection: surfaces shared worker, model, agent version, platform, MCP servers, skills, submission ID, task across group members
  • runIds included in each group for checkbox selection, report summaries, and bulk actions without expanding
  • Deterministic sort by group key (ascending)

Server-side filtering

  • status, outcome, and taskPromptId query params wired into the MongoDB $match filter (both flat and grouped modes)
  • Task filtering uses taskPromptId (portal task dropdown stores taskPromptId values, displays task names)
  • All filters propagate to expanded group runs queries
  • Client-side .filter() for status/outcome/task removed entirely

Database indexes (migration 009)

  • Single-field indexes on taskPromptId, status, outcome, workerType, deletedAt for the requests collection
  • Cosmos DB for MongoDB (RU) uses index intersection for multi-property filters, so single-field indexes are the recommended approach over compound indexes

Portal changes

  • RunsList.tsx refactored: uses api.listRunGroups() when groupBy is active, fetches individual runs on group expand
  • Group rows show: status/outcome progress bars, report progress bar, group-level checkbox, aggregated stats
  • Filter dropdowns pass values to API; query keys include all filter params for proper cache invalidation
  • Flat runs query disabled when grouping is active (enabled: groupBy === "none")

Dead code cleanup

  • Removed groupRuns, computeStats, and all client-side grouping/aggregation logic from apps/portal/src/lib/grouping.ts (kept only formatStatRange)
  • Removed unused computeStats from apps/api/src/grouping.ts (stats computed entirely in the MongoDB pipeline)
  • Removed associated tests for deleted functions

Shared types

  • GroupByKey, AggregateStats, GroupAggregates, GroupUniformValues, RunGroup in packages/shared
  • RunGroupSchema, GroupAggregatesSchema Zod schemas
  • ListRequestsQuerySchema extended with groupBy, status, outcome params

Documentation

  • New docs/architecture/database.md — documents all collections, indexes, and Cosmos DB indexing strategy
  • Updated docs/architecture/db-migrations.md — filled in missing migration entries 002–009

Tests

  • 12 unit tests for buildGroupingPipeline() (grouping, stats, uniform detection, edge cases)
  • 5 endpoint tests for status/outcome filtering (flat, grouped, combined)
  • All 1157 tests passing

Add runIds (string[]) to RunGroup type, schema, and aggregation pipeline
so that report summaries, group checkbox, and bulk actions work even when
a group row is collapsed. Previously these features required expanding
the group to fetch individual runs.
Add $sort { label: 1 } as the 4th pipeline stage so groups are
always returned in alphabetical order by task name or submission ID.
key (taskPromptId or submissionId) is unique per group, whereas label
(display name) can have ties, leading to non-deterministic ordering.
- Wire status and outcome query params into API handler filter object
  (both were already in ListRequestsQuerySchema but not read)
- Add status and outcome params to portal API client (listRuns, listRunGroups)
- Pass status, outcome, and taskPromptId from filter dropdowns to API queries
- Change task dropdown to store taskPromptId values (display task names)
- Merge URL taskPromptId with dropdown selection (dropdown takes precedence)
- Remove client-side .filter() for status/outcome/task
- Update query keys to include all filter params for proper cache invalidation
- Add 5 endpoint tests for status/outcome filtering (flat and grouped)
When expanding a group, the individual runs query was not passing
status and outcome filters, causing unfiltered runs to appear inside
filtered groups.
groupRuns(), computeStats(), and related helpers are no longer used
since grouping moved server-side. Keep only formatStatRange() which
is still used by RunsList for displaying aggregate stats.
…ping

# Conflicts:
#	apps/portal/src/lib/grouping.test.ts
#	apps/portal/src/lib/grouping.ts
The MongoDB aggregation pipeline computes stats directly via
$min/$max/$avg operators. computeStats was only used in its own
tests and never called from application code.
Add migration 009 with indexes on taskPromptId, status, outcome,
workerType, and deletedAt. Cosmos DB for MongoDB (RU) uses index
intersection for multi-field filters, so single-field indexes are
the recommended approach over compound indexes.
New docs/architecture/database.md documents all collections, their
indexes, and the indexing strategy for Cosmos DB for MongoDB (RU).

Updated the migrations table in db-migrations.md which was missing
entries 002-009.
- Add extensions uniform detection to aggregation pipeline
- Add extensions to GroupUniformValues type and Zod schema
- Add extensions to portal mirrored types
- Fix portal grouping.ts import: use ../types instead of shared
@cedricvidal Cedric Vidal (cedricvidal) added the type: enhancement New functionality or improvements to existing behavior. label Jul 29, 2026
@cedricvidal Cedric Vidal (cedricvidal) added topic: performance Improvements to speed, efficiency, or resource consumption. author: cedricvidal labels Jul 29, 2026
@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #733

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1173 1173 0 0 0 0 0 31.3s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #734

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1173 1173 0 0 0 0 0 28.6s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #743

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1173 1173 0 0 0 0 0 28.2s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #745

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1175 1175 0 0 0 0 0 28.1s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #746

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1175 1175 0 0 0 0 0 29.8s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #747

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1175 1175 0 0 0 0 0 29.5s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #750

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1177 1177 0 0 0 0 0 28.9s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #751

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1177 1177 0 0 0 0 0 29.7s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #752

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1177 1177 0 0 0 0 0 30.7s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #754

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1181 1181 0 0 0 0 0 30.2s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #756

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1181 1181 0 0 0 0 0 29.2s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #758

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1161 1161 0 0 0 0 0 33.6s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #759

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1157 1157 0 0 0 0 0 30.0s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #760

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1157 1157 0 0 0 0 0 30.6s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #761

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1157 1157 0 0 0 0 0 30.5s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #762

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1157 1157 0 0 0 0 0 29.7s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #763

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1157 1157 0 0 0 0 0 30.1s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #764

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1157 1157 0 0 0 0 0 31.2s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #765

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1157 1157 0 0 0 0 0 29.0s

🎉 All tests passed!

Github Test Reporter

@cedricvidal

Copy link
Copy Markdown
Collaborator Author

Original author: @github-actions[bot]

Test Results (Node.js 22)

test: Run #766

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
1157 1157 0 0 0 0 0 29.7s

🎉 All tests passed!

Github Test Reporter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: performance Improvements to speed, efficiency, or resource consumption. type: enhancement New functionality or improvements to existing behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move runs grouping server side

1 participant