Skip to content

Conversation

Pouyanpi
Copy link
Collaborator

When rails ran in parallel, the stopped rail's processing log was excluded from aggregation, causing compute_generation_log() to never create an ActivatedRail entry for the stopped rail. Additionally,
the post_event (OutputRailFinished/InputRailFinished) was incorrectly added even when a rail stopped.

@Pouyanpi
Copy link
Collaborator Author

@greptileai

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR fixes a critical bug in the parallel rails execution path where policy violations (stopped rails) were not properly recorded in the processing log. The fix ensures that when a rail detects a policy violation and stops, its processing log is now included in the aggregated result and the OutputRailFinished/InputRailFinished post-event is correctly omitted. This allows compute_generation_log() to create the required ActivatedRail entry with stop=True, enabling client code to identify which specific guardrail triggered and why.

How it works:

  • In runtime.py, when a parallel rail stops (detected via a "stop" BotIntent event), the code now captures that rail's processing log before canceling the task
  • The stopped rail's processing log is filtered (removing Listen and start_flow events) and merged into the main processing log
  • Post-events are now conditionally appended only when no stop event is present, preventing invalid event sequences
  • Five new test cases verify that stopped rails appear in activated_rails with stop=True, exactly one rail is marked as stopped per violation, and stopped/non-stopped rails are mutually exclusive

Potential Issues:

  1. Lines 446-453: The filtering logic that removes Listen and start_flow events from stopped task logs may be too aggressive—if these events contain critical context about why the rail stopped, discarding them could make debugging harder
  2. Lines 315-324: The stop detection relies on string matching event["intent"] == "stop" without validating the event structure; if the event dictionary is malformed (missing "intent" key), this will raise a KeyError
  3. Test coverage gap: The new tests only validate the Colang 1.0 runtime path but the fix is isolated to v1_0/runtime/runtime.py; if parallel rails exist in v2_0, they may still have the bug
  4. Line 389: The stopped_task_processing_log is captured after the task is canceled—there's a potential race condition where the processing log could be incomplete if the cancellation happens before all events are recorded

Confidence: 3/5 — The fix correctly addresses the stated problem and test coverage is good, but the event filtering logic and lack of error handling for malformed events introduce risk. Recommend adding validation for the event structure and clarifying whether Listen/start_flow events should really be discarded from stopped rails.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
nemoguardrails/colang/v1_0/runtime/runtime.py 62.50% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Pouyanpi Pouyanpi requested a review from Copilot October 22, 2025 08:50
@Pouyanpi Pouyanpi self-assigned this Oct 22, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where policy violations in parallel rails were not properly tracked. Specifically, when a rail stopped due to a policy violation, its processing log was excluded from aggregation, preventing the creation of an ActivatedRail entry for the stopped rail. Additionally, the OutputRailFinished/InputRailFinished events were incorrectly added even when a rail stopped.

Key Changes:

  • Modified the task_call_helper to check for stop events and conditionally add post_events
  • Added tracking of stopped rail processing logs to include them in the final aggregation
  • Added comprehensive test coverage for parallel rail stop behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/test_parallel_rails.py Adds four new test cases to verify stop flag behavior for input rails, output rails, client code patterns, and multiple activated rails
nemoguardrails/colang/v1_0/runtime/runtime.py Implements stop event detection, conditional post_event addition, and stopped rail processing log aggregation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Pouyanpi Pouyanpi force-pushed the fix/parallel-rails-stop-flag branch from 19a574f to c3594ae Compare October 22, 2025 08:52
@Pouyanpi Pouyanpi added this to the v0.18.0 milestone Oct 23, 2025
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