Skip to content

fix: runs.retrieve now uses the output stored on the TaskRun table instead of deprecated attempts table #1853

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

Merged
merged 2 commits into from
Mar 31, 2025

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Mar 31, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced task run details with streamlined output retrieval and more accurate attempt counting.
    • Introduced new tagging tasks that validate and confirm the expected tags during task execution.
    • Added a new property runTags for improved task run selection.

Copy link

changeset-bot bot commented Mar 31, 2025

⚠️ No Changeset found

Latest commit: c9353df

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Mar 31, 2025

Walkthrough

The PR updates the task run retrieval process in the API presenter by introducing a new runTags property and switching from an include to a select clause in the findRun method. Modifications include changes in the selected fields and simplified output retrieval in the call method with conditional handling for attempt counts. Additionally, the PR adds new task definitions in the tagging module that verify tag presence and test the execution flow of tagged tasks.

Changes

File(s) Change Summary
apps/webapp/.../ApiRetrieveRunPresenter.server.ts Added runTags to commonRunSelect; updated findRun to use a select clause with specified fields; modified call to simplify output retrieval and conditionally compute attempt count based on engine type.
references/hello-world/.../tags.ts Introduced new tasks taggedTask and tagTestTask that verify tag presence, manage execution delays, and validate task run outputs.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant P as ApiRetrieveRunPresenter
    participant DB as Database

    C->>P: Call run retrieval API
    P->>DB: Execute findRun with SELECT clause (including runTags)
    DB-->>P: Return run data
    P->>P: Simplify output retrieval and compute attemptCount
    P-->>C: Return processed run details
Loading
sequenceDiagram
    participant T as tagTestTask
    participant TT as taggedTask
    participant R as Task Registry

    T->>TT: Trigger taggedTask with initial tags
    TT->>TT: Check for required tags and wait
    TT-->>T: Return initial tags in output
    T->>R: Query currently executing tasks for validation
    R-->>T: Confirm task status
    T->>T: Verify final run details and tag output
Loading

Possibly related PRs

Poem

I'm a bunny coding away,
Hoping the tags come out to play,
With runTags added to the flow,
Our task runs now smartly glow,
Skipping through the code with glee 🐇,
Embracing changes perfectly!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fcb4dc and c9353df.

📒 Files selected for processing (1)
  • apps/webapp/app/presenters/v3/ApiRetrieveRunPresenter.server.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/webapp/app/presenters/v3/ApiRetrieveRunPresenter.server.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
references/hello-world/src/trigger/tags.ts (1)

49-105: Comprehensive tag verification test implementation.

The tagTestTask provides robust verification of the tagging system, including:

  • Triggering a tagged task
  • Verifying running tasks can be queried by tags
  • Confirming that tags persist through task execution

A few suggestions to improve robustness:

Consider making the wait times configurable rather than hardcoded to make the test more resilient:

-export const tagTestTask = task({
+export const tagTestTask = task({
   id: "tag-test",
-  run: async (payload, { ctx }) => {
+  run: async (payload: { waitForRunningMs?: number, waitForCompletionMs?: number } = {}, { ctx }) => {
     logger.info("Starting tag verification test");
 
     // Trigger a task with initial tags
     const handle = await taggedTask.trigger(
       { waitSeconds: 3 },
       {
         tags: ["test-tag-1", "test-tag-2"],
       }
     );
 
     // Wait a moment to ensure the task is running
-    await setTimeout(3_000);
+    await setTimeout(payload.waitForRunningMs ?? 3_000);
 
     // Query for running tasks with our tags
     const runningTasks = await runs.list({
       status: "EXECUTING",
       tag: ["test-tag-1", "test-tag-2"],
     });
 
     // ...
 
-    await wait.for({ seconds: 10 });
+    await wait.for({ seconds: payload.waitForCompletionMs ?? 10 });
apps/webapp/app/presenters/v3/ApiRetrieveRunPresenter.server.ts (1)

159-160: Updated attemptCount calculation to handle both engine types.

The code now properly computes attemptCount based on the engine type, using either attempts.length for "V1" or attemptNumber for newer engines.

Consider adding a brief comment explaining why this conditional logic exists to help future maintainers understand the different handling for V1 vs. newer engines:

        // We're removing attempts from the API
-        attemptCount:
-          taskRun.engine === "V1" ? taskRun.attempts.length : taskRun.attemptNumber ?? 0,
+        // For V1 engine, count attempts from the attempts array
+        // For newer engines, use the stored attemptNumber field
+        attemptCount:
+          taskRun.engine === "V1" ? taskRun.attempts.length : taskRun.attemptNumber ?? 0,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8977d25 and 7fcb4dc.

📒 Files selected for processing (2)
  • apps/webapp/app/presenters/v3/ApiRetrieveRunPresenter.server.ts (4 hunks)
  • references/hello-world/src/trigger/tags.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
references/hello-world/src/trigger/tags.ts (2)
apps/webapp/app/runEngine/services/batchTrigger.server.ts (1)
  • payload (652-682)
apps/webapp/app/runEngine/services/triggerTask.server.ts (2)
  • payload (516-547)
  • payload (549-559)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
references/hello-world/src/trigger/tags.ts (2)

1-3: Appropriate imports added to support new tagging functionality.

The additional imports for runs from the SDK, assert, and setTimeout are aligned with the new tag testing functionality being introduced in this file.


26-47: Well-structured task for tag verification.

The taggedTask implementation is clear and includes appropriate verification of expected tags, error handling, and a clean return value structure. The task is designed to be used in testing tag functionality.

apps/webapp/app/presenters/v3/ApiRetrieveRunPresenter.server.ts (3)

55-55: Added runTags to common selection fields.

The addition of runTags to commonRunSelect ensures that tag information is properly included in run queries.


73-87: Improved database query structure with more specific field selection.

Switching from include to select with specific field selection is a good improvement for performance and clarity. This change properly selects only the necessary fields from the database.


130-147: Simplified output retrieval directly from TaskRun.

This change correctly implements the PR objective by using output stored directly on the TaskRun table instead of searching through the deprecated attempts table.

@matt-aitken matt-aitken merged commit 0e77747 into main Mar 31, 2025
12 checks passed
@matt-aitken matt-aitken deleted the ea-branch-30 branch March 31, 2025 12:54
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.

3 participants