Repository navigation
fix(sdk): bind the cipher to LLMProfileStore so no profile load can drop it - #6612
VascoSch92 wants to merge 10 commits into
Conversation
…rop it LLMProfileStore.load() took the cipher per call, so each call site had to remember it; FallbackStrategy built its own store and forgot, handing the Fernet ciphertext to the provider as the API key (#4558). - LLMProfileStore(cipher=...) binds it; load/save/resolve_provider_connection use it and with_cipher() returns a bound view. A per-call cipher still works and is deprecated (1.61.0, removal 1.66.0). - LocalConversation binds its store and LLMRegistry; the registry binds each registered LLM's FallbackStrategy. The sub-agent factory and the cleanup profile bind theirs. - agent-server get_llm_profile_store(cipher) requires the cipher and returns a bound view of the singleton. - LaunchStores.cipher is removed; LLMProfileLoader.load(name) takes none. - A cross test fails when package code builds LLMProfileStore without cipher= or passes a per-call cipher. Fixes #4558. Part of #6456 (step 1).
This comment has been minimized.
This comment has been minimized.
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
LLM.model_copy shares its FallbackStrategy, and TaskManager / delegate build the sub-agent LLM as a copy of the parent's. Binding the registry cipher by mutating the strategy let a sub-agent registry without a cipher unbind the parent's fallback again. FallbackStrategy.with_cipher returns a bound copy the registry installs on the LLM it registers, and a registry without a cipher leaves an existing binding alone.
Coverage Report •
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
smolpaws
left a comment
There was a problem hiding this comment.
I agree with Codex’s three findings: shared-LLM cipher mutation, incomplete fallback binding, and removal of the published LaunchStores(cipher=...) constructor argument.
I’m SmolPaws, an AI agent posting on Engel’s behalf 🐾. I independently traced the shared-object and named-profile paths and checked the exported v1.60.1 constructor. I’m relaying our local Codex review as draft feedback, not approval; the runtime-validation limits below still apply.
Draft verdict: COMMENT — three material findings.
Reviewed head: b01019242f057f47f74cef69e05544e3485b9d97
Merge base: ff3a0b855d57eac804d66c4753843b36675ef677
-
P2 — Cipher binding still mutates shared LLMs — llm_registry.py:143. Two conversations may share the same Agent/LLM, as existing isolation tests explicitly support. Registering that LLM with cipher B replaces its fallback strategy for both conversations, discarding cipher A’s binding and cache. Conversation A subsequently decrypts its fallback profiles using B, losing usable credentials. Copying the strategy protects shallow-copied LLMs, but not a shared LLM instance. Keep the binding conversation-owned.
-
P2 — Named-profile fallback paths remain unbound — subagent/registry.py:234. Loading a named sub-agent profile decrypts its primary key but leaves its fallback strategy without a cipher. TaskManager/delegate construct the child conversation without
cipher, so registration never supplies it. Cleanup and title-profile LLMs likewise bypass cipher-bearing registration. Their encrypted fallback keys still reach the provider as ciphertext. This is an unresolved portion of #4558, rather than a newly introduced failure. Propagate the binding through these consumers; the inherited-parent test does not cover named profiles. -
P2 — Published launch constructor breaks without deprecation — launch/resolve.py:64.
LaunchStoresis exported byopenhands.sdk.launch, and v1.60.1 acceptscipher=. Removing it makes existing integrations fail immediately withTypeError. An isolated execution of the actual dataclass definitions confirmed acceptance on v1.60.1 and rejection here. Preserve deprecated constructor compatibility through migration; retaining the store’s per-call arguments does not protect this API.
Validation and acceptance coverage:
- Locally passed: 536 existing AST-guard checks, the deprecation checker, and
git diff --check. - Runtime pytest unavailable: the focused SDK/server selection failed before collection because the shared environment lacks
litellm.asystemone. No dependencies were installed or changed. - Exact-head CI: the four new fallback tests passed; server, cross-package, persisted-settings and REST-contract checks passed. SDK tests reported 8,150 passed, one failed. I verified the same MCP invalid-entry failure on main’s run
42395649611, so it is preexisting. - Main-conversation and inherited-LLM fallback coverage is present. Store/provider cipher forwarding and per-request cipher replacement look consistent by inspection. Alternate loaders retaining an optional cipher keyword remain compatible with the new protocol. Universal fallback coverage remains incomplete; local fork also drops the binding during serialization and omits the cipher when constructing the fork.
- No new plaintext persistence or serialization leakage was established. Runtime reproduction of the findings remains limited by the unavailable environment.
Saved reviews and inline discussions were empty. Metadata reports merge conflicts (mergeable=false, dirty), separately from these code findings. The worktree remains clean; nothing was posted or modified.
main moved two things this branch was built on, so the resolution re-fits the change instead of replaying it: - The agent-server hands out stores through ServerStores and FastAPI dependencies. ServerStores.llm_profiles is now built with the server cipher, so a route that asks for the store gets it bound. Code that is given a cipher of its own (launch stores, the title subscriber, the gateway profile check, the default-profile seed) binds that one with with_cipher(), as it passed it per call before. - LLMRegistry now owns per-conversation LLM sessions, and an LLM can be shared by several conversations. Binding the fallback strategy on the LLM object from the registry would let one conversation replace the cipher of another. The cipher travels in the conversation's LLMCallContext instead: LLM hands it to FallbackStrategy.try_fallback, which resolves and caches fallback profiles per cipher. A child conversation built without a cipher keeps its parent's. LLMRegistry(cipher=) and FallbackStrategy.with_cipher() are gone.
1.62.0 is released, so the per-call cipher= of LLMProfileStore is deprecated in 1.63.0 and removed in 1.68.0, like the other deprecations that landed on main since.
LaunchStores is exported from openhands.sdk.launch and accepted cipher= up to 1.62.0. Removing the field made that call a TypeError with no deprecation period. The argument is back, deprecated in 1.63.0 for removal in 1.68.0. While it is set, it is handed to llm_profiles.load per call as before, so a loader written for the per-call cipher keeps working. The cipher-binding guard allows that one call site until the argument is removed.
Agent-server conversation start benchmarkBase
How this is measuredEach create is a Canvas-shaped
A timing is flagged when the 95% CIs do not overlap and the medians differ by at least 50 ms, or when a row with at least 8 samples per side moves by at least 150 ms and 25%. A create stalled the server when its slowest |
…re-cipher-binding
…store Main gained two profile loads that pass the cipher per call: LocalConversation.add_model_router_route (#6835) and resolution_judge (#6962). The conversation's store and the server's store are bound to their cipher, so both now load and save without naming it. resolution_judge(cipher=...) was published in 1.63.0. It stays as a deprecated argument that binds the store, scheduled for removal in 1.70.0.
1.63.0 and 1.64.x shipped without this change, so the per-call cipher and LaunchStores(cipher=...) are deprecated in 1.65.0 and removed in 1.70.0, which keeps the five-minor runway.
|
Thanks for the review. All three findings were right, here is where each one landed (links are at ac980b5). The shared LLM one I could reproduce on the old head: a second registry with another cipher turned the first conversation's fallback key into For named profiles:
I also merged main again today (v1.64.1). It had two new per-call cipher loads, the model-router route and |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope gate: This is an SDK security fix (profile decryption) in the repository that owns the Python SDK and Agent Server, with clear direction from #4558 (priority:high, ready-for-dev, security-related) and the architecture tracker #6456. No maintainer decision needed; review continues.
Overall assessment — no material findings.
The approach matches the root cause: #4558 was structural — every LLMProfileStore call site had to remember the cipher, and the ones that forgot handed Fernet ciphertext to the provider as the API key. Binding the cipher at construction (LLMProfileStore(cipher=...), with_cipher() view) and routing every package call site through a bound store removes the failure mode class rather than patching one site. Verified on head ac980b5ba:
- Binding is complete. All 10 package constructions state
cipher=explicitly; the twocipher=Nonestores (switch_llmprofile names,vision_inspectcapabilities) only readlist_summaries()and never a secret. The agent-server'sServerStores.llm_profilesis bound to the server cipher, and every route'sget_cipher/service.cipherderives from the sameConfig, so thewith_cipher(...)calls at route level are equivalent 1:1 moves. I tracedget_profile,activate_profile,_load_active_profile_llm,_require_llm_profile,_seed_default_llm_profile, the OpenAI gateway, andAutoTitleSubscriber— old per-call semantics (decrypt with the server cipher, raw when none) are preserved, includingstrict=Trueandresolve_providerbehavior. - Shared-LLM regression from the earlier review is fixed. The cipher no longer lives on the
LLMor its strategy: it travels in the conversation'sLLMCallContext(inherited by sub-agent conversations) andFallbackStrategy._resolvedcaches decrypted fallbacks per cipher.test_conversations_sharing_an_llm_keep_their_own_cipherandtest_a_sub_agent_conversation_inherits_the_parents_ciphercover both scenarios from review 5919562555. - Backward compatibility follows the repo policy.
LaunchStores(cipher=...),resolution_judge(cipher=...), and per-call storecipher=stay functional with warnings scheduleddeprecated_in="1.65.0"/removed_in="1.70.0"(5-minor runway from the current 1.64.1);check_deprecations.pypasses.LaunchStores.cipheris still handed to a custom loader per call, so pre-existing custom loaders keep working (tested). TheLLMProfileLoaderprotocol narrowing toload(name)is satisfied by the documented enterprise signature. - A guard locks it in.
tests/cross/test_llm_profile_store_cipher_binding.pyfails CI if package code builds an unbound store or passes a per-call cipher, so the bug cannot re-enter one call site at a time.
Test evidence. Locally on the exact head: the guard suite (580 checks), tests/sdk/llm (1835 passed), tests/sdk/launch + tests/sdk/subagent (255 passed), tests/agent_server profile-store/conversation-service/profiles-router/settings-router/cipher-mismatch/lock/resume-secret and OpenAI-gateway launch suites (428 passed), plus check_deprecations.py. Three pre-existing, environment-dependent tests (OH_PERSISTENCE_DIR/HOME in this sandbox: test_credentials.py ×2, test_subagent_loader.py ×1) fail identically against main's own test sources and touch no PR-changed code. CI on this head is green for all code checks (build, sdk/cross/tools/agent-server tests, pre-commit, CodeQL, REST-contract). One non-code check, "Validate PR description", fails on this head — a repo PR-metadata gate about the HUMAN: note, owned by the PR author, not a code defect.
Known limitation, correctly scoped: a title/cleanup LLM call made outside any conversation cannot decrypt a fallback profile from a hand-edited profile JSON (since save() excludes fallback_strategy from serialization, save()-written profiles cannot carry one). The PR documents this; it does not affect save()-produced data and is a narrow follow-up, not a defect in this change.
✅ APPROVED
HUMAN:
As the title says :-)
AGENT:
Why
Step 1 of #6456 asks for the cipher to be "a required, store-bound argument". Today
LLMProfileStore.load()takes the cipher per call, so every call site has to remember it, and the ones that forget hand the Fernet ciphertext to the provider as the API key. That is #4558:FallbackStrategybuilds its own store and loads with no cipher. #4568 patches that one site; the next site would need another patch.Summary
LLMProfileStore(..., cipher=...)binds the cipher.load,saveandresolve_provider_connectionuse it;with_cipher()returns a bound view sharing the directory, lock and provider store. The per-callcipher=still works, deprecated in 1.65.0 for removal in 1.70.0.Every store owner binds it once:
LocalConversation, the sub-agent factory, the cleanup profile, and the agent-server'sServerStores.llm_profiles, so a route that depends on the store gets it bound.A fallback gets the cipher from the conversation making the call, which fixes Encrypted LLM profiles are decrypted only on the conversation path — FallbackStrategy (and sub-agents) load them without the cipher #4558:
Nothing is written on the
LLM, so two conversations that share one keep their own ciphers.LaunchStores(cipher=...)andresolution_judge(cipher=...)still work, deprecated in 1.65.0 for removal in 1.70.0.LLMProfileLoader.load(name)takes no cipher; the enterprise loader,load(self, name, *, cipher=None), still satisfies it.A guard,
tests/cross/test_llm_profile_store_cipher_binding.py, fails CI when package code buildsLLMProfileStore(...)withoutcipher=, or passes a per-callcipher=toload/save/resolve_provider_connection.Every agent-server call site is a 1:1 move of the same cipher from the call to the store: a route's
store.load(name, cipher=c)becomesstore.load(name)on the store bound toc, and code handed a cipher of its own callsstore.with_cipher(c).load(name).Issue Number
Fixes #4558. Part of #6456 (step 1, cipher part).
How to Test
Repro of #4558 through a real
LocalConversation(cipher=...): the fallback profile is saved encrypted, the primary model fails, the agent runs one step, and the script prints the key the fallback request carried:Regression evidence, at
ac980b5ba(main5f1430ebbmerged in):Main's sources fail the new checks. On main's
openhands-sdkandopenhands-agent-server, the repro sends the ciphertext shown above,test_llm_profile_store_is_bound_to_the_server_cipherfails because the server's store writessk-encin plain text when no call names the cipher, and the guard flags 14 modules.Suites, each in its own session, on macOS:
tests/agent_server(withoutcanvas_extensions, Linux only)tests/tools(withoutterminal)tests/crosstests/sdkNone of the 7 comes from this branch.
test_blocking_batch_export_does_not_hold_shutdown[False]and five of the six intests/sdk(plugin fetch ×3, MCP subprocess cleanup ×2) fail the same way on main's sources on this machine. The sixth,test_truncate, passes when its file runs alone.Checks. Pre-commit passes on every commit, and
check_deprecations.pypasses.Video/Screenshots
N/A
Type
Notes
launchis the follow-up: deprecating the threecreate_agents andcreate_agent_from_settings(public API, so a 5-minor runway), and removing_agent_from_base_state.cipher=Noneon purpose: the vision-profile scan and theswitch_llmtool's name list never read a key.5f1430ebbhad gained two per-call cipher loads since the previous merge:LocalConversation.add_model_router_route(Add runtime model router route updates #6835) andresolution_judge(Add a resolution judge on a saved resolution_judge LLM profile #6962). Both now go through the bound store.resolution_judge(cipher=...)was published in 1.63.0, so it stays as a deprecated argument that binds the store.0275e714d:None. The cipher no longer lives on theLLMor its strategy; it travels in the conversation'sLLMCallContext, next to the sessions main introduced for the same sharing problem.LLMRegistry(cipher=)andFallbackStrategy.with_cipher()are gone.test_conversations_sharing_an_llm_keep_their_own_ciphercovers it.LLM.fallback_strategyis excluded from serialization, so a profile written bysave()has none; only a hand-edited profile JSON can carry one. Such an LLM is now covered whenever it is called with a conversation's call context, which a sub-agent's conversation inherits from its parent (test_a_sub_agent_conversation_inherits_the_parents_cipher). A title or cleanup call made outside any conversation still has no cipher to give a hand-edited fallback.LaunchStores(cipher=...). Restored as a deprecated argument. It is handed tollm_profiles.loadper call as before, so a custom loader written for it keeps working.🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:ac980b5-pythonRun
All tags pushed for this build
About Multi-Architecture Support
ac980b5-python) is a multi-arch manifest supporting both amd64 and arm64ac980b5-python-amd64) are also available if needed