Skip to content

fix(embeddings): read managed session token from config-scoped store - #5363

Merged
senamakel merged 3 commits into
tinyhumansai:mainfrom
YellowSnnowmann:fix/5356-embeddings-managed-session-dir
Aug 4, 2026
Merged

fix(embeddings): read managed session token from config-scoped store#5363
senamakel merged 3 commits into
tinyhumansai:mainfrom
YellowSnnowmann:fix/5356-embeddings-managed-session-dir

Conversation

@YellowSnnowmann

@YellowSnnowmann YellowSnnowmann commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Managed (OpenHuman) embeddings Test connection no longer shows a sign-in error when the user is already signed in with Google.
  • The managed/cloud embedder now resolves the app-session bearer token from the same config-scoped credential store that sign-in writes to, instead of a hardcoded root path.

Problem

  • On a shipped desktop, clicking Test connection for Managed embeddings after a successful Google sign-in returned No backend session for cloud embeddings: log in to OpenHuman, even with a valid active session (Google sign-in succeeds but connection test in Embeddings tab still shows sign-in error #5356).
  • Root cause: the managed/cloud provider was built with a hardcoded OpenHumanCloudEmbedding::new(None, None, true, …). Its bearer resolver therefore read ~/.openhuman/auth-profiles.json (root, via default_state_dir()), but sign-in stores the app-session token under the user-scoped ~/.openhuman/users/<uid>/auth-profiles.json (via AuthService::from_config). With OPENHUMAN_WORKSPACE unset in the shipped app, the two directories never coincide, so the token was never found.
  • test_connection, live embed, and provider_from_config were all affected. The memory-tree path (build_cloud_embedder) already passed the config-derived values and was unaffected — which is why memory ingest/recall worked while the Embeddings-tab test did not.

Solution

  • Add create_embedding_provider_with_config(config, …) in src/openhuman/inference/embeddings/factory.rs. For managed/cloud it threads config.config_path.parent() + config.secrets.encrypt (mirroring AuthService::from_config and the existing memory-tree build_cloud_embedder); every other provider delegates to create_embedding_provider_with_credentials unchanged.
  • Route the three managed RPC paths — test_connection, live embed, and provider_from_config/build_embedder — through it.
  • Extract managed_credential_scope(config) as a pure fn so the (dir, encrypt) invariant is unit-testable without a network round-trip.
  • Frontend intentionally untouched: it faithfully mirrors the core session (isLocalSession correctly reflects a remote session) and clears the banner/error once the backend returns success.

Submission Checklist

  • Tests added or updated (happy path + failure/edge) — 7 new: managed builds with the config scope, round-trip resolution of a sign-in-stored token, managed test_connection/embed with no session report the backend-session error, non-managed delegation, and unknown-provider error.
  • Diff coverage ≥ 80% — every changed line is exercised by the 7 added tests; verified via targeted cargo test --lib inference::embeddings (68/68 pass). Full diff-cover runs in CI-Lite.
  • N/A: behaviour/bugfix only — no feature row added/removed/renamed in docs/TEST-COVERAGE-MATRIX.md.
  • N/A: no coverage-matrix feature IDs affected.
  • No new external network dependencies — the added tests short-circuit before any HTTP call (missing bearer) or only construct providers.
  • N/A: no release-cut surface added; manual smoke unchanged.
  • Linked issue closed via Closes #5356 in ## Related.

Impact

  • Desktop: fixes Managed embeddings Test connection (and live managed embed) for signed-in users. Memory ingest/recall was already correct and is unchanged.
  • Security: reads the credential store using the same (dir, encrypt) scope sign-in uses; no new secret exposure and no secrets logged (the added debug line logs only the directory + encrypt flag). Non-managed providers are byte-for-byte unchanged.
  • No migration; no performance impact (per-call construction unchanged).

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A — human-authored PR.
  • URL: N/A

Commit & Branch

  • Branch: N/A — human-authored PR.
  • Commit SHA: N/A

Validation Run

  • N/A — human-authored PR.

Validation Blocked

  • N/A — human-authored PR.

Behavior Changes

  • N/A — human-authored PR.

Parity Contract

  • N/A — human-authored PR.

Duplicate / Superseded PR Handling

  • N/A — human-authored PR.

Summary by CodeRabbit

  • New Features
    • Embedding providers can now be configured using application settings, including managed and cloud providers.
    • Credential handling automatically respects the configured environment and securely recovers saved tokens.
    • Cloud providers can be configured and validated without a network request.
  • Bug Fixes
    • Improved credential recovery for embedding and connection testing.
    • Added clearer errors when required managed-provider sessions are unavailable.
    • Improved embedding and connection setup across supported provider types.

The managed/cloud embedder was constructed with a hardcoded
(None state_dir, encrypt=true), so its bearer resolver read the root
~/.openhuman/auth-profiles.json via default_state_dir() instead of the
user-scoped ~/.openhuman/users/<uid>/ where sign-in stores the
app-session token. On a shipped desktop (OPENHUMAN_WORKSPACE unset) this
made the Embeddings-tab "Test connection" report "No backend session"
for an already signed-in user.

Add create_embedding_provider_with_config(config, ...) that threads
config.config_path.parent() + config.secrets.encrypt for managed/cloud
(mirroring AuthService::from_config and the memory-tree
build_cloud_embedder) and delegates every other provider unchanged. The
managed RPC paths (test_connection, embed, provider_from_config) now
route through it.

Closes tinyhumansai#5356
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 5f843efd-8c7e-44a3-84f1-5064cea1b66e

📥 Commits

Reviewing files that changed from the base of the PR and between 8d238d7 and 4a3c412.

📒 Files selected for processing (1)
  • src/openhuman/inference/embeddings/factory.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openhuman/inference/embeddings/factory.rs

📝 Walkthrough

Walkthrough

The change adds configuration-aware embedding-provider construction. Managed and cloud providers use configured credential scope and encryption settings. Embedding RPC operations now use this factory, with tests covering session recovery, provider creation, delegation, and error handling.

Changes

Embedding provider configuration

Layer / File(s) Summary
Config-aware provider factory implementation
src/openhuman/inference/embeddings/factory.rs
Adds path and config imports. Implements credential-scope derivation from configuration for managed and cloud providers. Delegates other providers to existing credentialed construction.
Factory tests and validation
src/openhuman/inference/embeddings/factory.rs
Tests verify configuration-derived credential scope, encryption handling, sign-in token recovery, managed and cloud provider construction, delegation behavior, and end-to-end authentication against a mock backend.
RPC factory integration
src/openhuman/inference/embeddings/mod.rs, src/openhuman/inference/embeddings/rpc.rs
Exports the config-aware factory. Uses it for embedding operations, connection testing, and shared provider construction. Imports credential factory in test module for custom-endpoint regression tests.
Managed-provider RPC validation
src/openhuman/inference/embeddings/rpc.rs
Adds tests verifying missing backend-session error handling in connection testing and embedding, and config-only managed-provider construction.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EmbeddingsRPC
  participant ConfigAwareFactory
  participant CredentialStore
  participant ManagedProvider
  EmbeddingsRPC->>ConfigAwareFactory: construct provider with Config
  ConfigAwareFactory->>CredentialStore: resolve configured credential scope
  CredentialStore-->>ConfigAwareFactory: return app-session token
  ConfigAwareFactory->>ManagedProvider: create managed or cloud provider
  ManagedProvider-->>EmbeddingsRPC: execute embed or connection test
Loading

Possibly related PRs

Suggested labels: rust-core

Suggested reviewers: m3ga-mind

Poem

A rabbit checks the session store,
The right token opens every door.
Config guides the cloud and managed trail,
While embedding calls no longer fail.
Hop, hop—the providers flow!

🚥 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 describes the main change: reading the managed session token from the config-scoped credential store.
Linked Issues check ✅ Passed The changes use config-scoped session credentials for managed embedding checks and test token authentication, meeting issue #5356 objectives.
Out of Scope Changes check ✅ Passed The factory, exports, RPC updates, and regression tests directly support config-scoped managed embedding authentication.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

@YellowSnnowmann
YellowSnnowmann marked this pull request as ready for review August 4, 2026 09:01
@YellowSnnowmann
YellowSnnowmann requested a review from a team August 4, 2026 09:01
@coderabbitai coderabbitai Bot added bug rust-core Core Rust runtime in src/: CLI, core_server, shared infrastructure. labels Aug 4, 2026
@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a bug (#5356) where Test connection for managed/cloud embeddings returned a false "No backend session" error even when the user was already signed in. The root cause was that OpenHumanCloudEmbedding::new(None, None, true, …) hardcoded the credential store path to default_state_dir() (~/.openhuman root), while sign-in writes the app-session token to the config-scoped user directory (~/.openhuman/users/<uid>/auth-profiles.json).

  • Adds create_embedding_provider_with_config(config, …) in factory.rs, which for managed/cloud providers derives the credential scope via managed_credential_scope (delegating to state_dir_from_config — the same helper AuthService::from_config uses at sign-in); all other providers delegate unchanged to the existing credential factory.
  • Routes the three affected RPC paths (embed, test_connection, build_embedder) through the new config-aware factory, and exports it from mod.rs; seven new unit/integration tests cover the regression, round-trip resolution, and delegation to non-managed providers.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to routing three RPC construction calls through a new config-aware factory, backed by seven tests including a full network round-trip mock.

The fix is minimal and surgical: the new factory function only diverges from the old one for managed/cloud providers, delegating all other providers byte-for-byte to the existing path. The credential scope helper delegates to state_dir_from_config, the exact same helper AuthService::from_config uses at sign-in, so there is no chance of a new divergence. Tests cover the regression, token round-trip isolation, construction, delegation, and an end-to-end mock-server embedding call.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/openhuman/inference/embeddings/factory.rs Adds create_embedding_provider_with_config and private managed_credential_scope; for managed/cloud providers derives credential scope from config via state_dir_from_config (mirroring AuthService::from_config); seven new tests cover the regression, round-trip, and delegation paths.
src/openhuman/inference/embeddings/mod.rs Re-exports the new create_embedding_provider_with_config function; trivial change with no logic of its own.
src/openhuman/inference/embeddings/rpc.rs Routes embed, test_connection, and build_embedder through create_embedding_provider_with_config instead of create_embedding_provider_with_credentials; adds three new RPC-level tests for the managed path.

Sequence Diagram

sequenceDiagram
    participant UI as Frontend
    participant RPC as rpc.rs
    participant Factory as factory.rs
    participant Cloud as OpenHumanCloudEmbedding
    participant Store as auth-profiles.json

    UI->>RPC: test_connection / embed (managed)
    Note over RPC,Factory: BEFORE: hardcoded (None, None, true)
    RPC->>Cloud: new(None, None, true, model, dims)
    Cloud->>Store: reads root ~/.openhuman (wrong path)
    Store-->>Cloud: not found
    Cloud-->>RPC: No backend session
    Note over RPC,Factory: AFTER: create_embedding_provider_with_config
    RPC->>Factory: create_embedding_provider_with_config(config, managed)
    Factory->>Factory: "managed_credential_scope -> state_dir_from_config"
    Factory->>Cloud: new(None, Some(config_dir), encrypt, model, dims)
    Cloud->>Store: reads config-scoped dir (correct path)
    Store-->>Cloud: app-session token found
    Cloud-->>RPC: embed vectors
    RPC-->>UI: success
Loading

Reviews (3): Last reviewed commit: "test(embeddings): bind managed factory o..." | Re-trigger Greptile

Comment thread src/openhuman/inference/embeddings/factory.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4dad0c7c21

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/openhuman/inference/embeddings/factory.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/inference/embeddings/rpc.rs`:
- Around line 1495-1545: Update the managed regression tests around
test_connection_managed_without_session_reports_no_backend_session,
embed_managed_without_session_errors_with_no_backend_session, and
provider_from_config_managed_builds_cloud to isolate the default credential
scope and store an app-session only under the TempDir-backed configuration
scope. Keep the tests offline, but assert via a mock or injected bearer-token
resolver that managed provider construction reads the scoped token, so the tests
fail if config is ignored; preserve coverage for missing-session errors and
cloud-provider construction.
🪄 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: 5bd2223b-2161-498b-915f-7e808d9ae710

📥 Commits

Reviewing files that changed from the base of the PR and between 5efb24a and 4dad0c7.

📒 Files selected for processing (3)
  • src/openhuman/inference/embeddings/factory.rs
  • src/openhuman/inference/embeddings/mod.rs
  • src/openhuman/inference/embeddings/rpc.rs

Comment thread src/openhuman/inference/embeddings/rpc.rs
- managed_credential_scope now delegates to state_dir_from_config (the exact
  helper AuthService::from_config uses), so it inherits the "." fallback when
  config_path has no parent and the "mirrors exactly" invariant holds — and
  stays DRY.
- Stop logging the user-scoped credential-store path (it embeds the OS username
  and/or users/<uid>); log only the non-identifying encrypt flag.
- Strengthen the config-scope regression test with an isolation half: the
  app-session token stored under the config scope must NOT resolve from a
  default_state_dir-like scope, so a managed construction that ignores config
  fails the test.
@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

Add factory_managed_provider_authenticates_with_config_scoped_token: build the
managed provider through create_embedding_provider_with_config against a local
mock cloud backend, and assert it authenticates with the app-session token
stored under the config scope. A regression to
OpenHumanCloudEmbedding::new(None, None, true, ...) would resolve no token from
default_state_dir() and fail with "No backend session" before any request, so
this pins the factory -> managed_credential_scope binding offline (no external
network; BACKEND_URL points at the mock under the shared backend-env test lock).
@coderabbitai coderabbitai Bot removed the bug label Aug 4, 2026
@senamakel
senamakel merged commit 74fd17a into tinyhumansai:main Aug 4, 2026
24 of 25 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Team Openhuman Aug 4, 2026
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.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Google sign-in succeeds but connection test in Embeddings tab still shows sign-in error

2 participants