Skip to content

[BugFix] Fix flaky Pendulum spec check and collector preemption ordering test (#3798)#3856

Open
discobot wants to merge 1 commit into
pytorch:mainfrom
discobot:fix/3798-pendulum-angle-wrap
Open

[BugFix] Fix flaky Pendulum spec check and collector preemption ordering test (#3798)#3856
discobot wants to merge 1 commit into
pytorch:mainfrom
discobot:fix/3798-pendulum-angle-wrap

Conversation

@discobot

Copy link
Copy Markdown

Description

The three tracked flakes have two independent causes: a real bug in PendulumEnv, and an over-constrained timing assertion in the collector ordering test.

PendulumEnv lets th drift out of its spec. _step computes new_th = th + new_thdot * dt without wrapping, while the th observation/state spec is Bounded(-pi, pi), so check_env_specs fails whenever the random rollout pushes the angle past the boundary — 8/500 seeds locally. The failure is value-domain, not device-dependent, which is why both the cpu and cuda variants flake. Fixed by wrapping with angle_normalize, which the pendulum tutorial's copy of this env already does; behavior-preserving, since the dynamics see th only through sin and angle_normalize, both 2*pi-periodic. Added a deterministic regression test that drives the pendulum across +pi at max speed and asserts spec containment.

The ordering test over-constrains preemption timing. It asserted slow envs are preempted after exactly one step, but the stop flag is only raised once the fastest workers have reported and workers poll it once per step, so on a loaded runner a slow env can legitimately log a second valid step before stopping (the CI failure shows traj_ids [4, 4, -1, -1, -1]). The _Interruptor itself is sound; only the test needed recalibrating. It now asserts a preempted env stops with a contiguous valid prefix shorter than a full rollout and extends the observation==env_id check to the valid rows of preempted envs (previously skipped). Slow-env step time widened 0.1s -> 0.3s for margin.

Tested: 500-seed check_env_specs sweep goes 8 failures -> 0; TestPendulum passes 100x repeat; the ordering test passes both normally and with an injected 0.25s stop-flag delay that reproduced the CI failure verbatim before the fix, plus 10x repeat under background CPU load.

Motivation and Context

Fixes #3798.

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

…ing test (pytorch#3798)

PendulumEnv._step let th drift past the Bounded(-pi, pi) observation/state spec, so check_env_specs failed for seeds whose random rollout crossed the boundary (8/500 seeds locally). Wrap the angle with angle_normalize like the pendulum tutorial already does; the dynamics only see th through sin and angle_normalize, both 2*pi-periodic, so trajectories are unchanged.

test_multi_sync_data_collector_ordering asserted slow envs are preempted after exactly one step, but the stop flag is only raised once the fastest workers have reported and workers poll it once per step, so on loaded runners a slow env can legitimately log a second valid step (CI showed traj_ids [4, 4, -1, -1, -1]). Assert instead that preempted envs stop with a contiguous valid prefix shorter than a full rollout, check observations over the valid rows for all envs, and widen the slow-env step time to 0.3s for margin.
@pytorch-bot

pytorch-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3856

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 15 Awaiting Approval

As of commit 1d9dfc6 with merge base 26ece89 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla

meta-cla Bot commented Jun 11, 2026

Copy link
Copy Markdown

Hi @discobot!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Jun 11, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Collectors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flaky Tests] 3 flaky test(s) detected

1 participant