# quality-engine

> Every algorithm contract in this domain is listed with its position on the derivation loop, its intent and invariant, the flow it walks, its productions as a…

Page: Ontology · Algorithms
Canonical: https://banes-lab.com/ontology/algorithms#algo-domain-quality-engine

Every algorithm contract in this domain is listed with its position on the derivation loop, its intent and invariant, the flow it walks, its productions as a grammar, what it composes and is composed by, which forces and principles it answers to, what grounds it and what it grounds, and an exemplar where the record carries one. The diagram shows what composes what inside the domain.

Relations diagram

What composes what inside this domain.

```mermaid
flowchart LR
n_quality_governance_loop["Quality Governance Loop"]
n_canonical_config_resolution["Canonical Config Resolution"]
n_stage_ordering["Stage Ordering"]
n_comment_normalization_remediation["Comment Normalization Remediation"]
n_custom_rule_derivation["Custom-Rule Derivation"]
n_machine_verdict_derivation["Machine Verdict Derivation"]
n_bounded_cascade_termination["Bounded Cascade Termination"]
n_quality_engine_concern["Quality-Engine Kernel"]
n_quality_governance_loop --> n_canonical_config_resolution
n_quality_governance_loop --> n_stage_ordering
n_quality_governance_loop --> n_comment_normalization_remediation
n_quality_governance_loop --> n_machine_verdict_derivation
n_quality_governance_loop --> n_bounded_cascade_termination
n_quality_engine_concern --> n_canonical_config_resolution
n_quality_engine_concern --> n_stage_ordering
n_quality_engine_concern --> n_quality_governance_loop
```

### Quality Governance Loop

- Math type: [computation](https://banes-lab.com/records/reason/math-type-computation.md)
- Yields: procedure

Details

Intent
On each update (an apply), normalize the proposal, resolve a CheckPlan, verify it, and on failure fix-then-reverify the downstream set until the verdict is clean or the pass bound is reached, then escalate.

Invariant
Every code update is a bounded verify-remediate loop keyed to the apply event, not the turn; the machine verdict — never the model's read — is its only completion signal.

Flow

```text
Update → Normalize → Resolve → Verify → Clean? → Fix → Reverify → Clean|Escalate
```

Productions

```bnf
QualityGovernanceLoop ::= <Update> "->" <NormalizationPrefix> "->" <CheckPlanResolution> "->" <Verification> "->" (<CleanVerdict> | <DownstreamFixCycle> "->" <QualityGovernanceLoop>)
DownstreamFixCycle ::= <InScopeFindings> "->" <ModelFixBurst> "->" <Reapply> "->" <BoundedReverify>
BoundedReverify ::= "passCount <= MAX_CASCADE_PASSES" "AND" "in_scope_findings_strictly_decrease" | "escalate"
```

Composes
[Recursion Control](https://banes-lab.com/records/algo/recursion-control.md), [Resilience Control](https://banes-lab.com/records/algo/resilience-control.md)

Composed by
[Quality-Engine Kernel](https://banes-lab.com/records/algo/quality-engine-concern.md)

Forces
[semantic_consistency](https://banes-lab.com/records/force/semantic-consistency.md), [correctness_verification](https://banes-lab.com/records/force/correctness-verification.md), [security_governance](https://banes-lab.com/records/force/security-governance.md), [model_governance](https://banes-lab.com/records/force/model-governance.md), [event_messaging](https://banes-lab.com/records/force/event-messaging.md)

Grounds
[derivation-loop](https://banes-lab.com/ontology/reasoning/reason-loop-derivation-loop.md)

Derivation map

derive
[Canonical Config Resolution](https://banes-lab.com/records/algo/canonical-config-resolution.md)

project
[Stage Ordering](https://banes-lab.com/records/algo/stage-ordering.md)

act
[Comment Normalization Remediation](https://banes-lab.com/records/algo/comment-normalization-remediation.md)

verify
[Machine Verdict Derivation](https://banes-lab.com/records/algo/machine-verdict-derivation.md)

terminate
[Bounded Cascade Termination](https://banes-lab.com/records/algo/bounded-cascade-termination.md)

Before

```text
A code edit judged clean by the model's read, not the machine verdict.
```

After

```text
apply → normalize → resolve CheckPlan → verify → {clean | fix in-scope + reverify, bounded, findings strictly decrease} → clean | escalate
```

### Canonical Config Resolution

- Stage: [derive](https://banes-lab.com/records/stage/derive.md)
- Axis: [reasoning](https://banes-lab.com/records/reason/axis-reasoning.md)
- Math type: [logic](https://banes-lab.com/records/reason/math-type-logic.md)
- Yields: boolean

Details

Intent
Expand one canonical config across selected profiles and native rules into per-tool config, resolve exactly one owner per contested surface, detect the four conflict kinds fail-closed, route loosening or self-certification to the developer's gate, and emit a resolved plan.

Invariant
A single canonical model expands to many tools without contradiction only when every contested surface has one owner and every conflict is caught before runtime.

Flow

```text
CanonicalConfig → Expand → OwnershipResolution → ConflictDetection → HumanAuthorityRouting → ResolvedPlan|ConflictReport
```

Productions

```bnf
CanonicalConfigResolution ::= <CanonicalConfig> "->" <PerToolExpansion> "->" <SingleOwnerPerSurface> "->" <ConflictDetection> "->" (<ResolvedPlan> | <ConflictReport>)
ConflictKind ::= "ownership_overlap" | "unsatisfiable_on_fixed" | "value_out_of_range" | "known_bad_pair"
Resolution ::= "single_owner_enabled" | "route_to_human_authority_gate"
```

Composes
[Centralization Kernel](https://banes-lab.com/records/algo/centralization-kernel.md), [Canonical Data](https://banes-lab.com/records/algo/canonical-data.md)

Composed by
[Quality-Engine Kernel](https://banes-lab.com/records/algo/quality-engine-concern.md)

Named in the derivation of
[Quality Governance Loop](https://banes-lab.com/records/algo/quality-governance-loop.md)

Forces
[semantic_consistency](https://banes-lab.com/records/force/semantic-consistency.md), [model_governance](https://banes-lab.com/records/force/model-governance.md)

Grounds
none

Before

```text
One config expanded to many tools with contradictory, unowned rules.
```

After

```text
canonical config → per-tool expansion → one owner per contested surface → detect conflicts{ownership overlap, unsatisfiable, out-of-range, known-bad-pair} fail-closed → resolved plan | conflict report
```

### Stage Ordering

- Stage: [project](https://banes-lab.com/records/stage/project.md)
- Axis: [reasoning](https://banes-lab.com/records/reason/axis-reasoning.md)
- Math type: [graph](https://banes-lab.com/records/reason/math-type-graph.md)
- Yields: edge-list

Details

Intent
Build the runnability DAG from dependsOn, topologically order the cascade by the invalidates relation so fixes point forward, partition into normalization prefix, structural band, and semantic suffix, and permit back-edges only inside the suffix.

Invariant
The order determines the total work scope; a forward-pointing order makes each fix dirty only later stages, so the prefix converges once and the suffix is bounded.

Flow

```text
Stages → RunnabilityDAG → InvalidatesTopoSort → BandPartition → OrderedStages
```

Productions

```bnf
StageOrdering ::= <StageSet> "->" <DependsOnDAG> "->" <InvalidatesOrder> "->" <BandPartition> "->" <OrderedStages>
BandPartition ::= "normalization_prefix" "," "structural_band" "," "semantic_suffix"
BackEdgePolicy ::= "allowed_only_in_semantic_suffix_resolved_at_runtime"
```

Composes
none

Composed by
[Quality-Engine Kernel](https://banes-lab.com/records/algo/quality-engine-concern.md)

Named in the derivation of
[Quality Governance Loop](https://banes-lab.com/records/algo/quality-governance-loop.md)

Forces
[semantic_consistency](https://banes-lab.com/records/force/semantic-consistency.md), [causality_ordering](https://banes-lab.com/records/force/causality-ordering.md)

Grounds
none

Before

```text
Checks run in arbitrary order, so a fix re-dirties an already-passed stage forever.
```

After

```text
stages → runnability DAG (dependsOn) → topo-order by invalidates (fixes point forward) → bands{normalization prefix, structural, semantic suffix}; back-edges only in the suffix
```

### Comment Normalization Remediation

- Stage: [act](https://banes-lab.com/records/stage/act.md)
- Axis: [formalisation](https://banes-lab.com/records/reason/axis-formalisation.md)
- Math type: [computation](https://banes-lab.com/records/reason/math-type-computation.md)
- Yields: procedure

Details

Intent
Express the comment-strip rule once as canonical behavior, bind it per language from a comment-grammar descriptor, run the toolchain-free token-scan backing on the in-memory proposal and the real-AST backing in the sandbox, preserve directive comments, and trust a backing only after calibration and adversarial testing.

Invariant
An agnostic auto-fix is behavior-as-data compiled per language behind a safety boundary — adding a language is adding a descriptor, not code.

Flow

```text
CanonicalRule + GrammarDescriptor → Compile → TokenScan|ASTBacking → DirectivePreservingStrip → CalibratedFix
```

Productions

```bnf
CommentNormalization ::= <CanonicalCommentRule> "->" <PerLanguageDescriptor> "->" <CompiledBacking> "->" <DirectivePreservingStrip> "->" <SafetyBoundary>
CompiledBacking ::= "ast_lite_token_scan_in_memory" | "real_ast_via_tier_p_sandbox"
SafetyBoundary ::= "tool_calibration" "," "adversarial_input_testing"
```

Composes
none

Named in the derivation of
[Quality Governance Loop](https://banes-lab.com/records/algo/quality-governance-loop.md)

Forces
[modularity](https://banes-lab.com/records/force/modularity.md), [semantic_consistency](https://banes-lab.com/records/force/semantic-consistency.md), [correctness_verification](https://banes-lab.com/records/force/correctness-verification.md)

Grounds
none

Before

```text
A comment-strip auto-fix hardcoded per language, so adding a language means new code.
```

After

```text
canonical rule + comment-grammar descriptor → compile per language → token-scan (in-memory) | real-AST (sandbox) → preserve directive comments → trust only after calibration + adversarial test
```

### Custom-Rule Derivation

- Stage: [act](https://banes-lab.com/records/stage/act.md)
- Axis: [formalisation](https://banes-lab.com/records/reason/axis-formalisation.md)
- Math type: [computation](https://banes-lab.com/records/reason/math-type-computation.md)
- Yields: procedure

Details

Intent
Derive a candidate rule from repeated evidence through anti-pattern classification, boundary-principle evaluation, and candidate selection, migrate with rollback, verify elimination, and admit a tightening rule while routing a self-certifying or loosening rule through the developer's gate.

Invariant
A rule that governs the model's own output cannot be authored or loosened by the model; tightening is admitted, self-certification is gated.

Flow

```text
Evidence → AntiPattern → BoundaryPrinciple → Candidate → Migrate → Verify → Admit|HumanGate
```

Productions

```bnf
CustomRuleDerivation ::= <RepeatedEvidence> "->" <AntiPatternClassification> "->" <BoundaryPrincipleEvaluation> "->" <CandidateSelection> "->" <BackupVerifiedMigration> "->" <SelfCertGate>
SelfCertGate ::= "tightening_admitted" | "self_certifying_or_loosening_routes_to_human_authority"
```

Composes
[Pattern Distiller Kernel](https://banes-lab.com/records/algo/pattern-distiller-kernel.md), [Anti-Pattern Classification](https://banes-lab.com/records/algo/anti-pattern-classification.md), [Backup-Verified Migration](https://banes-lab.com/records/algo/backup-verified-migration.md)

Forces
[modularity](https://banes-lab.com/records/force/modularity.md), [state_transaction](https://banes-lab.com/records/force/state-transaction.md), [correctness_verification](https://banes-lab.com/records/force/correctness-verification.md), [model_governance](https://banes-lab.com/records/force/model-governance.md)

Grounds
none

Before

```text
The model authors and loosens a rule that governs its own output.
```

After

```text
repeated evidence → anti-pattern classify → boundary principle → candidate → migrate with rollback → verify elimination → {tightening admitted | self-certify/loosen routes to the developer's gate}
```

### Machine Verdict Derivation

- Stage: [verify](https://banes-lab.com/records/stage/verify.md)
- Axis: [verification](https://banes-lab.com/records/reason/axis-verification.md)
- Math type: [logic](https://banes-lab.com/records/reason/math-type-logic.md)
- Yields: boolean

Details

Intent
Derive the verify-stage verdict from the toolchain's machine output — exit codes and parsed findings — never from the model's reading, so a clean verdict is an observed machine fact.

Invariant
The verify verdict is machine-derived from exit codes and parsed findings; a model's judgement is never the completion signal.

Flow

```text
CheckResults → ExitCodesAndFindings → MachineVerdict
```

Productions

```bnf
MachineVerdictDerivation ::= <CheckResults> "->" <ExitCodeAndFindingParse> "->" <MachineVerdict>
MachineVerdict ::= "clean" | "violations"
```

Composes
none

Named in the derivation of
[Quality Governance Loop](https://banes-lab.com/records/algo/quality-governance-loop.md)

Forces
[correctness_verification](https://banes-lab.com/records/force/correctness-verification.md), [model_governance](https://banes-lab.com/records/force/model-governance.md)

Grounds
[ver-evidence](https://banes-lab.com/records/reason/node-ver-evidence.md)

Before

```text
A pass declared from the model's reading of the diff, not the tool's exit.
```

After

```text
check results → exit codes + parsed findings → machine verdict{clean | violations}; the model's read is never the signal
```

### Bounded Cascade Termination

- Stage: [terminate](https://banes-lab.com/records/stage/terminate.md)
- Axis: [termination](https://banes-lab.com/records/reason/axis-termination.md)
- Math type: [optimisation](https://banes-lab.com/records/reason/math-type-optimisation.md)
- Yields: boolean | ranking

Details

Intent
Terminate the verify-remediate cascade on the completion AND-gate — a clean verdict, or bounded progress where findings strictly decrease within the pass bound — escalating when neither holds.

Invariant
The cascade terminates on a clean machine verdict or a violated progress bound; it never loops unbounded and never stops on an unclean state without escalating.

Flow

```text
PassResult → CompletionGate → Stop|Continue|Escalate
```

Productions

```bnf
BoundedCascadeTermination ::= <PassResult> "->" <CompletionGate> "->" (<Clean> | <BoundedContinue> | <Escalate>)
CompletionGate ::= "clean" | "findings_strictly_decrease" "AND" "passCount <= MAX_CASCADE_PASSES" | "escalate"
```

Composes
none

Named in the derivation of
[Quality Governance Loop](https://banes-lab.com/records/algo/quality-governance-loop.md)

Forces
[correctness_verification](https://banes-lab.com/records/force/correctness-verification.md), [resilience_recovery](https://banes-lab.com/records/force/resilience-recovery.md)

Grounds
[ter-stop](https://banes-lab.com/records/reason/node-ter-stop.md)

Before

```text
A remediation cascade that loops until it happens to pass, or forever.
```

After

```text
each pass → {clean: stop | findings strictly decrease AND passCount <= MAX: continue | else: escalate}
```

### Quality-Engine Kernel

- Meta record

Details

Intent
Resolve a canonical policy into a per-ecosystem CheckPlan, order its stages by the invalidates relation, normalize the proposal, run generation checks on the server and project tools via the relay, derive a machine verdict, and drive a bounded downstream cascade to clean — holding no runtime execution in the engine itself.

Invariant
Language-agnostic code governance is a pure planner-plus-judge behind a port; execution lives in the relay and the loop, the verdict is machine-derived, and the config gate has already removed every runtime contradiction.

Flow

```text
Policy → Resolve → Order → Normalize → Execute(G+P) → Verdict → Cascade → Clean|Escalate
```

Productions

```bnf
QualityEngineKernel ::= <QualityPolicy> "->" <CanonicalConfigResolution> "->" <StageOrdering> "->" <CommentNormalization> "->" <CheckPlanExecution> "->" <VerdictDerivation> "->" <QualityGovernanceLoop>
CheckPlanExecution ::= "generation_checks_server_side" "," "project_commands_via_relay"
VerdictDerivation ::= "exit_code" | "parse_findings"
EngineBoundary ::= "pure_core_no_runtime_execution_behind_port_adapter"
```

Composes
[Canonical Config Resolution](https://banes-lab.com/records/algo/canonical-config-resolution.md), [Stage Ordering](https://banes-lab.com/records/algo/stage-ordering.md), [Quality Governance Loop](https://banes-lab.com/records/algo/quality-governance-loop.md)

Forces
[semantic_consistency](https://banes-lab.com/records/force/semantic-consistency.md), [security_governance](https://banes-lab.com/records/force/security-governance.md)

Grounds
none

## Links to

- [Computation](https://banes-lab.com/records/reason/math-type-computation.md)
- [Recursion Control](https://banes-lab.com/records/algo/recursion-control.md)
- [Resilience Control](https://banes-lab.com/records/algo/resilience-control.md)
- [Quality-Engine Kernel](https://banes-lab.com/records/algo/quality-engine-concern.md)
- [semantic_consistency](https://banes-lab.com/records/force/semantic-consistency.md)
- [correctness_verification](https://banes-lab.com/records/force/correctness-verification.md)
- [security_governance](https://banes-lab.com/records/force/security-governance.md)
- [model_governance](https://banes-lab.com/records/force/model-governance.md)
- [event_messaging](https://banes-lab.com/records/force/event-messaging.md)
- [The derivation loop](https://banes-lab.com/ontology/reasoning/reason-loop-derivation-loop.md)
- [Canonical Config Resolution](https://banes-lab.com/records/algo/canonical-config-resolution.md)
- [Stage Ordering](https://banes-lab.com/records/algo/stage-ordering.md)
- [Comment Normalization Remediation](https://banes-lab.com/records/algo/comment-normalization-remediation.md)
- [Machine Verdict Derivation](https://banes-lab.com/records/algo/machine-verdict-derivation.md)
- [Bounded Cascade Termination](https://banes-lab.com/records/algo/bounded-cascade-termination.md)
- [Derive](https://banes-lab.com/records/stage/derive.md)
- [Reasoning](https://banes-lab.com/records/reason/axis-reasoning.md)
- [Logic](https://banes-lab.com/records/reason/math-type-logic.md)
- [Centralization Kernel](https://banes-lab.com/records/algo/centralization-kernel.md)
- [Canonical Data](https://banes-lab.com/records/algo/canonical-data.md)
- [Quality Governance Loop](https://banes-lab.com/records/algo/quality-governance-loop.md)
- [Project](https://banes-lab.com/records/stage/project.md)
- [Graph](https://banes-lab.com/records/reason/math-type-graph.md)
- [causality_ordering](https://banes-lab.com/records/force/causality-ordering.md)
- [Act](https://banes-lab.com/records/stage/act.md)
- [Formalisation](https://banes-lab.com/records/reason/axis-formalisation.md)
- [modularity](https://banes-lab.com/records/force/modularity.md)
- [Pattern Distiller Kernel](https://banes-lab.com/records/algo/pattern-distiller-kernel.md)
- [Anti-Pattern Classification](https://banes-lab.com/records/algo/anti-pattern-classification.md)
- [Backup-Verified Migration](https://banes-lab.com/records/algo/backup-verified-migration.md)
- [state_transaction](https://banes-lab.com/records/force/state-transaction.md)
- [Verify](https://banes-lab.com/records/stage/verify.md)
- [Verification](https://banes-lab.com/records/reason/axis-verification.md)
- [Ver Evidence](https://banes-lab.com/records/reason/node-ver-evidence.md)
- [Terminate](https://banes-lab.com/records/stage/terminate.md)
- [Termination](https://banes-lab.com/records/reason/axis-termination.md)
- [Optimisation](https://banes-lab.com/records/reason/math-type-optimisation.md)
- [resilience_recovery](https://banes-lab.com/records/force/resilience-recovery.md)
- [Ter Stop](https://banes-lab.com/records/reason/node-ter-stop.md)
