Skip to content

fix(eval): report trace exit when a local rollout is cancelled - #716

Closed
Monarch-25 wants to merge 1 commit into
hud-evals:mainfrom
Monarch-25:fix/709
Closed

Monarch-25 wants to merge 1 commit into
hud-evals:mainfrom
Monarch-25:fix/709

Conversation

@Monarch-25

@Monarch-25 Monarch-25 commented Oct 13, 2026 •

Copy link
Copy Markdown

Fixes #709.

Problem

When a local rollout (LocalRuntime, SubprocessRuntime, DockerRuntime, Runtime(url), ...) is cancelled, the except asyncio.CancelledError handler in hud/eval/run.py tore down the client and re-raised without calling trace_exit(run). POST /trace/{id}/enter was already sent when the rollout started, so the platform never heard that the trace ended.

Fix

In the cancellation path, before re-raising:

  • set the trace status to cancelled (error when the stop reason is timeout, mirroring Run.__aexit__), synthesizing a cancelled Run when the rollout was cancelled before it went live;
  • bind run.trace.trace_id (the normal path only binds receipt fields below the handlers, and trace_exit skips runs without an id);
  • report the exit under a 2s timeout (shielded, matching the existing client.cancel() bound) so Ctrl-C stays responsive.

Tests

  • test_cancelled_rollout_reports_trace_exit_as_cancelled: cancel mid-run, assert one enter yields one exit with matching id and cancelled status.
  • test_cancelled_rollout_before_launch_still_reports_trace_exit: cancel during provisioning, assert the exit is still reported.
  • Both fail on main (no exit reported) and pass with the fix.
  • test_rollout.py + test_job.py: 59 passed. ruff format --check / ruff check: clean. ty check: no new diagnostics. Full suite: only the 11 pre-existing test_docker_provider.py failures, identical on main.

Note

Medium Risk
Changes eval rollout teardown and platform trace lifecycle on cancellation; bounded trace_exit limits hang risk but mis-reporting could affect trace state in production.

Overview
Fixes orphaned traces when a local rollout is cancelled (e.g. Ctrl-C): after trace_enter, cancellation used to tear down the client and re-raise without notifying the platform that the trace ended.

The asyncio.CancelledError path in rollout now marks the trace cancelled (or error when stop_reason is timeout, matching Run.__aexit__), synthesizes a Run if cancel happens before the run is live, binds trace.trace_id, and calls trace_exit under a 2s shielded timeout before the existing cancel/abort cleanup.

New tests cover cancel mid-agent-loop and cancel during provisioning; both assert one enter pairs with one exit and cancelled status.

Reviewed by Cursor Bugbot for commit 4255ca7. Bugbot is set up for automated code reviews on this repo. Configure here.

The CancelledError handler in rollout() tore down the client and
re-raised without calling trace_exit(), leaving every entered trace
open on the platform. Set the cancelled status (synthesizing a run
when cancelled before launch), bind the trace id, and report the exit
under a short timeout before propagating the cancellation.

Fixes hud-evals#709.
@Monarch-25

Copy link
Copy Markdown
Author

Can someone mention if there is some channel to contact maintainers for PR? Couldn't find in the guidelines

@jdchawla29

Copy link
Copy Markdown
Collaborator

Superseded or resolved by #700.

@jdchawla29 jdchawla29 closed this Oct 27, 2026
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.

Cancelled local rollouts never report a trace exit

2 participants