Fix Ratchet() early-exit bookkeeping (A15-04) - #175
Merged
Conversation
Ratchet()'s stopAtScore= early-exit paths skipped the bookkeeping its return value depends on: - The already-met early return attached no "score" attribute and always returned a phylo, breaking MultiRatchet()'s vapply() and the documented returnAll = TRUE contract. - The mid-search BREAK path set bestScore before the edgeList <- candidate assignment (and, under returnAll, the forest append) that live below the break -- so the input tree could be returned carrying the improved score, and returnAll = TRUE could throw "No trees!?" on the success path. Both paths now perform the same bookkeeping the normal return does before exiting. Regression test asserts the property that failed: a returned tree's independently-recomputed TreeLength() must equal its own "score" attribute, on every exit path. Fixes #136 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ratchet(stopAtScore = )'s early-exit paths skipped the bookkeeping its return value depends on:phylowith no"score"attribute, and always aphyloeven underreturnAll = TRUE(documented to returnmultiPhylo). BrokeMultiRatchet()'svapply(trees, function(x) attr(x, "score"), double(1)).bestScorewas updated but theedgeList <- candidateassignment (and, underreturnAll, theforestappend) lived below theif (BREAK) break— so the input tree could be returned carrying the improved score (silent wrong answer), andreturnAll = TRUEcould throw"No trees!? Is suboptimal set to a sensible (positive) value?"on the success path.Both paths now perform the same bookkeeping the normal return does, before exiting.
Test plan
tests/testthat/test-Ratchet.Rassert the property that failed: a returned tree's independently-recomputedTreeLength()must equal its own"score"attribute, on every exit path (already-met entry, mid-search hit, bothreturnAllvalues, andMultiRatchet()).test-Ratchet.R+test-CustomSearch.R+test-NativeSearch.R(the files exercisingRatchet()/MultiRatchet()): 44/44 pass, 0 failures.external-reviewerpass — verdict "ship after addressing nits"; addressed: seeded the mid-search test's RNG, tightened a length assertion, canonicalized the early-return edge matrix for parity with the normal return path, test-file style nits.agent-check.ymlgreen on bothubuntu-arm64andwindows(run 31156683684).spelling::spell_check_test()clean.Known related edge case, out of scope here
Ratchet(returnAll = TRUE, ratchIter = 0)still throws the same misdirecting"No trees!?"error — but this is a different mechanism (zero iterations meansforestnever gets populated at all, regardless of thestopAtScorebookkeeping-skip bug this PR fixes), not covered by the issue's suggested fix either. Flagging for a possible follow-up issue rather than expanding this PR's scope.Note on PR authorship
ms609-agentis still suspended (gh api user→ 403 as of this PR), so this opened under the human maintainer'sghauth rather than the agent identity.cpp-searchis not branch-protected and prior PRs (#73–#134) merged the same way while the suspension has been in effect.Fixes #136