Skip to content

feat(workflows): selection math — seeded PPT primitives (V4, #2488) - #2512

Merged
flora131 merged 6 commits into
mainfrom
verifier/selection-math
Aug 19, 2026
Merged

feat(workflows): selection math — seeded PPT primitives (V4, #2488)#2512
flora131 merged 6 commits into
mainfrom
verifier/selection-math

Conversation

@flora131

@flora131 flora131 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Slice V4 of the LLM-as-a-Verifier adoption program (specs/2026-08-17-tournament-soft-selection.md §5.1): the pure, dependency-free selection-math primitives for the pivot-pairing tournament.

packages/workflows/builtin/selection-math.ts (new, no ctx / no I/O / no model calls):

  • seeded_rng — mulberry32-class, cross-platform deterministic
  • plan_comparisons({n, pivots, repeats, seed})ComparisonPlan: seeded Hamiltonian ring (every candidate once per slot), pivot rounds (non-pivot×pivot + pivot×pivot minus pairs already in the ring), jobs expanded × criteria × repeats with odd reps slot-swapped; refuses n<2, pivots<1, repeats<1; no pair scheduled twice
  • soft_win(a,b) — sigmoid over scores normalized from VERIFICATION_SCALE 1..20 to [0,1] (raw differences would saturate)
  • accumulate, select_pivots (top-k by w/c, ties by lower index), rank_candidates (length always n; c=0 defined as 0)

Base: verifier/prefix-cache-prompts (V3, #2510). Stack: V1 → V3 → V4 → V5 → V6.

Evidence

Produced by an implement→review→repair goal run (approved in 1 turn; completion/evidence/risk reviewers all complete; remaining_work: none):

  • npm run check — green (includes the coding-agent tsgo erasableSyntaxOnly pass)
  • npx vitest --run --project unit -t "selection-math" — green: seeded RNG reference vectors, valid Hamiltonian ring adjacency, deep-equal plan determinism under a fixed seed, ring∩pivot dedup, odd-rep slot-swap bookkeeping, Σc = 2×comparisons, pivot tie-break by lower index, ranking length always n, comparison budget ≤ N + k(N−k) + C(k,2)
  • Size cap: 157 changed source lines (< 500; tests uncapped — 298 total insertions)
  • CHANGELOG: packages/workflows/CHANGELOG.md under ## [Unreleased] ### Added

Spec contract: specs/2026-08-17-tournament-soft-selection.md §5.1 (Q1–Q3: pivots 1, n_evaluations 2, seed 0).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Greptile Summary

This change adds deterministic selection math for tournament planning and records the feature in the workflows changelog. Two-candidate plans currently schedule the same unordered matchup in both directions, causing duplicate evaluation and accumulated comparison mass. The changelog update also removes the existing 0.9.14-alpha.4 release heading and its adversarial-verification entry. The focused selection-math unit suite passes but does not cover the two-candidate planning path.

Confidence Score: 3/5

Not safe to merge until two-candidate tournament planning avoids reciprocal duplicate jobs and the removed alpha.4 changelog history is restored.

Two independent, non-security functional issues were reproduced with targeted executable checks: duplicate planning and accumulation for two candidates, and removal of prior release-history content.

Files Needing Attention: packages/workflows/builtin/selection-math.ts needs a two-candidate deduplication path; packages/workflows/CHANGELOG.md needs the 0.9.14-alpha.4 heading and adversarial-verification entry restored.

T-Rex T-Rex Logs

What T-Rex did

  • Produced a P1 finding proof for the two-candidate Hamiltonian-ring probe, including before- and after-output observations and the existing selection-math unit-test result.
  • Produced a P1 finding proof for the changelog deletion check, including the source and output showing missing alpha.4 history in HEAD.
  • Generated a P1 finding proof with no artifacts attached.
  • Validated the Hamiltonian-ring N2 probe against the current codebase; the probe source and before/after logs exited cleanly, and the unit tests completed with 1 of 9 tests passing.
  • Executed the changelog history deletion check script and confirmed via its output that alpha.4 is not present in HEAD, supporting the deletion claim.

View all artifacts

T-Rex Ran code and verified through T-Rex

Comments Outside Diff (2)

  1. General comment

    P1 Two-candidate ring schedules the sole comparison twice

    • Bug
      • At packages/workflows/builtin/selection-math.ts:57, modulo wrapping maps both permutation positions in an n=2 cycle to the same unordered pair in opposite directions. The executed path scheduled two jobs for criterion quality with repeats: 1, then accumulated two preferences and counts [2,2]. Thus the sole pair receives double evaluation and double total weight/count mass.
    • Cause
      • ring_cycle always returns one edge per vertex. In a directed 2-cycle, those edges are reciprocal representations of the same unordered pair, while later planning/jobs do not deduplicate ring entries.
    • Fix
      • Special-case n === 2 in ring_cycle (or deduplicate the ring before job creation) so it returns exactly one directed pair. Preserve one orientation deterministically from the shuffled permutation.

    T-Rex Ran code and verified through T-Rex

  2. General comment

    P1 Merge removes the 0.9.14-alpha.4 changelog release boundary and adversarial-verification entry

    • Bug
      • In packages/workflows/CHANGELOG.md, base commit d82b11dd has the adversarial-verification fan-out/mean-veto entry at line 19 and ## [0.9.14-alpha.4] - 2026-08-18 at line 20. At HEAD, both are absent: current lines 19-20 are unrelated Unreleased entries, followed by ### Fixed, and the next release heading is 0.9.14-alpha.3 at line 26. This confirms unrelated release history/version-boundary loss.
    • Cause
      • The HEAD merge resolution replaces the alpha.4 heading with Unreleased section content without retaining the release heading or its associated adversarial-verification record.
    • Fix
      • Restore ## [0.9.14-alpha.4] - 2026-08-18 and its adversarial-verification entry immediately after the Unreleased section, preserving the existing alpha.3 boundary below it.

    T-Rex Ran code and verified through T-Rex

Prompt To Fix All With AI
### Issue 1
packages/workflows/builtin/selection-math.ts:57
**Two-candidate ring schedules the sole comparison twice**

For `n === 2`, the modulo successor mapping produces both `{a: 1, b: 0}` and `{a: 0, b: 1}`. These are the same unordered comparison, but `jobs` schedules both directions and `accumulate` incorporates both results, giving each candidate a count of 2 for a single criterion/repeat. Return one deterministic pair for two candidates, or deduplicate before creating jobs, so the only matchup is evaluated once.

### Issue 2
packages/workflows/CHANGELOG.md:19-20
**Alpha.4 release history is removed**

This update drops both the `adversarial-verification` entry and the `## [0.9.14-alpha.4] - 2026-08-18` heading that were present in the prior changelog. The unreleased entries now flow directly into `0.9.14-alpha.3`, making the released alpha.4 changes and their version boundary disappear. Restore the alpha.4 heading and its associated entry after the Unreleased section.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "merge origin/main" | Re-trigger Greptile

Greptile also left 2 inline comments on this PR.

@flora131
flora131 changed the base branch from verifier/prefix-cache-prompts to main August 19, 2026 16:57
@flora131
flora131 merged commit d513354 into main Aug 19, 2026
11 of 14 checks passed
const other = Math.floor(rng() * (index + 1));
[permutation[index], permutation[other]] = [permutation[other]!, permutation[index]!];
}
return permutation.map((a, index) => ({ a, b: permutation[(index + 1) % n]! }));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Two-candidate ring schedules the sole comparison twice

For n === 2, the modulo successor mapping produces both {a: 1, b: 0} and {a: 0, b: 1}. These are the same unordered comparison, but jobs schedules both directions and accumulate incorporates both results, giving each candidate a count of 2 for a single criterion/repeat. Return one deterministic pair for two candidates, or deduplicate before creating jobs, so the only matchup is evaluated once.

Artifacts

Two-candidate Hamiltonian-ring executable probe source

  • Executable source imports the production planner, job builder, score normalization, and accumulator, then checks the two-candidate scheduling path; it is the exact code run to establish the duplication.

Two-candidate Hamiltonian-ring observed output before comparison

  • Executed `bun trex-artifacts/hamiltonian-ring-n2-probe.mts` from `/home/user/repo` with exit code 0; it shows reciprocal ring pairs, two jobs, and accumulated counts `[2,2]`, confirming duplicate evaluation.

Two-candidate Hamiltonian-ring observed output after comparison

  • Second executed capture of the same unchanged production code with exit code 0; it reproduces the reciprocal ring pairs, two jobs, and counts `[2,2]`, confirming the observation is stable.

Existing selection-math unit test result

  • Executed the focused repository unit suite with `npx --no-install vitest --run --project unit test/unit/selection-math.test.ts`; all 9 existing tests pass, showing this n=2 downstream consequence is currently untested.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/workflows/builtin/selection-math.ts
Line: 57

Comment:
**Two-candidate ring schedules the sole comparison twice**

For `n === 2`, the modulo successor mapping produces both `{a: 1, b: 0}` and `{a: 0, b: 1}`. These are the same unordered comparison, but `jobs` schedules both directions and `accumulate` incorporates both results, giving each candidate a count of 2 for a single criterion/repeat. Return one deterministic pair for two candidates, or deduplicate before creating jobs, so the only matchup is evaluated once.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +19 to +20
- Added prefix-cache-aware verification prompts with a byte-identical shared head, UTF-8 bounded candidate inlining with whole-family read fallback, and warm-first verifier fan-out scheduling that preserves input order while releasing later phases after warm failures ([#2493](https://github.com/bastani-inc/atomic/issues/2493)).
- Added pure, seeded selection math for probabilistic pivot tournaments: deterministic Hamiltonian ring and deduplicated pivot planning, criterion/repeat slot-swap jobs, normalized Bradley–Terry soft wins, count-normalized pivot selection, and complete candidate rankings ([#2488](https://github.com/bastani-inc/atomic/issues/2488)).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Alpha.4 release history is removed

This update drops both the adversarial-verification entry and the ## [0.9.14-alpha.4] - 2026-08-18 heading that were present in the prior changelog. The unreleased entries now flow directly into 0.9.14-alpha.3, making the released alpha.4 changes and their version boundary disappear. Restore the alpha.4 heading and its associated entry after the Unreleased section.

Artifacts

Executed changelog deletion check source

  • The runnable Bash check reads base and HEAD changelog Git objects and compares the exact entry and heading, ending with a nonzero result when HEAD lacks them.

Executed changelog deletion check output showing missing alpha.4 history in HEAD

  • The captured run shows both records at base lines 19-20, no matching HEAD records, and `RESULT=DELETED_FROM_HEAD`; takeaway: the claimed deletion is confirmed.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/workflows/CHANGELOG.md
Line: 19-20

Comment:
**Alpha.4 release history is removed**

This update drops both the `adversarial-verification` entry and the `## [0.9.14-alpha.4] - 2026-08-18` heading that were present in the prior changelog. The unreleased entries now flow directly into `0.9.14-alpha.3`, making the released alpha.4 changes and their version boundary disappear. Restore the alpha.4 heading and its associated entry after the Unreleased section.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

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