fix(cli): mofa agent logs --limit returns most-recent N lines (tail semantics)#1649
Open
SH20RAJ wants to merge 1 commit into
Open
fix(cli): mofa agent logs --limit returns most-recent N lines (tail semantics)#1649SH20RAJ wants to merge 1 commit into
SH20RAJ wants to merge 1 commit into
Conversation
Fixes mofa-org#1298 The old display_log_file broke from the while loop as soon as count >= max, returning the earliest N matching lines. Users expect tail semantics. Remove the early break. Collect all filtered lines, then slice the last max entries with saturating_sub. Added test_logs_limit_returns_most_recent_lines.
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.
Summary
Fixes #1298.
mofa agent logs <id> --limit Nwas returning the first N matchinglines instead of the most-recent N lines, making it behave like
head -n Ninstead of the expectedtail -n N.Root Cause
display_log_fileused an early-break pattern:This exits the read loop after
maxmatches, so only the oldest lineswere ever returned.
Fix
Remove the early break. Collect all filtered lines into a
Vec,then compute the tail with:
This is a simple O(file_size) solution: the
Vecis already being builtanyway, so there is no extra pass over the data.
Tests
Added
test_logs_limit_returns_most_recent_lineswhich writes fivenumbered lines and asserts that
--limit 2yields["line-4", "line-5"]and not
["line-1", "line-2"].Checklist
cargo check -p mofa-cli)