Skip to content

Prevent large outputs from overwriting each other #1971

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 3 commits into from
Apr 23, 2025
Merged

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Apr 23, 2025

We still used the deprecated attempt ID to generate output keys - that won't work. Fixed by generating keys from run ID + attempt number in all cases.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of large outputs to prevent them from overwriting each other during processing.
    • Enhanced consistency and uniqueness in tracking task attempts, reducing the risk of data conflicts.
  • Chores

    • Updated debug log outputs to display attempt numbers instead of attempt IDs for clearer run identification.

Copy link

changeset-bot bot commented Apr 23, 2025

🦋 Changeset detected

Latest commit: 9fab699

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

coderabbitai bot commented Apr 23, 2025

Walkthrough

This update introduces changes to the way attempt identifiers are handled within the system, replacing direct use of attempt IDs with a new, more granular composite key based on both the run ID and attempt number. The update includes the introduction of a new attemptKey function and associated type, which standardizes key generation for attempts. Several files in the CLI and core packages are updated to utilize this new approach, ensuring consistency in logging, task execution, heartbeat signaling, and output packet management. A changeset note is also added to describe the intent of preventing output overwrites for large outputs.

Changes

File(s) Change Summary
.changeset/spotty-pants-wink.md Adds a changeset note describing the update to prevent large outputs from overwriting each other in relevant packages.
packages/core/src/v3/idempotencyKeys.ts Modifies injectScope to use run ID and attempt number for attempts; adds AttemptKeyMaterial type and exported attemptKey function.
packages/cli-v3/src/entryPoints/dev-run-controller.ts Updates debug logging to use attemptNumber instead of attemptId for execution attempts.
packages/cli-v3/src/entryPoints/dev-run-worker.ts Imports and uses attemptKey for heartbeat messages instead of direct attempt ID access.
packages/cli-v3/src/executions/taskRunProcess.ts Replaces direct attempt ID usage with attemptKey for managing attempt statuses and promises.
packages/core/src/v3/workers/taskExecutor.ts Uses attemptKey to construct export paths for output packets instead of direct attempt ID.

Sequence Diagram(s)

sequenceDiagram
    participant DevRunController
    participant TaskRunProcess
    participant TaskExecutor
    participant IdempotencyKeys

    DevRunController->>TaskRunProcess: Initiate execution (with execution context)
    TaskRunProcess->>IdempotencyKeys: Generate attempt key (attemptKey)
    IdempotencyKeys-->>TaskRunProcess: Return composite key (runId-attemptNumber)
    TaskRunProcess->>TaskExecutor: Pass execution context (with attempt key)
    TaskExecutor->>IdempotencyKeys: Generate attempt key for output export
    IdempotencyKeys-->>TaskExecutor: Return composite key
    TaskExecutor->>TaskRunProcess: Complete execution, export output using composite key
Loading

Suggested reviewers

  • matt-aitken

Poem

In the warren where code bunnies play,
We stitched up our keys in a brand new way.
No more confusion, no outputs collide—
Each attempt’s now unique, with run and number beside!
With attemptKey in paw, we hop on ahead,
Keeping our packets safe, just as we said.
🐇✨


📜 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 853a7ef and 9fab699.

📒 Files selected for processing (6)
  • .changeset/spotty-pants-wink.md (1 hunks)
  • packages/cli-v3/src/entryPoints/dev-run-controller.ts (1 hunks)
  • packages/cli-v3/src/entryPoints/dev-run-worker.ts (2 hunks)
  • packages/cli-v3/src/executions/taskRunProcess.ts (3 hunks)
  • packages/core/src/v3/idempotencyKeys.ts (2 hunks)
  • packages/core/src/v3/workers/taskExecutor.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/cli-v3/src/entryPoints/dev-run-worker.ts (1)
packages/core/src/v3/idempotencyKeys.ts (1)
  • attemptKey (139-141)
packages/core/src/v3/workers/taskExecutor.ts (1)
packages/core/src/v3/idempotencyKeys.ts (1)
  • attemptKey (139-141)
packages/core/src/v3/idempotencyKeys.ts (1)
packages/core/src/v3/taskContext/index.ts (1)
  • ctx (26-28)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (13)
packages/core/src/v3/idempotencyKeys.ts (2)

107-110: Good improvement to idempotency scope granularity.

Enhancing the "attempt" scope to include both run ID and attempt number creates more unique keys and prevents potential collisions that could occur when using attempt IDs alone.


129-141: Well-structured new attemptKey function with clear type definition.

This function standardizes attempt key generation across the codebase and ensures consistency. The composite key structure using both run ID and attempt number will effectively prevent large outputs from overwriting each other as intended in the PR objectives.

.changeset/spotty-pants-wink.md (1)

1-7: Appropriate changeset with clear description.

The patch version bump and description accurately represent the nature of the changes - a bug fix to prevent large outputs from overwriting each other.

packages/cli-v3/src/entryPoints/dev-run-controller.ts (1)

625-628: Consistent logging update.

Changed debug logging to use attemptNumber instead of attemptId, which aligns with the new attempt identification approach implemented across the codebase.

packages/cli-v3/src/entryPoints/dev-run-worker.ts (2)

10-10: Added necessary import for the new attempt key function.

The import statement correctly includes the new attemptKey function needed for the implementation below.


549-551: Improved attempt identification in heartbeat messages.

Using the standardized attemptKey(_execution) instead of the raw attempt ID ensures consistent key generation across the codebase, supporting the PR objective to prevent large outputs from overwriting each other.

packages/core/src/v3/workers/taskExecutor.ts (2)

15-15: Well-placed import to support the task output key change.

The added import of attemptKey from "../index.js" is needed to support the composite key generation later in the file.


239-239: Good change to prevent output overwrites.

By using attemptKey(ctx) instead of directly using the attempt ID, this change ensures that output keys are uniquely identified by both run ID and attempt number. This will prevent large outputs from overwriting each other when multiple attempts are executed, addressing the core issue in the PR.

packages/cli-v3/src/executions/taskRunProcess.ts (5)

2-2: Well-placed import for the attempt key function.

Adding the attemptKey import is necessary to support the consistent key generation across the codebase.


168-170: Good replacement of direct attempt ID with composite key.

Using attemptKey(execution) instead of directly accessing the attempt ID ensures consistent key generation that uniquely identifies attempts by both run ID and attempt number in the task run completion handler.


176-176: Maintains consistent key approach for setting attempt status.

This change ensures that the same composite key is used when updating the attempt status.


178-178: Maintains consistent key approach for retrieving attempt promises.

This change ensures that the same composite key is used when looking up the attempt promise.


235-240: Consistently applies the key pattern for execute method.

The change in the execute method follows the same pattern, using attemptKey(params.payload.execution) to generate a consistent composite key for tracking attempt status and promises.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@nicktrn nicktrn merged commit 73214d7 into main Apr 23, 2025
12 checks passed
@nicktrn nicktrn deleted the fix/large-outputs branch April 23, 2025 18:21
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.

2 participants