Skip to content

T-302: fix LengthAdded negative delta (qmApp scalar)#244

Merged
ms609 merged 8 commits into
cpp-searchfrom
feature/pol-escapa-neg-delta
May 19, 2026
Merged

T-302: fix LengthAdded negative delta (qmApp scalar)#244
ms609 merged 8 commits into
cpp-searchfrom
feature/pol-escapa-neg-delta

Conversation

@ms609
Copy link
Copy Markdown
Owner

@ms609 ms609 commented May 18, 2026

Summary

  • Resolves negative deltas < 0 in PolEscapa.R:104 for ~19-taxon datasets
  • Root cause: multi-row qmApp matrix was not being reduced to a scalar before subtraction in LengthAdded
  • Removes the # Temp warning guard once the root cause is handled correctly

Test plan

  • Verify GHA 25777175952 already passed (ubuntu-arm64 + windows agent-check workflow)
  • R CMD check on cpp-search after merge

🤖 Generated with Claude Code

ms609 and others added 6 commits May 13, 2026 04:51
…(T-302)

Root cause: when multiple rows in the contrast matrix satisfy the
fully-ambiguous applicable condition, qmApp was left as a vector of
indices. Assigning a multi-element vector as a leaf token caused
TreeLength() to receive an invalid state, producing scores higher than
the original and yielding negative deltas. Fix: take qmApp[[1L]] so the
leaf always receives a single valid token index.

Also tighten the zero-sum contrast-row guard to only error when the
affected tokens are actually used by taxa in the character being scored
(#294). Removes the Temp warning from R/PolEscapa.R:104.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add expect_error assertion with Asher2005 char 67 (6-token char)
  confirming the message says "token(s) 6" when row 6 is zeroed.
- Restore # Temp warning for deltas < 0; remove once fix is proven
  robust across edge-case datasets.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
In R CMD check, R runs as a non-interactive subprocess with captured
stdout. R_FlushConsole() calls fflush() on that pipe; when the buffer
fills the call blocks indefinitely, causing the 6 h GHA timeout seen
on every ubuntu runner for PR #210.

Gate the \r-overwrite progress line and the flush behind R_Interactive
(FALSE in batch/check contexts). Interactive sessions are unchanged.
At verbosity >= 2 in batch mode, emit plain \n-terminated lines so
diagnostic logs still carry progress detail without the flush risk.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
R CMD check on this PR hangs in '* checking examples ...' on
ubuntu-24.04-arm, ubuntu-24.04 (devel) and macOS-latest (most recent
in-flight + 3 cancelled runs).  R CMD check emits no per-example
markers, so we cannot tell which Rd is the culprit from the logs.

This diagnostic-only commit inserts message("PR244-DIAG: BEGIN/END
<Rd>") into the \examples{} block of the six likeliest suspects:
the Rds that exercise Vinther2008 or run a parallel search.  The
LAST BEGIN line with no matching END in the CI log identifies the
hang.  Will be reverted before merge.

NOT a structural fix.
Previous diagnostic used message() calls; R CMD check buffers
example stderr to *-Ex.Rout files that are only echoed to the
visible log after the examples stage completes.  On hung runs the
stage never completes, so message() markers never appeared.

Switch to file-based markers: each \examples{} block opens with a
cat() that writes a timestamped line to ~/pr244-diag.log.  This
survives the cancel signal.  Extended to all 49 Rds (so the LAST
"PR244-DIAG: BEGIN <Rd>" line names the hung example regardless of
where in the alphabet it falls).  Add an if: always() workflow
step that cats ~/pr244-diag.log + any -Ex.Rout fragment.

Diagnostic-only; revert before merge.
ms609 added a commit that referenced this pull request May 19, 2026
Adds NA-aware dirty-set Pass 1 + Pass 2 (fitch_na_dirty_downpass and
fitch_na_dirty_uppass) mirroring the EW dirty-set, and wires them into
tbr_search's SPR accept path under has_inapplicable.  Pass 3 still runs
over the full tree because it populates internal down2 (read by
extract_char_steps) and counts NA-block steps; savings come from
skipping Pass 1 + Pass 2 on off-dirty nodes.

Bug found during validation: full_rescore for NA EW data routes through
fitch_score_ew which adds ds.ew_offset (topology-independent step count)
on top of fitch_na_score's return.  My accept path was reading
fitch_na_pass3_score directly without the offset — producing a
systematic diff=−3 on Vinther2008 (where ew_offset = 3).  Fix: add
ds.ew_offset in the EW branch (line 1183).  IW path is unaffected
because compute_weighted_score handles per-pattern step contributions
directly.

Validation: DEBUG_NA_RESCORE cross-check kept for one GHA cycle.
Local Vinther2008 run, 5 replicates each EW + IW:
  DEBUG_RESCORE     (EW, IW):      0 / 0 mismatches
  DEBUG_NA_RESCORE  (NA-EW, NA-IW): 0 / 0 mismatches

Also includes dev/plans/t300-test.R (the four-path test harness) and
dev/plans/pr244-examples-hang-brief.md (background-agent brief for the
separate PR #244 hang investigation).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
ms609 added 2 commits May 19, 2026 11:04
Reverts the diagnostic instrumentation added in e5254eb and
b94ada1: strips PR244-DIAG cat()/message() calls from all 49 Rds
and removes the post-Check-package dump step from the R-CMD-check
workflow.  Root cause (R_Interactive non-API call) was fixed in
2b6b6be via merge from cpp-search.
@ms609 ms609 merged commit d24cd7a into cpp-search May 19, 2026
8 of 10 checks passed
@ms609 ms609 deleted the feature/pol-escapa-neg-delta branch May 19, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant