Skip to content

trimMiddle: negative edge for maxLength<120 overflows output and reports impossible truncated count #571

Closed

Description

@anagnorisis2peripeteia

trimMiddle(text, maxLength) in src/clawsweeper-text.ts:11 computes edge = Math.floor((maxLength - 120) / 2), which goes negative for any maxLength < 120. The head/tail slices then take from the wrong ends and the reported "truncated N chars" count exceeds the input length.

Repro (property-test found via einsiedlerkrebs):

trimMiddle("x".repeat(25), 20)  =>  length 31 (> maxLength 20), text says "truncated 125 chars" for a 25-char input

Invariants violated: result length should be ~<= maxLength, and the reported removed-count should be in [0, text.length]. Guard edge to a sane minimum (and/or short-circuit when maxLength is below the header overhead).

Activity

  1. clawsweeper commented on Jul 15, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 18, 2026, 10:35 PM ET / July 19, 2026, 02:35 UTC.

    Summary
    Keep open: the merged implementation PR was deliberately narrowed to the separate compactText issue, and the recent reopening note explicitly confirms that this issue’s trimMiddle fix was removed before merge. This remains a small, independently reported boundary bug for maintainer triage.

    Reproducibility: no. high-confidence current-main execution was captured in this read-only review. The report provides a concrete source-level path and input/cap pair, so the bug is source-reproducible with focused helper coverage.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Include the exact command, prompt, or workflow that triggered it.
    • Add expected vs actual behavior.

    Next step
    Recent human direction reopened this separate bug for maintainer triage, while the clawsweeper:no-new-fix-pr label means ClawSweeper should not dispatch a duplicate repair automatically.

    Maintainer decision needed

    • Question: Should maintainers sponsor a narrow follow-up fix for trimMiddle now that the prior merged PR intentionally excluded this separate boundary bug?
    • Rationale: The defect is concrete and likely small, but the item carries clawsweeper:no-new-fix-pr and recent human direction explicitly restored it for separate maintainer triage rather than automatic duplicate dispatch.
    • Likely owner: steipete — The latest human decision on the merged PR scope and this issue’s reopened state came from steipete.
    • Options:
      • Sponsor a focused repair (recommended): Create or approve one narrow follow-up that bounds low-cap trimMiddle output and adds regression coverage for the reported invariants.
      • Defer the helper change: Leave the issue open until the current maintenance priorities permit a separately reviewed text-helper repair.
    Review details

    Best possible solution:

    Add a narrow trimMiddle low-cap path that never returns more than maxLength, reports a removed count within the input length, and is protected by focused boundary tests around caps below 120.

    Do we have a high-confidence way to reproduce the issue?

    No high-confidence current-main execution was captured in this read-only review. The report provides a concrete source-level path and input/cap pair, so the bug is source-reproducible with focused helper coverage.

    Is this the best way to solve the issue?

    Yes. A narrow low-cap guard or short-circuit in trimMiddle, with boundary regression tests, directly restores the stated output-length and removed-count invariants without adding product surface.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • A fix should preserve trimMiddle’s normal middle-truncation behavior while defining a bounded result and truthful removed-count for caps smaller than the marker overhead.
    • The previous linked PR is merged but intentionally does not own this fix, so reopening a duplicate implementation against that branch would be incorrect.

    Codex review notes: model internal, reasoning high; reviewed against f8d5393f5894.

    Label changes

    Label changes:

    • add issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.
    • add clawsweeper:needs-live-repro: Current issue advisory state selects this label.
    • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.
    • remove issue-rating: 🦞 diamond lobster: Current issue advisory state no longer selects this label.
    • remove clawsweeper:source-repro: Current issue advisory state no longer selects this label.
    • remove clawsweeper:linked-pr-open: Current issue advisory state no longer selects this label.

    Label justifications:

    • P3: This is a bounded text-formatting edge case with a clear invariant violation but no evidence of data loss, security impact, runtime unavailability, or broken message delivery.
    Evidence reviewed

    What I checked:

    Likely related people:

    • steipete: Reopened this issue immediately after merging the narrowed PR and documented that the merged change does not fix this separate behavior. (role: recent merger and triage decision owner; confidence: high; commits: f8d5393f5894)
    • brokemac79: Provided the earlier maintenance-pass direction for reviewing this report alongside its linked implementation before that implementation was narrowed. (role: recent triage contributor; confidence: medium)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P3
    issue-rating: 🦞 diamond lobster
    clawsweeper:source-repro
    clawsweeper:linked-pr-open
    clawsweeper:no-new-fix-pr
    on Jul 15, 2026
  3. added a commit that references this issue on Jul 15, 2026
    37c14fb
  4. brokemac79 commented on Jul 16, 2026

    @brokemac79
    Contributor

    Thanks for the report. We?ve confirmed this is separate from the recent ClawSweeper review/publication stability incident.

    Our immediate priority is keeping the recovered path stable and completing a careful maintainer review of outstanding changes. We will review this report and its linked implementation together in the next maintenance pass, then leave a specific decision here.

    Please do not treat this as a request for further changes at present.

  5. brokemac79 commented on Jul 18, 2026

    @brokemac79
    Contributor

    @clawsweeper re-review

  6. clawsweeper commented on Jul 18, 2026

    @clawsweeper
    Contributor

    🦞🧹
    ClawSweeper re-review requested.

    I asked ClawSweeper to review this item again.
    Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
    Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

    Re-review progress:

  7. steipete commented on Jul 19, 2026

    @steipete
    Contributor

    Reopening: #576 was deliberately narrowed before merge to the compactText fix for #573 only. This issue's implementation was removed from the final diff, so the merge did not fix it. GitHub nevertheless applied the PR's older closing relationship at merge time.

    No new contributor changes requested. This restores the pre-merge open state for separate maintainer triage.

  8. added
    issue-rating: 🐚 platinum hermit
    clawsweeper:needs-live-repro
    clawsweeper:needs-maintainer-review
    and removed
    issue-rating: 🦞 diamond lobster
    clawsweeper:source-repro
    clawsweeper:linked-pr-open
    on Jul 19, 2026
  9. steipete commented on Jul 19, 2026

    @steipete
    Contributor

    Fixed by #687.

    Proof:

  10. added a commit that references this issue on Jul 19, 2026
    f8d5393
  11. added a commit that references this issue on Sep 21, 2026
    38ddba6
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

    P3clawsweeper:needs-live-reproclawsweeper:needs-maintainer-reviewclawsweeper:no-new-fix-prissue-rating: 🐚 platinum hermit

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions