Skip to content

OpenRouter provider swap before B.8#7

Merged
tachyon-beep merged 3 commits into
sprint-2/b6-implfrom
sprint-2/openrouter-swap
May 17, 2026
Merged

OpenRouter provider swap before B.8#7
tachyon-beep merged 3 commits into
sprint-2/b6-implfrom
sprint-2/openrouter-swap

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

Summary

  • replace the live Anthropic provider implementation with an OpenRouter Chat Completions provider
  • switch the MCP LLM session gate from dollar estimates to token ceilings and preserve OpenRouter retryability/error metadata
  • update config parsing, install defaults, RecordingProvider replay fixtures, ADR notes, and operator docs for llm_policy

Context

This is intentionally stacked on PR #6 / sprint-2/b6-impl so B.8 measures the provider Clarion v0.1 actually ships with.

Verification

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo build --workspace --bins
  • cargo nextest run --workspace --all-features (281 passed)
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features
  • cargo deny check (passes with existing duplicate/license warnings)
  • plugins/python/.venv/bin/ruff check plugins/python
  • plugins/python/.venv/bin/ruff format --check plugins/python
  • plugins/python/.venv/bin/mypy --strict plugins/python
  • plugins/python/.venv/bin/pytest plugins/python (117 passed)
  • bash tests/e2e/sprint_1_walking_skeleton.sh
  • CARGO_BUILD=0 bash tests/e2e/sprint_2_mcp_surface.sh

Notes

No live OpenRouter calls are used in CI. The Sprint 2 MCP e2e now routes summary() through a RecordingProvider fixture that replays an OpenRouter-shaped response and verifies token stats.

@tachyon-beep
tachyon-beep marked this pull request as ready for review May 17, 2026 20:11
Copilot AI review requested due to automatic review settings May 17, 2026 20:11
@tachyon-beep
tachyon-beep merged commit 35be4db into sprint-2/b6-impl May 17, 2026
3 checks passed
@tachyon-beep
tachyon-beep deleted the sprint-2/openrouter-swap branch May 17, 2026 20:11

Copilot AI left a comment

Copy link
Copy Markdown

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 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::Provider are 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 on err.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())
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