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.
This commit is contained in:
ethernet
2026-10-02 15:43:10 -04:00
parent 4e3fcd5cd7
commit 38ce8a4d16

View File

@@ -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"]