Skip to content

fix(git): announce the cap on the filtered git log path - #4152

Merged
KuSh merged 1 commit into
rtk-ai:developfrom
KuSh:fix/4117-followup-filtered-log-cap
Oct 31, 2026
Merged

KuSh merged 1 commit into
rtk-ai:developfrom
KuSh:fix/4117-followup-filtered-log-cap

Conversation

@KuSh

@KuSh KuSh commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

What this changes

rtk git log without a raw-shape flag injects a limit of its own and said nothing about it: -10 by default, and -50 with the first 50 lines kept under --oneline, --pretty or --format. #4117 added the notice to the raw-shape path; this adds it to the filtered path, which most invocations take.

What a user newly sees

  • rtk git log on 80 commits: stderr gets [rtk] capped at 10 commits; pass -n <count> for more. --oneline says 50. Stdout is unchanged.
  • A format of several lines per commit that the 50-line cap cut, rtk git log --pretty=full on 25 commits: stdout ends with [+N hidden: rtk recall <id>], and rtk recall <id> returns those lines as shown, cut at 80 columns. With [retriever] mode = "tee" the hint is [see remaining: tail -n +51 <path>]. When the history goes on past the 50 commits git was asked for, stderr also gets capped at 50 commits. When git's own output costs fewer tokens than the lines shown with the hint, stdout is git's output instead, and the commit notice still goes to stderr when it is owed. If recall is off or the store cannot be written, stderr says capped at 50 lines instead.
  • Nothing when the cap took nothing away, or the user gave a count, or git refused the walk.
  • rtk git log HEAD~20..HEAD announces, since this path caps a range too.

How

With RTK's own format, git is asked for one commit more than is shown and each commit opens with a marker, so the run answers whether the cap cut and costs no second walk. --oneline does the same with its 51st line, one line to a commit. A flag that adds lines under each commit takes it out of that: the ones known from the arguments (--notes, --stat-count, -L and the like) ask git for 50 straight away, and any other one shows in the run, which is then set aside and asked for again with 50.

The other shapes ask git through walk_exceeds_limit: a user format where the printed lines leave the question open, a multi-line format whose cut was stored, --reverse, --boundary, --log-size and --output=<file> always. So does a run that prints text of its own ahead of a commit, because that text would stay in the walk shown: --show-signature, --show-linear-break, and log.showSignature given with -c or in the environment.

Known limits

Left for a follow-up:

  • log.showSignature set only in a git config file is not seen. If the commit past the cap is signed, the raw fallback prints its verdict and the savings ledger counts it.
  • -z with --oneline or a one-line format prints the walk on one line and is not announced.
  • On the filtered path a run that exits nonzero, such as --check on a history with whitespace errors, prints nothing on stdout, as on develop. rtk git log / git show print nothing when git exits non-zero with output on stdout #4547 tracks it.
  • Under --graph, a -L context line that holds a full commit opening behind the rails is read as a commit. Outside --graph it is content.

Cost

Release builds, hyperfine -N, a shallow clone of this repository with 2409 commits:

command develop this branch
rtk git log 5.4 ms 5.5 ms
rtk git log --reverse 5.5 ms 6.5 ms
rtk git log --oneline 5.8 ms 5.9 ms
rtk git log --oneline -G 'fn ' 72.9 ms 73.7 ms
rtk git log --pretty=full 5.9 ms 11.7 ms
rtk git log --format='%h %s%n%b' -G 'fn ' 73.3 ms 147.6 ms

The default format and --oneline start one git process, as develop does. A multi-line format the cap cuts starts a second one once the cut is stored, to ask whether commits lie past the 50 git returned, and under a diff filter such as -G that second walk scans the history again. With RTK's own format, the probe is a second process for --reverse, --boundary, --log-size, --output=<file>, --show-signature, --show-linear-break and log.showSignature given with -c or in the environment. Under --oneline, a flag that adds lines of its own costs the probe too, and one RTK cannot see in the arguments a second run of the walk before it.

