Conversation
…added_steps=0 - __getitem__ reconstructed a slice from key.start/key.stop only, silently discarding key.step. tape[::2], tape[::-1], tape[1:5:2] etc. all returned wrong data instead of applying the step. Fixed by passing the slice object through directly. - last_actions() computes tape.steps[-tape.metadata.n_added_steps:]. n_added_steps == 0 is the field's own default and a value __add__ legitimately produces when zero new steps were added, but Python's -0 == 0 makes that slice return the WHOLE list instead of empty. Environment.react()/areact() use this to decide which actions to execute against tools, so a zero-new-steps iteration would silently re-execute every action in the tape's entire history. Fixed with an explicit guard.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related bugs in
tapeagents/core.py'sTapeclass, found via code review (no existing issue).1.
Tape.__getitem__silently ignores a slice'sstepReconstructs the slice from
start/stoponly, droppingkey.stepentirely.tape[::-1],tape[::2],tape[1:5:2]etc. all silently return the wrong steps instead of applying the step or raising. Fixed by passing the slice object through directly (self.steps[key]), which Python already handles correctly.2.
last_actions()re-executes the entire tape history whenn_added_steps == 0n_added_stepsdefaults to0and__add__legitimately produces0when zero new steps were added (see the existingtest_add_empty_tape). Python's-0 == 0, sotape.steps[-0:]returns the entire list instead of an empty slice.This matters because
Environment.react()/areact()(environment.py,remote_environment.py) calllast_actions(tape)to decide which of the agent's latest actions to execute against tools. Withn_added_steps == 0, they'd silently re-execute every action ever taken in the tape's whole history and append duplicate observations, instead of doing nothing.How did you test it
Added 4 tests to
tests/test_core.py:test_getitem_slice_with_step_reversed,test_getitem_slice_with_step_stride,test_last_actions_zero_added_steps_returns_empty,test_last_actions_positive_n_added_steps_unchanged. Confirmed all 4 fail against the pre-fix code (git stash) and pass after.uv run pytest tests/ --ignore-glob="tests/*/*"(the CI'smake test-coretarget): 62 passed.uv run ruff checkclean on both changed files.