Skip to content

Conversation

borisarzentar
Copy link
Member

Description

DCO Affirmation

I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.

@borisarzentar borisarzentar self-assigned this Apr 25, 2025
Copy link

pull-checklist bot commented Apr 25, 2025

Please make sure all the checkboxes are checked:

  • I have tested these changes locally.
  • I have reviewed the code changes.
  • I have added end-to-end and unit tests (if applicable).
  • I have updated the documentation and README.md file (if necessary).
  • I have removed unnecessary code and debug statements.
  • PR title is clear and follows the convention.
  • I have tagged reviewers or team members for feedback.

Copy link
Contributor

coderabbitai bot commented Apr 25, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce an optional context dictionary parameter to the task execution pipeline in the codebase. This parameter is added to the function signatures of run_tasks_with_telemetry, run_tasks, run_tasks_base, and handle_task, allowing contextual information to be passed through all layers of task execution. The code now inspects task function signatures to determine if they accept a context argument and supplies it if needed. Additional updates include modifying logging behavior, removing a test fixture, and adding new and updated test cases to validate the context-passing functionality.

Changes

File(s) Change Summary
cognee/modules/pipelines/operations/run_tasks.py, cognee/modules/pipelines/operations/run_tasks_base.py Added optional context parameter to task execution functions; propagates through pipeline; inspects and provides context to tasks if required.
cognee/shared/logging_utils.py Broadened suppression of SQLAlchemy warnings to all log levels above DEBUG instead of only above WARNING.
cognee/tests/integration/run_toy_tasks/conftest.py Removed pytest fixture that copied a test database file to a target directory for integration tests.
cognee/tests/unit/modules/pipelines/run_tasks_test.py Added main guard to allow running the test file as a script.
cognee/tests/unit/modules/pipelines/run_tasks_with_context_test.py Added new async test module to verify pipeline execution with context; includes test functions and a main guard.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant run_tasks
    participant run_tasks_with_telemetry
    participant run_tasks_base
    participant handle_task
    participant Task

    Caller->>run_tasks: run_tasks(tasks, ..., context)
    run_tasks->>run_tasks_with_telemetry: run_tasks_with_telemetry(..., context)
    run_tasks_with_telemetry->>run_tasks_base: run_tasks_base(..., context)
    loop For each task
        run_tasks_base->>handle_task: handle_task(running_task, ..., context)
        alt Task accepts context
            handle_task->>Task: Task(..., context)
        else Task does not accept context
            handle_task->>Task: Task(...)
        end
    end
Loading

Possibly related PRs

  • feature: tighten run_tasks_base #730: Refactors run_tasks_base into a separate module with executors and a task handler; directly related as both PRs modify the task execution flow and related functions.

Suggested labels

run-checks

Suggested reviewers

  • soobrosa

Poem

A rabbit hops through code so bright,
Passing context left and right.
Each task now knows just what to do,
With context carried, fresh and new.
Tests now run, the warnings fade,
In pipelines strong, improvements made!
🐇✨


🪧 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.

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)
cognee/shared/logging_utils.py (1)

315-315: Broadened SQLAlchemy warning suppression scope

This change modifies when SQLAlchemy warnings are suppressed, now filtering them at all log levels above DEBUG (previously only above WARNING). While this reduces log noise at INFO and WARNING levels, consider whether this aligns with your overall logging strategy.

Since this is a behavioral change, consider adding a brief comment explaining the rationale for filtering SQLAlchemy warnings at these levels.

+    # Filter SQLAlchemy warnings at all levels above DEBUG to reduce noise while preserving debug-level visibility
     if log_level > logging.DEBUG:

Verify that this change is intentional and that important SQLAlchemy warnings that should be visible at INFO or WARNING levels aren't being suppressed. This may be related to the new context parameter implementation in tasks.

cognee/modules/pipelines/operations/run_tasks_base.py (1)

31-37: Good implementation of context detection and injection

This is a clean implementation that:

  1. Inspects the task's function signature to check if it accepts a "context" parameter
  2. Only provides the context to tasks that expect it

Minor optimization suggested:

-    has_context = any(
-        [key == "context" for key in inspect.signature(running_task.executable).parameters.keys()]
-    )
+    has_context = "context" in inspect.signature(running_task.executable).parameters

This change avoids creating a temporary list and simplifies the check, while also addressing the SIM118 static analysis hint.

🧰 Tools
🪛 Ruff (0.8.2)

32-32: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f94076b and 4cc5b81.

📒 Files selected for processing (6)
  • cognee/modules/pipelines/operations/run_tasks.py (4 hunks)
  • cognee/modules/pipelines/operations/run_tasks_base.py (4 hunks)
  • cognee/shared/logging_utils.py (1 hunks)
  • cognee/tests/integration/run_toy_tasks/conftest.py (0 hunks)
  • cognee/tests/unit/modules/pipelines/run_tasks_test.py (1 hunks)
  • cognee/tests/unit/modules/pipelines/run_tasks_with_context_test.py (1 hunks)
