Repository navigation
feat: attempt adjudication engine; port claim extractor and cost cap (0.13.0) - #6
Merged
Merged
Conversation
…(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.
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.
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:
maxRounds, default 2, max 3).JUDGE_PERSONA, same Majority / Minority / Unresolved sections).Blinding: each juror sees candidates under neutral labels
A, B, C…, in its own order drawn fromrandomSeedbefore any call. Candidate ids never reach a model, juror or judge. Labels are mapped back after parsing.Juror contract: one JSON object with
ranking,assessmentsandfindings(candidate, severity, file,lineor null, a verbatimquote, issue).buildJurorVerdictJsonSchema(labels)returns the matching schema in strict structured-output form: every property required, no additional properties, nullableline, 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:
failedcheck cannot be recommended unless every candidate failed one.Verdict: the leader is recommended only when all of these hold:
agreementThreshold(default 0.3);Otherwise the result is
no-clear-winnerwith a reason:incomplete,insufficient-votes,low-agreementortie. Dissent lists the jurors whose top pick isn't the leader.Budget:
budget.maxTokens,budget.deadlineMsand a caller-pricedbudget.costCap, alongsidesignal.stopReasonset totoken-budget,deadline,cost-caporaborted, keeping finished verdicts.Standalone exports:
bordaCount,kendallW,rankCandidates,decideVerdict,computeDissent,findingWeights.verifyFindings,quoteAppearsIn,mergeFindings,normalizeQuote,stripDiffMarkers.parseJurorVerdict,buildJurorVerdictJsonSchema.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):
extractConfidencenow reads the lastCONFIDENCE: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 changesrun()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,StopReasonand result type are CVP-specific. A method would have meant widening those exported types. The sibling sharesModelCaller,TypedEventEmitter,mulberry32/shuffle,JUDGE_PERSONAandbuildJudgeSystemPrompt.Why W alone doesn't decide the winner: Kendall's W measures agreement on the whole ordering, not on the winner.
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 testandnpm run buildpass 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.extractConfidenceto first-marker parsing (5 tests fail).ai-consensus-core@0.12.0[executed]:ConsensusEngineincluded) exceptextractConfidence, changed on purpose. It was checked before the parser fix; that commit touches onlyparser.tsamong existing source files..d.tsfiles for engine, prompts, stats, events and personas are identical.types.d.ts,parser.d.tsandindex.d.tsonly gain lines.git diffon existing source files had zero removed lines.zodremains 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.
ConsensusOptionsis unchanged. Roundtable's CVP cannot move ontorun()with identical behaviour without either: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.
extractJudgeConfidencestill takes the firstJUDGE_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.