Skip to content

fix(sdk): bind the cipher to LLMProfileStore so no profile load can drop it - #6612

Open
VascoSch92 wants to merge 10 commits into
mainfrom
vasco/llm-profile-store-cipher-binding
Open

VascoSch92 wants to merge 10 commits into
mainfrom
vasco/llm-profile-store-cipher-binding

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

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: FallbackStrategy builds 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, save and resolve_provider_connection use it; with_cipher() returns a bound view sharing the directory, lock and provider store. The per-call cipher= 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's ServerStores.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:

    LocalConversation(cipher=c)
      LLMCallContext(cipher=c)                 # a child conversation keeps its parent's
        llm.completion(call_context=ctx)       # primary fails
          FallbackStrategy.try_fallback(cipher=c)
            LLMProfileStore(dir, cipher=c).load(name)   # cached per cipher
    

    Nothing is written on the LLM, so two conversations that share one keep their own ciphers.

  • LaunchStores(cipher=...) and resolution_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 builds LLMProfileStore(...) without cipher=, or passes a per-call cipher= to load/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) becomes store.load(name) on the store bound to c, and code handed a cipher of its own calls store.with_cipher(c).load(name).

Issue Number

Fixes #4558. Part of #6456 (step 1, cipher part).

How to Test

uv run pytest tests/cross/test_llm_profile_store_cipher_binding.py tests/sdk/llm tests/sdk/launch tests/sdk/conversation/test_resolution.py tests/agent_server/test_profile_store_persistence_dir.py -q

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:

main (5f1430ebb, v1.64.1)  fallback api_key sent : gAAAAABrButmsA...   is Fernet ciphertext? : True
this branch (ac980b5ba)    fallback api_key sent : sk-REAL             is Fernet ciphertext? : False

Regression evidence, at ac980b5ba (main 5f1430ebb merged in):

  • Main's sources fail the new checks. On main's openhands-sdk and openhands-agent-server, the repro sends the ciphertext shown above, test_llm_profile_store_is_bound_to_the_server_cipher fails because the server's store writes sk-enc in plain text when no call names the cipher, and the guard flags 14 modules.

  • Suites, each in its own session, on macOS:

    suite passed failed
    tests/agent_server (without canvas_extensions, Linux only) 3347 1
    tests/tools (without terminal) 904 0
    tests/cross 1366 0
    tests/sdk 8633 6

    None of the 7 comes from this branch. test_blocking_batch_export_does_not_hold_shutdown[False] and five of the six in tests/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.py passes.

Video/Screenshots

N/A

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • This is the cipher half of step 1 only. Building agents only through launch is the follow-up: deprecating the three create_agents and create_agent_from_settings (public API, so a 5-minor runway), and removing _agent_from_base_state.
  • Two stores state cipher=None on purpose: the vision-profile scan and the switch_llm tool's name list never read a key.
  • Makes fix(sdk): decrypt encrypted fallback profiles #4568 (the fallback call site) unnecessary. fix: decrypt LLM profiles for subagents #4183 targets the sub-agent factory, which already passes the cipher on main.
  • Main at 5f1430ebb had gained two per-call cipher loads since the previous merge: LocalConversation.add_model_router_route (Add runtime model router route updates #6835) and resolution_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.
  • On review 5919562555, after merging main at 0275e714d:
    1. Shared LLM. Reproduced on the old head: a second registry with another cipher turned the fallback key into None. The cipher no longer lives on the LLM or its strategy; it travels in the conversation's LLMCallContext, next to the sessions main introduced for the same sharing problem. LLMRegistry(cipher=) and FallbackStrategy.with_cipher() are gone. test_conversations_sharing_an_llm_keep_their_own_cipher covers it.
    2. Named profiles. LLM.fallback_strategy is excluded from serialization, so a profile written by save() 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.
    3. LaunchStores(cipher=...). Restored as a deprecated argument. It is handed to llm_profiles.load per 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:ac980b5-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-ac980b5-python \
  ghcr.io/openhands/agent-server:ac980b5-python

All tags pushed for this build

ghcr.io/openhands/agent-server:ac980b5-golang-amd64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-golang-amd64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-golang-amd64
ghcr.io/openhands/agent-server:ac980b5-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:ac980b5-golang-arm64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-golang-arm64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-golang-arm64
ghcr.io/openhands/agent-server:ac980b5-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:ac980b5-java-amd64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-java-amd64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-java-amd64
ghcr.io/openhands/agent-server:ac980b5-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:ac980b5-java-arm64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-java-arm64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-java-arm64
ghcr.io/openhands/agent-server:ac980b5-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:ac980b5-python-amd64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python-amd64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python-amd64
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime-amd64
ghcr.io/openhands/agent-server:ac980b5-python-arm64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python-arm64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python-arm64
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime-arm64
ghcr.io/openhands/agent-server:ac980b5-python-minimal-amd64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python-minimal-amd64
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:ac980b5-python-minimal-arm64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python-minimal-arm64
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:ac980b5-python-slim-amd64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python-slim-amd64
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:ac980b5-python-slim-arm64
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python-slim-arm64
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:ac980b5-golang
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-golang
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-golang
ghcr.io/openhands/agent-server:ac980b5-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:ac980b5-java
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-java
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-java
ghcr.io/openhands/agent-server:ac980b5-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:ac980b5-python-minimal
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python-minimal
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python-minimal
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime-minimal
ghcr.io/openhands/agent-server:ac980b5-python-slim
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python-slim
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python-slim
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime-slim
ghcr.io/openhands/agent-server:ac980b5-python
ghcr.io/openhands/agent-server:ac980b5baf17889764bb11be449e3ecea76629b2-python
ghcr.io/openhands/agent-server:vasco-llm-profile-store-cipher-binding-python
ghcr.io/openhands/agent-server:ac980b5-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., ac980b5-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., ac980b5-python-amd64) are also available if needed

…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).
@datadog-official

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

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.
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   agent_profiles_router.py2261394%105, 193, 197, 201, 219, 222, 317, 320, 323–324, 510, 544–545
   conversation_router.py3712294%134–135, 138–139, 364, 497–498, 545, 631, 710, 726, 783, 787–788, 888, 958–960, 1005, 1045–1046, 1077
   conversation_service.py141510693%221–222, 304, 325, 509–510, 675–676, 681, 692, 698, 820, 871–872, 876, 881, 931, 983–984, 991, 1024–1025, 1041, 1073, 1077, 1090, 1113, 1134–1135, 1144, 1223, 1248, 1254–1255, 1259–1260, 1292, 1366, 1381, 1426, 1432, 1452–1453, 1475, 1493, 1530, 1534–1538, 1561, 1610, 1639, 1650, 1936, 1965–1968, 2010, 2022–2023, 2029–2031, 2049, 2063, 2194, 2214, 2217, 2224–2226, 2229–2230, 2236, 2246, 2250, 2279, 2288, 2350–2352, 2387, 2528, 2531, 2560, 2570, 2575–2578, 2592, 2603, 2615–2616, 2649, 2750, 2819, 2877, 2892–2893, 3138, 3141, 3320
   launch.py125497%165, 168–169, 194
   profiles_router.py195697%538–543
   resolution_judge.py20290%45–46
   settings_router.py202598%624, 626–627, 667, 672
openhands-agent-server/openhands/agent_server/openai
   service.py3695585%116, 126–129, 137, 141–151, 153–157, 172, 198–203, 234, 243, 245, 268, 278–279, 384, 391, 398, 417–420, 517–518, 637–638, 645, 651, 653, 739–740, 769, 786, 797, 864
openhands-agent-server/openhands/agent_server/persistence
   store.py5146987%52–53, 103, 107, 111, 115, 119, 125, 148–149, 171, 174–177, 179–180, 185, 222, 224–228, 230–234, 239–244, 267, 270–271, 389–390, 395, 397–398, 547, 580–581, 586, 588–589, 597, 674–675, 754, 756, 775, 779, 797–798, 804, 872–873, 877–879, 898, 947–948, 1146–1147
openhands-sdk/openhands/sdk/conversation
   resolution.py1371192%416–417, 422, 443–450
