OpenHands / OpenHands/software-agent-sdk
[Bug]: AgentContext.current_datetime persists in settings.json, causing stale CURRENT_DATETIME in prompts
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 539
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 137
Description
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
AgentContext.current_datetime defaults to datetime.now().astimezone() (openhands-sdk/openhands/sdk/context/agent_context.py), but the value is also serialized into ~/.openhands/settings.json under agent_settings.agent_context.current_datetime.
Once persisted as a string, FileSettingsStore.load() deserializes it verbatim (the default_factory only fires when the key is absent) and save() full-dumps the object. Result: every settings save re-freezes the timestamp, and every new conversation renders that frozen value in the <CURRENT_DATETIME> prompt block.
Observed 35 days stale in a live install; a no-op PATCH /api/settings re-persisted a fresh "now-at-save-time" value, proving the round-trip.
Expected Behavior
A "now" value is not user configuration and should not round-trip through persisted settings. Each conversation should render a live timestamp, not a value that re-freezes on every settings save.
Actual Behavior
The persisted current_datetime string is re-read verbatim on load and re-written on every settings save, so the injected CURRENT_DATETIME stays stale for all conversations until the key is manually deleted — where it then re-appears on the next save.
Reproduced on a local agent-server install (Agent Canvas 1.16.0, SDK 1.44.0, Python 3.13.12, macOS 26.5.2):
```bash
1) Simulate what FileSettingsStore.load() does with a persisted value:
python -c "from openhands.sdk.context.agent_context import AgentContext; print(AgentContext(current_datetime='2026-07-25T21:34:21.341574Z').get_formatted_datetime())"
-> 2026-07-25T21:34 (stale value used as-is; the default_factory now() only applies when the key is absent)
2) Compare with a fresh context (no persisted key):
python -c "from openhands.sdk.context.agent_context import AgentContext; print(AgentContext().get_formatted_datetime())"
-> live current time
3) On a live install, after any settings save the key is on disk, re-frozen to save-time:
grep current_datetime ~/.openhands/settings.json
"current_datetime": "2026-08-29T21:04:21.388304+01:00"
a no-op PATCH /api/settings re-persists a new save-time value
```
Steps to Reproduce
- Run a local agent-server (e.g. via Agent Canvas).
- Save any setting once (e.g. PATCH /api/settings, or a no-op change). The agent writes agent_settings.agent_context.current_datetime into ~/.openhands/settings.json as an ISO string.
- Observe: the prompt's <CURRENT_DATETIME> is frozen at that save time for all subsequent conversations.
- Repeat any settings save: the timestamp is re-frozen to the new save time (proven by a no-op PATCH re-persisting it).
- Workaround: delete the key from settings.json; it re-appears on the next settings save.
Acceptance Criteria
- A no-op settings save does not change agent_settings.agent_context.current_datetime in settings.json
- A new conversation renders a CURRENT_DATETIME matching live system time
- current_datetime no longer round-trips through PersistedSettings serialization (or is refreshed to now() on load / at conversation start)
Installation Method
Agent Canvas 1.16.0 (npm @openhands/agent-canvas), which runs the agent-server from a uv-managed Python environment. Not a direct pip install.
If you selected "Other", please specify
No response
SDK Version
1.44.0 (latest bundled with Agent Canvas 1.16.0); confirmed unfixed in 1.44.1 source.
Version Confirmation
- I have confirmed this bug exists on the LATEST version of OpenHands SDK
Python Version
3.13.12
Model Name (if applicable)
N/A — this is a prompt/context-persistence bug, not model-specific.
Operating System
MacOS
Logs and Error Messages
No stack trace (silent misbehavior). Evidence:
$ grep current_datetime ~/.openhands/settings.json
current_datetime": "2026-08-29T21:04:21.388304+01:00" # frozen on first settings save of the new stack
after a no-op PATCH /api/settings, the value was re-persisted to the new save time.
Minimal Code Sample
Illustrates the round-trip: a persisted string wins over the now() default.
from openhands.sdk.context.agent_context import AgentContext
default (no key) -> live now:
print(AgentContext().current_datetime)
but a deserialized value (what FileSettingsStore.load() produces from
settings.json) is used verbatim and re-saved on every save():
ctx = AgentContext(current_datetime="2026-07-25T21:34:21.341574Z")
print(ctx.current_datetime) # stale value, no refresh
Screenshots and Additional Context
Suggested fixes (any one):
- Exclude current_datetime from PersistedSettings serialization (drop on dump).
- Refresh to datetime.now() in FileSettingsStore.load() / from_persisted.
- Replace a persisted string with a fresh timestamp at conversation start.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with openhands-sdk/openhands/sdk/context/agent_context.py and trace how FileSettingsStore.load() and save() serialize agent_context.current_datetime. Run the provided Python reproduction and settings-save steps to confirm the persisted value is reused. Done means no-op saves do not round-trip the timestamp and new conversations render live CURRENT_DATETIME values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100