Skip to content

Lenses and policy ​

The panel is where a finding is judged. Its lenses say what each voter is asked, and the profile's policy says how many kept votes each confidence level needs. This page covers lenses, the policy rules and their checks, how a confidence is computed, what a failed vote does, and what a confidence level means and does not.

Lenses ​

A lens is an id and a question:

ts
const lens = { id: 'reachability', question: 'Is this sink actually reachable from untrusted input in normal flow - not just syntactically present?' }
  • One vote per lens per finding. Every finding that reaches the panel goes to every lens of the profile, each through the provider its ports name for that lens, so a finding costs one call per lens.
  • Blind. Each vote request is built only from the finding, the lens's rendered instructions, the diff context and the profile's guidelines: no request carries another vote, its verdict or its reasoning, and the votes of one finding are requested together, none waiting for another's answer.
  • The question reaches the voter through the vote template's {{lens.question}}, and the lens id through {{lens.id}}: Templates.

The security profile has three lenses, reachability, impact and defenses, each an angle from which the finding may not hold. Three is not a round number waiting for more: self-consistency research shows most of the gain of repeated sampling arriving by roughly five to ten samples on a capable model, while each vote costs one more call per finding and running them in parallel has a real latency cost, so three differently angled votes are close to the cost-effective floor. Three is also the fewest lenses with which the default policy has a level below unanimity: 2 of 3.

The built-in profiles' lenses ​

The other three built-in profiles (The built-in profiles) have three lenses each, nine in all, under the same policy as the security profile's and the same vote template: a refutation angle, keep=false unless genuinely convinced. A lens's question is the only text of the profile a voter reads, with the rule its finding cites.

code-review:

LensQuestion
realDoes the quoted code, as written, misbehave: is there an input or a sequence of events, shown in the diff or plainly possible, that makes it fail, rather than code that only looks unusual?
introducedIs the defect in what this change adds or alters, rather than in code it leaves as it was?
consequentialWould a maintainer fix it before merging: does it crash, lose or corrupt data, return a wrong result or break a caller, rather than being a matter of style or design?

best-practices:

LensQuestion
askedDoes the cited rule's text really ask for what the finding says is missing, for this kind of code? Keep=false when the finding stretches the rule or the rule does not fit this code.
absentIs the required piece really missing? A handler, check, wrapper, cleanup or test that the diff or the other blocks show elsewhere refutes the claim, and so does a line the test-coverage block shows as covered.
introducedIs the gap in code this change adds or alters, rather than in code it leaves as it was?

performance:

LensQuestion
visibleDo the changed lines show both halves: the loop, handler or growing structure, and the costly operation inside it? Keep=false when either half is inferred rather than shown.
hotDoes this run often or on input that can grow: per request, per item or per message, on data a user or the outside world controls? Keep=false for code that runs once or on small fixed input.
unmitigatedIs the cost left in place: does no batching, cache, index, limit, pagination or early exit, in the diff or the other blocks, already bound it?

Every lens's vote receives the one rule its finding cites, in the rule block (The citation), and the asked lens judges by it. absent speaks of a test-coverage block, which a lens that sets testCoverage is sent in a review that reads a coverage report (Test coverage in a lens). The built-in best-practices profile reads test coverage and its absent lens alone is sent the cited file's line, in a review given an lcov report with --lcov (Test coverage); in any other review, its voters judge from the diff and the other blocks they do receive, as they always did. The clause about the block is in the lens's text whatever the review reads, so the text, and with it every vote's digest, is the same with a coverage report and without, and a bench of best-practices before and after compares.

Test coverage in a lens ​

A lens sets testCoverage: true to be sent the state of the lines the change adds in the file its finding cites. The built-in best-practices profile sets it on absent, and a program or a config sets it on a lens of its own:

ts
import { performanceProfile } from '@tobi-or-not/quorum'
import type { Profile } from '@tobi-or-not/quorum'

const tested: Profile = {
  ...performanceProfile,
  testCoverage: true,
  lenses: performanceProfile.lenses.map(lens => lens.id === 'unmitigated'
    ? { ...lens, testCoverage: true }
    : lens),
}
yaml
profiles:
  team-practices:
    extends: best-practices
    lenses:
    - id: asked
      question: Does the cited rule's text really ask for what the finding says is missing?
    - id: absent
      question: Is the required piece really missing? A line the test-coverage block shows as covered refutes the claim.
      testCoverage: true
    - id: introduced
      question: Is the gap in code this change adds or alters, rather than in code it leaves as it was?

