-
Notifications
You must be signed in to change notification settings - Fork 167
feat: implement per-cell source provenance #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,9 @@ | ||||||||||||
| import { internalMutation, internalQuery } from "./_generated/server.js"; | ||||||||||||
| import { v } from "convex/values"; | ||||||||||||
|
|
||||||||||||
| const DEFAULT_PAGE_SIZE = 50; | ||||||||||||
| const MAX_PAGE_SIZE = 200; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Insert a populate-run metrics record. | ||||||||||||
| * | ||||||||||||
|
|
@@ -68,33 +71,52 @@ export const getByWorkflowRunId = internalQuery({ | |||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * List all runs for a dataset, newest first. | ||||||||||||
| * TODO: paginate — .collect() loads all docs into memory and will degrade | ||||||||||||
| * as run history grows. Add cursor-based pagination when this is exposed | ||||||||||||
| * to the frontend or run counts become large. | ||||||||||||
| * List runs for a dataset, newest first. | ||||||||||||
| * Cursor-based pagination keeps memory bounded as run history grows. | ||||||||||||
| */ | ||||||||||||
| export const listByDataset = internalQuery({ | ||||||||||||
| args: { datasetId: v.string() }, | ||||||||||||
| args: { | ||||||||||||
| datasetId: v.string(), | ||||||||||||
| cursor: v.optional(v.string()), | ||||||||||||
| limit: v.optional(v.number()), | ||||||||||||
| }, | ||||||||||||
| handler: async (ctx, args) => { | ||||||||||||
| const runs = await ctx.db | ||||||||||||
| const limit = Math.min(args.limit ?? DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE); | ||||||||||||
| const { page, isDone, continueCursor } = await ctx.db | ||||||||||||
| .query("runStats") | ||||||||||||
| .withIndex("by_dataset", (q) => q.eq("datasetId", args.datasetId)) | ||||||||||||
| .collect(); | ||||||||||||
| return runs.sort((a, b) => b.startedAt - a.startedAt); | ||||||||||||
| .withIndex("by_dataset_started_at", (q) => | ||||||||||||
| q.eq("datasetId", args.datasetId), | ||||||||||||
| ) | ||||||||||||
| .order("desc") | ||||||||||||
| .paginate({ | ||||||||||||
| cursor: args.cursor ?? null, | ||||||||||||
| numItems: limit, | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| return { runs: page, isDone, continueCursor }; | ||||||||||||
| }, | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * List all runs for a user, newest first. | ||||||||||||
| * TODO: paginate — same concern as listByDataset above. | ||||||||||||
| * List runs for a user, newest first. | ||||||||||||
| */ | ||||||||||||
| export const listByUser = internalQuery({ | ||||||||||||
| args: { userId: v.string() }, | ||||||||||||
| args: { | ||||||||||||
| userId: v.string(), | ||||||||||||
| cursor: v.optional(v.string()), | ||||||||||||
| limit: v.optional(v.number()), | ||||||||||||
| }, | ||||||||||||
| handler: async (ctx, args) => { | ||||||||||||
| const runs = await ctx.db | ||||||||||||
| const limit = Math.min(args.limit ?? DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation to ensure limit is positive. Same issue as in 🛡️ Suggested fix to enforce positive limit- const limit = Math.min(args.limit ?? DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE);
+ const limit = Math.min(
+ Math.max(args.limit ?? DEFAULT_PAGE_SIZE, 1),
+ MAX_PAGE_SIZE
+ );📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| const { page, isDone, continueCursor } = await ctx.db | ||||||||||||
| .query("runStats") | ||||||||||||
| .withIndex("by_user", (q) => q.eq("userId", args.userId)) | ||||||||||||
| .collect(); | ||||||||||||
| return runs.sort((a, b) => b.startedAt - a.startedAt); | ||||||||||||
| .withIndex("by_user_started_at", (q) => q.eq("userId", args.userId)) | ||||||||||||
| .order("desc") | ||||||||||||
| .paginate({ | ||||||||||||
| cursor: args.cursor ?? null, | ||||||||||||
| numItems: limit, | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| return { runs: page, isDone, continueCursor }; | ||||||||||||
| }, | ||||||||||||
| }); | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation to ensure limit is positive.
The current limit calculation allows negative or zero values to pass through if explicitly provided in
args.limit. This could cause unexpected pagination behavior or errors in the underlyingpaginate()call.🛡️ Suggested fix to enforce positive limit
📝 Committable suggestion
🤖 Prompt for AI Agents