Files
Open_Ultra_SAST/docs/architecture.md
T
Marius Ciepluch c10dc11a43 docs(readme): a system map above the documentation index; open parts link docs to the roadmap
The maintainer's request of 2026-11-28, in chat, after 6ef8381: use Archify to map the
system and add the map to the README, before the index that links each part to its
documentation; say which parts to document and which open parts the documentation
should link into the roadmap. Two menus followed, each answered with the option
recommended. Menu 3: all fourteen parts, in four groups; all nine open parts, listed
on the roadmap page and linked from the seven pages that describe them; a static SVG
in the README, the interactive HTML left out of the repository; the open parts show
the states as the records hold them today, not the decisions of the earlier menu.
Menu 4: the wording of the section and of the seven sentences, and the caption of the
image, each "Write it as shown (Recommended)".

Four places differ from that wording, each on a finding of the reviewer. The two
cells follow the answer that the section show the states as the records hold them
today: the row on graph reuse says "Not scheduled; no step owns it" where the wording
said R5, and the row on the proof arm says "R4, if it needs it" where it said R4.
The pre-push page gained a sentence in front of its link: "No pre-push capability is
admitted yet." And the box of the proof arm in the map names "Use case", the page
that describes the arm, where it named "Where we stand".

What changed. Measured in /tmp/opencode/s10_rd2_diffcheck.out and s10_rd2_svg.out:
nine tracked files changed (39 insertions, 4 deletions) and one file is new.
- docs/system-map.svg, new: 225,027 bytes, 922 by 936, exported by Archify 3.3.2
  from its checked HTML (four gates passed, no crossover). Fourteen components in
  four groups: what you call, inside a scan, maintainers only, how detection is
  measured. The second line of each component names its page in short. The
  candidate cites forty source ranges, read at 6ef8381. The labels are text. The
  file is ASCII: the exporter's hover titles hold a middle dot, replaced by a
  hyphen. It holds no digit in its text, no ".kiro", no "kiro-", and none of the
  five patterns that test_plane_literals forbids under docs.
- README.md, 301 lines: the image and one caption at the top of "Documentation",
  before the site paragraph and the table.
- docs/roadmap.md, 140 lines: a section "Open parts" before "Rules at every step",
  nine rows: the open part, its state today, the page that describes it, and the
  step that closes it. The words "on synthetic review batches" in the first row
  are the handover's, which is not tracked; the reviewer found them consistent
  with commits 825e680, 6d66501 and c2b5f5b.
- Seven pages, one linking sentence each, with a link to that section:
  docs/evaluation.md, docs/pre-push-for-developers.md,
  docs/detection-techniques.md, docs/architecture.md,
  docs/use-case-fix-and-reverify.md, docs/deployment.md and
  docs/decision-engine.md.

The map was drawn by a subagent with the Archify skill, from a list of fourteen
parts and fifteen relationships; it attached the sources. It was corrected twice,
after its reports and my reading of the captures. The arrow between the report and
the plane pointed from the report to the plane, which suggests that a scan sends
something to the plane. It now runs from the plane to the quick rules, "runs the
quick scan on both pins", on the call in src/openultrasast/plane/tasks/alerts.py
(lines 117 to 168, cited on the caller). The legend's "Frontend" became
"Entry point". Two arrows simplify the code, as the subagent reported: the overlay
asks the engine for a flow and merges it, and the engine's answers are graded on
the evidence ladder. I inspected the captures at 900 pixels: light and dark of the
first delivery, and light of the second and of the third; the third differs from the
second in one second line. The labels read. The title of the second group sits at
the top middle of its frame, above the arrow labelled "standard".

Checks, in files under /tmp/opencode/ that start with their command.
- s10_rd2_pytest_docs.out: 30 passed in the five test files that read the README,
  docs and ops, with the strict build, run after the last edit.
- s10_rd2_site.out: a strict build to /tmp/opencode/site-rd2-check copies the SVG
  into the site, and no page of that site contains ".kiro" or "kiro-".
- s10_rd2_links.out (script s10_rd2_links.py): the relative links resolve, anchors
  included: 42 in the README, 14 in docs/roadmap.md. The script names three
  anchors of docs/deployment.md that it cannot find; they lead into the pages that
  include ops/ax/README.md and ops/README.md, and the strict build accepts them.
- s10_rd2_svg.out: the size, the viewBox, 49 lines with a text element, and the
  counts above.
- s10_rd2_diffcheck.out: the added text is ASCII; git diff --check exits 0.
- s10_rd2_gates_run.out and s10_rd2_exits.txt: the gates of label rd2 give ten
  zeros. They ran before the last edits, which touch documentation only.
