Repository navigation
fix(typescript): pair uneven replacement blocks by content and move the sibling guards onto it (#7524) - #7554
Conversation
…replacement block (#7524) Two removed lines meeting one added line, and two meeting three: the substring check passes on both messages, so the truth is not_discriminated, but main pairs the added throw with the removed comment (or with nothing) and reads exposed. A title control pins the old message. TypeScript false verdicts on main: 8/106. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
…he sibling guards onto it (#7524) ChangedFile::aligned_counterparts pairs an even block by position, an uneven block by mutual single-best match on code tokens (string literals and comments left out, crossing pairs dropped), and an interrupted run by coordinate. When content pairs the run's first added line with nothing, it keeps main's coordinate match unless another removed line matches it better. Work is bounded by a 65,536-cell and a 256-token cap, with a sorted-merge token intersection. The TypeScript adapter's old-line lookup, annotation-only guard and new-declaration guard all read this one pairing. The new-declaration guard now treats a counterpart that does not look like the line as no counterpart. replacement_counterparts (Rust probes) is unchanged. Corpus: mocha-label-throw-uneven-{shorter,longer}-block move from false exposed to ideal gap; TypeScript false verdicts 8/106 -> 6/106; the title control and every other TypeScript and Rust row hold. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedThe included review limit has been reached and this organization has disabled usage-based review continuation. Wait for reviews to reset or ask a billing admin to change After included review limits. Next included review available in 7 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Summary by CodeRabbit
WalkthroughThe diff model now aligns lines in replacement blocks using position or content matches. TypeScript analysis uses aligned lines in its guards and classification. Tests and verdict-corpus fixtures cover equal-length and uneven replacement cases. ChangesTypeScript Replacement Pairing
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant ChangedFile
participant TypeScriptAdapter
participant ProbeClassification
TypeScriptAdapter->>ChangedFile: Request aligned counterparts
ChangedFile-->>TypeScriptAdapter: Return added and removed line pairs
TypeScriptAdapter->>ProbeClassification: Supply aligned old-line text
ProbeClassification-->>TypeScriptAdapter: Return classification
Merge Risk: ⚪ Minimal · up to
|
Review of record — head 83e55d7Angles (two independent agent reviewers, read-only, exact working tree before publication):
Findings and resolutions:
Verified by the reviewers:
Proof on this head:
Missing: hosted CI and external bot reviews. I'll add an addendum if they find anything. Generated by Claude Code |
There was a problem hiding this comment.
Confirmed findings
- The PR claim 'ambiguous blocks pair nothing' is enforced by 'tied = true' in single_best, but the code does not have a unit test for an exact row-column symmetry tie (e.g., two removed lines each exactly matching two added lines). The 'a_better_match_elsewhere_wins' test covers similar shape but not symmetric tie. Functional correctness likely fine via the tied guard; test gap is the only concern.
- crates/ripr/src/analysis/language/typescript/replaced_block_tests.rs:217 — Regression coverage for the wide commentary claim (4 negative experiments on main) is not encoded as a sibling test. Add a test that asserts
replacement_counterparts()(or temporary old code path) yields None for the uneven throw so a regression on main would surface in CI rather than only in the PR description.
Verification questions
- Confirm all added tests target the proposed behavior, none proves the previous behavior would have failed: PR description claims 4 negative experiments on main, but no test asserts that main produced a different verdict for the same fixture.
- Confirm even block / even interrupt / uneven block paths are disjoint in aligned_counterparts; the coordinate fallback only fires when content pairing leaves the first added line unmapped AND first_removed is unpaired AND no later removed line scores strictly higher.
Refuted
Box::from(slice)allocation failure does not returnNone; recoverable fallback claims are dropped.- Stale Vec in similarity matrix could alias tokens if ChangedLine.text mutates between construction and use; refuted because: Removed/added slices and their token Vec<&str> live only for the align_by_content call; no mutation of ChangedLine text occurs on this path; aliasing risk is theoretical and not exercised by the diff.
- PR #7554 introduces or affects a JS-backed worker handoff, transferable, detach, SharedArrayBuffer, or postMessage boundary.; refuted because: Diff changes are confined to ripr (Rust) analysis/diff model, the TypeScript analysis adapter, its unit tests, and verdict-corpus fixtures + SPEC.md prose. No JS/TS runtime, worker, or message-channel surface is added; crate ripr has no such bindings. aligned_counterparts/replacement_runs/lines_look_alike operate synchronously on owned slices/strings and are pure (no async, no threads, no FFI).
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Parked follow-ups
- Park, do not broaden: Python, JavaScript, and Java adapters reuse the same new-side-coordinate lookup the PR fixes for TypeScript. Each is a separate accepted-track follow-up against #7524, mirroring the same
aligned_counterpartsswap when those languages need it. - TypeScript is the only adapter wired to
aligned_counterparts; Python/JS/Javaold_line_textlookups still key onremoved_lines.iter().find(...new_side_line == added.line)and remain vulnerable to the same coordinate-only defect #7524 describes. By PR design these are out of scope; park as one tracked follow-up per language. code_tokensskips strings/comments but does not handle regex literals (/.../) or template${...}interpolation; athrowwhose only change is${label} is blank->${label} must not be blanktokens are identical and still pair, which is fine. Park regex-literal coverage as a separate scan rather than broadening this PR.replacement_counterparts(the unchanged Rust probe entry point) still maps by position only and bails on uneven/interrupted blocks; PR keeps it intentionally untouched. Park the question of unifyingreplacement_counterpartswithaligned_counterpartsrather than broadening this PR.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
|
Addendum to the review of record for the automated review on 83e55d7, new head bdc85d7.
Generated by Claude Code |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- align_by_content's
single_bestrefuses ties via tied=true but only checks score equality; a tie where two added rows score identically high but the removed row has a strictly higher third candidate is still a real tie. Existing a_symmetric_tie_pairs_nothing_by_content covers the symmetric case; a 3-removed × 3-added row-column tie variant is not encoded. - PR body claim that even/interrupted/uneven branches are disjoint (if/else if/else in aligned_counterparts) is asserted by the author and visible in the diff, but no unit test pins the disjointness; the three regression tests cover each branch independently.
Verification questions
- Confirm a_very_long_line_does_not_pair_by_content uses elapsed<2s wall-clock guard; CI runners (especially under sandbox/cgroup pressure) can flake this. Test is medium-value (proves MAX_ALIGNED_TOKENS short-circuits), but timing is orthogonal to correctness.
Refuted
- Resizable/active view (ArrayBuffer/TypedArray resize/detach/transfer) is at risk in this diff.; refuted because: Diff adds no ArrayBuffer, no TypedArray, no Vec-backed buffer with detached/reattached semantics, no SharedArrayBuffer, no &mut [u8] over a resizable region, no wasm memory. align_by_content owns Vec<Vec> similarity built locally and dropped at function return. lines_look_alike and code_tokens take &str only. No JS/WASM FFI surface added.
- The new align_by_content similarity matrix or single_best closures could leak memory across worker handoffs because Vec<Vec> is large (65,536 cells).; refuted because: similarity is a local Vec<Vec> in align_by_content, dropped at function return; no cross-thread sharing, no transfer of ownership. Bounded by MAX_ALIGNED_CELLS=65_536.
Parked follow-ups
- Python adapter shares the coordinate-only lookup pattern (python.rs:803, :823 per the author's addendum); not in the diff but parked as #7556.
- Python adapter (same coordinate-lookup shape as TS pre-fix) is out of scope but explicitly tracked as #7556; merge landing without that follow-up risks Python parity drift noted in the PR body.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
…ertion; scan each line once in the fallback (#7524) Review of #7554: `+comment -old +new` skipped the run, so the new line lost the old line main's coordinate match gave it; and the first-line fallback re-tokenized a long added line per removed line. Wall-clock guards in the bound tests loosened to 10 s. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Addendum 2 to the review of record, head ffac8a6 Devin found two problems, both confirmed and fixed:
github-actions review:
Checks on this head:
Nothing blocking remains open from any review. Toggled Draft→Ready for the required check. Generated by Claude Code |
Main was red on this row: #6716 counts no_static_path_with_related_tests only when a listed test calls the owner, and the row was never re-blessed. Same one-row change #6792 and #7563 carry; no-ops once one of them lands. Verdict unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
|
It reproduces on current Fix, ported:
Next I'll toggle Draft→Ready for the required check. Generated by Claude Code |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Confirmed findings
- Strengthen the Python parity sibling: PR restriction to TS only is principled, but the aligned_counterparts effect on Python probe candidates is not measured. A regression test or corpus row mirroring the mocha-label-throw-uneven-* cases under a Python subject would make parity visible. Park #7556 covers the open sibling, but no plan reuses the corpus mechanism across languages.
- Wall-clock guards (
started.elapsed() < Duration::from_secs(10)) in two long-line tests can flake on loaded CI sandboxes. Author widened from 2s to 10s in addendum; still timing-dependent for what is a structural bound. Not a correctness gap, just a noise source. - No secret-material handling, network, FFI, or new unsafe surfaces introduced. TypeScript corpus re-labelling and Rust spec0115 re-bless are non-security and bounded by their own corpora. No public security regression expected from this PR.
- crates/ripr/src/analysis/diff/model.rs:462 —
a_long_first_line_beside_many_removed_lines_stays_boundedchecks elapsed<10s andmap.len()==1but never asserts the first-line fallback path was exercised. If a future refactor routes that block through coordinate-only matching the timing test still passes. Pin which branch fed the single pair. - crates/ripr/src/analysis/diff/model.rs:363 — align_by_content's crossing filter operates after mutual single-best; if removal rows 0..=k all single-best-match added columns 0..=k in reverse order, all crossings drop and the run pairs nothing, including the run's first added line. This is by design, but the only test covering crossing pairs is
crossing_pairs_are_dropped. Consider adding a 3x3 mutual-best crossing case (mutual single-best, reversed) to pin the no-crossing invariant. - Python adapter still uses the shared new-side coordinate match alone for added lines inside replacement blocks (file:python.rs:803, :823). Same coordinate-only flaw this PR fixes for TypeScript could surface in Python. Author filed #7556; out of scope here.
Verification questions
- Confirm eight model unit tests plus four adapter tests target aligned_counterparts and the three guards; every behavior test is described as failing on the main adapter.
- Confirm test asymmetric: only one control (uneven-shorter pinned) for two uneven labels; uneven-longer has no control sibling to pin fault.
- Confirm repository new function 'helper' replacing 3 comment lines expects even-block pairing by position to keep it from probing the opening line; that pairing only tests the even branch, not content. The three siblings (even/interrupted/uneven) are tested independently but disjointness is asserted, not pinned.
Refuted
- Tokens/lines carrying tokens leak secret material to a sink or log.; refuted because: code_tokens returns &[&str] over the same line buffers; no copy, no allocator growth past the bounded Vec, no fmt/println/log added. lines_look_alike is inlined by adapter callers, no I/O.
Evidence gaps
- awaiting late cargo-test receipt; lib typescript diff tests 1491 passed claimed in body but receipt not in this packet.
- Model proof intent was rejected by deterministic validation.
|
Final addendum to the review of record. Head 96d9c82 is green: The latest github-actions review raised only suggestions, with nothing marked blocking. Here is how each one is handled:
Merging under the thread's merge authority. Generated by Claude Code |
Summary
Before: in a replacement block where the removed and added line counts differ, only the block's first added line found an old line, and that old line was the block's first removed line, often a comment. Deleting or adding a comment beside a message-only
throwchange therefore hid that change from the RIPR-SPEC-0243 rule 4 guard. A chaito.throw("blank")that passes on both messages readexposed. The annotation-only and new-declaration guards still matched only by coordinate.After: an uneven block pairs lines by content, so that
throwreadsweakly_exposed. The adapter's old-line lookup, the annotation-only guard and the new-declaration guard all read one pairing.How:
ChangedFile::aligned_counterparts(analysis/diff/model.rs) pairs lines in one of three ways.//comments are left out. Ties pair nothing, and pairs that would cross are dropped.When content pairs the run's first added line with nothing, that line keeps main's coordinate match unless another removed line matches it better. A tie therefore never loses a guard that fired on main. The new-declaration guard treats a counterpart that does not look like the line as no counterpart. Work is bounded in three ways: blocks of at most 65,536 cells, lines of at most 256 tokens, and a sorted-merge intersection over tokens computed once per line.
replacement_counterparts, which the Rust probes use, is unchanged.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Spec: RIPR-SPEC-0243 rule 4 (example 14); RIPR-SPEC-0245 (TypeScript corpus)
Governing issue or accepted claim: #7524 follow-ups (the sibling guards and uneven blocks)
Acceptance delta (one sentence): a message-only
throwchange in an uneven replacement block meets the error-payload guard, and both sibling guards read the same pairing.Candidate Relationships
Candidate branch:
claude/project-thread-svy0f3-unevenBuilds on: #7529 (merged as 38b0eae)
Scope
authored-ts-mocha-ledger, labeled by runningnpx mochaon the edited package:mocha-label-throw-uneven-shorter-block: two removed lines, one added. Gap.mocha-label-throw-uneven-longer-block: two removed lines, three added. Gap.mocha-title-throw-uneven-shorter-block: the control. The test pins the old message, so the expected verdict is credited.ChangedFile::aligned_counterpartsandlines_look_alike.Non-goals:
added_run_starton the Rust probe path is unchanged.Proof
Corpus. I committed the cases first (3aa1c88) and scored them on main's adapter. Both label cases read
credited/exposed, which is false exposed: 8/106. After the fix both readgap, giving 6/106. The control stays ideal, and no other row moves.Negative experiments:
throwtests;Review
Two independent agent reviews (correctness and edge cases; tests, corpus and contract) found two blockers, both fixed before publication:
Their other findings were also applied:
Claim Boundary
May claim: a message-only
throwchange inside an uneven replacement block reaches the rule 4 guard when the oldthrowis the single best match. Must not claim: ambiguous blocks, or blocks above the caps.Rollback
Revert the squash commit and re-bless the TypeScript corpus.
Static Language Check
killed,survived,untested,proven, andadequate.🤖 Generated with Claude Code
https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
Generated by Claude Code