openhands-sdk/openhands/sdk/conversation/impl
   local_conversation.py14259593%204, 454, 521, 557–560, 562, 817–818, 942, 1407, 1409, 1480, 1604, 1636, 1775–1776, 1782, 1791–1794, 1842, 1855, 1883–1884, 1890–1892, 1921, 1928–1931, 1984, 2005–2007, 2056, 2188, 2527–2528, 2532, 2537, 2540, 2548–2549, 2553–2555, 2577–2581, 2584, 2588–2589, 2599–2601, 2607, 2611–2612, 2712, 2909, 2912–2913, 3133, 3170, 3174, 3178, 3199, 3251, 3255, 3289, 3296–3297, 3305, 3309–3310, 3314, 3321, 3630–3631, 3649–3650, 3685, 3901, 3905, 3926, 3977, 3984–3985
openhands-sdk/openhands/sdk/launch
   resolve.py1512087%134, 149, 195–196, 203, 211–212, 215–218, 235–236, 264, 269–272, 288–289
openhands-sdk/openhands/sdk/llm
   cleanup_profile.py48492%79–81, 146
   fallback_strategy.py58198%172
   llm.py12086695%806, 835–836, 841, 1341, 1396, 1410, 1436, 1516, 1526, 1676, 1851, 2123, 2127–2128, 2330, 2347, 2436, 2440–2441, 2521, 2542, 2613, 2626, 2644, 2658, 2660, 2662, 2687, 2689, 2698–2699, 2723, 2932, 3118, 3275, 3289, 3476–3477, 3486, 3537–3538, 3546, 3549, 3552–3553, 3564, 3569, 3635, 3637, 3639–3642, 3644–3647, 3652–3655, 3670, 3681, 3741, 3743
   llm_profile_store.py2011195%66–67, 79–80, 82, 219–220, 418–419, 451, 457
openhands-sdk/openhands/sdk/subagent
   registry.py142696%118, 252–253, 257, 329–330
openhands-sdk/openhands/sdk/tool/builtins
   classify_and_switch_llm.py2592590%55–57, 81–83, 85–93, 199, 258–259, 281, 324, 431, 512–513, 589–590
   switch_llm.py651183%34–40, 62, 106, 123, 167
   vision_inspect.py1242183%57, 85, 107, 110–111, 113–114, 117–118, 120, 131, 172, 184, 191, 204, 220–221, 233, 275, 323, 327
TOTAL60825982584% 

@smolpaws smolpaws 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.

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

  1. 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.

  2. 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.

  3. P2 — Published launch constructor breaks without deprecation — launch/resolve.py:64. LaunchStores is exported by openhands.sdk.launch, and v1.60.1 accepts cipher=. Removing it makes existing integrations fail immediately with TypeError. 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.
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Agent-server conversation start benchmark

Base main@5f1430ebbec30747efe0d0e5e041fb7be36d782e vs this PR merge e652b4e751, measured in the same job on the same runner, interleaved: 5 server starts per side and scenario. Medians with 95% bootstrap CIs. The LLM is a mock that answers instantly, so this is agent-server overhead only.

base this PR change
Create conversation (warm) 0.085 s [0.081, 0.088] 0.088 s [0.083, 0.092] +3% ≈ same
↳ first agent event 0.122 s [0.119, 0.125] 0.124 s [0.118, 0.129] +1% ≈ same
First create right after server start 0.220 s [0.101, 0.293] 0.120 s [0.100, 0.126] -45% ≈ same
↳ first agent event 0.373 s [0.276, 0.549] 0.298 s [0.270, 0.330] -20% ≈ same
First create 3 s after server start 0.123 s [0.109, 0.162] 0.123 s [0.105, 0.135] +0% ≈ same
↳ first agent event 0.287 s [0.267, 0.337] 0.293 s [0.289, 0.324] +2% ≈ same
Create in a new git worktree (warm, 0.5 s git fetch) 0.612 s [0.610, 0.618] 0.613 s [0.607, 0.625] +0% ≈ same
↳ first agent event 0.650 s [0.646, 0.657] 0.654 s [0.641, 0.665] +1% ≈ same
Worktree creates that stalled the server > 20 ms 1/20 (5%) 0/20 (0%) -5 pts ≈ same
Create with one stdio MCP server (warm, 3 s startup) 1.088 s [1.083, 1.091] 1.084 s [1.078, 1.090] -0% ≈ same
↳ first agent event 3.574 s [3.557, 3.589] 3.572 s [3.550, 3.604] -0% ≈ same
Creates that stalled the server > 20 ms 0/35 (0%) 0/35 (0%) +0 pts ≈ same
Server startup (/alive) 3.535 s [3.457, 3.667] 3.611 s [3.460, 3.690] +2% ≈ same
How this is measured

