Repository navigation
Conversation
There was a problem hiding this comment.
I'm an AI agent helping Engel Nyst (@enyst) with project work.
Thank you @kyletser, the fix itself is right. On a local agent-server, ConversationService._cipher_for returns the same server cipher for every conversation id. So the key the fork is now encrypted with is the key the server decrypts with when it resumes the fork with agent=None, both right after the fork and after a restart. Docker mode is the only setup with per-conversation keys, and its fork route returns 501, so that mismatch can't happen. We ran a small script against this head: a ConversationService with a cipher forks a conversation and then restarts. The fork comes back with the real LLM key. With the line reverted, it comes back None. The same line also keeps MCP env secrets and agent_context.secrets intact on the fork, which were silently lost before. The new test fails without the fix, tests/sdk/conversation passes (864 tests), and the branch rebases onto current main without conflicts.
A few things before this can merge:
Needs changes
- pyright fails on the new test, so
Pre-commit checkswill go red (see the inline comment ontest_fork.py:381). - Version bump guard fails only because the branch is 29 commits behind
main. It compares the packages as 1.53.0 → 1.51.0. Merging or rebasing onto currentmainclears it. - PR description: the required check wants the repo template, which needs a first line
HUMAN:with a short note in your own words, thenAGENT:, and the## Summaryand## How to Testsections.
Suggestions (from #5465's own acceptance criteria; either here or as a follow-up, but then the issue shouldn't close on this PR alone)
- Runtime secrets are still dropped by fork. Secrets added with
POST /conversations/{id}/secretsgo into the conversation'ssecret_registry, andfork()never copies it. In our script the fork lost a secret added that way while the source kept it. The triage asks for those to be preserved too. - An agent-server test: the triage asks for coverage under
tests/agent_server/, and it doesn't need a live LLM. Building aConversationServicewith a cipher, forking, resuming the fork and asserting itsllm.api_keywould cover the user-facing path. - Test style (nit): the test asserts private state (
fork._state._cipher is src._state._cipher) and calls_save_base_statedirectly. AGENTS.md prefers observable behavior. Reloading the fork's persisted state with the cipher and asserting the key would survive refactors.
bf67b53 to
583fb5e
Compare
|
Pushed 583fb5e addressing the review, rebased on current main:
All three tests fail without the fix. Conversation-local suite (234), agent-server service suite (132), ruff, and pyright all pass. The PR description now follows the repo template. |
…penHands#5465) LocalConversation.fork() built the fork without the source cipher, so the fork's base_state.json stored the LLM api_key redacted instead of encrypted, and its first resumed turn failed with LLMAuthenticationError. Runtime-added secrets (update_secrets) were dropped as well. Forward self._cipher to the fork constructor and copy the source secret_registry, reassigning the public field so the autosave persists the sources encrypted with the fork's cipher. Co-authored-by: openhands <openhands@all-hands.dev>
583fb5e to
8934ffa
Compare
|
Rebased onto Also updated in this push:
The remaining |
|
For #5465 we are driving #5765 to merge: it carries the same cipher fix, also copies the source's secret registry, and already incorporates this PR's server-restart regression test ( This comment/PR was created by an AI agent (OpenHands) on behalf of Graham Neubig. |
|
Closing as superseded now that #5765 has landed — thanks for pointing it out, and glad the server-restart regression test carried over. |
HUMAN: I reviewed the fix, the test evidence, and the maintainer feedback, and I am comfortable submitting this change for review.
AGENT:
This PR was prepared with AI assistance. The fix, tests, and description follow the maintainer's review of the initial submission.
Why
LocalConversation.fork()built the fork without the source conversation's cipher, so the fork'sbase_state.jsonstored the LLMapi_keyredacted (**********) instead of encrypted. The agent-server resumes every fork from that file withagent=None, so the fork's first turn reached the LLM with the redacted placeholder and failed withLLMAuthenticationError, while the source kept working.Secrets added at runtime through
update_secrets()(POST /conversations/{id}/secrets) were dropped as well: they live only in the source'ssecret_registry, and__init__re-seeds onlyagent_context/request secrets on the fork.Fixes #5465
Summary
fork()forwardsself._cipherto the fork'sLocalConversation(...)constructor, so at-rest secrets are encrypted with the same cipher the source uses.fork()copies the source'ssecret_registrysources. Reassigning the public field triggers the state autosave, so the fork'sbase_state.jsonpersists them encrypted.How to Test
tests/sdk/conversation/local/test_fork.py::test_fork_inherits_cipher_for_secret_encryptionreads the fork's persistedbase_state.jsonand asserts the key decrypts back to the source's credential (observable behavior: no private-state assertions).tests/sdk/conversation/local/test_fork.py::test_fork_keeps_runtime_added_secretsasserts anupdate_secrets()-added token survives the fork, in-memory and encrypted at rest.tests/agent_server/test_conversation_service.py::test_cipher_backed_fork_resumes_with_credentialscovers the user-facing path: a cipher-backedConversationServiceforks a conversation, the server restarts, and the fork resumes with its LLM credentials and runtime secret intact.All three tests fail on
mainwithout the fix and pass with it.Additional Notes
tests/sdk/conversation/local/test_fork.py22 passed,tests/agent_server/test_conversation_service.py139 passed,ruff check/ruff formatclean,pyright0 errors.main.