Skip to content

refactor(api): update GET /api/tasks/runs documentation and validation#488

Open
pradipthaadhi wants to merge 2 commits intotestfrom
feat/api-task-runs-enhance
Open

refactor(api): update GET /api/tasks/runs documentation and validation#488
pradipthaadhi wants to merge 2 commits intotestfrom
feat/api-task-runs-enhance

Conversation

@pradipthaadhi
Copy link
Copy Markdown
Collaborator

@pradipthaadhi pradipthaadhi commented Apr 28, 2026

  • Enhanced the documentation for the GET /api/tasks/runs endpoint to clarify the response structure and query parameters, including optional runId, account_id, and limit.
  • Updated the validation schema for account_id to ensure it is a valid UUID, improving error handling for invalid inputs.
  • Added tests to validate the new behavior for account ID handling, including checks for valid and invalid UUIDs.

Summary by CodeRabbit

  • Documentation

    • Enhanced GET /api/tasks/runs endpoint documentation with clarified request parameters and response structure details
  • Bug Fixes

    • Strengthened account identifier validation to require UUID format compliance

- Enhanced the documentation for the GET /api/tasks/runs endpoint to clarify the response structure and query parameters, including optional `runId`, `account_id`, and `limit`.
- Updated the validation schema for `account_id` to ensure it is a valid UUID, improving error handling for invalid inputs.
- Added tests to validate the new behavior for account ID handling, including checks for valid and invalid UUIDs.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api Ready Ready Preview Apr 28, 2026 7:54pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Warning

Rate limit exceeded

@pradipthaadhi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 45 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 290e9e22-588d-4c65-bd20-6bf1090d7ebb

📥 Commits

Reviewing files that changed from the base of the PR and between ec879c6 and 774dd5f.

⛔ Files ignored due to path filters (1)
  • lib/tasks/__tests__/validateGetTaskRunQuery.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (1)
  • lib/tasks/validateGetTaskRunQuery.ts
📝 Walkthrough

Walkthrough

The endpoint documentation for GET /api/tasks/runs is updated to describe optional runId parameter supporting both single-run and list modes, with account-scoped filtering. Account ID validation is enhanced to require UUID format rather than just non-empty string.

Changes

Cohort / File(s) Summary
Endpoint Documentation
app/api/tasks/runs/route.ts
Updated endpoint docs to clarify dual-mode behavior: single-run mode when runId is present, list mode returning account-scoped recent runs (default 20, max 100 limit) when omitted.
Query Validation Schema
lib/tasks/validateGetTaskRunQuery.ts
Enhanced account_id validation to enforce UUID format with explicit error message, replacing previous non-empty string validation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • sweetmantech

Poem

✨ A UUID guard stands tall and true,
Validating paths both old and new.
Optional runs, a dual-mode dance—
Single or listed, at your command's glance. 🎯

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Solid & Clean Code ❓ Inconclusive Shell scripts provided lack actual verification output; git commands and code analysis checks show no execution results or concrete findings. Execute the provided shell scripts against the actual codebase to generate verification data, then re-evaluate code quality against SOLID principles and maintainability standards.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/api-task-runs-enhance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/tasks/validateGetTaskRunQuery.ts`:
- Around line 15-19: The account_id Zod chain trims after validation causing
UUIDs with surrounding whitespace to fail; change the schema for account_id to
preprocess/trim the raw value before running .uuid() (e.g. use z.preprocess(val
=> typeof val === "string" ? val.trim() : val, z.string().uuid("account_id must
be a valid UUID")). Update the account_id declaration (the current
.string().uuid(...).transform(...) chain) to use this preprocess approach so
trimming happens prior to UUID validation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 16afaaf9-8ce5-4a26-b424-5b3f7f04a3ae

📥 Commits

Reviewing files that changed from the base of the PR and between a35b9ea and ec879c6.

⛔ Files ignored due to path filters (1)
  • lib/tasks/__tests__/validateGetTaskRunQuery.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (2)
  • app/api/tasks/runs/route.ts
  • lib/tasks/validateGetTaskRunQuery.ts

Comment thread lib/tasks/validateGetTaskRunQuery.ts Outdated
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: This PR introduces stricter API validation (requiring account_id to be a UUID), which is a potential breaking change for clients and requires verification of existing identifier formats.

Architecture diagram
sequenceDiagram
    participant Client
    participant Route as API Route (GET /tasks/runs)
    participant Auth as validateAuthContext
    participant Val as validateGetTaskRunQuery
    participant Access as Access Control
    participant DB as Task Service

    Note over Client,DB: Request Validation & Auth Flow

    Client->>Route: GET /api/tasks/runs?account_id={uuid}&runId={id}&limit=20
    Route->>Auth: validateAuthContext()
    Auth-->>Route: { accountId, authToken }

    Route->>Val: validateGetTaskRunQuery(request)
    
    rect rgb(240, 240, 240)
    Note right of Val: NEW: Zod UUID Validation
    alt account_id is provided AND is not a valid UUID
        Val-->>Route: Return 400 Bad Request
        Route-->>Client: 400 "account_id must be a valid UUID"
    else account_id is valid UUID or missing
        Val->>Access: checkIsAdmin(currentAccountId)
        Access-->>Val: isAdmin status

        opt NOT Admin AND account_id override provided
            Val->>Access: CHANGED: validateAccountIdOverride(target, current)
            Access-->>Val: Verified accountId
        end
        Val-->>Route: Validated Query Params (mode: list | single)
    end
    end

    Note over Route,DB: Data Retrieval Flow

    alt mode == "single" (runId provided)
        Route->>DB: Fetch specific run
        alt Run exists
            DB-->>Route: Task Run data
            Route-->>Client: 200 OK { status: "success", runs: [...] }
        else Run not found
            DB-->>Route: null
            Route-->>Client: 404 Not Found
        end
    else mode == "list" (runId omitted)
        Route->>DB: Fetch recent runs for account (limit: 1-100)
        DB-->>Route: Task Runs list
        Route-->>Client: 200 OK { status: "success", runs: [...] }
    end
Loading

…ng test

- Simplified the validation schema for `account_id` by combining the transformation and validation into a single line.
- Added a test to ensure that whitespace is trimmed from `account_id` before UUID validation, enhancing input handling for the GET /api/tasks/runs endpoint.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Requires human review: This PR modifies API validation logic by enforcing UUID format on account_id, which could be a breaking change for existing API consumers not using UUIDs.

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.

1 participant