Each create is a Canvas-shaped POST /api/conversations (agent profile, worktree: true, first message included, so the request waits for agent startup). A side task polls /alive every 20 ms to catch event-loop stalls. Scenarios, each on its own server starts:

  • default: a fresh directory per create, 8 creates per start.
  • pause: the first create waits 3 s after startup, as a user opening the UI would.
  • worktree: every create branches a new worktree from a local repository whose origin answers fetches after 0.5 s.
  • mcp: the agent profile enables one stdio MCP server that starts after 3 s, like an npx/uvx launch.

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 /alive took over 20 ms; stall rows are flagged when the share of stalled creates moves by at least 20 points with a Fisher exact p below 0.01. The first-create rows have one sample per server start, so they are flagged only on a clear change. A "↳ first agent event" row times the create above it until the agent's first event arrives on a socket opened after the create returns, as Agent Canvas does, so it includes the connect and replay. Runner: blacksmith-2vcpu-ubuntu-2404-72gqanw273guw7y3, 178 environment variables. Run it locally with python scripts/agent_server_benchmarks/conversation_start.py --help.

…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.
@VascoSch92

Copy link
Copy Markdown
Member Author

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 None. The cipher no longer lives on the LLM or its strategy. It travels in the conversation's LLMCallContext, and try_fallback gets it per call. LLMRegistry(cipher=) and FallbackStrategy.with_cipher() are gone, and this test runs two conversations on one LLM.

For named profiles: LLM.fallback_strategy is excluded from serialization, so a profile written by save() never has one, and only a hand-edited profile JSON can carry it. Such an LLM is covered whenever it is called inside a conversation, and a sub-agent's conversation inherits its parent's cipher. One case is still not covered: a title or cleanup call made outside any conversation has no cipher to give a hand-edited fallback.

LaunchStores(cipher=...) is back as a deprecated argument. It is handed to llm_profiles.load per call as before, so a custom loader written for it keeps working.

I also merged main again today (v1.64.1). It had two new per-call cipher loads, the model-router route and resolution_judge. Both now go through the bound store, and the per-call cipher= deprecations are scheduled for 1.65.0 with removal in 1.70.0.

@VascoSch92
VascoSch92 marked this pull request as ready for review November 25, 2026 14:28

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 two cipher=None stores (switch_llm profile names, vision_inspect capabilities) only read list_summaries() and never a secret. The agent-server's ServerStores.llm_profiles is bound to the server cipher, and every route's get_cipher/service.cipher derives from the same Config, so the with_cipher(...) calls at route level are equivalent 1:1 moves. I traced get_profile, activate_profile, _load_active_profile_llm, _require_llm_profile, _seed_default_llm_profile, the OpenAI gateway, and AutoTitleSubscriber — old per-call semantics (decrypt with the server cipher, raw when none) are preserved, including strict=True and resolve_provider behavior.
  • Shared-LLM regression from the earlier review is fixed. The cipher no longer lives on the LLM or its strategy: it travels in the conversation's LLMCallContext (inherited by sub-agent conversations) and FallbackStrategy._resolved caches decrypted fallbacks per cipher. test_conversations_sharing_an_llm_keep_their_own_cipher and test_a_sub_agent_conversation_inherits_the_parents_cipher cover both scenarios from review 5919562555.
  • Backward compatibility follows the repo policy. LaunchStores(cipher=...), resolution_judge(cipher=...), and per-call store cipher= stay functional with warnings scheduled deprecated_in="1.65.0" / removed_in="1.70.0" (5-minor runway from the current 1.64.1); check_deprecations.py passes. LaunchStores.cipher is still handed to a custom loader per call, so pre-existing custom loaders keep working (tested). The LLMProfileLoader protocol narrowing to load(name) is satisfied by the documented enterprise signature.
  • A guard locks it in. tests/cross/test_llm_profile_store_cipher_binding.py fails 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

@all-hands-bot
all-hands-bot requested a review from enyst November 27, 2026 02:02
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.

Encrypted LLM profiles are decrypted only on the conversation path — FallbackStrategy (and sub-agents) load them without the cipher

3 participants