Skip to content

feat: attempt adjudication engine; port claim extractor and cost cap (0.13.0) - #6

Merged
marceloceccon merged 1 commit into
mainfrom
feat/attempt-adjudication
Nov 20, 2026
Merged

marceloceccon merged 1 commit into
mainfrom
feat/attempt-adjudication

Conversation

@marceloceccon

@marceloceccon marceloceccon commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What changed

AdjudicationEngine (new, src/adjudication.ts) judges N candidate solutions to one coding task, such as the branches of a best-of-N run.

Flow:

  1. One blind, parallel round of jurors.
  2. Deterministic aggregation of their votes.
  3. A rebuttal round, only while agreement is below the threshold (maxRounds, default 2, max 3).
  4. The existing non-voting judge (JUDGE_PERSONA, same Majority / Minority / Unresolved sections).

Blinding: each juror sees candidates under neutral labels A, B, C…, in its own order drawn from randomSeed before any call. Candidate ids never reach a model, juror or judge. Labels are mapped back after parsing.

Juror contract: one JSON object with ranking, assessments and findings (candidate, severity, file, line or null, a verbatim quote, issue).

  • Anything malformed counts as an abstention, never a crash.
  • buildJurorVerdictJsonSchema(labels) returns the matching schema in strict structured-output form: every property required, no additional properties, nullable line, no label-keyed maps.

Verification: a finding is kept only if its quote appears in the candidate it names, after whitespace normalization, verbatim or without diff markers. Dropped counts are reported per candidate and in total. No extra model calls.

Aggregation:

  • Borda count, then Kendall's W.
  • Tie-break order: first-place votes, then fewer severity-weighted verified findings, then candidate id.
  • Failed-check rule: a candidate with a failed check cannot be recommended unless every candidate failed one.

Verdict: the leader is recommended only when all of these hold:

  • the first round completed;
  • at least 2 votes were counted;
  • W ≥ agreementThreshold (default 0.3);
  • the leader has a strict Borda lead over the next eligible candidate.

Otherwise the result is no-clear-winner with a reason: incomplete, insufficient-votes, low-agreement or tie. Dissent lists the jurors whose top pick isn't the leader.

Budget: budget.maxTokens, budget.deadlineMs and a caller-priced budget.costCap, alongside signal.

  • Before each round and before the judge, the worst case is checked before dispatch; after each call, actual usage is checked.
  • A breach cancels in-flight calls; callers that ignore their signal are abandoned at the deadline.
  • The run returns a partial result with stopReason set to token-budget, deadline, cost-cap or aborted, keeping finished verdicts.

Standalone exports:

  • Aggregation: bordaCount, kendallW, rankCandidates, decideVerdict, computeDissent, findingWeights.
  • Verification: verifyFindings, quoteAppearsIn, mergeFindings, normalizeQuote, stripDiffMarkers.
  • Juror contract: parseJurorVerdict, buildJurorVerdictJsonSchema.
  • Prompt builders and schemas.

