Skip to content

rtk diff reports "Files are identical" (exit 0) when changed lines share any word #2811

Closed

Description

@mattmarano

Summary

rtk diff FILE1 FILE2 prints [ok] Files are identical and exits 0 for files that
differ, whenever the changed line pairs share at least one word. Zero-overlap line
changes render correctly; any word overlap between the old and new line silently
suppresses the change — apparently classified as a "modified" pair and then dropped
entirely from both the summary counts and the rendered output.

This is dangerous for the tool's primary audience (AI agents): an agent that runs
rtk diff to verify a deploy or compare configs gets a confident wrong answer with a
clean exit code. We hit it comparing two agent-definition files whose only difference
was one frontmatter line — rtk diff said identical; /usr/bin/diff showed the change.

Reproduction (rtk 0.42.4, macOS arm64, Homebrew bottle)

printf 'alpha beta\n' > /tmp/v1.txt
printf 'alpha zzzz\n' > /tmp/v2.txt

rtk diff /tmp/v1.txt /tmp/v2.txt
# [ok] Files are identical      <- WRONG
# exit 0

diff /tmp/v1.txt /tmp/v2.txt
# 1c1
# < alpha beta
# > alpha zzzz
# exit 1

Boundary matrix (all verified)

old line new line shared words rtk diff result
alpha beta alpha zzzz 1 of 2 "identical" (WRONG)
alpha beta gamma delta alpha beta XXXXX delta 3 of 4 "identical" (WRONG)
alpha beta gamma delta alpha beta gamma 3 (suffix trim) "identical" (WRONG)
alpha beta gamma delta XXXXX beta gamma delta 3 of 4 "identical" (WRONG)
alpha beta gggg zzzz 0 correct +/- output
aaaa zzzz 0 correct +/- output
old3 new3 0 correct +/- output

Multi-line context doesn't matter: a 36-line file with one word-overlapping changed
line is also reported identical. -v/-vv add the "Comparing:" banner but still say
identical.

Suspected mechanism: the word-similarity pairing classifies overlapping line pairs as
"modified" (the summary header prints ~0 modified in the working cases, suggesting a
modified bucket exists), but modified pairs are then omitted from output AND counted as
zero — when a diff consists only of such pairs, the tool concludes "identical".

Also: exit code

Even when rtk diff renders changes correctly, it exits 0 (real diff exits 1 on
difference). Scripts using rtk diff a b && echo same misbehave. Notably rtk diff -q
DOES exit 1 correctly — only the full-output path is wrong.

Workarounds

  • rtk diff -q — correct differ/identical verdict + exit code (but no hunk output)
  • rtk proxy diff … — bypasses filtering, real diff semantics

Environment

  • rtk 0.42.4 (Homebrew bottle, homebrew/core, arm64, macOS 26 / Darwin 25.3.0)
  • Found via Claude Code hook usage (diff auto-rewritten to rtk diff), where the
    false "identical" briefly masked a real config divergence.

Activity

  1. pszymkowiak commented on Jul 4, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 95%

    Summary

    rtk diff falsely reports 'Files are identical' (and exits 0) whenever changed line pairs share any word, due to word-similarity pairing misclassifying them as 'modified' and dropping them from both counts and output — fix the modified-pair handling in the diff renderer/summary and the full-output exit code.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.


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

  2. AllanCardosobr commented on Jul 10, 2026

    @AllanCardosobr

    Confirmed on rtk 0.36.0 (macOS, Darwin 25.3.0), so this predates the 0.42.x reports — long-standing behavior rather than a recent regression.

    $ printf 'x = 1\nprint(x)\n' > a.py
    $ printf 'x = 2\nprint(x)\n' > b.py
    $ rtk diff a.py b.py
    [ok] Files are identical
    $ echo $?
    0
    
    $ /usr/bin/diff a.py b.py
    1c1
    < x = 1
    ---
    > x = 2
    $ echo $?
    1

    Consistent with the word-overlap hypothesis: x = 1 → x = 2 (shared words) is swallowed as "identical", while AAAA → BBBB (zero overlap) renders correctly — though still with exit 0, as covered in #2446.

    Impact matches the OP: hit via an AI agent (Claude Code with the rewrite hook) using diff as an equality check and acting on the false "identical".

  3. qx54 commented on Jul 17, 2026

    @qx54

    Different results on rtk 0.43.0 (macOS): the false [ok] Files are identical no longer reproduces, and the exit code is now correct (1).

    However, the output format looks wrong: instead of a standard diff, it prints both files in their entirety, separated by ---, with no </> markers or hunk headers.

    % rtk diff a.py b.py
    x = 1
    print(x)
    
    ---
    x = 2
    print(x)
    % echo $?
    1
    
    % /usr/bin/diff a.py b.py
    1c1
    < x = 1
    ---
    > x = 2
    

    This has been open for more than one month now, see #2446

  4. KuSh commented on Aug 30, 2026

    @KuSh
    Collaborator

    Closing — this is fixed on current develop. Verified with the exact reproduction from the report, on 0.46.0:

    $ printf 'alpha beta\n' > /tmp/v1.txt
    $ printf 'alpha zzzz\n' > /tmp/v2.txt
    $ rtk diff /tmp/v1.txt /tmp/v2.txt; echo "exit=$?"
    alpha beta
    
    ---
    alpha zzzz
    exit=1
    

    The cause was the identical-files guard testing added == 0 && removed == 0, which ignored the modified counter — so a line pair classified as a modification (similarity > 0.5, i.e. any meaningful word overlap) was counted, then reported as no change at all. render_file_diff now branches on diff.changes.is_empty(), which covers modified-only diffs by construction.

    Two related defects from your report are still open, so this isn't the end of the story for rtk diff:

    Thanks for the boundary matrix in the original report — that's what made the classification bug obvious rather than just the symptom.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibugpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions