Skip to content

refactor(workflow): enhance request status handling and workflow cleanup #898

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 1 commit into from
Jul 9, 2025

Conversation

pcfreak30
Copy link
Member

@pcfreak30 pcfreak30 commented Jul 9, 2025

  • Added GetDefaultStatusMessage helper function to core.RequestStatus
  • Implemented ComputeRequestStatus to consolidate status calculation logic
  • Improved workflow status tracking with weighted progress calculation
  • Added CleanupWorkflow method to WorkflowCoordinator interface
  • Enhanced workflow completion handling with automatic cleanup
  • Updated request status updates to include timestamp refresh
  • Separated GetRequestStatus from ComputeRequestStatus for clarity
  • Improved error handling throughout workflow operations
  • Added better logging for workflow transitions and cleanup

Key changes:

  • Status calculation now combines step progress (50%) and internal operation progress (50%)
  • Workflows now automatically trigger cleanup upon completion
  • More robust status message handling using default messages
  • Better separation between status computation and status retrieval

Summary by CodeRabbit

  • New Features

    • Added automatic cleanup of workflows after completion, ensuring associated requests are properly handled.
    • Introduced default human-readable status messages for requests.
    • Enhanced workflow progress reporting with a unified progress calculation.
  • Improvements

    • Status updates now refresh the last updated timestamp for better tracking.
    • Status retrieval distinguishes between detailed computed status and basic stored status for greater clarity.
    • Improved error handling and logging during workflow cleanup processes.

Copy link

changeset-bot bot commented Jul 9, 2025

⚠️ No Changeset found

Latest commit: 89db14a

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

coderabbitai bot commented Jul 9, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

New mechanisms for workflow cleanup and status management were introduced. A centralized function for default status messages was added. Workflow completion now triggers cleanup of the workflow chain. Status computation and updates were refactored for clarity, and progress reporting was enhanced with weighted calculations. Several method signatures were updated or added.

Changes

File(s) Change Summary
core/request.go Added GetDefaultStatusMessage function to map status types to default messages.
core/workflow.go Extended WorkflowCoordinator interface with CleanupWorkflow(ctx, requestID) method.
service/request.go Refactored status computation: renamed/updated methods, added timestamp updates, introduced status/message split.
service/workflow.go Added workflow cleanup after completion, implemented CleanupWorkflow, improved status/progress calculation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant WorkflowCoordinator
    participant RequestService
    participant OperationHandler

    Client->>WorkflowCoordinator: CompleteWorkflowStep(requestID)
    WorkflowCoordinator->>RequestService: GetRequest(requestID)
    WorkflowCoordinator->>RequestService: GetRequestMetadata(requestID)
    alt Workflow not disabled
        loop For each request in workflow chain
            WorkflowCoordinator->>RequestService: GetRequest(currentRequestID)
            WorkflowCoordinator->>RequestService: DeleteRequest(currentRequestID)
        end
    end
    WorkflowCoordinator->>Client: Return completion or error
Loading
sequenceDiagram
    participant Client
    participant RequestService
    participant OperationHandler

    Client->>RequestService: ExecuteRequest(requestID)
    RequestService->>RequestService: ComputeRequestStatus(requestID)
    RequestService->>RequestService: UpdateRequestStatus(requestID, status)
    RequestService->>OperationHandler: Execute(request)
    RequestService->>RequestService: ComputeRequestStatus(requestID)
    RequestService->>RequestService: UpdateRequestStatus(requestID, status)
    RequestService->>Client: Return result
Loading

Possibly related PRs

Poem

A workflow’s end, a cleanup begun,
Statuses clearer, their messages spun.
Progress now weighted, more true to the task,
Old chains are tidied, no questions to ask.
The rabbit looks on, with a satisfied hop—
Code neat and complete, from bottom to top!
🐇✨


📜 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 77a2914 and 89db14a.

📒 Files selected for processing (4)
  • core/request.go (1 hunks)
  • core/workflow.go (1 hunks)
  • service/request.go (9 hunks)
  • service/workflow.go (3 hunks)
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 28dd875 and 77a2914.

📒 Files selected for processing (4)
  • core/request.go (1 hunks)
  • core/workflow.go (1 hunks)
  • service/request.go (9 hunks)
  • service/workflow.go (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
core/request.go (1)
db/models/request.go (5)
  • RequestStatusType (10-10)
  • RequestStatusPending (14-14)
  • RequestStatusProcessing (15-15)
  • RequestStatusCompleted (16-16)
  • RequestStatusFailed (17-17)
service/request.go (3)
db/models/request.go (2)
  • RequestStatusType (10-10)
  • RequestStatusFailed (17-17)
core/context.go (1)
  • Context (18-46)
core/request.go (2)
  • RequestStatus (61-67)
  • GetDefaultStatusMessage (70-83)
service/workflow.go (3)
core/workflow.go (1)
  • WorkflowStatus (328-338)
db/models/request.go (1)
  • RequestStatusCompleted (16-16)
core/context.go (1)
  • Context (18-46)
🔇 Additional comments (9)
core/workflow.go (1)

48-49: Interface extension looks good!

The new CleanupWorkflow method is a well-designed addition to the interface, providing a clear contract for cleaning up workflow resources.

core/request.go (1)

69-83: Clean implementation of centralized status messages!

The GetDefaultStatusMessage function provides a single source of truth for default status messages, improving consistency across the codebase.

service/request.go (5)

145-157: Improved status tracking during execution!

The enhanced execution flow now properly computes and updates the request status both before and after handler execution, providing more accurate status tracking throughout the operation lifecycle.

Also applies to: 181-188


324-324: Good addition of timestamp tracking!

Updating the updated_at field ensures accurate tracking of when status changes occur.


341-341: Correct method usage after renaming.

The change to use ComputeRequestStatus aligns with the refactored status computation logic.


365-406: Well-structured status computation logic!

The refactored ComputeRequestStatus method provides a clear hierarchy for status determination:

  1. Detailed status from operation handler (if available)
  2. Basic status from request model (fallback)
  3. Centralized default messages with special handling for failure reasons

This improves status reporting consistency and accuracy.


423-442: Clear separation of status retrieval methods!

The new GetRequestStatus method provides a lightweight way to retrieve stored status without querying handlers, complementing the more comprehensive ComputeRequestStatus method.

service/workflow.go (2)

391-400: Automatic cleanup on workflow completion!

Good addition of automatic cleanup when workflows complete. The error handling appropriately logs failures while still propagating the error.


547-580: Enhanced progress tracking with weighted calculation!

The new weighted progress calculation provides more accurate progress reporting by combining:

  • 50% weight from step progression through the workflow
  • 50% weight from the current step's internal progress

This gives users better visibility into both macro (workflow) and micro (step) progress.

- Added GetDefaultStatusMessage helper function to core.RequestStatus
- Implemented ComputeRequestStatus to consolidate status calculation logic
- Improved workflow status tracking with weighted progress calculation
- Added CleanupWorkflow method to WorkflowCoordinator interface
- Enhanced workflow completion handling with automatic cleanup
- Updated request status updates to include timestamp refresh
- Separated GetRequestStatus from ComputeRequestStatus for clarity
- Improved error handling throughout workflow operations
- Added better logging for workflow transitions and cleanup

Key changes:
- Status calculation now combines step progress (50%) and internal operation progress (50%)
- Workflows now automatically trigger cleanup upon completion
- More robust status message handling using default messages
- Better separation between status computation and status retrieval
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