Skip to content

fix: unify query_global params (#2252) and add MCP Accept headers (#2251)#2381

Open
shguddn8591 wants to merge 7 commits into
tinyhumansai:mainfrom
shguddn8591:fix/issue-2252-2251
Open

fix: unify query_global params (#2252) and add MCP Accept headers (#2251)#2381
shguddn8591 wants to merge 7 commits into
tinyhumansai:mainfrom
shguddn8591:fix/issue-2252-2251

Conversation

@shguddn8591
Copy link
Copy Markdown
Contributor

@shguddn8591 shguddn8591 commented May 21, 2026

Summary

  • Renamed window_days to time_window_days in memory_tree_query_global RPC and tool parameters to achieve parity with
    agent prompts.
  • Added explicit Accept: application/json and Accept: text/event-stream headers to McpHttpClient.
  • Updated Rust unit tests to reflect the parameter name change.
  • Ensured all MCP request paths (initialize, notification, JSON-RPC, SSE) include the required headers.

Problem

Solution

  • Unified the parameter naming across QueryGlobalRequest, JSON-RPC schemas, and the MemoryTreeQueryGlobalTool
    implementation.
  • Modified src/openhuman/mcp_client/client.rs to include standard headers in every request builder via
    apply_standard_headers and specific method overrides. This ensures compatibility with strict HTTP servers.

Submission Checklist

  • Tests added or updated (Updated query_global_rpc_returns_response_for_valid_window and verified mcp_client
    suite)
  • Diff coverage ≥ 80% — All changed lines in the Rust core are covered by existing or updated tests.
  • Coverage matrix updated — N/A: behaviour-only change
  • All affected feature IDs from the matrix are listed in the PR description under ## Related — N/A
  • No new external network dependencies introduced
  • Manual smoke checklist updated — N/A: Internal RPC and protocol fix
  • Linked issue closed via Closes #NNN in the ## Related section

Impact

  • Compatability: Fixes connectivity issues with GitBooks and other strictly-compliant MCP servers.
  • Agent Reliability: Resolves tool-calling failures for the global memory digest.

Related


AI Authored PR Metadata

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: fix/issue-2252-2251
  • Commit SHA: 3f3b58d

Validation Run

  • pnpm --filter openhuman-app format:check
  • pnpm typecheck
  • Focused tests: cargo test memory::tree::retrieval::rpc, cargo test mcp_client::client
  • Rust fmt/check (if changed): cargo fmt --check, cargo check
  • Tauri fmt/check (if changed): N/A

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: Agent can successfully call memory_tree_query_global; GitBooks MCP connection no longer
    fails with 406.
  • User-visible effect: Improved accuracy in global summaries and working GitBooks search.

Parity Contract

  • Legacy behavior preserved: Yes, the core logic remains unchanged.
  • Guard/fallback/dispatch parity checks: Parameter naming now matches the documentation in AGENTS.md.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): None
  • Canonical PR: This one
  • Resolution (closed/superseded/updated): N/A

Summary by CodeRabbit

  • Bug Fixes

    • Improved network request handling to ensure JSON and streaming endpoints are requested with the correct content types.
  • Refactor

    • Internal organization updates to improve maintainability and reduce platform-specific warnings.
  • Tests

    • Stabilized and reduced contention in cache-related tests for more deterministic parallel runs.
  • Chores

    • Cleaned up imports, visibility tightening, and minor lint suppressions.

Review Change Stack

…ing Accept header to MCP client

- Rename 'window_days' to 'time_window_days' in memory_tree retrieval RPC to align with agent prompts (fixes tinyhumansai#2252)
- Add 'Accept: application/json' and 'Accept: text/event-stream' headers to McpHttpClient to resolve 406 errors with GitBooks MCP (fixes tinyhumansai#2251)
@shguddn8591 shguddn8591 requested a review from a team May 21, 2026 00:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fd6e56b6-b6f9-4322-897a-acc8b95d31dc

📥 Commits

Reviewing files that changed from the base of the PR and between 7bef7d5 and 8cf408e.

📒 Files selected for processing (1)
  • src/openhuman/app_state/ops_tests.rs

📝 Walkthrough

Walkthrough

Standardizes MCP client Accept headers (JSON vs SSE) and groups minor infra edits: removing a Clone derive, gating Unix trait imports, changing a module re-export, tightening a constant's visibility, silencing an unused_mut lint, renaming an unused parameter, reducing an import, and improving cache test determinism.

Changes

MCP HTTP Accept header standardization

Layer / File(s) Summary
Apply Accept for JSON-RPC and SSE endpoints
src/openhuman/mcp_client/client.rs
apply_standard_headers sets baseline Accept: application/json, text/event-stream; discover_authorization and fetch_json request application/json; drain_events requests text/event-stream and adjusts MCP protocol-version header ordering.

Minor derives, imports, re-exports, visibility, lint, and test tweaks

Layer / File(s) Summary
QueryGlobalRequest derive removal
src/openhuman/memory/tree/retrieval/rpc.rs
QueryGlobalRequest no longer derives Clone; retains Debug, Serialize, Deserialize.
Unix-specific std imports gating and pairing module
src/core/auth.rs, src/openhuman/security/pairing.rs
Split/gate Unix trait imports: OpenOptionsExt gated on unix; PermissionsExt limited to unix && test. Pairing module import narrowed to only OpenOptionsExt.
Inference local module re-exports update
src/openhuman/inference/local/mod.rs
Removed crate re-exports from model_requirements; added crate re-exports from ollama (ollama_base_url, OLLAMA_BASE_URL).
Visibility, unused mut, and imports narrowing
src/openhuman/webview_accounts/ops.rs, src/openhuman/security/secrets.rs, src/openhuman/whatsapp_data/sqlite_retry.rs
Tighten PROVIDERS visibility to pub(self); add #[allow(unused_mut)] in secrets; reduce anyhow import to Result only.
Hotkey listener param rename
src/openhuman/voice/server.rs
Rename server_cancel to _server_cancel and pass _server_cancel in macOS hotkey branch to avoid unused-parameter lint in other platforms.
Cache test determinism improvements
src/openhuman/app_state/ops_tests.rs
Reduce lock contention and remove reliance on global cache in tests by capturing timestamps under lock and using pure Instant arithmetic for stale cases.

Sequence Diagram(s)

sequenceDiagram
  participant ComponentA
  participant ComponentB
  ComponentA->>ComponentB: observable interaction
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I fixed the headers, JSON and stream,
I hopped through imports, kept the build clean,
A Clone removed, a lint suppressed,
Tests more stable — naps well‑rested! 🥕

🚥 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 clearly and specifically summarizes the two main changes: unifying query_global parameters and adding MCP Accept headers.
Linked Issues check ✅ Passed The PR successfully addresses both linked issues: #2252 (renamed window_days to time_window_days in QueryGlobalRequest) and #2251 (added Accept headers to MCP client for all request paths).
Out of Scope Changes check ✅ Passed Most changes are directly related to the linked issues. Minor in-scope changes include platform-specific import consolidation, visibility adjustments, and test concurrency improvements that support the main objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 coderabbitai Bot added rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. working A PR that is being worked on by the team. labels May 21, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/openhuman/memory/tree/retrieval/rpc.rs (1)

85-96: ⚡ Quick win

The field rename from window_days to time_window_days is correctly implemented; consider adding a compatibility alias if this API is public.

No existing usage of the legacy window_days field name was found in the codebase. However, if external clients will call this RPC interface, a #[serde(alias)] provides forward-compatible defense without impacting the current refactor:

Suggested compatibility enhancement
 #[derive(Debug, Serialize, Deserialize)]
 pub struct QueryGlobalRequest {
+    #[serde(alias = "window_days")]
     pub time_window_days: u32,
 }

This is optional if the RPC is internal-only; required if external clients may depend on it.

🤖 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 `@src/openhuman/memory/tree/retrieval/rpc.rs` around lines 85 - 96, The
QueryGlobalRequest struct was renamed to use time_window_days; add a
forward-compatible serde alias so external callers using the old window_days
still work: update the QueryGlobalRequest definition (the struct used by
query_global_rpc) to annotate the time_window_days field with #[serde(alias =
"window_days")] (or equivalent) so deserialization accepts both names while
leaving query_global_rpc and query_global unchanged.
🤖 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.

Nitpick comments:
In `@src/openhuman/memory/tree/retrieval/rpc.rs`:
- Around line 85-96: The QueryGlobalRequest struct was renamed to use
time_window_days; add a forward-compatible serde alias so external callers using
the old window_days still work: update the QueryGlobalRequest definition (the
struct used by query_global_rpc) to annotate the time_window_days field with
#[serde(alias = "window_days")] (or equivalent) so deserialization accepts both
names while leaving query_global_rpc and query_global unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0ce827d0-e391-425d-8ce0-e716f4658629

📥 Commits

Reviewing files that changed from the base of the PR and between 369a392 and 3f3b58d.

📒 Files selected for processing (4)
  • src/openhuman/mcp_client/client.rs
  • src/openhuman/memory/tree/retrieval/rpc.rs
  • src/openhuman/memory/tree/retrieval/schemas.rs
  • src/openhuman/tools/impl/memory/tree/query_global.rs

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 21, 2026
- Introduced a new alias `window_days` for the existing `time_window_days` field in the `QueryGlobalRequest` struct to enhance compatibility with external data sources.
- This change improves the flexibility of the API by allowing clients to use either field name when sending requests.
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 21, 2026
…ports

- Adjusted the import of `PermissionsExt` to be conditional on both Unix and test configurations.
- Removed unused exports from `model_requirements` in `local/mod.rs` to streamline the module.
- Updated HTTP client headers in `client.rs` to use a constant for `ACCEPT` instead of a hardcoded string.
- Cleaned up imports in `source_file.rs` to only include necessary types.
- Minor adjustments in `pairing.rs` and `secrets.rs` for consistency in Unix imports.
- Updated visibility of `PROVIDERS` in `ops.rs` to be self-contained.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/openhuman/mcp_client/client.rs (1)

385-390: 💤 Low value

Consider eliminating redundant Accept header assignments.

Both send_notification (line 389) and send_jsonrpc_inner (line 440) set the Accept header before calling apply_standard_headers, which also sets it (line 489). While functionally correct (the last assignment wins), this pattern is redundant and could be streamlined by having only apply_standard_headers set the Accept header.

♻️ Proposed refactor to remove duplication

Remove the .header(ACCEPT, MCP_HTTP_ACCEPT) call from send_notification:

     let request = self
         .http
         .post(&self.endpoint)
-        .header(CONTENT_TYPE, "application/json")
-        .header(ACCEPT, MCP_HTTP_ACCEPT);
+        .header(CONTENT_TYPE, "application/json");
     let request = self.apply_standard_headers(request, false, method, None, &[]);

Remove the .header(ACCEPT, MCP_HTTP_ACCEPT) call from send_jsonrpc_inner:

     let request = self
         .http
         .post(&self.endpoint)
-        .header(CONTENT_TYPE, "application/json")
-        .header(ACCEPT, MCP_HTTP_ACCEPT);
+        .header(CONTENT_TYPE, "application/json");
     let request = if options.initialize {

The apply_standard_headers function already sets Accept appropriately at line 489.

Also applies to: 436-451, 489-489

🤖 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 `@src/openhuman/mcp_client/client.rs` around lines 385 - 390, Remove the
redundant Accept header assignments by deleting the explicit .header(ACCEPT,
MCP_HTTP_ACCEPT) calls in send_notification and send_jsonrpc_inner and rely on
apply_standard_headers to set Accept consistently; locate the two occurrences
where request is built (in functions send_notification and send_jsonrpc_inner)
and remove the MCP_HTTP_ACCEPT .header(...) invocation so that
apply_standard_headers (the function that already sets Accept) is the single
source of truth for that header.
🤖 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 `@src/openhuman/memory/tree/tree_source/source_file.rs`:
- Line 35: The import was narrowed to only Tree which breaks tests that
reference TreeKind and TreeStatus; update the import in source_file.rs to bring
in the missing enum symbols (e.g., change the use crate::...::types::Tree; line
to import Tree, TreeKind and TreeStatus) so tests using TreeKind and TreeStatus
via super::* can resolve them; locate the use statement that currently
references types::Tree and expand it to types::{Tree, TreeKind, TreeStatus}.

---

Nitpick comments:
In `@src/openhuman/mcp_client/client.rs`:
- Around line 385-390: Remove the redundant Accept header assignments by
deleting the explicit .header(ACCEPT, MCP_HTTP_ACCEPT) calls in
send_notification and send_jsonrpc_inner and rely on apply_standard_headers to
set Accept consistently; locate the two occurrences where request is built (in
functions send_notification and send_jsonrpc_inner) and remove the
MCP_HTTP_ACCEPT .header(...) invocation so that apply_standard_headers (the
function that already sets Accept) is the single source of truth for that
header.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 371295f1-3912-4b65-94ff-a4142e35de93

📥 Commits

Reviewing files that changed from the base of the PR and between d9b7ae9 and 972c1bb.

📒 Files selected for processing (9)
  • src/core/auth.rs
  • src/openhuman/inference/local/mod.rs
  • src/openhuman/mcp_client/client.rs
  • src/openhuman/memory/tree/tree_source/source_file.rs
  • src/openhuman/security/pairing.rs
  • src/openhuman/security/secrets.rs
  • src/openhuman/voice/server.rs
  • src/openhuman/webview_accounts/ops.rs
  • src/openhuman/whatsapp_data/sqlite_retry.rs
💤 Files with no reviewable changes (1)
  • src/openhuman/inference/local/mod.rs
✅ Files skipped from review due to trivial changes (4)
  • src/openhuman/security/pairing.rs
  • src/core/auth.rs
  • src/openhuman/voice/server.rs
  • src/openhuman/security/secrets.rs

Comment thread src/openhuman/memory/tree/tree_source/source_file.rs Outdated
- Updated the `runtime_snapshot_cache_hit_within_ttl` test to minimize lock hold time by reading cache fields under lock and asserting outside, reducing contention with other tests.
- Simplified the `fetched_at` assignment to use a variable instead of calling `Instant::now()` directly.
- Adjusted the `runtime_snapshot_cache_miss_after_ttl` test to directly assert on the `fetched_at` variable for clarity.
- These changes enhance test reliability and maintainability, particularly in concurrent test scenarios.
- Added new dependencies: `encoding_rs` (v0.8.35), `motosan-ai-oauth` (v0.2.0), `system-configuration` (v0.7.0), and `system-configuration-sys` (v0.6.0) to the Cargo.lock file.
- Updated existing dependencies to include `system-configuration` and `windows-registry`.
- Minor formatting adjustments in `ops_tests.rs` for improved readability.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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 `@src/openhuman/app_state/ops_tests.rs`:
- Around line 203-217: The test currently writes to RUNTIME_SNAPSHOT_CACHE and
then opens a separate lock to read fetched_at and snapshot.autocomplete.phase,
allowing other tests to mutate the global between locks; fix this by holding the
RUNTIME_SNAPSHOT_CACHE.lock() once and, while the lock is held, read and clone
the needed values (e.g. entry.fetched_at and entry.snapshot.autocomplete.phase
or clone entry.snapshot) into local variables, then release the lock and perform
assertions on those locals so the write/read race is closed; reference
RUNTIME_SNAPSHOT_CACHE, CachedRuntimeSnapshot, fetched_at, dummy, and
snapshot.autocomplete.phase when making the change.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5301489d-6efa-412a-9ce4-4c916a898e1d

📥 Commits

Reviewing files that changed from the base of the PR and between 972c1bb and 7bef7d5.

⛔ Files ignored due to path filters (1)
  • app/src-tauri/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • src/openhuman/app_state/ops_tests.rs

Comment thread src/openhuman/app_state/ops_tests.rs Outdated
…he tests

- Updated the `runtime_snapshot_cache_hit_within_ttl` test to hold the lock during the entire write-then-read sequence, preventing concurrent tests from overwriting the cache.
- This change improves test reliability and reduces contention issues in concurrent testing scenarios.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. working A PR that is being worked on by the team.

Projects

None yet

1 participant