The entry's lenses replace best-practices's, so one that writes its own sets testCoverage: true on the lens that asks for the line, and the profile keeps the testCoverage: true it extends. testCoverage: false on the profile turns the reading off, and the flag absent carries with it.

Its profile reads test coverage too (testCoverage: true, Writing a profile): a lens that sets it in a profile that does not warns <id>.lenses.<index>.testCoverage: has no effect while the profile reads no test coverage, and takes nothing. When the review read a coverage report (Test coverage), such a lens's vote carries one more block, tests, after the rule blocks and before the guidelines: the line of the cited file as the research's block writes it, src/a.js: zero hits 12-15, 20; missed branch 16; not measured 22-24; covered 10-11 or src/a.js: not in the coverage report, cut at 1,024 bytes with , and <n> more range(s). The data notice names it: which changed lines the project's tests ran, read by code from a coverage report: covered, zero hits, a missed branch, or not measured, by file and line range. A line not measured is no proof that no test runs it. The line is code's words and the diff's own file name, and no word of the report.

Only the lenses that ask are sent it, and not every voter of the profile. A text sent to every voter lowered kept recall in an ablation of 0.13, from 60% to 40%: a voter judging whether a rule fits, or whether code is new, has no use for it, and its votes stay the ones they were. The line is evidence for one refutation angle, whether the required piece is really missing, which is the angle absent takes: a line the block shows as covered refutes the claim that no test runs it. A lens that asks for it is sent it for every finding it votes on, a scanner's candidate or the finder's, and the state of the finding's line is kept in the verdict whatever the lenses read.

A lens sets relatedCode: true to be given related code: the excerpts of the repository's code outside the diff that its finding's cited row names, which rules of code pick and no model chooses, read at a commit quorum resolves. The flag is the lens's, and the config's relatedCode is the switch that turns the reading on for the whole review (The config), off when unset. With the switch off, a review sends, records and prints what it did before, whatever its lenses set, and no warning is earned for a flag while it is off. What is read, at which commit and under which bounds: Related code.

Four built-in lenses set it, the ones whose question rests on code the diff does not show:

LensWhy it asks
security's reachabilityWhether the sink is reachable from untrusted input depends on what calls the function around it
security's defensesWhether an existing check already neutralizes the finding is a question about code elsewhere
code-review's realWhether the quoted code misbehaves depends on what the names it uses are defined to do and who calls it
performance's hotWhether the code runs often, or on input that can grow, depends on who calls it

Every other lens judges from the finding and the diff, and its request is the one it always was: impact of security; introduced and consequential of code-review; asked, absent and introduced of best-practices; visible and unmitigated of performance. absent and unmitigated speak of "the other blocks" in their questions too, and stay unflagged until a suite has measured the four that ask.

A config sets it on a lens as it sets testCoverage:

yaml
relatedCode: true
profiles:
  security: {}
  team-security:
    extends: security
    lenses:
    - id: defenses
      question: Do existing checks elsewhere already neutralize this?
      relatedCode: true
  • A profile that extends a built-in profile inherits its lenses' flags, so team: { extends: security } asks on reachability and defenses and not on impact, and the profile of the same name as a built-in one does as well.
  • An entry that writes its own lenses sets its own. The entry's lenses replace the base's, each holding the relatedCode it states, so team-security above asks on defenses alone, and a lens that writes relatedCode: false is no flag.
  • A profile has no field of its own for it. The switch is the config's, so a profile asks as its lenses say.

A relatedCode that is no boolean is refused where it is written, relatedCode: must be true or false for the switch and profiles.<id>.lenses.<index>.relatedCode: must be true or false for a lens. A quorum whose switch is on and whose profiles have no lens that asks warns once, relatedCode: is on, and no lens of the quorum's profiles asks for related code: set relatedCode on a lens, and runs as it would without it. --print-config prints the switch after strict, and under each profile the lenses that ask, relatedCode: { lenses: [<ids>] }, while it is on (Printing the resolved config); the settings record of a result holds relatedCode: true after strict and on each lens that asks, while it is on (The settings).

Policy rules ​

A policy gives one rule for each level, high, medium and low, and each rule resolves to the number of kept votes the level needs, its threshold, once the lens count n is known:

