Skip to main content
The Consensus Engine runs several verification engines on one query, with fault tolerance. Its result is advisory only.
Consensus is advisory only (releases after v11.0.0). Every engine decides a model’s translation of your query, and the query states no claim of yours, so engines that agree have not verified anything. /verify/consensus returns UNVERIFIABLE or BLOCKED, never VERIFIED, in every mode. Every response carries advisory_only: true and meets_requirement: false, its proof_ref is always null, and none carries an attestation. Use the result as a signal for review, not as a verification.
Changed in v4.0.4: Python code verification within consensus now runs exclusively through the secure Docker executor (SecureCodeExecutor). If the Docker sandbox is unavailable, consensus returns a blocked_secure_execution status and the API responds with HTTP 503. From v6.0.0, the API responds with HTTP 200 and BLOCKED instead.

Features

  • Async parallel execution — Run engines concurrently
  • Circuit breaker — Temporarily excludes engines that time out or raise errors
  • Engine health monitoring — Track reliability
  • Weighted consensus — Consider engine reliability
  • Secure code execution — Python engine runs through the Docker sandbox only

Usage

Changed in v10.0.0
One engine is not a consensus. In the example, SymPy verifies the answer and the Python engine is advisory only, so the answer has been verified by one engine alone. The result is BLOCKED with constraint_id: "consensus.no_independent_verification" and confidence: 0.0. When two distinct engines verify, the result is still not VERIFIED. It is UNVERIFIABLE, because consensus is advisory only.

Verification modes

The high and maximum modes include the Python engine, which requires the secure Docker sandbox. If Docker is unavailable, these modes return blocked_secure_execution instead of falling back to in-process execution. This status takes precedence over no_independent_verification, so it is returned even when SymPy verified the answer. The /verify/consensus response is then BLOCKED with HTTP 200, not an HTTP error.

Async execution

Circuit breaker

The circuit breaker excludes an engine that stops answering. It measures engine health, not verdicts:
  • A verdict is never a failure. An engine that returns a result within the execution deadline counts as healthy, whatever it decides: a wrong claim, an unsatisfiable model or a question it cannot use.
  • Only an engine that does not answer counts as a failure: a timeout, or an exception the engine does not handle.
  • Three consecutive failures open the circuit for 30 seconds. During that time the engine is skipped and recorded as a BLOCKED result with the error Engine excluded by open circuit breaker. A skipped engine records no new failure. After 30 seconds the engine is degraded and runs again, and one success returns it to healthy. Any success resets the count of consecutive failures. While the engine is degraded, one more failure opens the circuit again for another 30 seconds, because only a success resets the count.
  • The breaker is shared by every request handled by the same server process. One caller’s timeouts can exclude an engine for every other caller until the circuit closes.
Before this fix, an engine’s verdict counted as a failure, so three wrong claims in a row opened SymPy’s circuit for 30 seconds for every caller.

Execution deadlines and partial results

Consensus verification runs under a single 30-second aggregate deadline that covers all engines. No engine call can hold a request open indefinitely, and /verify/consensus never hangs or returns HTTP 500 because one engine stalled. How the deadline applies:
  • One aggregate budget, not per-engine stacking. All selected engines share the same 30-second wall clock. Sequential per-engine waits cannot accumulate beyond it.
  • Timed-out engines become explicit BLOCKED results. An engine that misses the deadline is recorded in verification_chain as a BLOCKED EngineResult with the timeout in its error field (for example, "Engine timed out after 30s"). The failure is also recorded with the circuit breaker.
  • Circuit-open engines are recorded too. An engine skipped because its circuit breaker is open appears as a BLOCKED result rather than being silently dropped.
  • Partial results still aggregate. Engines that finished within the deadline contribute normally. The consensus verdict is computed from the results that arrived, with the fail-closed status propagation rules applied. The consensus is UNVERIFIABLE, or BLOCKED when every engine is blocked, not all of them for a translation cause, or only one engine verified. In releases after v11.0.0, a translating engine that started and was still waiting for the model at the deadline carries the cause translation.failed, so when every engine stops that way the consensus is UNVERIFIABLE with agreement_status not_translated. An engine that already had its translation, or never started, names no cause. An engine skipped because its circuit breaker is open names no cause either.
  • Off the event loop. Engine execution runs in a dedicated per-call executor, so a slow consensus request degrades only itself, not other API traffic.