💤 Files with no reviewable changes (1)
  • cognee/tests/integration/run_toy_tasks/conftest.py
🧰 Additional context used
🧬 Code Graph Analysis (3)
cognee/tests/unit/modules/pipelines/run_tasks_test.py (1)
cognee/tests/unit/modules/pipelines/run_tasks_with_context_test.py (1)
  • test_run_tasks (42-43)
cognee/modules/pipelines/operations/run_tasks.py (2)
cognee/modules/pipelines/tasks/task.py (1)
  • Task (5-97)
cognee/modules/pipelines/operations/run_tasks_base.py (1)
  • run_tasks_base (66-82)
cognee/tests/unit/modules/pipelines/run_tasks_with_context_test.py (4)
cognee/modules/pipelines/tasks/task.py (1)
  • Task (5-97)
cognee/modules/users/methods/get_default_user.py (1)
  • get_default_user (12-37)
cognee/modules/pipelines/operations/run_tasks_base.py (1)
  • run_tasks_base (66-82)
cognee/tests/unit/modules/pipelines/run_tasks_test.py (1)
  • run_and_check_tasks (10-46)
🪛 Ruff (0.8.2)
cognee/modules/pipelines/operations/run_tasks_base.py

32-32: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Basic Tests / Run Unit Tests
  • GitHub Check: Basic Tests / Run Simple Examples
  • GitHub Check: Basic Tests / Run Basic Graph Tests
  • GitHub Check: End-to-End Tests / S3 Bucket Test
  • GitHub Check: End-to-End Tests / Deletion Test
  • GitHub Check: End-to-End Tests / Server Start Test
  • GitHub Check: End-to-End Tests / Run Telemetry Pipeline Test
  • GitHub Check: End-to-End Tests / Deduplication Test
🔇 Additional comments (12)
cognee/tests/unit/modules/pipelines/run_tasks_test.py (1)

53-54: Good addition of an entry point!

Adding the if __name__ == "__main__": block allows this test module to be executed as a standalone script, which is a good Python practice. This aligns with the approach used in the new context-aware test module.

cognee/tests/unit/modules/pipelines/run_tasks_with_context_test.py (3)

14-21: Well-structured task definitions with context support

Good job defining tasks with different signatures - some accepting context (task_1, task_3) and some without (task_2). This effectively tests how the pipeline properly provides context only to functions that need it.


26-35: Good test pipeline setup with context parameter

The pipeline is properly set up using run_tasks_base with the new context parameter. This tests the core functionality of passing context through the execution pipeline.


37-39: Correct verification of pipeline results

The test correctly verifies that the final result matches what's expected from the chain of operations:

  • task_1(5, 7) = 12
  • task_2(12) = 24
  • task_3(24, 7) = 24^7 = 4,586,471,424
cognee/modules/pipelines/operations/run_tasks.py (4)

23-25: Good addition of context parameter

The context parameter is properly added to the function signature with a sensible default value (None). This maintains backward compatibility while supporting the new feature.


41-41: Proper context propagation

The context parameter is correctly forwarded to the run_tasks_base function, ensuring it's available throughout the task execution pipeline.


77-77: Good addition of context parameter

The context parameter is properly added to the run_tasks function with a sensible default value (None), maintaining backward compatibility.


87-93: Good use of explicit parameter names

The function call is now using explicit parameter names, which improves readability and makes it clear that context is being passed through the pipeline.

cognee/modules/pipelines/operations/run_tasks_base.py (4)

17-17: Good addition of context parameter

The context parameter is properly added to the handle_task function with a sensible default value (None), maintaining backward compatibility.


40-40: Proper recursive propagation of context

The context parameter is correctly passed to the recursive call to run_tasks_base, ensuring it's available for downstream tasks.


66-66: Good addition of context parameter

The context parameter is properly added to the run_tasks_base function with a sensible default value (None), maintaining backward compatibility.


79-81: Proper context forwarding

The context parameter is correctly passed to the handle_task function, ensuring tasks that need context can access it.

hande-k and others added 2 commits April 26, 2025 00:03
<!-- .github/pull_request_template.md -->

## Description
<!-- Provide a clear description of the changes in this PR -->

## DCO Affirmation
I affirm that all code in every commit of this pull request conforms to
the terms of the Topoteretes Developer Certificate of Origin.

---------

Co-authored-by: Vasilije <8619304+Vasilije1990@users.noreply.github.com>
@borisarzentar borisarzentar changed the base branch from main to dev April 29, 2025 11:24
@borisarzentar borisarzentar merged commit 5970d96 into dev Apr 30, 2025
50 checks passed
@borisarzentar borisarzentar deleted the feature/cog-1786-pass-context-argument-to-tasks-that-require-it branch April 30, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants