openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

[codex] Record channel response model metadata

Open ron-liu opened this issue 5 months ago • 1 comments

Summary

  • add provider/model fields to ChannelMessageProcessed events
  • propagate the selected route metadata from channel dispatch into processed events
  • persist assistant channel turns with modelProvider and model metadata so Telegram replies can be audited later

Why

When OpenHuman is configured with advanced routing, users need a way to verify which provider/model answered a given channel message. The processed channel event already sits at the point where the selected route is known, so this stores that metadata with the conversation turn.

Validation

  • cargo fmt
  • git diff --check
  • CARGO_TARGET_DIR=/private/tmp/openhuman/target cargo test -q openhuman::channels::providers::telegram::bus_tests
  • CARGO_TARGET_DIR=/private/tmp/openhuman/target cargo test -q memory_conversations::bus::tests::persists_inbound_and_processed_turns_into_workspace_thread

Note: a first test attempt without the shared target directory failed because this environment lacks cmake for rebuilding whisper-rs-sys; rerunning against the existing OpenHuman target directory completed successfully.

Summary by CodeRabbit

New Features

  • Channel message processing events now include the resolved AI provider and model.
  • Conversation persistence records this provider/model metadata for each processed message.
  • Inference routing and agent turn responses now track and propagate the resolved provider/model throughout the dispatch flow.

Tests

  • Updated fixtures and stubs to use the new response/event fields.
  • Added coverage to verify events are published with the correct resolved provider/model and that routing metadata is recorded end-to-end.

ron-liu avatar Jun 15 '26 08:06 ron-liu

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements end-to-end tracking of which LLM provider and model are resolved during agent execution and inference routing. It introduces task-local storage for recording the resolved provider/model, extends AgentTurnResponse to carry resolved metadata, records routes through the router and provider hierarchy, updates ChannelMessageProcessed events with provider/model fields, and persists them in conversation turn metadata.

Changes

Resolved Provider/Model Tracking

Layer / File(s) Summary
Task-local resolved provider route infrastructure
src/openhuman/inference/provider/resolved_route.rs, src/openhuman/inference/provider/mod.rs
Introduces ResolvedProviderRoute struct and Tokio task_local! storage for per-task resolved provider/model metadata. Provides with_resolved_provider_route_scope to initialize context, record_resolved_provider_route to store values, and current_resolved_provider_route to retrieve them. Exposed via public submodule with test coverage.
Agent turn response structure with resolved provider/model metadata
src/openhuman/agent/bus.rs
AgentTurnResponse gains optional resolved_provider and resolved_model fields. New constructors ::new(text) and ::with_resolved_route(...) encapsulate response building. The agent.run_turn handler wraps execution in with_resolved_provider_route_scope, retrieves the resolved route after execution, and conditionally constructs the response with metadata.
ChannelMessageProcessed event schema with provider and model fields
src/core/event_bus/events.rs, src/core/event_bus/events_tests.rs
DomainEvent::ChannelMessageProcessed gains provider: String and model: String fields to capture which LLM provider/model handled the message. Domain-correctness test updated to supply matching test values.
Processor preserves and extracts provider/model from agent response
src/openhuman/channels/runtime/dispatch/processor.rs
process_channel_message preserves the full AgentTurnResponse object to access resolved metadata. Extracted response_text and provider/model (with fallback to route values) are carried through history writes, user replies, and event emission. On errors/timeouts, provider/model derive from the selected route.
Router, reliable provider, and intelligent routing record resolved provider
src/openhuman/inference/provider/router.rs, src/openhuman/inference/provider/reliable.rs, src/openhuman/routing/provider.rs
Router, ReliableProvider, and IntelligentRoutingProvider all call record_resolved_provider_route before dispatching inference. Router records in all four chat methods. ReliableProvider records per-attempt in retry loops. IntelligentRoutingProvider records both primary selection and local-to-remote fallback paths.
Memory conversation persistence stores provider/model in turn metadata
src/openhuman/memory_conversations/bus.rs
ChannelTurnDescriptor gains optional model_provider and model fields. ChannelMessageProcessed events populate them with actual values; ChannelMessageReceived events set them to None. persist_channel_turn writes modelProvider and model into persisted message extra_metadata. Tests verify correct persistence and drop behavior.
Test updates: AgentTurnResponse constructors and event fields
src/core/event_bus/native_request.rs, src/openhuman/agent/triage/evaluator_tests.rs, src/openhuman/channels/runtime/test_support.rs, src/openhuman/channels/tests/*.rs, src/openhuman/channels/providers/telegram/bus_tests.rs
Comprehensive updates to use AgentTurnResponse::new(...) constructor instead of struct literals. Telegram bus tests add provider and model to event fixtures. Doc examples and test stubs updated across Discord, Telegram, and runtime dispatch tests.
Integration tests verify resolved provider route recording
src/openhuman/channels/tests/runtime_dispatch.rs, src/openhuman/inference/provider/router_tests.rs, src/openhuman/inference/provider/reliable_tests.rs, src/openhuman/routing/provider_tests.rs
Four new integration tests verify end-to-end resolved provider recording: channel message processed event carries resolved metadata, router records hint-resolved routes, reliable provider records fallback routes, and intelligent routing records lightweight task routes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

feature, rust-core, agent, memory

Suggested reviewers

  • sanil-23

Poem

🐇 Through task-locals, the provider hops, Recording routes where inference stops. The agent wraps with scope so bright, Each model choice now tracked just right. Persisted metadata tells the tale— Which provider answered without fail! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] Record channel response model metadata' clearly and concisely describes the main objective of the changeset: adding provider and model metadata tracking to channel message processed events.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Jun 15 '26 08:06 coderabbitai[bot]

I addressed the remaining CodeRabbit threads plus the Rust Core Coverage compile failure in a helper PR because direct push to the head fork returned 403: https://github.com/ron-liu/openhuman/pull/1

What changed:

  • moved src/openhuman/inference/provider/resolved_route.rs to src/openhuman/inference/provider/resolved_route/mod.rs
  • bounded the ChannelMessageProcessed event-consumption loop in untime_dispatch.rs so the test fails fast if the expected message is not observed
  • fixed the Rust Core Coverage compile failure by replacing the three stale direct AgentTurnResponse { ... } initializers in ests/inference_agent_raw_coverage_e2e.rs with AgentTurnResponse::new(...)

Validation:

  • cargo fmt --manifest-path Cargo.toml --check

I also tried cargo test --manifest-path Cargo.toml --lib resolved_provider_route_scopes_and_clears locally, but on this Windows environment it stayed in heavy Rust compilation and timed out after 5 minutes without diagnostics. The failing CI log was clear, though: it reported three E0063 errors for missing esolved_provider / esolved_model fields in ests/inference_agent_raw_coverage_e2e.rs, and the helper PR fixes those exact three sites.

Felyx-Fu avatar Jun 17 '26 11:06 Felyx-Fu