[CLI/Core] Polymorphic agent dispatch + TestRun owns trial counter#933
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthrough
ChangesDSE Agent Run Delegation and Failure Reporting
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/cloudai/configurator/base_agent.py`:
- Around line 143-145: The run() method checks if select_action() returns None
and uses this as a stop signal, but the abstract select_action() method's return
type annotation and documentation do not declare None as a valid return value.
Update the return type annotation of the select_action() method to include None
(e.g., change from tuple[int, dict[str, Any]] to tuple[int, dict[str, Any]] |
None), and update its docstring to document that returning None signals
termination of the agent loop. This aligns the method's declared contract with
how it is actually used in run().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: f47da465-3eed-4c1e-88f9-d4d27b909176
📒 Files selected for processing (7)
src/cloudai/_core/test_scenario.pysrc/cloudai/cli/handlers.pysrc/cloudai/configurator/base_agent.pysrc/cloudai/configurator/cloudai_gym.pytests/test_cloudaigym.pytests/test_handlers.pytests/test_test_scenario.py
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@podkidyshev — this PR supersedes the closed #893 (head branch was renamed, which auto-closed it). Carrying over your two review threads from there since GitHub stranded them on the closed PR: 1. 2. |
|
@podkidyshev — re: item 2 above (early This is resolved — handled as a hybrid policy in
Lives on #933 (agent-run-polymorphism), inherited up the stack; routing + the mixed-job guard are on #934. Covered by |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/cloudai/configurator/base_agent.py (1)
91-103: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winClarify step index semantics in the
select_action()docstring.The docstring describes the return as "The current step index" but doesn't specify whether it's 0-indexed or 1-indexed, or how it relates to the
test_run.stepcounter. Sinceselect_action()is abstract and defines a contract for implementers, the docstring should be precise.Based on the
run()usage (comparingsteptomax_steps, logging "Running step N (of max_steps)", and the fact thatCloudAIGymEnv.step()callsincrement_step()at the start), the step index should be 1-indexed and match the value thatTestRun.increment_step()will return.Consider updating the Returns section to:
Returns: Tuple[int, Dict[str, Any]] | None: The 1-indexed trial number (matching ``test_run.step`` after ``env.step()`` increments it) and a dictionary mapping action keys to selected values, or ``None`` to signal loop termination.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/cloudai/configurator/base_agent.py` around lines 91 - 103, The Returns section of the select_action() docstring uses vague language ("The current step index") without clarifying the indexing scheme or its relationship to TestRun.increment_step(). Update the Returns section to explicitly state that the returned step index is 1-indexed and matches the value of test_run.step after env.step() increments it, making the contract clear for implementers of this abstract method.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/cloudai/configurator/base_agent.py`:
- Around line 91-103: The Returns section of the select_action() docstring uses
vague language ("The current step index") without clarifying the indexing scheme
or its relationship to TestRun.increment_step(). Update the Returns section to
explicitly state that the returned step index is 1-indexed and matches the value
of test_run.step after env.step() increments it, making the contract clear for
implementers of this abstract method.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: fae375c0-dcee-49e0-95b7-5e6da91bd513
📒 Files selected for processing (1)
src/cloudai/configurator/base_agent.py
…ole mutator The trial index lives on TestRun and is advanced exactly once per CloudAIGymEnv.step(), before output_path and the trajectory row are computed. Step artifacts and trajectory rows are therefore tagged with the advanced index rather than the pre-step value.
handle_dse_job calls agent.run() uniformly; agents (e.g. RLlib-based) implement their own training loop in run(). Failure handling follows a hybrid contract: a non-zero rc accumulates via `err |= rc` and the sweep continues, while an unexpected exception hard-fails the scenario after reports are generated and the aborting error is documented.
run() already treats a None return from select_action() as a stop signal, but the abstract method declared only tuple[int, dict[str, Any]]. Widen the return annotation to tuple[int, dict[str, Any]] | None and document the termination semantics so the declared contract matches run()'s usage.
Convert the two f-string logging.info calls in the default run loop to %-style args so formatting is deferred when the log level is disabled (Ruff G004, CodeRabbit).
88d35c5 to
13355ba
Compare
Issue
TestRun.stephad multiple writers; RLlib's frequentreset()collapsed every trial ontostep=1, overwritingtrajectory.csv/env.csvrows.Fix
BaseAgent.run()is the single polymorphic entry point;handle_dse_jobis justerr |= agent.run()— agents implement their own training loop inrun().TestRun.increment_step()is the sole mutator, called only byCloudAIGymEnv.step()(advances beforeoutput_path/trajectory are computed).<scenario_root>/dse_failure.txt, then re-raised).Testing
pytest testsgreen; ruff + pyright + vulture clean.