Tests

tests/git_log_cap_notice_test.rs and unit tests in git_cmd.rs: the notice at the cap and one past it, the number of git walks each shape costs, the commit notice beside a stored hint in recall and tee mode, git's own output where the hint would cost more than the lines it hides, boundary walks, the line bound, recall and tee round trips, signed commits, the linear-break bar, a graph over a criss-cross merge. Against develop over 59 cases, stdout is identical except for the recall hint, or git's own output where the hint would cost more, and stderr differs only by the notice on a walk that exits 0.

🤖 Generated with Claude Code

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working cli git labels Sep 20, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes rtk's filtered git log path so it announces (via stderr) when RTK's injected limit (10 commits by default, 50 lines under a format flag) cut off the walk, mirroring the notice already added for the raw-shape path in #4117. It also fixes --exit-code runs that previously printed nothing, and adjusts the walk_exceeds_limit probe to account for --no-merges and --skip so the cap notice fires accurately.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@aeppling aeppling 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.

The goal is right, and the commit-cap notice is correct. Fuzzed against develop on log/diff/show/pipe: no stdout or exit-code regressions, and the notices match what git selects.

Blocking: on multi-line formats the cap is in lines, and RTK already holds the output it drops. git log --pretty=full makes one git call that returns 566 lines (50 commits), then shows 50 lines (3 commits, the last cut mid-body). The -n hint sends the agent back to git, and it re-reads output it already saw: 550 lines, now including merges, because a user-given limit drops the injected --no-merges. That case should go through the shared recall helper, force_tee_tail_hint, which stores into the sqlite recall store by default ([+N hidden: rtk recall …], as git stash show does). Keep the -n notice only as the fallback when recall is disabled.

#4148 lands first, so this needs a rebase on it: drop the duplicated --skip hunk.

@KuSh

KuSh commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Both points are in 040ba7e97:

  • A format of several lines per commit is now cut through force_tee_tail_hint: the hidden lines are stored as shown and named by [+N hidden: rtk recall <id>] ([see remaining: tail -n +51 <path>] in tee mode), so rtk git log --pretty=full no longer sends the agent back to git. The -n notice is kept only as the fallback when recall cannot store them. When that hint is shown it is the whole announcement: commits past the 50 asked of git are not announced on top of it.
  • Rebased on develop after fix(git): only announce the log cap on a walk git ran, and count it right #4148: the duplicated --skip hunk is gone.

CI is green apart from a_clustered_h_is_answered_by_git_once on the Windows gnu job, which runs git 2.56. That one fails on develop too and is fixed by #4578.

@KuSh
KuSh requested a review from aeppling October 15, 2026 17:44
@KuSh
KuSh force-pushed the fix/4117-followup-filtered-log-cap branch 2 times, most recently from 2f135bf to 407a34d Compare October 16, 2026 20:38

@aeppling aeppling 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.

Both points from the last round are in, thanks.

Blocking: when the 50-line cut and the 50-commit cap both hit, only the recall hint shows. On git log --format='%h %s%n%b' v0.49.0..v0.50.0 (182 commits), 3 are shown, 47 are recallable, and nothing mentions the other 132. filtered_log_cut returns before its probe in that branch; running the probe there too and printing the commit notice beside the hint would close it.

Nit: under --oneline, asking git for 51 commits would avoid the second git process, which doubles --oneline -G here.

@KuSh
KuSh force-pushed the fix/4117-followup-filtered-log-cap branch from 407a34d to 48e9d11 Compare October 21, 2026 12:46
@KuSh

