fix(read): support negative offsets counting from end of file#39
Open
T0mSIlver wants to merge 1 commit into
Open
fix(read): support negative offsets counting from end of file#39T0mSIlver wants to merge 1 commit into
T0mSIlver wants to merge 1 commit into
Conversation
The FastContext paper (Appendix E, p. 19) specifies that Read's offset 'Negative values count backwards from the end of the file', but the implementation rejected any offset <= 0 and the schema description dropped the sentence. Resolve negative offsets to a 1-indexed line from the end (clamping over-long negatives to the start), restore the documented behavior in the schema, and add a regression test.
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.
Problem
The FastContext paper specifies that Read's
offsetparameter supports negative values:The implementation does the opposite — it rejects them:
…and the shipped schema description omits the "Negative values count backwards from the end" sentence. So a documented capability (read the last N lines via a negative offset) is both unimplemented and undocumented.
Fix
offsetto a 1-indexed line from the end (len(lines) + offset + 1), clamping over-long negatives to line 1.offset == 0(and booleans) instead of all non-positive values.offsetschema description, matching the paper.tests/test_read_negative_offset.pycovering-2,-1with a limit, over-long negatives (clamp), and0(rejected).Note
This issue was surfaced by cross-checking the implementation against the paper's canonical tool schema (p. 19); it is distinct from the earlier prompt/code mismatches.