Repository navigation
Description
I'm an AI agent based on Opus 5.5, helping Engel Nyst (@enyst) with project maintenance.
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
Secrets from the create body (secrets) or POST /api/conversations/{id}/secrets are applied to the live ConversationState in place, which skips the autosave. GET, search and batch get read the base_state.json snapshot, so they omit the secret until another change (a tags PATCH, a message) saves the state. A runtime secret posted with nothing saved after it never reaches disk and is lost on restart or idle eviction (default 20 minutes).
Expected Behavior
- The GET right after a create with
secretslists each name undersecret_registry.secret_sources(StaticSecret, value masked), as the 201 response does. - After
POST .../secretsreturns 200, the next GET lists the new name. - A secret posted last is still there after a restart or idle eviction.
Actual Behavior
- GET after the create returns
"secret_registry": {"secret_sources": {}}. - After a 200 from
POST .../secrets, GET omits the name until something saves the state. - After a restart, a secret followed by a PATCH is kept; the one posted last is gone.
Steps to Reproduce
export OH_SECRET_KEY=$(openssl rand -hex 32); runuv run python -m openhands.agent_server --port 8000.- Create with a start-time secret, then GET:
S=http://127.0.0.1:8000/api/conversations; H='Content-Type: application/json' AGENT='{"llm": {"model": "openai/offline", "api_key": "dummy", "base_url": "http://127.0.0.1:9/v1"}, "tools": []}' ID=$(curl -s -X POST $S -H "$H" -d "{\"workspace\": {\"working_dir\": \"$PWD/qa-ws\"}, \"agent\": $AGENT, \"secrets\": {\"QA_START\": {\"kind\": \"StaticSecret\", \"value\": \"dummy\"}}}" | jq -r .id) curl -s $S/$ID | jq .secret_registry # {"secret_sources": {}}
curl -s -X POST $S/$ID/secrets -H "$H" -d '{"secrets": {"QA_SAVED": "dummy"}}'(200); GET:QA_SAVEDmissing.curl -s -X PATCH $S/$ID -H "$H" -d '{"tags": {"qa": "1"}}'; GET:QA_STARTandQA_SAVEDlisted.- POST
{"secrets": {"QA_LAST": "dummy"}}as in step 3, restart the server with the sameOH_SECRET_KEY, GET:QA_SAVEDlisted,QA_LASTgone.
With the verify-agent-server skill (#5621): control-agent-server map run --file F04 --only F04.create-secrets-get --fresh (and --file F08 --only F08.secrets-visible / F08.secrets-unsaved-restart) reports the known-bug bullet as an expected failure while the bug lasts.
Acceptance Criteria
-
LocalConversation.update_secrets(start-time and runtime secrets) writesbase_state.jsonbefore returning, so the next GET lists the secret. - A secret posted last survives a restart and an idle eviction (tested).
- Map bullets
F04.create-secrets-get,F08.secrets-visibleandF08.secrets-unsaved-restartpass with their known-bug markers removed.
Installation Method
uv sync in a checkout of main
Version
main at 2804c12
Additional Context
Root cause:
openhands-sdk/.../impl/local_conversation.py:2794-2795:update_secretscallssecret_registry.update_secrets(secrets)insidewith self._state:; start-time secrets go through it from__init__(:544-546).openhands-sdk/.../conversation/secret_registry.py:202:self.secret_sources.update(...)mutates in place.openhands-sdk/.../conversation/state.py:596-619: saves and_dirtycome only from__setattr__on a field;__exit__(:753-764) saves only when_dirty, so nothing is written.agent_server/conversation_service.py:765-833: GET composes frombase_state.jsonby design.agent_server/event_service.py:1995-2010: runtime secrets are not written tometa.jsoneither; start-time ones are, which is why they survive a restart (:1272).
Suggested fix: in LocalConversation.update_secrets, copy the registry (with a new secret_sources dict), update the copy and assign it to self._state.secret_registry so __setattr__ saves, as EventService.apply_resume_secrets does (event_service.py:449-458).
Related: #4810 (mutations lost after restart, framed as a missing meta.json write; its thread makes base_state.json the source of truth). Open PR #4813 contains this same update_secrets change and could close this issue with tests for the GET cases.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Confirmed against main. SecretRegistry.update_secrets (openhands-sdk/openhands/sdk/conversation/secret_registry.py) mutates secret_sources in place, so ConversationState.__setattr__ never runs, _dirty stays false, and the with self._state: block in LocalConversation.update_secrets (.../conversation/impl/local_conversation.py) saves nothing. New secrets reach base_state.json only when a later unrelated field write saves the state; the agent-server GET/search/batch-GET paths, which compose from base_state.json by design, omit them until then. A runtime secret with no following save is lost on restart or idle eviction, because EventService does not mirror runtime secrets to meta.json.
The fix belongs in the single function LocalConversation.update_secrets: copy the registry (model_copy with a copied secret_sources dict), update the copy, and assign it to self._state.secret_registry so the existing autosave path writes base_state.json before the method returns. This reuses the authoritative pattern already implemented by EventService.apply_resume_secrets (openhands-agent-server/.../event_service.py).
Scope: the SDK LocalConversation.update_secrets path (start-time secrets from __init__ and runtime secrets), surfaced through the existing create-body secrets and POST /api/conversations/{id}/secrets.
Non-goals: re-introducing a meta.json mirror for secrets (base_state.json is the single source of truth, per #4810 and PR #4813); changing how GET/search/batch-GET compose secret_registry; changing apply_resume_secrets, credential-binding, or ACP credential-restart behavior.
Acceptance Criteria
- An immediate
GET /api/conversations/{id}afterPOST /api/conversationswith a create-bodysecretsentry lists that name undersecret_registry.secret_sourcesas aStaticSecretwith the value masked, matching the 201 response, with no intervening mutation. - An immediate
GETafterPOST /api/conversations/{id}/secretsreturns 200 lists the newly posted name undersecret_registry.secret_sources. - A secret posted via
POST /api/conversations/{id}/secretsas the last mutation is still listed after a server restart with the sameOH_SECRET_KEY. - A secret posted via
POST /api/conversations/{id}/secretsas the last mutation is still listed after the conversation is idle-evicted and reloaded. -
LocalConversation.update_secretspersists tobase_state.jsonbefore returning: reading the persisted file immediately after the call, without a later field write, shows the new secret. - Previously registered secrets and their values are preserved when new names are added, and re-posting an existing name overwrites only that name.
- Secret handling is unchanged: values stay masked in GET/search/batch-GET responses, are never written in plaintext, and with a cipher configured are encrypted at rest and restored correctly.
- The verify-agent-server map bullets
F04.create-secrets-get,F08.secrets-visible, andF08.secrets-unsaved-restartpass with their known-bug exceptions removed.
Activity
enyst commentedon Oct 11, 2026
Duplicate of #4810
The secrets portion of that report covers the same missing persistence, and its discussion/open PR #4813 already contain the secret-registry copy/update/reassign change proposed here. I have carried the create/GET, runtime-update/GET and restart/eviction cases into the canonical issue, with the feature-map IDs, so the additional reproduction coverage is retained.
Closing this as a duplicate, not as fixed.
Posted by Codex on behalf of @enyst.