diff --git a/azurelinuxagent/common/event.py b/azurelinuxagent/common/event.py
index 84a439f5..7fc084d9 100644
--- a/azurelinuxagent/common/event.py
+++ b/azurelinuxagent/common/event.py
@@ -254,7 +254,11 @@ __event_logger__ = EventLogger()
 
 
 def elapsed_milliseconds(utc_start):
-    d = datetime.utcnow() - utc_start
+    now = datetime.utcnow()
+    if now < utc_start:
+        return 0
+
+    d = now - utc_start
     return int(((d.days * 24 * 60 * 60 + d.seconds) * 1000) + \
                     (d.microseconds / 1000.0))
 

The ProcessGoalState Duration is Too Large
The Duration telemetry value exceeds the size of an Int64, which does not make sense.  This has been seen in at least two different agent versions (2.1.3 and 2.2.21).
diff --git a/tests/common/test_event.py b/tests/common/test_event.py
index 01bcd7b9..4d9afeff 100644
--- a/tests/common/test_event.py
+++ b/tests/common/test_event.py
@@ -17,14 +17,10 @@
 
 from __future__ import print_function
 
-from datetime import datetime
-
-import azurelinuxagent.common.event as event
-import azurelinuxagent.common.logger as logger
+from datetime import datetime, timedelta
 
 from azurelinuxagent.common.event import add_event, \
-                                    mark_event_status, should_emit_event, \
-                                    WALAEventOperation
+    WALAEventOperation, elapsed_milliseconds
 from azurelinuxagent.common.future import ustr
 from azurelinuxagent.common.version import CURRENT_VERSION
 
@@ -217,3 +213,7 @@ class TestEvent(AgentTestCase):
         with open(last_event) as last_fh:
             last_event_text = last_fh.read()
             self.assertTrue('last event' in last_event_text)
+
+    def test_elapsed_milliseconds(self):
+        utc_start = datetime.utcnow() + timedelta(days=1)
+        self.assertEqual(0, elapsed_milliseconds(utc_start))

pip install -e .
parse_log_pytest
pytest
pytest pyasn1
apt-get update apt-get install -y gcc
3.7
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///croot/attrs_1668696182826/work
certifi @ file:///croot/certifi_1671487769961/work/certifi
flit_core @ file:///opt/conda/conda-bld/flit-core_1644941570762/work/source/flit_core
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1648562407465/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
packaging @ file:///croot/packaging_1671697413597/work
pluggy @ file:///tmp/build/80754af9/pluggy_1648042572264/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyasn1==0.5.1
pytest==7.1.2
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
typing_extensions @ file:///croot/typing_extensions_1669924550328/work
-e git+https://github.com/Azure/WALinuxAgent.git@53a429b06b67031d30351b45e798ec204484b8ef#egg=WALinuxAgent
zipp @ file:///croot/zipp_1672387121353/work

name: WALinuxAgent
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=22.1.0=py37h06a4308_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - flit-core=3.6.0=pyhd3eb1b0_0
  - importlib-metadata=4.11.3=py37h06a4308_0
  - importlib_metadata=4.11.3=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=22.0=py37h06a4308_0
  - pip=22.3.1=py37h06a4308_0
  - pluggy=1.0.0=py37h06a4308_1
  - py=1.11.0=pyhd3eb1b0_0
  - pytest=7.1.2=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py37h06a4308_0
  - typing_extensions=4.4.0=py37h06a4308_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.11.0=py37h06a4308_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - pyasn1==0.5.1
prefix: /opt/conda/envs/WALinuxAgent

tests/common/test_event.py::TestEvent::test_elapsed_milliseconds
tests/common/test_event.py::TestEvent::test_event_status_defaults_to_success tests/common/test_event.py::TestEvent::test_event_status_event_marked tests/common/test_event.py::TestEvent::test_event_status_preserves_state tests/common/test_event.py::TestEvent::test_event_status_records_status tests/common/test_event.py::TestEvent::test_periodic_does_not_emit_if_previously_sent tests/common/test_event.py::TestEvent::test_periodic_emits_after_elapsed_delta tests/common/test_event.py::TestEvent::test_periodic_emits_if_forced tests/common/test_event.py::TestEvent::test_periodic_emits_if_not_previously_sent tests/common/test_event.py::TestEvent::test_periodic_forwards_args tests/common/test_event.py::TestEvent::test_save_event tests/common/test_event.py::TestEvent::test_save_event_cleanup tests/common/test_event.py::TestEvent::test_save_event_rollover tests/common/test_event.py::TestEvent::test_should_emit_event_handles_known_operations tests/common/test_event.py::TestEvent::test_should_emit_event_ignores_unknown_operations
azurelinuxagent/common/event.py
azurelinuxagent/common/event.py