Skip to content

[RLlib] Fix broken rllib.connectors docstring examples and make them run - #67759

Merged
pseudo-rnd-thoughts merged 2 commits into
masterfrom
doc-1926-rllib-connectors-example-fixes
Nov 4, 2026
Merged

pseudo-rnd-thoughts merged 2 commits into
masterfrom
doc-1926-rllib-connectors-example-fixes

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

This is a correctness change for RLlib review. It fixes rllib.connectors docstring examples that were wrong, and it converts the last two testcode blocks in rllib/connectors. Those blocks needed an expected-output change, so they stayed out of the syntax-only conversion in #67758. After this PR, no testcode or testoutput remains in rllib/connectors.

Stacked on #67758. Review that PR first. This diff is against its branch.

testcode blocks this PR converts

  • AddObservationsFromEpisodesToBatch and AddNextObservationsFromEpisodesToTrainBatch: each example prints observations drawn from obs_space.sample() and shows no expected output. Each print now shows its output, with ... in place of the random values, such as 1st Episode's last obs is [...]. The next-observations example shows that get_observations([1, 2]) returns a list of float32 arrays. Both now run.

Examples that were wrong

  • AgentConnector: the FrameSkippingAgentConnector sketch called default_dict, which doesn't exist. It also indexed the frame count with ac_data.env_id, but ac_data is the input list, not an item. It now uses collections.defaultdict, and it indexes with d.env_id and d.agent_id. With the fix, the class emits an item on every nth call, and reset() clears the count. The doctest defines the class but doesn't call it. This also fixes the "prosessed" typo in the prose that follows.
  • ActionConnector: the example called np.zeros_like without importing NumPy. It now imports it.
  • AddColumnsFromEpisodesToTrainBatch: the config snippet ended with a stray backtick. It also called config.training(learner_connector=...), which is deprecated in favor of config.learners(learner_connector=...), so it now calls learners(). It stays a render-only python code block, because it sits mid-prose and uses the reader's own config.
  • AddTimeDimToBatchAndZeroPad: a comment said the learner connector uses a sequence length of 4. The dummy module sets max_seq_len to 3, and the checked output is chunked by 3, so the comment now says 3.

Review fixes

  • AgentConnector: the FrameSkippingAgentConnector.reset sketch used del self._frame_count[env_id], which raises KeyError for an env that hasn't stepped yet. It now uses pop(env_id, None). From a gemini-code-assist comment.

Related issues

Stacked on #67758. Related to #66753.

Additional information

Not a duplicate. I searched open PRs for RLlib testcode, doctest, and docstring-example changes, and none touches these docstrings.

Tests run

These ran in a Python 3.12 virtualenv with ray[rllib]==2.59.0, torch, and tensorflow 2.21:

  • ci/ray_ci/doc/run_docstring_examples.py on all 5 changed files: "5 docstring(s) run, 0 failed, 0 skipped, in 5 file(s)."
  • A strict stdlib doctest pass over the same docstrings with ELLIPSIS, which fails on unexpected output the way the RLlib doctest() target does: all 5 pass.
  • ci/ray_ci/doc/check_docstring_only.py --base doc-1926-rllib-connectors-doctests: "5 file(s), docstrings only."
  • pre-commit run --files on all 5 files: all hooks pass.

The PR carries the docstring-only label. Its commit carries an @rtd-build line for the Read the Docs preview.

AI assistance (Claude Code) was used for this PR.

🤖 Generated with Claude Code

@dstrodtman dstrodtman added rllib RLlib related issues docstring-only Skip heavy library tests for Ray API docstring edits. go add ONLY when ready to merge, run all tests labels Nov 3, 2026
@dstrodtman
dstrodtman marked this pull request as ready for review November 3, 2026 20:57
@dstrodtman
dstrodtman requested a review from a team as a code owner November 3, 2026 20:57

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request primarily updates docstrings, doctests, and examples across several RLlib connector files to improve correctness and formatting. Key changes include converting testcode blocks to doctest examples, fixing variable references and typos, and updating outdated configuration APIs. A review comment correctly points out that in the FrameSkippingAgentConnector example, using del on a defaultdict for a non-existent env_id will raise a KeyError, and suggests using .pop(env_id, None) instead to safely remove the key.

... def __init__(self, n):
... self._n = n
... self._frame_count = default_dict(str, default_dict(str, int))
... self._frame_count = defaultdict(lambda: defaultdict(int))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In the FrameSkippingAgentConnector example, the reset method uses del self._frame_count[env_id]. Since self._frame_count is a defaultdict, attempting to delete a non-existent key (e.g., when resetting an environment that hasn't been stepped in yet) will raise a KeyError. Consider using .pop(env_id, None) instead to safely remove the key if it exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in 1d00d04.

Base automatically changed from doc-1926-rllib-connectors-doctests to master November 4, 2026 15:17
dstrodtman and others added 2 commits November 4, 2026 11:24
Convert the last `testcode` blocks in `rllib/connectors`, whose prints of
random observations need expected output, and fix examples that were
wrong: the `FrameSkippingAgentConnector` sketch, the missing NumPy import
in the `ActionConnector` example, the stray backtick and deprecated
`config.training(learner_connector=...)` call in
`AddColumnsFromEpisodesToTrainBatch`, and a wrong sequence length in an
`AddTimeDimToBatchAndZeroPad` comment.

@rtd-build

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
Fixes issues gemini-code-assist found in the converted examples: unused or
duplicated imports and variables, example code that mutates shared state or
drops data, and a typo.

@rtd-build

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman force-pushed the doc-1926-rllib-connectors-example-fixes branch from 1d00d04 to 8c81c1b Compare November 4, 2026 16:26
@pseudo-rnd-thoughts
pseudo-rnd-thoughts enabled auto-merge (squash) November 4, 2026 16:39
@pseudo-rnd-thoughts
pseudo-rnd-thoughts merged commit 19c91e6 into master Nov 4, 2026
7 checks passed
@pseudo-rnd-thoughts
pseudo-rnd-thoughts deleted the doc-1926-rllib-connectors-example-fixes branch November 4, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docstring-only Skip heavy library tests for Ray API docstring edits. go add ONLY when ready to merge, run all tests rllib RLlib related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants