edit: seen-line guard rejects unshifted lines below an earlier edit
A fix is already open in #13982.
Problem
With edit.enforceSeenLines on (the default), hashline edits are rejected as "never displayed" after an earlier edit to the same file. This happens even when a full read showed the line and the earlier edit did not move it.
Repro
- Read all 40 lines of a 40-line file.
- Under the read's tag, apply
PUT >10:with one row andCUT 20.=20in the same edit. The net line change is zero, so lines 21-40 keep their number and content. - Under the tag from the edit response, apply
PUT 35.=35:.
Expected: the edit applies, because the read displayed line 35 and line 35 did not change.
Actual:
This edit anchors to lines 35 of a.txt that [a.txt#…] never displayed (it showed a partial range, a search hit, or a folded summary).Cause
Since cea3caf71f (#13144), every edit records its response rows as seen lines on the tag it mints, so the guard is active after every edit. carried_seen_lines in crates/pi-edit/src/session.rs carries prior-read lines only for the unchanged run above the first change. So every line below the first hunk counts as unseen. The function's doc comment promises lines "that keep both their number and content", but the code keeps only the leading run.
Impact
From 14 days of local session transcripts (5,218 edit calls):
- 264 seen-line rejections. 197 of them (75%) name a tag minted by an edit response.
- 152 of the 264 retries were byte-identical to the rejected call, so the anchors were already correct.
- Seen-line rejections per edit/write call rose from 1.67% (up to 09-24) to 4.44% (from 09-25).
Source: can1357/oh-my-pi