Skip to content

🤖 Draft merge: removeDraftBlock follow-ups (indentation as a boundary, scan cost) #5586

Description

@ThomasK33

Follow-up from PR #5577 (#5567, whole-block draft matching). Two normal-review findings on its head 7037a70e83, deferred because the PR's review budget was spent. Both are in removeDraftBlock (src/common/utils/composerDraftText.ts).

  1. Indentation counts as a block boundary. whitespaceRun skips the same-line indentation before it counts the blank line, so in alpha\n\n yes\n\nomega an indented code line yes matches a send yes. mergeWrite can then take that line out of a window's write as a stale copy, and observeSends marks it inUnsavedText. Before 🤖 fix: match a send's text in the draft merge only as a whole block #5577 the middle check (\n\n<block>\n\n) did not match it, but the end checks (removeSentText) did. Fix: only whitespace on separator lines may sit between the block and the blank line. Indentation or trailing spaces on the block's own line must prevent the match.
  2. Per-occurrence scan cost. The loop visits every occurrence of the block. A near-limit draft (MAX_DRAFT_JSON_CHARS) of millions of a with a send a and no whole-block match runs the loop millions of times, for each pending send in mergeWrite, on the backend event loop. Fix: search only separator-delimited candidates (for example, look for \n + block and check the edges), so the work is bounded by line count.

Both need the send's text to equal a line of the user's draft (1) or a pathological draft (2). Neither was reported by a user.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $5.67

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions