Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
ScenarioBuilder class to OO-SDKScenarioBuilder class to OO-SDK
Sequence DiagramThis PR adds a new fluent builder flow for creating scenarios from the OO SDK. Users can now start from sequenceDiagram
participant User
participant ScenarioOps
participant ScenarioBuilder
participant ScenariosAPI
participant Scenario
User->>ScenarioOps: builder scenario name
ScenarioOps-->>User: ScenarioBuilder instance
User->>ScenarioBuilder: Configure problem environment and scorers
User->>ScenarioBuilder: push
ScenarioBuilder->>ScenariosAPI: Create scenario with built params
ScenariosAPI-->>ScenarioBuilder: Created scenario id
ScenarioBuilder-->>User: Scenario object from id
Generated by CodeAnt AI |
Nitpicks 🔍
|
src/sdk/scenario-builder.ts
Outdated
| if (weight <= 0) { | ||
| throw new Error(`Scorer weight must be positive, got ${weight}`); |
There was a problem hiding this comment.
Suggestion: addScorer only checks weight <= 0, which allows non-finite values like NaN and Infinity. Those values pass the check but break normalization in build() (s.weight / totalWeight), producing invalid weights (NaN) that will cause malformed scoring payloads and API failures. Validate that weight is finite before accepting it. [logic error]
Severity Level: Major ⚠️
- ❌ Scenario creation payload can contain null scorer weights.
- ⚠️ `runloop.scenario.builder(...).push()` may fail API validation.| if (weight <= 0) { | |
| throw new Error(`Scorer weight must be positive, got ${weight}`); | |
| if (!Number.isFinite(weight) || weight <= 0) { | |
| throw new Error(`Scorer weight must be a finite positive number, got ${weight}`); |
Steps of Reproduction ✅
1. Use the public OO-SDK entrypoint `ScenarioOps.builder()` at `src/sdk.ts:1988-1990` to
create a `ScenarioBuilder` instance (normal scenario creation flow exposed to users).
2. Add a scorer with a non-finite computed weight (for example `1/0` or `0/0`) through
`addTestCommandScorer()` at `src/sdk/scenario-builder.ts:156-170`, which forwards to
`addScorer()` at `src/sdk/scenario-builder.ts:437-442`.
3. In `addScorer()` (`src/sdk/scenario-builder.ts:438`), `if (weight <= 0)` does not
reject `NaN`/`Infinity`, so invalid weight is stored in `_scorers`.
4. Call `push()` (`src/sdk/scenario-builder.ts:431-434`) or `build()` (`:366-408`):
normalization computes `weight: s.weight / totalWeight` (`:378-382`), then request
serialization in `src/core.ts:335` uses `JSON.stringify`, which serializes non-finite
numbers to `null`, producing invalid scorer weights in `/v1/scenarios` create payload
(`src/resources/scenarios/scenarios.ts:37-39`).Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** src/sdk/scenario-builder.ts
**Line:** 438:439
**Comment:**
*Logic Error: `addScorer` only checks `weight <= 0`, which allows non-finite values like `NaN` and `Infinity`. Those values pass the check but break normalization in `build()` (`s.weight / totalWeight`), producing invalid weights (`NaN`) that will cause malformed scoring payloads and API failures. Validate that weight is finite before accepting it.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.|
CodeAnt AI finished reviewing your PR. |
❌ Object Smoke Tests FailedTest Results❌ Some smoke tests failed Failed Tests:
Please fix the failing tests before checking coverage. |
a4e4e2f to
e6202b8
Compare
CodeAnt-AI Description
Add a fluent ScenarioBuilder to construct and push scenarios from the SDK
What Changed
Impact
✅ Shorter scenario setup code✅ Clearer validation errors when required fields are missing✅ Fewer manual API calls to assemble and create scenarios💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.