A consensus response that includes timed-out engines is a valid partial result, not an error. Check verification_chain to see which engines contributed and treat the aggregate status as authoritative.

Async failure handling

When an unexpected error occurs during async engine aggregation, the Consensus Engine records the failure as a dedicated EngineResult entry rather than silently dropping it. This ensures that:
  • The failure is visible in the results array returned to the caller
  • Aggregate confidence scores account for the failed engine
  • The error is logged via logger.exception for post-mortem debugging
The recorded result uses engine_name: "consensus_orchestrator", method: "async_aggregation", success: false, and includes the error message in the error field.

Secure execution gates

Before any Python code runs in the Docker sandbox, two validation layers apply. Both fail closed: a rejected input returns a security error instead of executing.

Single-expression gate on translated math

When consensus translates a natural-language math query, the translated expression is interpolated into the generated verification code. The translator therefore enforces that the output is exactly one Python expression:
  • The expression must parse with ast.parse(..., mode="eval"). Multi-statement input, semicolon chains, assignments, imports, and multi-line newline smuggling all fail by construction.
  • Expressions longer than 500 characters are rejected before parsing, so deeply nested adversarial input never reaches the parser.
  • The existing character-set and denylist checks remain as defense in depth.
Bracketed multi-line expressions (a single expression wrapped in parentheses across lines) still pass. Anything that is not one expression does not.

Module-indirection blocklist on executed code

The pre-execution AST check on sandboxed Python code inspects every dotted segment, not just the first:
  • Imports of OS, process, and reflection modules (os, sys, subprocess, socket, posix, nt, importlib, ctypes, builtins, and network clients) are blocked wherever the module name appears in the import path, including from ... import os as safe aliasing.
  • Attribute chains are blocked when any segment names a dangerous module, so package-internal re-exports (reaching the OS module through pandas or numpy internals) are caught even though the chain is rooted at an innocuous alias.
  • OS-primitive calls (system, popen, import_module, the exec*/spawn* families, fork) are blocked as bare names and as attribute targets, which also stops importlib.import_module("os")-style indirection.
Legitimate pandas and numpy verification code at the public API surface (np.linalg.norm, pd.Timestamp.now) is unaffected.

Runtime module and builtin allowlist

Since v7.3.0, sandboxed code also runs in an isolated namespace inside the container. This runtime layer applies even if code gets past the static checks:
  • Imports are limited to an allowlist of analysis modules (the same allowlist the Stats engine uses): numpy, pandas, scipy, sklearn, statsmodels, patsy, math, cmath, statistics, decimal, fractions, random, datetime, json, re, collections, itertools, functools, operator, array, bisect, heapq, string, and typing. Importing any other module, or using a relative import, raises ImportError and the execution fails.
  • Builtins are reduced to safe names. eval, exec, compile, getattr, setattr, delattr, vars, globals, locals, open, input, and memoryview are not available.
  • np/numpy and pd/pandas are pre-bound, so generated code doesn’t need to import them. Assign the output to result.
Behavior change in v7.3.0. Sandboxed code that imported a module outside the allowlist now fails. Rewrite it to use the allowlisted modules. See GHSA-j3x4-v3p2-4mq3.

Engine selection

The consensus engine automatically selects which engines to run based on the verification mode:

Z3 engine in maximum mode

