Skip to content

Known issue (C parity): score-only score for unreachable alignments evaluated at an unset end position #23

Open

Description

@cjfields

Status: undefined behaviour in C WFA2-lib, reproduced for output parity. Affects only score-only output with a match reward (match < 0) for alignments that end unreachable (banded, X-drop). Not yet reported upstream.

Symptom

For unreachable alignments, C's wavefront_unialign_terminate computes the classic (SW) score at alignment_end_pos, which is still its initial value (k = DPMATRIX_DIAGONAL_NULL = INT_MAX, offset = WAVEFRONT_OFFSET_NULL = INT32_MIN/2). end_v = offset - k overflows (signed overflow, undefined behaviour); in practice it wraps so that v + h == 1, and the reported score is (swg_match - score) / 2. That depends only on the score at which the alignment gave up, not on any alignment.

Example: wfa.utest.seq pair 262, -a gap-affine-wfa --affine-penalties=-3,5,3,2 --wfa-score-only --wfa-heuristic=xdrop --wfa-heuristic-parameters=20,1 gives -113 (in CIGAR mode the same pair is -1 -, unreachable). (Corrected 2026-10-17: this example originally named pair 101, which is reachable.)

Related, not undefined behaviour: with match == 0 an unreachable pair's score-only output is the negated score where the search gave up, and a failed BiWFA score search prints INT32_MIN.

Rust

Reproduced for byte parity: the CLI evaluates the classic score at the same position with wrapping arithmetic (wf_score_to_sw_score is now wrapping), and the end position is initialized as in C. A saner output would be the -1 sentinel or the score at the best cell.

Corrected mode (#57): with --no-c-compat, the CLI prints -1 in score-only mode whenever there is no alignment (all three cases), as CIGAR mode does. Compat::C still reproduces C.

Plan

  • Report upstream: overflow/UB, plus a suggestion for unreachable alignments.

Activity

  1. added
    bugSomething isn't working
    C parityIssues related to upstream WFA2-lib parity, candidates for a gated approach
    on Oct 13, 2026
  2. added a commit that references this issue on Oct 17, 2026
  3. cjfields commented on Oct 17, 2026

    @cjfields
    MemberAuthor

    Fixed in the CLI's corrected mode by #57 (c9e97eb); keeping this open until upstream C resolves it. With --no-c-compat, score-only prints -1 when there's no alignment. That covers this overflow case, the give-up score with match == 0, and BiWFA's INT32_MIN. I corrected the example above: pair 101 is reachable, and pair 262 reproduces the overflow (-113). Known limitation: BiWFA score-only has no partial result, so when its search Z-drops it prints -1 even though CIGAR mode returns a partial alignment (FIXED_BUGS 14h).

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

    C parityIssues related to upstream WFA2-lib parity, candidates for a gated approachbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions