fix(ai): unchud model routing#4273
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR adopts a 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (2)
rust/cloud-storage/agent/src/model/types.rs (1)
26-26: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse a
charpattern to satisfy clippy.
split_once('/')avoids theclippy::single_char_patternlint, which is warn-by-default and may failjust clippyif warnings are denied.♻️ Proposed tweak
- .split_once("/") + .split_once('/')🤖 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 `@rust/cloud-storage/agent/src/model/types.rs` at line 26, The split_once method call is using a string pattern "/" instead of a character pattern, which triggers the clippy::single_char_pattern lint warning. Replace the string literal "/" with a character literal '/' in the split_once call to satisfy clippy and avoid potential lint failures.js/app/packages/core/component/AI/component/input/ChatInput.tsx (1)
58-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
createEffecthere triggers a state update rather than syncing an external system.This effect's sole job is to call
input.setModel(...)when the selected id is stale — i.e. it derives/repairs reactive state, which the SolidJS convention explicitly steers away from. Prefer wrapping the setter (validate-on-set) or exposing a derived "effective model" rather than reconciling via an effect.As per path instructions: "Avoid createEffect in SolidJs. Only use for syncing with external/imperative systems... Do not use to derive state or trigger updates—use a derived signal or wrap the setter instead".
🤖 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 `@js/app/packages/core/component/AI/component/input/ChatInput.tsx` around lines 58 - 65, The createEffect hook is being used to derive and update state (calling input.setModel) rather than syncing with an external system, which violates SolidJS conventions. Replace this effect by either wrapping the input.setModel setter function itself to validate that the model id exists in modelOptions before updating, or by creating a derived signal that computes the effective model (returning the current model if valid, or the first option if stale) and using that derived signal throughout the component instead of the raw model signal.Sources: Coding guidelines, Path instructions
🤖 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 `@js/app/scripts/generate-api-schema.ts`:
- Around line 49-52: The conditional block in buildOpenApiBinaries() that adds
the gen_tool_schemas binary to binArgs when document_cognition_service is
included is redundant because generate-dcs-tools.ts independently builds and
runs its own copy of this binary. Remove the entire if statement that checks if
crateNames.includes("document_cognition_service") and the subsequent
binArgs.push calls for the gen_tool_schemas binary, consolidating the build
responsibility entirely to generate-dcs-tools.ts.
In `@rust/cloud-storage/agent/src/model/router.rs`:
- Around line 337-348: The FinalResponse branch in the stream handling code is
emitting a duplicate StreamPart::Usage that is already being sent by
StreamBridge::on_stream_completion_response_finish, causing DCS consumers to
receive usage information twice. Remove the yield Ok(StreamPart::Usage(...))
call from this FinalResponse match arm while keeping the recorder.record() call
intact, since usage recording is still needed here even though the stream part
emission should happen only in the other path.
- Around line 258-260: The route_or_default method currently returns a routed
model but discards information about whether the default fallback was used,
causing callers to record and prompt with the requested model id even when the
default Anthropic model is actually being used. Modify the route_or_default
method to return the effective/actual model that will be used (indicating
whether the requested model was successfully routed or if the default was used
as a fallback), and ensure callers use this returned effective model id for
usage recording and per-session model prompts instead of the originally
requested id.
- Around line 41-45: The environment variable name in the ApiKeys struct field
creates a mismatch between code expectations and infrastructure provisioning.
The env_var! macro transforms OpenAiApiKey into OPEN_AI_API_KEY (with underscore
between OPEN and AI), but the Pulumi infrastructure provides openai_api_key
without the underscore. To fix this, either rename the OpenAiApiKey field in the
ApiKeys struct to OpenaiApiKey (which will transform to OPENAI_API_KEY matching
the infrastructure provisioning), or update the Pulumi configuration files to
provision the variable as open_ai_api_key instead. Ensure consistency so that
ModelRouter::shared() can successfully initialize ApiKeys::new() during startup.
In `@rust/cloud-storage/agent/src/model/types.rs`:
- Around line 4-18: Add documentation comments to all public items in the Model
struct to comply with the #![deny(missing_docs)] requirement. Add a doc comment
above the Model struct itself explaining its purpose, then add doc comments
above each of the public fields (provider and name) describing what they
represent, and finally add doc comments above each of the public accessor
methods (provider() and name()) explaining what they return. Ensure each doc
comment uses the standard Rust documentation format starting with three forward
slashes (///).
---
Nitpick comments:
In `@js/app/packages/core/component/AI/component/input/ChatInput.tsx`:
- Around line 58-65: The createEffect hook is being used to derive and update
state (calling input.setModel) rather than syncing with an external system,
which violates SolidJS conventions. Replace this effect by either wrapping the
input.setModel setter function itself to validate that the model id exists in
modelOptions before updating, or by creating a derived signal that computes the
effective model (returning the current model if valid, or the first option if
stale) and using that derived signal throughout the component instead of the raw
model signal.
In `@rust/cloud-storage/agent/src/model/types.rs`:
- Line 26: The split_once method call is using a string pattern "/" instead of a
character pattern, which triggers the clippy::single_char_pattern lint warning.
Replace the string literal "/" with a character literal '/' in the split_once
call to satisfy clippy and avoid potential lint failures.
🪄 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: CHILL
Plan: Pro
Run ID: 0e689060-3240-4faa-b0a5-5521e0ddcd9e
⛔ Files ignored due to path filters (7)
flake.lockis excluded by!**/*.lockjs/app/packages/service-clients/service-cognition/generated/client.tsis excluded by!**/generated/**js/app/packages/service-clients/service-cognition/generated/schemas/index.tsis excluded by!**/generated/**js/app/packages/service-clients/service-cognition/generated/schemas/model.tsis excluded by!**/generated/**js/app/packages/service-clients/service-cognition/generated/schemas/modelAccess.tsis excluded by!**/generated/**js/app/packages/service-clients/service-cognition/generated/schemas/modelsResponse.tsis excluded by!**/generated/**js/bun.lockis excluded by!**/*.lock,!**/bun.lock
📒 Files selected for processing (35)
js/app/packages/core/component/AI/component/debug/HttpStream.tsxjs/app/packages/core/component/AI/component/input/ChatInput.tsxjs/app/packages/core/component/AI/constant/model.tsjs/app/packages/queries/chat.tsjs/app/packages/service-clients/service-cognition/client.tsjs/app/packages/service-clients/service-cognition/openapi.jsonjs/app/scripts/generate-api-schema.tsjs/app/scripts/generate-dcs-models.tsjs/app/scripts/generate-dcs-types.tsrust/cloud-storage/agent/src/agent_loop.rsrust/cloud-storage/agent/src/completion.rsrust/cloud-storage/agent/src/error.rsrust/cloud-storage/agent/src/lib.rsrust/cloud-storage/agent/src/model/anthropic.rsrust/cloud-storage/agent/src/model/mod.rsrust/cloud-storage/agent/src/model/openai.rsrust/cloud-storage/agent/src/model/predefined_model.rsrust/cloud-storage/agent/src/model/router.rsrust/cloud-storage/agent/src/model/router/anthropic.rsrust/cloud-storage/agent/src/model/router/openai.rsrust/cloud-storage/agent/src/model/router/test.rsrust/cloud-storage/agent/src/model/test.rsrust/cloud-storage/agent/src/model/types.rsrust/cloud-storage/agent/src/provider_env.rsrust/cloud-storage/chat/src/domain/models/mod.rsrust/cloud-storage/chat/src/domain/models/model_access.rsrust/cloud-storage/chat/src/domain/ports/model_access.rsrust/cloud-storage/chat/src/domain/service/model_access.rsrust/cloud-storage/chat/src/domain/service/model_access/test.rsrust/cloud-storage/chat/src/inbound/http/mod.rsrust/cloud-storage/chat/src/inbound/http/models.rsrust/cloud-storage/document_cognition_service/Cargo.tomlrust/cloud-storage/document_cognition_service/src/api/chats/mod.rsrust/cloud-storage/document_cognition_service/src/api/swagger.rsrust/cloud-storage/document_cognition_service/src/models_bin.rs
💤 Files with no reviewable changes (16)
- rust/cloud-storage/agent/src/model/router/test.rs
- js/app/packages/queries/chat.ts
- js/app/scripts/generate-dcs-types.ts
- js/app/scripts/generate-dcs-models.ts
- rust/cloud-storage/agent/src/model/router/anthropic.rs
- rust/cloud-storage/chat/src/inbound/http/mod.rs
- rust/cloud-storage/document_cognition_service/Cargo.toml
- rust/cloud-storage/agent/src/model/router/openai.rs
- rust/cloud-storage/agent/src/provider_env.rs
- js/app/packages/service-clients/service-cognition/client.ts
- rust/cloud-storage/document_cognition_service/src/models_bin.rs
- rust/cloud-storage/chat/src/inbound/http/models.rs
- rust/cloud-storage/chat/src/domain/service/model_access/test.rs
- rust/cloud-storage/agent/src/model/test.rs
- js/app/packages/service-clients/service-cognition/openapi.json
- rust/cloud-storage/chat/src/domain/models/model_access.rs
37cdb95 to
8ebf130
Compare
8ebf130 to
21a3b97
Compare
No description provided.