OpenRouter provider swap before B.8#7
Merged
Conversation
Tasks: T2 T3 T4 T5 T6 T8 Issue: clarion-0009a39e0e
Tasks: T7 Issue: clarion-0009a39e0e
tachyon-beep
marked this pull request as ready for review
May 17, 2026 20:11
There was a problem hiding this comment.
Pull request overview
This PR swaps Clarion’s live LLM integration from the prior Anthropic-specific provider to an OpenRouter Chat Completions provider, while keeping the LlmProvider abstraction and recording-based test path intact.
Changes:
- Adds OpenRouter provider/config support, attribution headers, token-ceiling accounting, and recording fixture loading.
- Updates MCP summary/inferred-edge tests and Sprint 2 e2e coverage to exercise token usage and recording replay.
- Adds operator docs and amends ADR/design notes for the OpenRouter/token-ceiling model.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/clarion-core/src/llm_provider.rs |
Replaces Anthropic provider implementation with OpenRouter Chat Completions handling. |
crates/clarion-core/src/lib.rs |
Re-exports OpenRouter provider types. |
crates/clarion-mcp/src/config.rs |
Adds llm_policy/OpenRouter config parsing and provider selection. |
crates/clarion-mcp/src/lib.rs |
Switches MCP LLM budget handling from cost ceilings to token ceilings. |
crates/clarion-mcp/tests/storage_tools.rs |
Updates MCP tests for OpenRouter model IDs and token accounting. |
crates/clarion-cli/src/serve.rs |
Wires clarion serve to construct OpenRouter or recording providers. |
crates/clarion-cli/src/install.rs |
Updates generated clarion.yaml defaults for llm_policy. |
crates/clarion-cli/tests/serve.rs |
Updates cached summary fixture model ID expectations. |
tests/e2e/sprint_2_mcp_surface.sh |
Adds recording-backed summary() e2e coverage and token assertions. |
docs/README.md |
Links the new operator documentation area. |
docs/operator/README.md |
Adds operator notes index. |
docs/operator/openrouter.md |
Documents OpenRouter configuration and token-ceiling behavior. |
docs/implementation/sprint-2/openrouter-provider-swap.md |
Adds provider swap design memo. |
docs/clarion/adr/ADR-030-on-demand-summary-scope.md |
Amends ADR-030 for OpenRouter and token ceilings. |
docs/clarion/adr/ADR-007-summary-cache-key.md |
Clarifies OpenRouter concrete model IDs in the summary cache key. |
Comments suppressed due to low confidence (1)
crates/clarion-mcp/src/lib.rs:1074
- Provider errors are converted to a string plus retryable flag here, so OpenRouter status/code/metadata/retry-after fields captured in
LlmProviderError::Providerare dropped from the MCP summary response. This breaks the stated retryability/error-metadata preservation; include those fields in the error/diagnostic details instead of relying only onerr.to_string().
return tool_error_envelope(
"llm-provider-error",
&err.to_string(),
err.retryable(),
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
938
to
940
| let response = llm.provider.invoke(request).map_err(|err| { | ||
| InferredDispatchFailure::new("llm-provider-error", &err.to_string(), true) | ||
| InferredDispatchFailure::new("llm-provider-error", &err.to_string(), err.retryable()) | ||
| })?; |
Comment on lines
+412
to
+416
| fn retry_after_seconds(headers: &reqwest::header::HeaderMap) -> Option<u64> { | ||
| headers | ||
| .get(reqwest::header::RETRY_AFTER) | ||
| .and_then(|value| value.to_str().ok()) | ||
| .and_then(|value| value.parse::<u64>().ok()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
llm_policyContext
This is intentionally stacked on PR #6 /
sprint-2/b6-implso B.8 measures the provider Clarion v0.1 actually ships with.Verification
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo build --workspace --binscargo nextest run --workspace --all-features(281 passed)RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-featurescargo deny check(passes with existing duplicate/license warnings)plugins/python/.venv/bin/ruff check plugins/pythonplugins/python/.venv/bin/ruff format --check plugins/pythonplugins/python/.venv/bin/mypy --strict plugins/pythonplugins/python/.venv/bin/pytest plugins/python(117 passed)bash tests/e2e/sprint_1_walking_skeleton.shCARGO_BUILD=0 bash tests/e2e/sprint_2_mcp_surface.shNotes
No live OpenRouter calls are used in CI. The Sprint 2 MCP e2e now routes
summary()through aRecordingProviderfixture that replays an OpenRouter-shaped response and verifies token stats.