Ported from Roundtable so it can drop its copies:

  • extractClaims, parseClaimsJSON, CLAIM_EXTRACTOR_SYSTEM_PROMPT, buildClaimExtractorUserPrompt (prompt, parser and fuzzy quote check unchanged; Roundtable's parser tests are ported too).
  • CostCapExceededError, assertWithinCostCap, CostCap.

Parser fix (behaviour change, approved): extractConfidence now reads the last CONFIDENCE: marker followed by digits, Roundtable's semantics. Before, the first marker won, so an earlier preview captured the score. An inline "Confidence: high" made a response score 50 even with a valid trailing line. This changes run() scores for responses that mention "confidence:" before their trailing line. Default 50 and clamping are unchanged.

Version is 0.13.0, with a README section "Attempt adjudication" and a CHANGELOG entry.

Why

The CVP debate scores on self-reported confidence, which says nothing about which diff is correct, and a multi-round debate is too slow to sit at the end of every best-of-N.

Why a sibling class, not a method on ConsensusEngine: its event map, StopReason and result type are CVP-specific. A method would have meant widening those exported types. The sibling shares ModelCaller, TypedEventEmitter, mulberry32/shuffle, JUDGE_PERSONA and buildJudgeSystemPrompt.

Why W alone doesn't decide the winner: Kendall's W measures agreement on the whole ordering, not on the winner.

  • Two jurors who swap the top two of four candidates give W = 0.90 with a 1–1 split on the winner.
  • 2 of 3 jurors putting A first, with the third putting A second, give W = 0.33.

So a clear winner needs both W ≥ threshold and a strict points lead; the deterministic tie-break only orders the ranking. The README has the W table behind the 0.3 default.

How it was verified

  • npm run typecheck, npm test and npm run build pass on Node 24.22, and the tests pass on Node 20.20.2 [executed]. That is 260 tests: 145 existing, of which one was inverted for the parser fix, plus 115 new. CI ran green on Node 20 and 22 before the parser fix.
  • Fake jurors are blind: they see only the prompt and recognise candidates by content, not id. So the blinding and label-mapping tests check what a juror actually saw against the recorded presentation.
  • Mutation checks: I broke each contract in the source and confirmed a test fails [executed]:
    • removing the per-juror shuffle;
    • mapping labels without the shuffle;
    • always verifying quotes;
    • removing the failed-check rule;
    • never running the rebuttal;
    • ignoring a post-judge budget breach (this one needed a new test, now included);
    • reverting extractConfidence to first-marker parsing (5 tests fail).
  • Backward compatibility, against published ai-consensus-core@0.12.0 [executed]:
    • All 25 existing runtime exports are present.
    • Every existing function and class has byte-identical source (ConsensusEngine included) except extractConfidence, changed on purpose. It was checked before the parser fix; that commit touches only parser.ts among existing source files.
    • The .d.ts files for engine, prompts, stats, events and personas are identical.
    • types.d.ts, parser.d.ts and index.d.ts only gain lines.
    • Before the parser fix, git diff on existing source files had zero removed lines.
  • No new runtime dependency: zod remains the only one.

What is left / open questions

  • Not exercised against live models (scripted callers only) [assumed]. In particular, how often real models produce a strictly valid verdict is unmeasured; the MCP PR enforces the schema on CLI jurors.

  • ConsensusOptions is unchanged. Roundtable's CVP cannot move onto run() with identical behaviour without either:

    • a 1-participant allowance (Roundtable accepts 1-seat runs; core requires 2); or
    • a pluggable confidence parser (Roundtable takes the last marker; core takes the first).

    That would change an existing exported type, so it was not done here. The parser fix removes the confidence half of this. What remains is the 1-participant allowance (plus cosmetic error-text differences). Details are in the Roundtable PR.

  • extractJudgeConfidence still takes the first JUDGE_CONFIDENCE: marker. It's the same pattern, but it was outside the approved change; flipping it is a one-line follow-up if wanted.

  • The 0.3 agreement threshold is a judgment call, documented with the W table.

  • Juror free text (issue, summary) is passed to the judge and rebuttal prompts as written, so a juror that ignores the instruction not to mention labels can leak its own (per-juror) labels there. Rankings and findings are mapped structurally and are unaffected.

  • Not published to npm; Roundtable and ai-consensus-mcp PRs depend on this release.

…(0.13.0)

AdjudicationEngine judges N candidate solutions to one task (best-of-N
branches): one blind parallel round of jurors under per-juror shuffled
neutral labels, a strict JSON verdict contract (malformed output is an
abstention), quote verification of findings against the candidate they
name, Borda count + Kendall's W with a deterministic tie-break, the
failed-check eligibility rule, a rebuttal round only below the agreement
threshold, then the existing non-voting judge. Token ceiling, wall-clock
deadline and a caller-priced cost cap sit next to the AbortSignal; a
breach returns a partial result with a distinct stopReason.

A sibling class rather than a method on ConsensusEngine, so the CVP event
map, StopReason and result types stay untouched.

Also ports Roundtable's claim extractor (prompt, parser and fuzzy quote
check unchanged), its cost-cap error, and its trailing-marker confidence
parser as extractTrailingConfidence.

Additive only: every 0.12 export keeps identical runtime source and the
existing .d.ts declarations are unchanged. 145 existing tests unmodified,
113 new.
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