KuSh commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks @aeppling. Both are in 48e9d116a:

  • When the 50-line cut is stored, in recall or tee mode, and the history goes on past the 50 commits git returned, stderr also gets [rtk] capped at 50 commits; pass -n <count> for more beside the hint. Your --format='%h %s%n%b' v0.49.0..v0.50.0 now ends with [+644 hidden: rtk recall <id>] and that notice. The lines cannot say where the commits end, so git is asked, and only once the cut is stored: with recall off, the lines notice already sends the agent back to git with -n. That walk is the cost, --format='%h %s%n%b' -G 'fn ' going from 73 to 148 ms here.
  • Under --oneline, git is asked for 51 commits and the 51st line answers, so --oneline -G 'fn ' is back to develop's time, 73.7 ms against 72.9. A flag that adds lines under each commit takes it off that path: --notes, --stat-count, -L and the like are known from the arguments and keep 50 and the probe, and any other one shows in the run, which is then run again for 50 so the extra commit never reaches recall or the ledger.

The PR body has the updated cost table and drops the limit this closes.

@aeppling aeppling 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.

Thanks, both are in: v0.49.0..v0.50.0 shows the hint and the commit notice, and --oneline -G is back to develop's time.

Blocking: the recall hint is added after never_worse, so stdout can exceed raw when the hidden lines are shorter than the hint. In a test repo, --pretty=full on 9 commits gives 929 bytes against 926, and --format=%h%n%h HEAD~26..HEAD gives 441 against 416. Send the hint case through emit_guarded, as CONTRIBUTING asks; raw then wins and matches git's output. Leave the no-hint path as it is (moving it changes stdout against develop), keep the commit notice when raw wins, and add a test, since the current ones pass either way.

`rtk git log` without a raw-shape flag injects a limit of its own, 10
commits by default and 50 lines under a format, and said nothing about it,
so a walk of 80 commits read as a history of 10.

Announce it as the raw-shape path does: a notice on stderr when the cap cut
commits. A format of several lines per commit is cut by lines instead: the
hidden lines are stored as shown, cut at 80 columns, and named by `[+N hidden:
rtk recall <id>]` (`[see remaining: tail -n +51 <path>]` in tee mode). When
the history goes on past the 50 commits git was asked for, the commit notice
is printed beside the hint. The hint is weighed with the lines it closes,
so when git's own output costs fewer tokens than the lines shown with the
hint, git's output is printed instead. The lines notice is the fallback when recall cannot store
them.

With RTK's own format, git is asked for one commit more than is shown and
the format opens each commit, so the run answers whether the cap cut and
costs no second walk. `--oneline` does the same with one line to a commit,
unless a flag adds lines of its own, which the arguments or the run show.
Another user format answers from its own lines where they settle it. The
rest ask git through `walk_exceeds_limit`: `--reverse`, `--boundary`,
`--log-size`, `--output=<file>`, and a run that prints text of its own
ahead of a commit (`--show-signature`, `--show-linear-break`,
`log.showSignature` given with `-c` or in the environment), which would
otherwise stay in the walk shown. A walk git refused owes nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@KuSh
KuSh force-pushed the fix/4117-followup-filtered-log-cap branch from 48e9d11 to 1973c4a Compare October 30, 2026 18:07
@KuSh

KuSh commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. In 1973c4a73 the hint case goes through emit_guarded, so when git's own output costs fewer tokens than the lines shown with the hint, stdout is git's output. The commit notice is decided before the guard and still goes to stderr when it is owed. The no-hint path is unchanged.

a_cut_that_hides_less_than_its_hint_prints_what_git_printed compares stdout with git log -50 --no-merges byte for byte on --pretty=full over 9 commits, --format=%h%n%h over 26, and --format=%h%n%-b over 60 commits, where the notice is owed. Each of the three fails with the hint appended as before. a_blank_last_shown_line_stays_above_the_hint keeps a blank 50th line above the hint, which emit_guarded would otherwise read as the terminator of the 49th.

One point on the 9-commit case: the guard weighs tokens and a tie keeps the composed form, so where the two sides round to the same count the hint stays. With the test repo's t <[email protected]> identity, plain --pretty=full on 9 commits gives 1035 bytes against 1034, both 259 tokens, so the test gives the oldest commit a one-letter subject to put the two a token apart.

@aeppling aeppling 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.

lgtm thanks

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

Labels

bug Something isn't working cli git

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants