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
With two agent servers on one conversations directory, the second reads every meta.json once at startup. Its first load of a conversation (takeover from a dead owner, or a claim after the owner released it) starts from that copy and writes it back to meta.json. A title or updated_at the owner stored in between is lost; per the code, tags and stored secrets revert the same way. Failover and rolling restarts on shared storage hit this.
Expected Behavior
After the second server loads the conversation, meta.json and its GET /api/conversations/{id} keep the owner's last title (after B) and updated_at.
Actual Behavior
The load claims the lease (generation 2 after a SIGKILL of the owner, 1 after a graceful stop), but meta.json is rewritten with the second server's startup title (before B) and older updated_at, and its GET returns before B.
Steps to Reproduce
- In a checkout of main after
uv sync:export SHARED=$(mktemp -d) OH_SECRET_KEY=$(openssl rand -hex 32) export OH_CONVERSATIONS_PATH=$SHARED/conversations .venv/bin/python -m openhands.agent_server --port 8001 & A=$!
- Create a conversation on A (never run) and title it:
H='Content-Type: application/json' ID=$(curl -s -X POST localhost:8001/api/conversations -H "$H" -d '{"agent_settings":{"agent_kind":"openhands","llm":{"model":"openai/x","api_key":"x","base_url":"http://127.0.0.1:9/v1"},"tools":[]},"workspace":{"kind":"LocalWorkspace","working_dir":"'"$SHARED"'/ws"},"autotitle":false}' | jq -r .id) curl -s -X PATCH localhost:8001/api/conversations/$ID -H "$H" -d '{"title":"before B"}'
- Start B on the same directory:
.venv/bin/python -m openhands.agent_server --port 8002 & - Rename on A: PATCH
{"title":"after B"}as above returns{"success": true};jq .title $OH_CONVERSATIONS_PATH/${ID//-/}/meta.jsonprints"after B". - Stop A:
kill $A(graceful) orkill -9 $A(takeover). - Load on B:
curl -s localhost:8002/api/conversations/$ID/events/countreturns 200. jq '{title, updated_at}' $OH_CONVERSATIONS_PATH/${ID//-/}/meta.jsonandcurl -s localhost:8002/api/conversations/$ID | jq .titleboth showbefore B.
With the verify-agent-server skill (#5621): control-agent-server map run --file F31 --only F31.takeover-keeps-metadata --fresh reports the known-bug bullet as an expected failure while the bug lasts.
Acceptance Criteria
- Loading a persisted conversation reads
meta.jsonfrom disk after the lease claim, so the previous owner's title, tags, secrets andupdated_atsurvive inmeta.jsonand the loading server's GET. - A regression test in
tests/agent_server: a secondConversationServicestarted before the first one renames the conversation keeps the newer title after loading it. - The
F31.takeover-keeps-metadatamap bullet passes with its# bugmarkers removed.
Installation Method
uv sync in a checkout of main
Version
main at 2804c12
Additional Context
Root cause (under openhands-agent-server/openhands/agent_server/):
__aenter__reads the catalog once (conversation_service.py:2025,_load_catalog_sync:544); later onlyexecution_statusis refreshed (:843), andrefresh_persisted_conversation(:924) is only called by the Docker runtime._get_or_load_event_service_lockedpasses that snapshot,record.stored, to_start_event_service(:1068-1070)._start_event_servicebuilds theEventServicefrom it (:2272);EventService.start()claims the lease (event_service.py:1160), thensave_meta()(conversation_service.py:2320) writes the stale copy over the newermeta.json, and the catalog record is replaced with it (:2339-2342).EventService.load_meta()(event_service.py:279) is never called.
Suggested fix: when resuming (not is_new_conversation), re-read meta.json after the lease claim and before any write, e.g. call load_meta() in EventService.start() right after self._lease.claim() when meta.json exists, and have _start_event_service use event_service.stored afterwards (the autotitle check at :2296 reads the stale argument). Reading before the claim races the outgoing owner's last write.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Real bug in the shared-storage load path, scoped to the agent-server package:
ConversationService.__aenter__ snapshots every meta.json once at startup
(conversation_service.py:2025 → _load_catalog_sync :544); on a later load
_get_or_load_event_service_locked passes that snapshot to _start_event_service
(:1068–1070), which builds the EventService from it (:2272). EventService.start()
claims the lease (event_service.py:1160) and _start_event_service then writes the
stale copy back with save_meta() (:2320) and replaces the catalog record (:2339–2342).
The previous owner's title, tags, stored secrets and updated_at are lost.
EventService.load_meta() (event_service.py:279) is the existing reader for
meta.json and is not on this path.
Scope: on resume (base_state.json exists, i.e. not is_new_conversation), re-read
meta.json from disk after the lease claim and before any write, and make the catalog
record, the subsequent save_meta(), the autotitle decision, and the composed
ConversationInfo all derive from that re-read copy. load_meta() and save_meta()
are the authoritative read/write mechanisms and should be reused rather than duplicated.
Non-goals: no change to lease semantics or RefreshPersistedConversation/Docker-runtime
behavior; no meta.json schema, persisted-settings version, or REST contract change; no
new public Python/REST API; no redesign of the catalog cache or a speculative cross-server
merge strategy. This issue should not prescribe the implementation beyond reusing those
existing helpers; the suggested fix is a lead, not a requirement.
Acceptance Criteria
- After a second agent-server process claims a persisted conversation whose owner last wrote newer metadata (title, tags, stored secret,
updated_at), the load leaves the owner's values intact inmeta.jsonand in the loading server'sGET /api/conversations/{id}. With the Steps to Reproduce, bothjq .title $OH_CONVERSATIONS_PATH/${ID//-/}/meta.jsonand the GET reportafter B(for both graceful stop and SIGKILL takeover). - The re-read happens after the lease claim and before the first write: for a resume the
EventServicestarts from themeta.jsonread on disk, not from theStoredConversationcaptured atConversationService.__aenter__. The catalog record stored back, the autotitle check (stored.autotitle and stored.title is None), the subsequentsave_meta(), and the returnedConversationInfoall reflect the re-read copy. - A new conversation (
base_state.jsonabsent) is unchanged: it does not re-read a pre-existingmeta.jsonand still persists the creating request's metadata. - Regression test in
tests/agent_server: a secondConversationServiceis constructed (loading the catalog) before a first service renames a conversation viaupdate_conversation; after the first service is stopped and the second loads that conversation, the newer title (andupdated_at) survive in both the on-diskmeta.jsonand the returnedConversationInfo. The test drives the realConversationService/EventServiceload path, not mocks. - Failure and edge cases: when the conversation is held by a live owner, the second server does not load it and leaves
meta.jsonuntouched; and a conversation whosemeta.jsoncannot be read/parsed fails the load through the existing startup-failure cleanup rather than overwriting it with the stale startup copy. - Compatibility and lifecycle: no change to the
meta.jsonschema, persisted-settings versions, or REST request/response shapes; secrets continue through the existingopenhands.sdk.utils.pydantic_secrets+ cipher path with no new redaction and no plaintext in logs; existing start-failure rollback/close behavior is preserved. - Validation:
uv run pytest tests/agent_serverpasses including the new regression test, and the reproduction in Steps to Reproduce showsafter Bin bothmeta.jsonand the GET on the fix revision. Once Add verify-agent-server: an executable feature map and control CLI for the Agent Server API #5621 is onmainand theverify-agent-serverskill is available,control-agent-server map run --file F31 --only F31.takeover-keeps-metadata --freshpasses after removing that bullet's# bugmarkers.
Activity
Jaxon1216 commentedon Oct 13, 2026
I’m working on a focused fix for this. I’ll reload persisted metadata after acquiring the lease, keep the catalog and returned conversation info aligned with that metadata, and cover graceful release plus forced takeover with a real two-server reproduction and regression tests. AI-assisted development.
enyst commentedon Oct 13, 2026
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Going through the triage acceptance criteria above, with how #5777 handles each one. That PR is an independent fix, written at the maintainer's request for comparison with the open contributor PR, without reading it.
EventService.start()calls the existingload_meta()right afterself._lease.claim()and before_scrub_persisted_credentials()(the first possible write) on every resume. The catalog record,save_meta(), the autotitle check (stored.autotitle and stored.title is None), the telemetry context and the returnedConversationInfoall use the re-read copy._start_event_serviceis not called withis_new_conversation=True, so creation and forks still persist the request's metadata. Nometa.jsonfile is re-read for them.mainboth showbefore B; on the PR both showafter B, with the owner'supdated_atinmeta.jsonand the GET. The full output is in the PR.ConversationLeaseHeldErrorbefore any read or write, someta.jsonis untouched.meta.json. The load now fails through the existing startup-failure cleanup (close, nosave_meta()) and leaves the file as it was. Onmainit was overwritten with the startup copy; a regression test covers this. Ameta.jsonthat is missing at load time keeps the catalog copy, which is the current behaviour.load_meta()/save_meta().start_conversationon an existing id used to inject the ChatGPT auth fallback by patching the catalog record before loading. A plain re-read would have dropped it. It is now passed explicitly asresume_secretsand layered over the re-read secrets, the same precedence as before.ConversationServicestarted before the owner'supdate_conversation) passes.F31.takeover-keeps-metadatashowedxfailtwice onmainandxpasstwice on the PR, and it passes with its# bugmarkers removed in the same PR. Add verify-agent-server: an executable feature map and control CLI for the Agent Server API #5621 is merged, so the map bullet is updated there.No point here seems to need a maintainer decision beyond choosing between the two PRs.
Generated by Claude Code