The Z3 engine proves a claim, as /verify/logic does. The model translates the query into constraints and a claim, and Z3 decides whether the claim follows from the constraints. Before this fix, the Z3 engine failed on every query and was recorded as BLOCKED. The Z3 engine’s VERIFIED is its own verdict on the translated claim, shown in verification_chain. It cannot make the consensus VERIFIED. Z3 decides whether a claim holds, not a value, so it does not vote on the answer. It still counts as an engine that verified: when SymPy and Z3 both verify, the consensus is UNVERIFIABLE, and when only Z3 verifies, the consensus is BLOCKED with no final_answer. The Z3 solve runs on the same dedicated thread as /verify/logic solves and is bounded by QWED_Z3_TIMEOUT (default 15 seconds), counted from when the solve is queued. A solve that does not finish in time is recorded as a BLOCKED Z3 result and as a failure with the circuit breaker. Its error in verification_chain reads Engine execution failed, not a timeout message, so a check for "timed out" like the example above does not catch it. The 30-second consensus deadline still applies to the whole engine run, translation included.
The fact engine is excluded from automatic engine selection. Fact verification requires external context, and including it in consensus without that context would create self-referential verification loops. If fact verification is invoked during consensus, it returns an error indicating that external context is required.

Consensus calculation

The engine weights each answer by engine reliability: Final confidence = weighted average of agreeing engines. Z3 does not vote on the answer (see Z3 engine in maximum mode). Agreement and confidence never make the result VERIFIED.

Agreement statuses

Status propagation

Consensus is advisory, not a proof engine. Per the 3-tier engine classification, the consensus result is UNVERIFIABLE or BLOCKED, never VERIFIED:
  • The prompt-injection check refuses the query → the consensus result is BLOCKED with agreement_status blocked, constraint_id security.input_refused and no answer. This check runs before any engine is selected, so no engine runs, none answers the query and none records a failure with its circuit breaker. It is the check /verify/natural_language applies, so it also refuses a query over 2,000 characters or one that contains words such as mode, root or system.
  • The Python engine finds the Docker sandbox unavailable → the consensus result is BLOCKED with agreement_status blocked_secure_execution, whatever the other engines returned. This rule is checked first among engine results.
  • All engines stop for a translation cause → the consensus result is UNVERIFIABLE with agreement_status not_translated and that cause. An engine still waiting for the model at its deadline counts as translation.failed. An engine cancelled before it started names no cause.
  • All engines return BLOCKED → the consensus result is BLOCKED, with the shared cause when every engine was refused for the same one.
  • Otherwise, only one engine verifies the answer → the consensus result is BLOCKED with constraint_id: "consensus.no_independent_verification" and confidence 0.0, whatever the other engines returned (advisory, blocked or absent). One engine is not a consensus.
  • Otherwise → the consensus result is UNVERIFIABLE, whether the engines agree or not and however many verified. Before this change, a consensus was VERIFIED only when two distinct engines verified the same answer, which no two engines did, as the Z3 engine failed on every query.
  • The route passes every result through one more check: any status other than UNVERIFIABLE or BLOCKED is returned as UNVERIFIABLE, so the consensus status never reaches the response, the attestation or the audit row as VERIFIED. Each verification_chain entry keeps its engine’s own status, which can be VERIFIED.
  • Math-query translation failures fail closed — the engine raises rather than fabricating a numeric answer from a regex or decimal guess.
Individual engine outcomes are exposed via the status field on each EngineResult in the aggregated result.

Sub-engine status contract

Not every sub-engine that runs under consensus can emit VERIFIED. The table below makes the fail-closed contract explicit — these engines never contribute a VERIFIED vote, even on a successful computation, so their output stays advisory: This mirrors the existing Fact engine heuristic contract: a TF-IDF SUPPORTED verdict is capped at UNVERIFIABLE because heuristic support is not a proof. A query answered only by Stats or code execution stops at UNVERIFIABLE, with the computed value carried through as advisory data.

ConsensusResult

Async and sync consensus verification both return a ConsensusResult dataclass that carries the aggregated verdict along with per-engine detail:
status is now a DiagnosticStatus enum rather than a bare string. Code that compared result.status == "BLOCKED" should use result.status is DiagnosticStatus.BLOCKED or check result.status.value for the string form.

.to_diagnostic_result()

ConsensusResult converts to a DiagnosticResult that is UNVERIFIABLE or BLOCKED, with advisory_only: true in its developer fields:
The conversion is fail-closed: a ConsensusResult whose status says VERIFIED, such as one built by hand, converts to UNVERIFIABLE. The /verify/consensus endpoint’s meets_requirement flag is always false, on every response. Confidence alone is never sufficient.