# Detect, log, fix

> Seen from outside, the work is one cycle, as shown in the loop from outside]. The tools run with their fixers on and report what the fixers could not repair.

Page: Methodology · Build
Canonical: https://banes-lab.com/disciplined-methodology/build#detect-log-fix

This section is stop 31 of 102 in the learning route. Previous: [05 - Integrating algorithms](https://banes-lab.com/pag/patterns/algorithm-integration.md). Next: [18 - The gate holds the line](https://banes-lab.com/disciplined-methodology/build/the-gate-holds-the-line.md). It builds on [02 - Who does what](https://banes-lab.com/disciplined-methodology/start/who-does-what.md).

Seen from outside, the work is one cycle, as shown in [A1·a the loop from outside](https://banes-lab.com/disciplined-methodology/build#detect-log-fix-panel-a). The tools run with their fixers on and report what the fixers could not repair. The model then fixes what the report names, and the tools run again, until they report nothing. The cycle closes because the tools speak to the model in a typed format, the finding shown in [A1·b an actionable finding](https://banes-lab.com/disciplined-methodology/build#detect-log-fix-panel-b), and because the report on disk holds the state of the work rather than the output of a single run. The architecture page arrives at the same contract from the author's side: because [the author is probabilistic](https://banes-lab.com/software-architecture/scale/the-author-is-probabilistic.md), a finding is the contract between the check and the model.

### Detect, heal, report, fix

Telling the model about your principles and hoping for [compliance](https://banes-lab.com/records/arch/compliance.md) does not hold across a session. You explain the architecture at length, the model agrees, and the next file it writes breaks it in a way the explanation did not anticipate. A principle has to be turned into an action again at every line, and the model is likely to turn it into a different action each time.

For this reason I give the model specific findings rather than abstract principles, because a model refactoring against a finding tends to do better than a model generating from a principle. The effort goes into the check that produces findings, rather than into the explanation that produces agreement. In practice, the model is given the finding rather than the rule: which file, which line, what the tool expected, what it found, and the one action that would close it. It is asked to repair that and nothing else, and the tools run again once the tree has changed.

To check this, compare a session driven by findings with one driven by explanation, and count the fixes that stuck. The findings session should keep more of them; if it does not, the findings are not specific enough. A finding whose only repair the toolchain refuses to perform is withdrawn or exempted, with that refusal given as the reason. A report that can never be emptied teaches you and the model to discount its colour, and the findings beside it pay for that.

Healing comes before reporting, and the ontology calls this [auto-remediation](https://banes-lab.com/records/arch/auto-remediation.md). A violation whose repair has exactly [one correct answer](https://banes-lab.com/disciplined-methodology/verify/one-correct-answer.md) is repaired in the same run that caught it, without the developer or the model asking: a missing type the grammar computes, a form the registry records, or a name whose only legal spelling can be derived. The fix flag can switch healing off but never on, because a fix that has to be opted into turns a computed repair into a queue of work. A fix is applied, validated again and converges, so applying it twice changes nothing, which is [idempotency](https://banes-lab.com/records/arch/idempotency.md); a fix that fails its own check is not a fix. What reaches the model is what remains: the findings that need judgement, such as which concern a file belongs to, whether two roles should be split, or where a duplicated fact should live.

The error log is how the tools talk to the model, so it is typed. A finding carries the id of the check that fired, the path and the position inside the file, the steps the check took to reach its result, the value it found, the value it expected where one can be derived, a repair stated as an action with real operands, and whether the fixer already applied it. Prose in a finding counts as a defect, because the model reading it should not have to repeat the analysis the check already did. A sentence describing a rename is only a description, while the action and its two operands are a contract the model can carry out.

Because every run leaves its report on disk, the reports also serve as [audit logging](https://banes-lab.com/records/arch/audit-logging.md): you can go back and read what each run found, as described in [a report, not a checkbox](https://banes-lab.com/disciplined-methodology/verify/a-report-not-a-checkbox.md).

A1·a the loop from outside

```mermaid
flowchart TB
detect["Detect · the one command, fixers on"]
heal["Heal · every finding with one correct answer, in the same run"]
report["Report · the findings the fixers left, as data on disk"]
fix["Fix · the model, one finding at a time, from the report"]
detect --> heal --> report --> fix
fix -- until the report is empty --> detect
```

A1·b an actionable finding

```text
engine/registries/route.registry.ts:41
rule      literal-in-lookup
locus     the first argument of the lookup call
trail     resolved the callee verb, matched the lookup form, read the argument
expected  an imported constant as the lookup key
found     the string literal "home"
fix       replace the argument with the id from the ids module: HOME_PAGE
healed    no
```

## Links to

- [The author is probabilistic](https://banes-lab.com/software-architecture/scale/the-author-is-probabilistic.md)
- [Compliance](https://banes-lab.com/records/arch/compliance.md)
- [Auto-Remediation](https://banes-lab.com/records/arch/auto-remediation.md)
- [One correct answer](https://banes-lab.com/disciplined-methodology/verify/one-correct-answer.md)
- [Idempotency](https://banes-lab.com/records/arch/idempotency.md)
- [Audit Logging](https://banes-lab.com/records/arch/audit-logging.md)
- [A report, not a checkbox](https://banes-lab.com/disciplined-methodology/verify/a-report-not-a-checkbox.md)

## Linked from

- [Who does what](https://banes-lab.com/disciplined-methodology/start/who-does-what.md)
- [A check matches a shape](https://banes-lab.com/disciplined-methodology/build/a-check-matches-a-shape.md)
- [The author is probabilistic](https://banes-lab.com/software-architecture/scale/the-author-is-probabilistic.md)
