Skip to content

fix(tail): avoid preallocating from the requested line count - #319

Open
ikenyal wants to merge 1 commit into
strands-agents:mainfrom
ikenyal:fix/tail-large-line-counts
Open

ikenyal wants to merge 1 commit into
strands-agents:mainfrom
ikenyal:fix/tail-large-line-counts

Conversation

@ikenyal

@ikenyal ikenyal commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

tail -n N allocated a ring buffer from N before reading any input. Very large counts could abort the host process, and usize::MAX overflowed in debug builds. Start the ring buffer empty and let it grow with the input, retaining the existing last-N-lines behavior.

Regression coverage checks huge counts on stdin, files and empty input, plus zero, one, exact-length and longer-than-input counts. The maximum-count test fails on unmodified main.

Related Issues

Fixes #311

Documentation PR

Not needed; this restores existing behavior.

Type of Change

Bug fix

Testing

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Validated on macOS against main after #315 with the full Rust check, workspace doctests, and Node-feature Rust unit tests. Both changes also passed direct CLI checks during initial validation. Existing lint warnings remain.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Documentation changes are not needed: this restores existing shell behavior.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions github-actions Bot added the bug Something isn't working label Nov 18, 2026
@ikenyal
ikenyal marked this pull request as ready for review November 18, 2026 23:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] tail -n with a huge count aborts the process with an allocation failure

1 participant