Skip to content

fix(agent_context): use utc_now() for current_datetime default#3544

Open
Oxygen56 wants to merge 1 commit into
OpenHands:mainfrom
Oxygen56:fix/use-utc-now-for-agent-context
Open

fix(agent_context): use utc_now() for current_datetime default#3544
Oxygen56 wants to merge 1 commit into
OpenHands:mainfrom
Oxygen56:fix/use-utc-now-for-agent-context

Conversation

@Oxygen56

@Oxygen56 Oxygen56 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

HUMAN:

Fixed the current_datetime default by replacing datetime.now().astimezone() with utc_now(). Verified by importing the module and checking the default factory output.

  • A human has tested these changes.

AGENT:

Why

datetime.now().astimezone() uses local timezone which is non-deterministic for LLM agents running across different hosts. UTC is the standard for server-side timestamps.

Summary

  • Replace datetime.now().astimezone() with utc_now() helper in agent_context.py
  • UTC output is unambiguous and includes +00:00 offset via isoformat()

Issue Number

Fixes #3438

How to Test

from openhands.sdk.context.agent_context import AgentContext
ctx = AgentContext()
print(ctx.current_datetime)  # Should show UTC time with +00:00

Replace datetime.now().astimezone() with the SDK's own utc_now()
helper for consistency. UTC is unambiguous for LLM agents and the
.isoformat() output includes the timezone offset.

The staleness issue (frozen at AgentContext construction time) is
noted but requires broader lifecycle changes. Tracked in OpenHands#3438.

Fixes OpenHands#3438
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @Oxygen56, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was created by an AI agent (OpenHands) on behalf of the user.

@VascoSch92

Copy link
Copy Markdown
Member

Hey @Oxygen56
thanks for the PR, but I think this fix was already merged...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Injected system-prompt datetime is timezone-ambiguous and stale (naive local time, frozen at AgentContext construction)

3 participants