Not verified: the image through GitHub's proxy; the switch to the light theme was
seen in headless Chromium only. Not in the repository: the interactive HTML and the
candidate, which stay under /tmp/opencode/archify-system-map/.

Review.
Three rounds. Round one blocked on two points; rounds two and three checked the fixes and the
message. The graph reuse row (docs/roadmap.md:121) now says "Not scheduled; no step owns it",
as the records say; the Proof arm box of docs/system-map.svg names "Use case", the page that
describes the arm; the pre-push page gained a sentence in front of its link; the proof arm row
reads "R4, if it needs it" (roadmap.md:122). Round three found the tree as in round two: the
nine blobs and the SVG are those I approved. Measured: 225,027 bytes, 922 by 936, 49 text
lines, 14 boxes, 15 arrows (11 labelled), ASCII, no digit, none of the five patterns; 40 source
ranges inside files at 6ef8381; 42 and 14 relative links; six anchors in a strict build of my
own; 11 tests passed, again in round three; the captures of the three deliveries read at 900
pixels. Remark: line 88 of the pre-push page is 131 columns wide and line 89 is 91; the
page's other lines stop at 84.
2026-11-28 17:48:16 +01:00

165 lines
8.2 KiB
Markdown

# Architecture
This page covers four things:
- how a scan works;
- how a finding earns its place;
- how severity and the project score are decided;
- how scan calibration works.
State as of 2026-10-02; module paths are under `src/openultrasast/`.
## The scan pipeline
The CLI is thin. `HarnessRuntime` owns the lifecycle. It writes an event trace for every stage
(`trace/events.jsonl`). `MODE_STAGES` in `stages.py` lists the stages each mode requests:
- `quick` runs STATIC;
- `standard` adds MAP;
- `deep` requests the REGRESS stage, which was retired on 2026-10-13: the scan records a `regress_retired` degradation and otherwise equals `standard`. Execution proof now comes from the search-with-proof arm.
```
policy_load ─▶ ruleset_load ─▶ policy_check (fail loud on an ungoverned CWE)
─▶ static_mapping (SARIF ingest) ─▶ preprocess ─▶ entry_point_mapping
─▶ rank ─▶ calibrate (demote previously rejected scopes)
─▶ findings quick, deep: quick_findings (language-scoped pattern rules)
│ standard: hunter_pool (the same rules, scheduled per ranked target)
─▶ verify ─▶ record_calibration ─▶ fusion (standard only, deterministic) ─▶ score
─▶ MAP (standard, deep)
│ map complexity map and hotspots
│ overlay semantic overlay over the findings (tree-sitter with the `semantic` extra)
│ obligations absence bugs: an obligated operation with no governing guard
│ model one Joern CPG per repository; taint, dominance and configuration arbiters
│ tool hunter only with `[models] hunter`
─▶ REGRESS (deep) retired 2026-10-13, recorded as `regress_retired`
─▶ report.md, report.sarif, manifest.json
```
Before `policy_load`, the `tree_digest` stage takes a sha256 of the tree's files: the key of a
ledger under the runs directory, for a tree the scan cannot write into ("Scoped calibration",
point 3).
**The model layer** (`model/`, `cpg/`) is the core of `standard`. It builds one code property
graph (CPG: a graph of the program's syntax, control flow and data flow) per scan with Joern.
It runs `joern-parse`, then batched `joern --script` queries from `cpg/queries/*.sc`. Each
question goes to the arbiter (a checker that decides one kind of question) for its spec type:
- taint (untrusted input reaching a dangerous call): source to sink with no discharging sanitizer;
- dominance: does a guard govern the obligated operation;
- configuration: constant abstraction over a value.
Taint facts ship for C, Java, JavaScript, PHP and Python (`ruleset/semantic/*.toml`). Without
Joern, the layer records `cpg_unavailable` and the rest of the scan is unchanged. The Docker
image ships Joern and `php-cli`, which the PHP frontend needs. [Detection
techniques](detection-techniques.md) explains the representations and techniques behind each
stage.
The model layer reports on a rung ladder:
```
execution_confirmed a test or sandbox reproduced it
model_entailed the graph decided: a flow with no discharge, an obligation with no
guard, a permissive value
model_corroborated the graph found the shape; a judge agreed on the residual question
suspicion proposed, nothing corroborated it
```
The LLM answers only the residual question: the part the graph cannot settle
(`model/pipeline.py`, `residual_question`). It is asked only about a flow the graph already
found. It can confirm or contradict that flow, but never create one. When the graph resolved
nothing, the LLM sees the enumerator's candidates (at most `MAX_JUDGED_CANDIDATES`, 8).
Anything it affirms is reported at `suspicion`. Without a provider key, neither question is
asked. Only the graph's entailed findings are reported then.
**REGRESS** was retired on 2026-10-13. Deep mode records a `regress_retired` degradation and otherwise equals standard. Execution proof is the search-with-proof arm's job (`search/verify.py`, bubblewrap sandbox, differential runs against owned canaries).
Reusing the graph across revisions, which would let a changed-code scan fit its 30 second budget, is
not scheduled; see [Open parts](roadmap.md#open-parts) on the roadmap page.
## Evidence ladder: how a false positive is eliminated
Evidence level is a state machine, not a label a model may assign. The verifier
(`verification.py`) runs on independent context and enforces it:
```
suspicion ─▶ static_corroboration ─▶ crash_reproduced ─▶ root_cause_explained
─▶ exploit_demonstrated ─▶ patch_validated
```
- below `static_corroboration`: `NEEDS_EVIDENCE`;
- `static_corroboration` with reachability unknown: `REJECTED`, with a tie-breaker demanding
call-graph, route, CLI, parser or dynamic evidence;
- `static_corroboration` with function-level reachability: `ACCEPTED`.
The rung ladder above and this evidence ladder are two vocabularies kept apart on purpose: a text
match is `static_corroboration` here and is not a rung. `detection-techniques.md` says why.
A rejected finding becomes a **scoped false-positive learning** (`calibration.py`). It has a
scope and a reason from a fixed taxonomy: `unreachable_path`, `missing_attacker_control`,
`sanitizer_disproved`, `static_rule_mismatch`, `incorrect_model_assumption`, `duplicate`,
`insufficient_impact`, `unsupported`, `contradicted`, `unverified`. A rejection in `auth/`
demotes only `auth/...`, never the whole class
(`tests/test_calibration.py::test_scoped_false_positive_demotion_does_not_suppress_class_globally`).
## How a false negative is surfaced
An expected vulnerability that no finding matched becomes a `BenchmarkCalibrationRecord` in
`calibration_records.json`. Each record names a `next_improvement_candidate`: a static rule,
SARIF source, entry-point mapping, retrieval package, hunter prompt, dynamic reproducer or
skill route. Once a miss is closed, the detection gate keeps it closed in CI.
## Central CWE policy and the project score
**Policy** (`policy/verycode.py`): a vendored `CWE_Score.tsv` (verycode-policies) is the single
source of truth. Each CWE carries:
- a flaw category;
- a severity (0-5);
- `static`/`dynamic` scope flags.
A finding's severity comes only from policy, keyed on CWE. CWEs that are not `static` resolve
to 0 and are report-only. `assert_rules_resolve` runs as the `policy_check` stage. An enabled
rule that names an ungoverned CWE aborts the scan. Verycode has no CWE-120, so the C/C++
buffer rules carry CWE-121.
**Score** (`scoring/project_score.py`): each finding's penalty is
`SEV_WEIGHT[severity] x REACH_MULT[reachability]`. The score is `100 * e^(-total/k)` with
`k = 60`.
| Severity | Weight | | Reachability | Multiplier |
| --- | --- | --- | --- | --- |
| 5 | 50 | | `reachable` | 1.0 |
| 4 | 25 | | `inferred-file-surface` | 0.6 |
| 3 | 10 | | `unknown` | 0.4 |
| 2 / 1 / 0 | 2 / 1 / 0 | | | |
A confirmed false positive lowers a finding's reachability multiplier. The rule is not
deleted. The score gate works like this:
- a severity-5 reachable finding always fails it;
- `score < min_score` (default 80) fails it only with `[score] blocking = true`.
The `score` stage writes `score.json` and merges it into `manifest.json`.
## Scoped calibration (every scan)
```
scan ─▶ verify ─▶ non-accepted findings ─▶ scoped learnings
(.openultrasast/calibration/false_positive_learnings.json)
next scan ─▶ rank ─▶ calibrate (demote rejected scopes) ─▶ findings
```
1. `record_calibration` runs after `verify`. It merges this run's non-accepted outcomes into
the ledger, de-duplicated by finding ID.
2. `calibrate` runs after `rank`. It demotes the priority of every scope that produced a
rejection and writes `applied_calibrations.json`.
3. `tree_digest` runs on every scan, before `preprocess`: a sha256 of every file's name and bytes
under the target. It is the key of a second ledger under the runs directory,
`<runs_dir>/calibration/<digest>.json`, in which `record_calibration` keeps what it learned when
the tree refused the write, as the image's read-only mount does. Only a scan of the very same
bytes reads it; the first scan that can write the tree carries its entries into the tree's ledger
and removes it (`src/openultrasast/digest_ledger.py`, `tests/test_digest_ledger.py`).
Demotion is scoped and reversible (`tests/test_pipeline_calibration.py`).