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
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
BLOCKEDresult with the errorEngine excluded by open circuit breaker. A skipped engine records no new failure. After 30 seconds the engine isdegradedand runs again, and one success returns it tohealthy. Any success resets the count of consecutive failures. While the engine isdegraded, 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.
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
BLOCKEDresults. An engine that misses the deadline is recorded inverification_chainas aBLOCKEDEngineResultwith the timeout in itserrorfield (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
BLOCKEDresult 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, orBLOCKEDwhen 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 causetranslation.failed, so when every engine stops that way the consensus isUNVERIFIABLEwithagreement_statusnot_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 dedicatedEngineResult entry rather than silently dropping it. This ensures that:
- The failure is visible in the
resultsarray returned to the caller - Aggregate confidence scores account for the failed engine
- The error is logged via
logger.exceptionfor post-mortem debugging
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.
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, includingfrom ... import os as safealiasing. - 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, theexec*/spawn*families,fork) are blocked as bare names and as attribute targets, which also stopsimportlib.import_module("os")-style indirection.
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, andtyping. Importing any other module, or using a relative import, raisesImportErrorand the execution fails. - Builtins are reduced to safe names.
eval,exec,compile,getattr,setattr,delattr,vars,globals,locals,open,input, andmemoryvieware not available. np/numpyandpd/pandasare pre-bound, so generated code doesn’t need to import them. Assign the output toresult.
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 isUNVERIFIABLE or BLOCKED, never VERIFIED:
- The prompt-injection check refuses the query → the consensus result is
BLOCKEDwithagreement_statusblocked,constraint_idsecurity.input_refusedand 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_languageapplies, so it also refuses a query over 2,000 characters or one that contains words such asmode,rootorsystem. - The Python engine finds the Docker sandbox unavailable → the consensus result is
BLOCKEDwithagreement_statusblocked_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
UNVERIFIABLEwithagreement_statusnot_translatedand that cause. An engine still waiting for the model at its deadline counts astranslation.failed. An engine cancelled before it started names no cause. - All engines return
BLOCKED→ the consensus result isBLOCKED, with the shared cause when every engine was refused for the same one. - Otherwise, only one engine verifies the answer → the consensus result is
BLOCKEDwithconstraint_id: "consensus.no_independent_verification"andconfidence0.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 wasVERIFIEDonly 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
UNVERIFIABLEorBLOCKEDis returned asUNVERIFIABLE, so the consensusstatusnever reaches the response, the attestation or the audit row asVERIFIED. Eachverification_chainentry keeps its engine’s own status, which can beVERIFIED. - Math-query translation failures fail closed — the engine raises rather than fabricating a numeric answer from a regex or decimal guess.
status field on each EngineResult in the aggregated result.
Sub-engine status contract
Not every sub-engine that runs under consensus can emitVERIFIED. 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 aConsensusResult 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:
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.