From 38ce8a4d16ac1ae8a700e7fa347bd97633d2f1c1 Mon Sep 17 00:00:00 2001 From: ethernet Date: Fri, 2 Oct 2026 15:43:10 -0400 Subject: [PATCH] test(observability): cut the direct-runtime test's daily package at task close, not by race The daily package is cut by the first export that runs, and the export runs on the `hermes-shared-metrics-flush` worker. The test asserted the exact metric set of a package cut after the task closed but before the session-summary rows (`hermes.context_peak.count`, `hermes.session.count`) were emitted, and read the outbox without waiting for the worker. Which side of the session close the worker landed on was scheduler luck. Delaying the worker (sleep in `_flush_and_export`): 0.01s and up cut the package after the session close and the assertion failed on the extra metrics; with no wait at all the outbox could still be empty. Join the worker the task close scheduled before the session closes. The package is then always the task's, and the read no longer races it. --- tests/hermes_cli/test_relay_shared_metrics_runtime.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/hermes_cli/test_relay_shared_metrics_runtime.py b/tests/hermes_cli/test_relay_shared_metrics_runtime.py index a0eca6cad4..c7241bb681 100644 --- a/tests/hermes_cli/test_relay_shared_metrics_runtime.py +++ b/tests/hermes_cli/test_relay_shared_metrics_runtime.py @@ -349,6 +349,10 @@ def test_direct_runtime_records_without_enabling_a_plugin(direct_runtime, tmp_pa interrupted=False, turn_exit_reason="text_response(stop)", ) + # The daily package is cut by the first export that runs. Let the one the task + # close scheduled finish before the session closes, so the package holds exactly the + # task's metrics instead of racing the session-summary rows. + _join_export_workers() lifecycle.finalize_session(session_id=base["session_id"]) starts = [event for event in direct_runtime.events if event[0] == "llm.call"]