Skip to content
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

Reload model changes. #1106

Closed
wants to merge 2 commits into from

Conversation

nupur-khare
Copy link
Contributor

@nupur-khare nupur-khare commented Jan 3, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced user activity logging for model reload actions.
    • Implemented checks to prevent concurrent model reloads.
  • Bug Fixes

    • Improved error handling in the model reload process.
  • Refactor

    • Split and streamlined the reload functionality for better management and logging.
  • Tests

    • Added new integration and unit tests for model reload behavior and logging.
    • Expanded test coverage to include checks for concurrent reload prevention.
  • Documentation

    • No visible documentation changes for end-users.

Copy link

coderabbitai bot commented Jan 3, 2024

Warning

Rate Limit Exceeded

@nupur-khare has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 27 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. 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.

Commits Files that changed from the base of the PR and between d5f22db and eef8367.

Walkthrough

The recent updates focus on enhancing the model reload functionality with better error handling, user activity logging, and audit logging. Changes include splitting the reload function for improved clarity, adding checks to prevent concurrent reloads, and ensuring that user activities are logged and audited appropriately. These modifications aim to streamline the reload process, making it more robust and transparent for users and administrators.

Changes

Files Change Summaries
kairon/chat/agent_processor.py
kairon/chat/utils.py
Enhanced reload function with user activity logging, split reload functionality, and improved error handling.
kairon/chat/routers/web_client.py Added check for model reload in progress to prevent concurrent reload tasks.
kairon/shared/constants.py Introduced new constants for user activity types related to model reloading.
kairon/shared/data/audit/processor.py Updated user info retrieval logic to consider bot information for audit logging.
tests/integration_test/chat_service_test.py
tests/integration_test/services_test.py
Included new tests for reload functionality and handling of concurrent reload scenarios.
tests/unit_test/.../agent_processor_test.py
tests/unit_test/.../data_processor_test.py
tests/unit_test/utility_test.py
Updated tests to accommodate changes in agent retrieval and user activity logging.

Poem

In the land of code, where the data hops, 🐇💻

A rabbit worked hard on the model ops.

No more clashes, reloads are neat, 🔄

Logging each step, the task's complete! 🎉

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

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.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 44fc36f and d5f22db.
Files selected for processing (10)
  • kairon/chat/agent_processor.py (3 hunks)
  • kairon/chat/routers/web_client.py (2 hunks)
  • kairon/chat/utils.py (2 hunks)
  • kairon/shared/constants.py (1 hunks)
  • kairon/shared/data/audit/processor.py (1 hunks)
  • tests/integration_test/chat_service_test.py (4 hunks)
  • tests/integration_test/services_test.py (1 hunks)
  • tests/unit_test/data_processor/agent_processor_test.py (3 hunks)
  • tests/unit_test/data_processor/data_processor_test.py (1 hunks)
  • tests/unit_test/utility_test.py (4 hunks)
Additional comments: 25
kairon/chat/routers/web_client.py (1)
  • 79-81: The changes to reload_model function introduce a check to prevent concurrent reloads, which is a good practice to avoid race conditions. However, ensure that the ChatUtils.is_reload_model_in_progress method is atomic and thread-safe to prevent race conditions in a multi-threaded or multi-process environment.
kairon/chat/agent_processor.py (3)
  • 47-47: The reload function signature has been modified to include an email parameter for logging purposes. Ensure that all calls to this function have been updated to include the new parameter.

  • 64-70: User activity is logged upon successful model reload. It's important to ensure that the UserActivityLogger.add_log method handles any exceptions internally and does not disrupt the reload process.

  • 68-70: The logging of a model reload failure is done within the except block. Verify that the UserActivityLogger.add_log method is robust and does not raise exceptions that could mask the original exception causing the reload to fail.

kairon/shared/data/audit/processor.py (1)
  • 32-32: The logic to fetch user information now considers bot data if account data is not provided. Ensure that this change does not introduce any security or privacy concerns, especially in cases where the bot data might not be intended to be used for user identification.
kairon/shared/constants.py (1)
  • 61-63: The addition of reload_model_enqueued, reload_model_failure, and reload_model_completion to the UserActivityType enum is consistent with the changes in other files to enhance logging and tracking of the model reload process.
kairon/chat/utils.py (2)
  • 39-57: The new is_reload_model_in_progress method introduces a mechanism to check for ongoing reloads. Verify that this method is reliable and does not return false negatives, which could lead to concurrent reloads.

  • 60-70: The updated reload method now includes error handling and user activity logging. Ensure that the error handling is comprehensive and that the logging does not interfere with the reload process or exception propagation.

