Repository navigation
Description
Summary
agent_settings.agent_context.load_memory is exposed as a global user preference, but it is only applied when a conversation is started via agent_profile_id. Conversations started with a concrete agent (or an agent_settings payload) silently lose the setting, so persistent memory is never injected.
There is no error and no warning. <MEMORY_CONTEXT> is simply absent, and <MEMORY> renders its other variant, telling the agent that AGENTS.md is its persistent memory — which reads like a working feature.
Impact
Measured on a self-hosted Agent Canvas deployment with load_memory: true in settings:
- 642 of 767 conversations launched with
load_memory: false - 0 of 767 ever rendered a
<MEMORY_CONTEXT>block - The 24 that did carry
load_memory: truewere ones whose client happened to copy the storedagent_contextverbatim — it worked by accident, not by design
Stored preference vs. what actually launched, for a representative conversation:
| field | settings | as launched |
|---|---|---|
load_memory |
True |
False |
load_user_skills |
False |
True |
load_project_skills |
False |
True |
load_public_skills |
False |
True |
skills |
0 | 57 |
Root cause
StartConversationRequest accepts three mutually-exclusive shapes (openhands-sdk/openhands/sdk/conversation/request.py:280):
agent_profile_id— resolved server-side inconversation_serviceagent— a concrete agent payloadagent_settings— converted toagentby the_populate_agent_from_settingsvalidator (mode="before"), sorequest.agentis already populated before the service sees it
The load_memory stamp only exists on path 1. _resolve_agent_from_profile applies it at openhands-agent-server/openhands/agent_server/conversation_service.py:392:
if load_memory:
context = agent.agent_context or AgentContext()
agent = agent.model_copy(
update={"agent_context": context.model_copy(update={"load_memory": True})}
)and that function is only called at :1480, inside if request.agent_profile_id is not None:. Paths 2 and 3 never touch it.
The helper's own docstring already makes the argument:
An
AgentProfilehas noagent_contextfield, so the preference cannot ride the profile — it is stamped onto the resolved agent below, else a profile-launched conversation would silently ignore the setting.
The same reasoning applies to paths 2 and 3, which are the common cases.
The rest of the chain is fine
For memory to render, all of these must hold. Only step 1 is broken:
- ❌
agent.agent_context.load_memoryisTrueon the agent the conversation starts with - ✅
LocalConversationresolves it —openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:1156 - ✅
load_memory()reads~/.openhands/memory/MEMORY.mdand<workspace>/.openhands/memory/MEMORY.md, returnsNoneif neither has content - ✅
MemoryContextSection.guard()—openhands-sdk/openhands/sdk/context/prompts/sections/dynamic.py:82
Why it is easy to miss
- Nothing is logged when the preference is dropped
MemoryContextSectioncorrectly declines to emit an empty block, so "flag lost" and "no memory recorded yet" look identicalMemorySectionrenders exactly one of two variants; with the flag off the agent is toldAGENTS.mdis its memory, so transcripts look healthyAgentContext.memory_contextis excluded from serialization, so persisted state gives no signal either
Scope
In scope: make the stored load_memory preference apply to every conversation start, regardless of which of the three request shapes was used.
Out of scope: the memory file format, load_memory() itself, the prompt sections, and the AGENTS.md/memory guidance split — all behave correctly once the flag arrives.
Implementation plan
All changes in openhands-agent-server/openhands/agent_server/conversation_service.py.
Because agent_settings is already converted to agent by a validator, request.agent is populated for paths 2 and 3 by the time _start_conversation runs — and for path 1 immediately after the profile branch. So the stamp can happen once, after the branch, covering all three shapes with a single code path.
1. Add a helper next to _append_system_message_suffix (currently line 124).
That function is the existing precedent for this exact agent_context copy-update pattern; put the new one beside it. AgentBase and AgentContext are already imported at module level (lines 52 and 49) — no new imports needed.
def _with_load_memory(agent: AgentBase) -> AgentBase:
"""Stamp the global persistent-memory preference onto an agent.
``load_memory`` is a user-level setting, not part of any agent, profile or
client payload, so it is applied here regardless of how the agent reached
the request.
"""
context = agent.agent_context or AgentContext()
return agent.model_copy(
update={"agent_context": context.model_copy(update={"load_memory": True})}
)2. Hoist the settings read above the profile branch in _start_conversation (~line 1462).
Keep the import function-local — it is inside the branch today, most likely to avoid a circular import; just move it up rather than to module scope.
launched_agent_profile: LaunchedAgentProfile | None = None
from openhands.agent_server.persistence import (
PersistedSettings,
get_settings_store,
)
settings = get_settings_store().load() or PersistedSettings()
# ``ACPAgentSettings.agent_context`` is nullable, hence the guard.
stored_context = settings.agent_settings.agent_context
load_memory = bool(stored_context and stored_context.load_memory)
if request.agent_profile_id is not None:
mcp_config = settings.agent_settings.mcp_config
resolved_agent, launched_agent_profile = await asyncio.to_thread(
_resolve_agent_from_profile,
request.agent_profile_id,
self.cipher,
mcp_config,
)
request = request.model_copy(update={"agent": resolved_agent})
if load_memory and request.agent is not None:
request = request.model_copy(
update={"agent": _with_load_memory(request.agent)}
)3. Remove load_memory from _resolve_agent_from_profile (line 296 signature, lines 307–311 docstring, lines 392–396 body).
The post-branch stamp now covers the profile path too, so the parameter and its inline block become dead. This is a net deletion.
Note request.agent is declared AgentBase = Field(default=cast(AgentBase, None)) — typed non-optional but nullable in practice — hence the is not None guard.
Tests
Existing coverage lives in tests/agent_server/test_agent_profile_conv_start.py:
test_profile_launch_inherits_the_stored_memory_preference(line 709, parametrized over["openhands", "acp"])test_profile_launch_leaves_memory_off_without_the_preference(line 751)
Both drive service.start_conversation(...) through the helper _start_from_profile(...), so they should stay green unchanged — they now exercise the post-branch stamp instead of the in-helper one. If any test calls _resolve_agent_from_profile directly with load_memory=, it needs updating.
Add direct-agent equivalents mirroring the existing pair:
test_direct_agent_launch_inherits_the_stored_memory_preference— persistPersistedSettings(agent_settings=OpenHandsAgentSettings(agent_context=AgentContext(load_memory=True))), start with a concreteagent, assertagent.agent_context.load_memory is Truetest_direct_agent_launch_leaves_memory_off_without_the_preference— same parametrization as the existing negative case (preference-offandstored-settings-without-agent-context), assertFalse- Ideally one case starting from an
agent_settingspayload rather than a concreteagent, to lock in path 3
A new _start_with_agent(...) helper will be needed; _start_from_profile is profile-specific.
Acceptance criteria
- With
load_memory: truestored, a conversation started with a concreteagenthasagent_context.load_memory is True - Same for an
agent_settingspayload - Same for
agent_profile_id(existing behaviour preserved) - With the preference off, or with
agent_contextabsent from stored settings, all three paths leaveload_memoryatFalse - An agent that already sets
load_memory=Trueitself is unaffected -
_resolve_agent_from_profileno longer takes aload_memoryparameter - Existing tests in
tests/agent_server/test_agent_profile_conv_start.pypass unchanged
Verifying end to end
The unit tests above are the reliable check. For a manual pass, examples/01_standalone_sdk/55_persistent_memory.py shows the working shape; the failing case is the same thing started through the agent-server with a concrete agent instead of a profile. Write a non-empty ~/.openhands/memory/MEMORY.md first — with no memory file, load_memory() returns None and the block is legitimately absent regardless of this bug.
Notes for the implementer
ACP agents. request.agent may be an ACPAgent. load_memory is declared acp_compatible: True in its field json_schema_extra, and the existing profile test already parametrizes over acp, so no special-casing is expected. Both start_conversation (line 1298) and start_acp_conversation (line 1303) delegate to _start_conversation (line 1308), so one fix covers both entry points.
Settings load frequency. get_settings_store().load() currently runs only for profile launches; hoisting makes it run on every start. It is a local store read, so the cost should be negligible — but if that is unwelcome, compute load_memory inside each branch instead. Same behaviour, two duplicated lines, no hoist.
Optional companion change
Independent of the above, load_skills_from_agent_server() (openhands-sdk/openhands/sdk/workspace/remote/base.py:912) discards the caller's AgentContext outright:
agent_context = AgentContext(skills=loaded_skills, load_public_skills=False)Beyond load_memory, this also resets load_user_skills, load_project_skills, disabled_skills, marketplace_path, and both message suffixes. Accepting an optional base context and using model_copy(update={"skills": ...}) would make the helper non-destructive.
Worth doing on its own merits, but not a substitute for the fix above — hand-written agent payloads never pass a base context at all, so only the server-side stamp covers every client.
Not related: #4527
For anyone landing here from that PR — #4527 touches the same MemorySection class but is unrelated. It adds one line to _AGENTS_MD_GUIDANCE about locating previous conversation event history under workspace/conversations/; it does not touch the load_memory plumbing, and it will not conflict with this fix (different package).
It does illustrate the blast radius, though: because load_memory almost never arrives, nearly every conversation renders the _AGENTS_MD_GUIDANCE variant, so that line will be seen essentially everywhere — while the two-tier memory guidance it sits opposite stays unreachable in practice.
Actual Behavior
Reproduce on a self-hosted Agent Canvas deployment:
- Set
agent_settings.agent_context.load_memory: truein persisted settings. - Create a non-empty
~/.openhands/memory/MEMORY.mdor<workspace>/.openhands/memory/MEMORY.md. - Start a conversation through the agent-server with a concrete
agentpayload or anagent_settingspayload, then inspect the launched agent context. The relevant server-side regression suite is run with:
uv run pytest tests/agent_server/test_agent_profile_conv_start.py -qObserved: despite the stored preference being true and memory being present, the launched agent has agent_context.load_memory == false; therefore <MEMORY_CONTEXT> is not rendered. Launches via agent_profile_id do not show this failure.
Activity
github-actions commentedon Aug 19, 2026
✅
ready-for-devlabel appliedThis issue meets the readiness criteria and is ready for contribution.
A contributor can now open a PR that links this issue (
Fixes #<number>).This is an automated check — no AI was used to generate this comment.
vnktadithya commentedon Aug 20, 2026
Hi @VascoSch92 — I'd like to work on this. Traced the same root cause: the
load_memorystamp only exists in_resolve_agent_from_profile, which only runs on theagent_profile_idbranch, so the 'agent' andagent_settingsshapes never see it. I'll hoist the settings read above the profile branch in_start_conversation, apply the stamp once via a_with_load_memoryhelper (mirroring_append_system_message_suffix's pattern) after all three shapes resolve torequest.agent, and drop the now-deadload_memoryparam from_resolve_agent_from_profile. Will add the direct-agent andagent_settingsregression tests alongside the existing profile pair. Will drop the PR soon!VascoSch92 commentedon Aug 20, 2026
@vnktadithya Please in the PR attach also a video (or a script in the folder .pr) where you show that the functionality is working properly. Thanks.
vnktadithya commentedon Aug 20, 2026
Sure @VascoSch92. I'll include a script under .pr/ exercising all three launch paths rather than a video, since it's a backend-only change that you can run directly.
vnktadithya commentedon Aug 21, 2026
Opened #4566 — root cause and fix as scoped in the issue: hoisted the settings read above the
agent_profile_idbranch so the stamp applies once, after all three shapes converge onrequest.agent, instead of only on the profile path. Added new test cases for theagentandagent_settingsshapes plus a case confirming an already-Trueagent is left untouched, and a.pr/script verifying it against a real settings store and a realMEMORY.md, not mocks. I'll file theload_skills_from_agent_server()companion change as its own issue rather than including it here.vnktadithya commentedon Aug 27, 2026
@VascoSch92 — checking in after a week, and I also found something that needs your input specifically, not just a review. The
Validate PR descriptioncheck on #4566 is failing with: "Linked issue(s) (#4542) carry neither ready-for-dev nor a pre-rollout creation date." You addedready-for-devto this issue earlier, but the bot removed it again shortly after, and I want you to look into what's tripping the automated check. Not something I can fix from my side — let me know if it just needs the label re-applied or if something in the issue needs adjusting.VascoSch92 commentedon Sep 1, 2026
I think the @vnktadithya It should be good now