Repository navigation
Description
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
LocalConversation.fork() builds the fork without the source conversation's cipher (openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:863), so the fork's base_state.json stores the LLM api_key redacted (**********) while the source stores it encrypted. The agent-server resumes every fork from that file (EventService.start passes agent=None once base_state.json exists), so the fork's first turn fails with:
ConversationErrorEvent code=LLMAuthenticationError
"Your LLM API key appears to be invalid or has expired."
The source conversation keeps working. Only the fork breaks. Agent Canvas forks through POST /api/conversations/{id}/fork (use-fork-conversation.ts), and the same fork() code ships in v1.50.1. Found while QA'ing #5406. Identical on main (048c9be) and on that branch.
Expected Behavior
A fork keeps the source's credentials. Its base_state.json stores the key encrypted with the same cipher, and the fork's next turn reaches the LLM.
Actual Behavior
$ uv run python repro_fork_key.py
source base_state.json agent.llm.api_key: encrypted
fork base_state.json agent.llm.api_key: redacted
On a live agent-server (start a conversation, POST /api/conversations/{id}/fork, send a message to the fork):
- source
base_state.jsonagent.llm.api_key: a Fernet token - fork
base_state.jsonagent.llm.api_key:null - fork events after the message:
MessageEvent, 3×ConversationStateUpdateEvent, thenConversationErrorEvent(LLMAuthenticationError)
Steps to Reproduce
- In an SDK checkout, save as
repro_fork_key.py:
import json
import tempfile
from pathlib import Path
from pydantic import SecretStr
from openhands.sdk import LLM, Agent
from openhands.sdk.conversation.impl.local_conversation import LocalConversation
from openhands.sdk.utils.cipher import Cipher
root = Path(tempfile.mkdtemp())
source = LocalConversation(
agent=Agent(llm=LLM(model="openai/gpt-4o-mini", api_key=SecretStr("sk-test"), usage_id="agent"), tools=[]),
workspace=str(root / "workspace"),
persistence_dir=str(root / "conversations"),
cipher=Cipher("test-secret-key"),
)
fork = source.fork()
for name, conv in (("source", source), ("fork", fork)):
state = json.loads((Path(conv.state.persistence_dir) / "base_state.json").read_text())
key = state["agent"]["llm"]["api_key"]
shape = "null" if key is None else "plaintext" if key == "sk-test" else "redacted" if set(key) == {"*"} else "encrypted"
print(f"{name} base_state.json agent.llm.api_key: {shape}")uv run python repro_fork_key.py
Acceptance Criteria
-
LocalConversation.fork()persists the fork with the source conversation's cipher, so the fork'sbase_state.jsonkeeps the key encrypted. - A regression test forks a cipher-backed conversation and asserts that the fork's persisted key decrypts to the source's key.
- A fork created through
POST /api/conversations/{id}/forkon a server with a secret key completes an LLM turn.
Installation Method
From source (uv sync in this repo)
SDK Version
main at 048c9be. The same fork() code is in v1.50.1.
Python Version
3.13.7
Operating System
macOS
Additional Context
Suggested fix, verified locally on main: pass cipher=self._cipher to the LocalConversation(...) call in fork(). With that line, the repro prints encrypted for both, and a fork on a live agent-server completes a real LLM turn.
Found by an AI agent (Claude Code) while QA'ing #5406. Every result above was reproduced on main (048c9be).
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Confirmed in code. LocalConversation.fork() (around local_conversation.py:863) constructs the fork without forwarding self._cipher, so ConversationState.create gets no cipher and _save_base_state serializes the LLM api_key (and other secrets) redacted rather than encrypted. The agent-server resumes the fork from that base_state.json with agent=None, so the fork's first turn authenticates with the redacted placeholder and emits LLMAuthenticationError, while the source keeps working. This path is shared by every SDK consumer of fork(), including the server's POST /api/conversations/{id}/fork.
Bounded scope: forward the source conversation's cipher to the fork inside LocalConversation.fork(), so the fork's persisted base state encrypts secrets with the same cipher the source uses, and lock that in with a regression test. The cipher is the repository's authoritative mechanism (openhands.sdk.utils.cipher.Cipher, routed through ConversationState/pydantic_secrets), so the fix must reuse it rather than a parallel redaction path.
Non-goals: not changing how the agent-server resolves a cipher per conversation (ConversationService._cipher_for), not inventing a new secret-propagation mechanism or new public API, and not altering redaction for conversations that genuinely have no cipher.
Priority is priority:low: the report reproduces a real failure in the product path, but the evidence here is a synthetic SDK/server reproduction with no external user report, support ticket, or production impact recorded.
Acceptance Criteria
-
LocalConversation.fork()forwards the source's cipher to the fork'sLocalConversation, so a cipher-backed source yields a fork whosebase_state.jsonstoresagent.llm.api_keyas a cipher-encrypted token (not redacted**********and notnull) matching the source. - Secrets held in the source's
secret_registry/agent_context.secretsare preserved on the fork's persisted state under the same cipher, not just the LLM key. - Resuming the fork from its persisted directory with
agent=None(the agent-server resume path) yields LLM credentials that decrypt to the source's original value. - A regression test in
tests/sdk/conversation/local/test_fork.pyforks a cipher-backed conversation, reads the fork'sbase_state.json, and asserts the persisted key decrypts to the source's key; it fails against currentmainand passes with the fix. - A fork created through
POST /api/conversations/{id}/forkon an agent-server configured with a cipher completes a subsequent LLM turn withoutLLMAuthenticationError(covered undertests/agent_server/; if that cannot reach a live LLM, validate on a live server and note the limitation). - Forks of conversations without a cipher keep the existing redacted behavior, so cipher-less conversations are not regressed.
Reproduction on main (91e8b5b)
Agent Canvas (OpenHands 46f20ab, Vite dev frontend) against an agent-server run from software-agent-sdk main at 91e8b5b68 with OH_SECRET_KEY set, and an LLM profile pointing at a local fake OpenAI-compatible server that only accepts a dummy key. The source conversation answers; after Branch from here, the branch's first message fails with "Your LLM API key appears to be invalid or has expired." (ConversationErrorEvent LLMAuthenticationError). On disk, the source's base_state.json holds agent.llm.api_key as a Fernet token, and the fork's has no api_key at all.
Still frame of the failing branch: 
This comment/PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.

Activity
simonrosenberg commentedon Oct 2, 2026
Still reproduces on
mainat35410b3af(after #5406 merged): the repro printssource … encrypted/fork … redacted, andfork()atlocal_conversation.py:863still builds the fork withoutcipher=self._cipher.enyst commentedon Oct 5, 2026
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project work. While mapping every user-facing Agent Canvas feature, an independent agent reproduced this through the UI. It breaks Agent Canvas's "Branch from here" for every branch, so it is user-facing, which may matter for the priority.
Steps on Agent Canvas 1.24.0 (Agent Server 1.50.1, local backend):
The branch goes to
errorwithin a second withConversationErrorEventLLMAuthenticationError("Your LLM API key appears to be invalid or has expired."), and the composer shows that banner. On disk, the source'sbase_state.jsonholds a Fernet token foragent.llm.api_key; the branch's holdsnull. This is consistent with the missingcipher=self._cipherinfork(). Canvas's own fork call is fine, so once the pin moves past #5473 no Canvas change should be needed.Generated by Claude Code
enyst commentedon Oct 9, 2026
I'm an AI agent based on Opus 5.5, helping Engel Nyst (@enyst) with project maintenance.
This still reproduces on
mainat 2804c12. The Agent Server feature map in #5621 drives it end to end on a fresh server and keeps it as a known-bug bullet (F10.fork-keeps-credentials,F10.fork-run-memory), so once a fix lands the map reports an unexpected pass:What it observes:
The fork answers 201. The source's
base_state.jsonholds both keys as Fernet tokens; the fork's has neither (null). The fork's first run ends inerrorwithin seconds with aConversationErrorEventwhosecodeisLLMAuthenticationError.It is listed with the other bugs from the mapping pass in the umbrella issue, #5653.
Generated by Claude Code
fix(conversation): pass cipher and secrets to forked conversations (O…
enyst commentedon Oct 13, 2026
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Answers to the triage acceptance criteria, with the fix in #5765:
fork()passescipher=self._cipher, so the fork'sbase_state.jsonholdsagent.llm.api_keyas a Fernet token from the same cipher.secret_registry/agent_context.secrets.agent_context.secretslive on the agent, whichfork()already deep-copies, so the cipher alone keeps them.secret_registrysecrets (secrets=/update_secrets) were not copied byfork()at all, with or without a cipher. fix(sdk): keep the source's cipher and secrets on a forked conversation #5765 copies them into the fork. On the agent-server this was already covered (the server re-appliesmeta.jsonsecrets on resume), so the change only matters to direct SDK users.agent=Nonegets the real key. Covered: the regression test loads the fork'sbase_state.jsonwith the cipher and checks the key decrypts to the source's value.tests/sdk/conversation/local/test_fork.py. Added. It fails on main and passes with the fix.POST /api/conversations/{id}/forkcompletes an LLM turn. Checked on a live agent-server with DeepSeek through the verify-agent-server map (F10.fork-keeps-credentials,F10.fork-run-memory):xfailtwice on main,xpasstwice with the fix, and the fork's run finishes and recalls a fact only the source was told. The PR also removes both known-bug markers.The other point, which cipher the fork should use: the server resolves a cipher per conversation (
ConversationService._cipher_for), but fork returns 501 in Docker runtime mode, the only mode where that resolver gives a per-conversation key. Everywhere a fork can be made, the source's cipher is the server's cipher.Maintainer decisions:
secret_registry(point 2) goes slightly past the cipher fix. I included it because the triage criteria ask for it andfork()is documented as a deep copy. The alternative is a cipher-only fix: SDK forks would then keep dropping conversation secrets, and the agent-server would behave the same either way.Generated by Claude Code
fix(conversation): pass cipher and secrets to forked conversations (O…
Add before/after Agent Canvas evidence for #5465 under .pr/