tests/unit_test/data_processor/agent_processor_test.py (2)
  • 34-35: The test setup now includes pytest.email and pytest.account assignments. Verify that these new assignments are used consistently across all relevant test cases and that they align with the new changes in the codebase.

  • 131-141: New test cases have been added to set up a user and bot for testing. Ensure that these test cases are complete and cover the scenarios introduced by the new changes, particularly the logging and error handling in the reload process.

tests/integration_test/chat_service_test.py (6)
  • 5-5: Import of datetime module is correct and necessary for timestamping in tests.

  • 31-32: Import statements for AuditLogData and AuditlogActions are correct and necessary for audit logging in tests.

  • 802-804: The addition of mock_reload_model_in_progress parameter to test_reload function is necessary to mock the state of model reloading.

  • 846-866: The new test function test_reload_event_already_in_progress correctly tests the scenario where a reload event is already in progress.

  • 869-891: The new test function test_reload_event_exception_in_reload correctly tests the scenario where an exception occurs during the model reload.

  • 843-895: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [2-893]

No further issues found in the rest of the file.

tests/unit_test/utility_test.py (6)
  • 7-7: Import of datetime module added.

  • 30-30: Import of TelegramResponseConverter added.

  • 31-31: Import of ChatUtils added.

  • 34-34: Import of UserActivityType added.

  • 37-37: Modification of DEFAULT_SYSTEM_PROMPT import.

  • 2787-2797: New test method test_is_reload_model_in_progress_failure added to check if the model reload is already in progress and raises an exception if it is.

def test_is_reload_model_in_progress_failure(self):
    AuditLogData(
        attributes=[{"key": "bot", "value": pytest.bot}], user="test", timestamp=datetime.utcnow(),
        action=AuditlogActions.ACTIVITY.value,
        entity=UserActivityType.reload_model_enqueued.value,
        data={'message': 'Model reload enqueued!'}
    ).save()
    in_progress = ChatUtils.is_reload_model_in_progress(pytest.bot, False)
    assert in_progress
    with pytest.raises(AppException, match='Model reload enqueued. Check logs.'):
        ChatUtils.is_reload_model_in_progress(pytest.bot)
tests/integration_test/services_test.py (1)
  • 5863-5889: The test test_reload_model_in_progress is well-structured and includes proper mocking and assertions to validate the behavior when a model reload is already in progress. It checks the response status, message, and success flag, which aligns with the PR objectives to handle concurrent reload tasks.
tests/unit_test/data_processor/data_processor_test.py (2)
  • 15303-15305: The addition of account_response and bot_response variables suggests that the test now includes creating an account and a bot before retrieving an agent. Ensure that these additions align with the test's purpose and that the created entities are properly cleaned up after the test to prevent side effects on other tests.

  • 15313-15316: The test case test_get_agent_from_cache_does_not_exists now includes setup steps for account and bot creation. Ensure that the AppException is raised for the correct reason (agent not found) and not due to any other error. Also, confirm that any entities created during the test are properly cleaned up afterwards.

agent = AgentProcessor.get_agent("tests")
account_response = AccountProcessor.add_account('test_agent_account', 'testAgent')
bot_response = AccountProcessor.add_bot("tests", account_response["_id"], "testAgent")
agent = AgentProcessor.get_agent("tests", account_response["_id"])
Copy link

Choose a reason for hiding this comment

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

The verification process has revealed the following:

  • The AgentProcessor.get_agent method is called with a single parameter in multiple locations within the codebase, which does not match the updated method signature that requires two parameters.
  • The new method signature with two parameters is used in a few locations, but not consistently across the entire codebase.

Given this information, it is clear that not all calls to the AgentProcessor.get_agent method have been updated to match the new signature. This inconsistency can lead to runtime errors where the method is called with an incorrect number of arguments.

Based on the findings:

  • : Calls to AgentProcessor.get_agent with the old signature still exist in the codebase, which do not match the updated method signature requiring two parameters.
Analysis chain

The get_agent method now takes an additional parameter. Verify that all calls to this method across the codebase have been updated to match the new signature.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old method signature to find omissions. Expecting no results.
ast-grep --lang python --pattern $'AgentProcessor.get_agent($_)'
# Search for the new method signature to validate usage. Expecting list of locations where the new signature is used.
ast-grep --lang python --pattern $'AgentProcessor.get_agent($_, $_)'

Length of output: 2170

@nupur-khare nupur-khare closed this Jan 9, 2024
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