RuleThreshold with n lenses
'unanimous'n
'majority'More than half: n halved and rounded down, plus 1
'any'1
'off' or falseNone: the level is disabled
{ minVotes: k }k, an integer from 1 to n
{ minRatio: r }r times n, rounded up, and at least 1; r is greater than 0 and at most 1
ts
import type { PolicyRules } from '@tobi-or-not/quorum'

const policy: PolicyRules = {
  high: 'unanimous',
  medium: { minRatio: 0.5 },
  low: 'off'
}

A profile without a policy gets defaultPolicy, exported by @tobi-or-not/quorum: { high: 'unanimous', medium: 'majority', low: 'off' }. It resolves this way:

Lenseshighmedium
111, never reached: a warning
222, never reached: a warning
332
443
553

meta.profiles.<id>.policy records the thresholds a review used, null for a disabled level.

Validation ​

Each of these is an issue of the ConfigError that createQuorum throws, at the path of the level, here with three lenses:

MessageCause
expected unanimous, majority, any, off, { minVotes } or { minRatio }The rule is none of these, or the level is missing
minVotes must be an integer between 1 and 3minVotes is not an integer from 1 to the lens count
minRatio must be a number greater than 0 and at most 1minRatio is out of range
a rule holds either minVotes or minRatio, not bothThe rule names both
needs 3 votes, more than policy.high (2)A level needs more kept votes than an enabled level above it
at least one confidence level must be enabledEvery level is off, at the path <id>.policy

The levels are compared in order, high, then medium, then low, skipping a disabled one. A level that needs exactly as many votes as the enabled level above it can never be reached, since the higher one wins: that is a warning, not an issue, because the default policy does it with one or two lenses.

Confidence ​

A finding's confidence is the highest level whose threshold its kept votes reach: high first, then medium, then low. A verdict that reaches a level is kept at that level. One that reaches none has no confidence, and is discarded or unreviewed, by its failed votes.

No model has a say in it. The vote reply is { keep, reasoning } with no confidence field, and anything else a voter writes is dropped, so a 2 of 3 split is medium under the security profile however certain each voter sounded.

Failed votes ​

A vote fails when its call fails or its reply is unusable, or when its provider refuses the request as too large for its model. It is recorded with its error and its failure's kind, and counts as a reject, but a discard never rests on it:

  • Unreviewed. When the finding reaches no level, quorum counts its failed votes as if they had been keeps. If that would reach an enabled level, the outcome was never decided: the finding is unreviewed, neither kept nor cleared.
  • Kept, with a gap. When a kept finding's failed votes, counted as keeps, would reach a higher level than the one it earned, it stays kept at its level, and a vote-failed entry in meta.incomplete records that the gate between the two levels rested on a vote never cast.

Both make the review incomplete: for a gating profile, the CLI exits 4, unless a gating profile kept a finding at or above its fail-on level, high by default. A vote refused as too large counts as any failed vote, and its finding also records a request-too-large gap whatever its status (kept, discarded or unreviewed), which --allow-incomplete does not lift for a gating profile: a pull request can cause it by padding the diff. The flag lifts a finding's vote-failed gap, or an unreviewed finding, only when every failed vote failed in passing: a dropped connection, a timeout of its own, or an HTTP 408, 409, 429 or 5xx. It never lifts a vote that was refused, cut off at its token limit or unusable, which planted text can cause, and such a vote beside the others keeps the exit at 4: a failed vote's kind and status say which it was (A vote). On a gating profile, do not use the flag for a pull request you do not trust. Under the security profile:

KeptRejectedFailedVerdict
300Kept, high
210Kept, medium
201Kept, medium, and a vote-failed gap: it could have been high
120Discarded
111Unreviewed: one more keep would reach medium
102Unreviewed
030Discarded
021Discarded: one more keep would still reach no level
012Unreviewed
003Unreviewed

A review cut by its abort signal records no failed vote: it rejects instead, as Abort says.

What a confidence level means ​

A level is a procedural fact: under the profile's policy, that many lenses kept the finding, each judging from its own request, which holds the finding, its evidence and the diff, never another vote. With the security profile, high means all three lenses kept it, and medium that two did.

It is not a probability, and the votes are not statistically independent judgments. Voters blind to each other reason independently, but voters on one model share its failure modes: three lenses on one model are probably worth one or two votes. A provider per lens reduces variance, and nothing shows that it stops a tuned attack. The panel filters false positives; it cannot restore a finding the finder never proposed. The Threat model has the evidence behind this.

Next ​

Prompts — the layout of every request, the templates and their variables, the notices, and what is not configurable and why.

Released under the MIT License.