Commit Graph
8 Commits
Author SHA1 Message Date
Marius Ciepluch 312c09bdbf fix(scan): a scan in the image prunes the wrapper's runs directory too (item 5b)
The maintainer's answer 7 of 2026-11-27 (the ninth session's menu). The label is in
.kiro/specs/contributor-scan/spec.json (80abac5). The record, .kiro/handover.md:1335-1337
(not tracked), in full:

    7. The wrapper's runs are never pruned by a scan in the image. Answer: "Image scan
    prunes too": a scan in the image prunes its runs directory when the wrapper's
    override is set; a change in the scan path, a test first. Not chosen: "Document:
    never pruned" (the session's recommendation); "Queue in step 8"; "Leave it".

The option as offered (handover.md:1435-1436): "the scan path prunes its runs
directory when the wrapper's override is set; a code change, a test first."

A second decision, taken on this change. The reviewer found that the wrapper passes no
OPENULTRASAST_RUNS_RETENTION_DAYS into the image, so with this change alone a scan
through the wrapper would remove runs older than 30 days from
~/.cache/openultrasast/runs, native runs included, even for a user who keeps every run
natively with 0. Asked, the maintainer chose "Pass it through (Recommended)": the
wrappers pass OPENULTRASAST_RUNS_RETENTION_DAYS into the container, one more -e in
ops/shell/ousast.sh and ops/shell/ousast.ps1, a test first. That is the next commit.
This one is the scan path alone, as answer 7 says. The wrapper builds its image only
when it is missing (ops/shell/ousast.sh:64-67), so until the image is rebuilt the
wrapper's scans run the code shipped in it and remove nothing (measured below).

The fault. The shell wrapper mounts ~/.cache/openultrasast/runs at /reports and passes
-e OPENULTRASAST_RUNS_DIR=/reports (d1f61fb). prune_scan_runs returned nothing whenever
OPENULTRASAST_RUNS_DIR was set, so a scan in the image never removed an expired run:
the wrapper's runs were removed only by a later native scan on the default location.

What changed.
- src/openultrasast/config.py: WRAPPER_RUNS_MOUNT = "/reports" and
  runs_dir_is_the_wrappers(), true when OPENULTRASAST_RUNS_DIR is that path.
- src/openultrasast/run.py: prune_scan_runs prunes config.runs_dir when the override
  is unset (as before) or is the wrapper's. Any other override still removes nothing.
- README.md, docs/examples.md and .agents/skills/openultrasast-scan/SKILL.md said that
  nothing is removed from a location chosen with OPENULTRASAST_RUNS_DIR; each says now
  that the shell wrapper is the one exception. The decision says "a change in the scan
  path"; these three sentences state the rule the change alters, and would be false
  without them.
- tests/test_run_pruning.py: its module docstring, and three tests (below).

The session's readings of the decision, to be confirmed by the maintainer.
1. "The wrapper's override" is recognised by its value. Both wrappers pass exactly
   /reports (ops/shell/ousast.sh:91, ops/shell/ousast.ps1:50), and nothing in the
   container's environment tells the wrapper's run from a compose run started by hand.
   Two consequences, by reading: a native scan with OPENULTRASAST_RUNS_DIR=/reports is
   pruned as well; and a compose run started by hand with the same -e and the default
   ./reports mounted prunes run-shaped directories older than 30 days under the
   checkout's reports/ (docker-compose.yml:33-34).
2. The compose file's own value, /reports/runs (docker-compose.yml:47), is a chosen
   location and is not pruned: there ./reports on the host is mounted, which may hold
   more than runs.

This amends the run retention decided on 2026-11-24 (spec.json, approval_history entry
six: "after each scan, with no OPENULTRASAST_RUNS_DIR set, runs in the default location
older than 30 days are removed"): the wrapper's mount is pruned as well.

Measured, in an image. The script is /tmp/opencode/s10_c7_probe.sh and its files are
under /tmp/opencode/s10_c7_probe/, one per measurement; the files of the four scans
and of the listings after them start with the command they ran. The four scans' stamps
run from 17:57:27Z to 17:57:32Z; the listings carry none. The probe image is
openultrasast:dev (3f959b31f2f2, uid 1000) with the working tree's package copied
over it: 295 files, equal to the tree by
sha256 (03_probe_sources.out is a bare list of digests; the comparison is
/tmp/opencode/s10_c7_sources_cmp.out, which starts with its command). Every runs
directory is a scratch directory mounted at /reports; the real ~/.cache/openultrasast/
runs was not mounted. Network off, no key. The subject is a fresh copy of the four C
files and their README (04_subject.out). Each scratch runs directory held a run of 40
days ago, a run of 5 days ago and a directory called notes.
- With the wrapper's override, on the probe image (10_wrapper_override.out): exit 0,
  file_targets=4, findings=4, and the line
  "notice: removed 1 run older than 30 days from /reports". The expired run is gone;
  the run of 5 days ago, the new run and notes remain (11_wrapper_override_after.out).
- With the compose file's /reports/runs (20_compose_override.out,
  21_compose_override_after.out): no notice, all three entries remain.
- With the wrapper's override on the shipped image (30_shipped_image.out,
  31_shipped_image_after.out): no notice, all three remain: the fault as shipped.
- With the wrapper's override and OPENULTRASAST_RUNS_RETENTION_DAYS=0 passed into the
  container (40_retention_zero.out, 41_retention_zero_after.out): no notice, all three
  remain.
- The probe image is removed (90_remove_probe.out); no container remains
  (91_containers_after.out).
The wrapper itself was not run.

Tests (tests/test_run_pruning.py).
- test_a_scan_through_the_wrapper_removes_the_expired_runs_from_the_mounted_runs_directory
  calls prune_scan_runs, as cli.py:720 does, with OPENULTRASAST_RUNS_DIR=/reports and
  a runs directory that stands in for /reports, which only root can make on the host.
  It expects one notice, and the run of 5 days ago and the current run to remain.
- test_a_scan_that_compose_runs_without_the_wrapper_removes_nothing: /reports/runs
  removes nothing and says nothing.
- test_the_wrapper_passes_the_override_that_a_scan_prunes: the shell wrapper's command
  holds "-e OPENULTRASAST_RUNS_DIR=" + WRAPPER_RUNS_MOUNT, so its word and the scan's
  mount point cannot drift apart. Nothing reads the PowerShell wrapper's.
RED. An archive of HEAD (src, tests, pyproject.toml) with the first test as written,
the package imported from the archive (s10_c7_red_where.out): 1 failed, 1 passed; the
passed one was a throwaway test that printed where the package came from and was
removed after. The failure is at
"assert () == ('removed 1 run older than 30 days from .../reports',)"
(s10_c7_red.out). The command, run from the archive's directory, where the throwaway
test was tests/test_zz_where.py:
env -u OPENROUTER_API_KEY -u DEEPSEEK_API_KEY PYTHONPATH=/tmp/opencode/s10_c7_head/src
/home/mc/Source/OpenUltraSAST/.venv/bin/python -m pytest -q -p no:cacheprovider
tests/test_run_pruning.py tests/test_zz_where.py -k "where or through_the_wrapper"
GREEN: 250 passed on the final tree (s10_c7_green4.out; the command is not
in the file) over
tests/test_run_pruning.py tests/test_scan_output_location.py tests/test_config.py
tests/test_run.py tests/test_mcp.py tests/test_agent_skills.py
tests/test_shell_wrapper.py tests/test_task_images.py tests/test_benchmark.py
tests/test_benchmark_artifact_contract.py tests/test_model_scope.py
tests/test_pair_harvest.py.
Mutants, to show the two guards bite: the tree's sources with one line changed and the
final test file (the copies are /tmp/opencode/s10_c7_mutA, mutB, mutC).
- the predicate "_runs_dir_override().startswith(WRAPPER_RUNS_MOUNT)" fails the
  compose test alone (s10_c7_mutA2.out: 1 failed, 36 passed);
- WRAPPER_RUNS_MOUNT = "/reports2" fails the wrapper test and the first test
  (s10_c7_mutB2.out: 2 failed, 35 passed);
- HEAD's condition, "if runs_dir_is_overridden():", fails the first test alone, at the
  assertion above (s10_c7_mutC2.out: 1 failed, 36 passed).

Checks on the final tree. mkdocs build --strict exits 0 (s10_c7_mkdocs2.out; its
examples page is byte-identical to the first build's); ruff format, ruff check, mypy,
compileall and the three gates pass, and the gates print what they printed before the
change (s10_c7d_exits.txt). Three files date from before the test module's docstring
was edited, on documentation unchanged since: the first build's examples page holds
each of the three added phrases once and the old wording zero times
(s10_c7_site_sentence.out), and tests/test_docs_site.py with
tests/test_removed_plane_references.py gave 8 passed (s10_c7_docs_tests.out). An
earlier gates run found an unused name in the first test (s10_c7_ruff_check.out); it
is removed.

- Review: two rounds by a reviewer subagent, reading and re-running, no docker. Round one
  found the code right for answer 7 (RED reproduced on an archive of HEAD, 250 passed over
  the 12 files, the three mutants failing as stated) and conditioned the commit on a
  decision: the wrapper passed no retention variable into the image, so this change alone
  broke "0 keeps every run" on the wrapper path. Asked, the maintainer chose "Pass it
  through (Recommended)"; the wrapper's commit follows at once, before other work and any
  push. Round two found the delta to be the test module's docstring; re-ran the 12 files
  (250 passed), the docs tests, ruff, mypy, mkdocs and the three mutants; checked the
  round-two evidence against the test file's last change and every sentence of this
  message, and had two false sentences corrected: the spec.json path and the RED command.

By reading, not measured.
- cli.py:720 passes the config whose runs_dir is /reports in the image (config.py,
  _runs_dir), so the scan in the image prunes that directory.
- ops/shell/ousast.ps1:50 passes the same override; PowerShell is not installed here.
- A failed removal still costs the scan nothing: prune_scan_runs catches OSError and
  RecursionError, and tests/test_run_pruning.py has two scans whose removal fails.
- `ousast benchmark` in the image goes through the same line (cli.py:1123, then
  cli.py:720) and prunes once per benchmark scan. That is answer 7's rule.

Found and not fixed, for the maintainer.
- The notice names the path the scan sees, /reports, not the host's
  ~/.cache/openultrasast/runs.

Not checked: the whole test suite; the wrapper and a compose run (the image was run
with docker run on scratch mounts); a removal that fails inside the container; Windows
and ops/shell/ousast.ps1; a native scan with OPENULTRASAST_RUNS_DIR=/reports.
2026-11-27 19:36:15 +01:00
Marius Ciepluch f6b1406541 fix(model): a failed judge call is recorded and ends the asking (item 5b)
The maintainer's answer of 2026-11-27 to question 2 of the ninth session's menu, "Record and stop
asking", as offered: "a failed judge call adds a degradation to the manifest, with the count; the
report says those questions went unasked; after one transport failure the remaining questions are
not asked." Measured by the ninth session: with a key in the environment and no network, 16 judge
calls failed in one scan of a four-file subject, three attempts each, and each dropped its claim
as a "no" would (model/pipeline.py); the manifest counted model_calls 16 and recorded no failure,
and the report said less than that of a run without an endpoint.

What changed:
- model/scan.py, `_CountingClient`: a call that raises is counted in `failed` and ends the asking.
  The calls left in the question being put are refused without reaching the client (`refused`),
  and the driver withholds the judge from every question after it, as it does when the budget runs
  out. An answer with no decision in it (empty, not JSON, no boolean `vulnerable`) is counted in
  `failed` as well and does not end the asking. The graph still arbitrates every region.
- Two degradations, each with a sentence under "What could not be analysed" (reports.py) and a
  line in the scan skill's list:
  - `judge_calls_failed`, `count`: the judge calls that gave no decision.
  - `judge_withheld`, `questions`: the judge calls refused after the failure in the question
    being put. Of the questions after it the report says that none was put to the judge; they are
    not counted, because some of them would have put nothing to the judge.
- model/pipeline.py: the parsing half of `_ask` is moved as it was into `judge_decision`, so the
  driver reads a decision the way `_ask` does. `_ask` returns what it returned.
- The claim of every such question is still dropped, as before: "Keep the claim" was not chosen.

The session's two readings of the decision, open to correction:
- A transport failure is read as a judge call that raised, whatever the exception. The transport
  has already made its three attempts for what is transient (provider/openrouter.py), so one
  raised call ends the asking for the whole scan. That holds for a connection failure and for a
  timeout, and also for a request the endpoint refuses with an error status, where the transport
  makes one attempt: there the scan withholds every later question, where before it dropped that
  claim alone and went on. The judge_withheld line says so in the report.
- A failed judge call is read as a call that raised or a call whose answer gave no decision. Both
  are counted.

Measured on fresh copies of the four C files the ninth session used, with a placeholder key and
the network off (the scratch is /tmp/opencode/s10_c2_* and is not kept):
- Native, in a network namespace without routes: one "judge call failed" line, file_targets=4,
  findings=15, exit 0, 45 s (s10_c2_native_key3.out). The ninth session's run of the same bytes:
  16 lines, 68 s.
- In a probe image built from openultrasast:dev 3f959b31f2f2 with src copied over, network none:
  one line, file_targets=4, findings=15, exit 0, 43 s (s10_c2_image_key3.out). The ninth
  session's run: 16 lines, 65 s. The probe image is removed.
- Both manifests: model_calls 1, judge_calls_failed with count 1, judge_withheld with questions
  7; report.md carries the two sentences (s10_c2_native_inspect3.out, s10_c2_image_inspect3.out).
  The findings are the 15 the ninth session recorded with a key and without one.

Tests, one at a time, each red before its code:
- test_a_judge_that_cannot_be_reached_is_recorded_and_asked_no_further: on a git archive of
  HEAD, assert 120 == 1; after, one call, model_calls 1, ten regions arbitrated, the two
  degradations with count 1 and questions 5.
- test_a_judge_answer_with_no_decision_in_it_is_counted_and_the_rest_are_still_asked: red with
  no degradation; after, count 120 and no judge_withheld.
- test_a_failed_judge_call_is_reported_as_unasked_and_not_as_a_no: red with the two bare
  reasons; after, the two sentences. The three red runs, with the package imported from the
  archive, are in s10_c2_red8.out: 3 failed, 1 passed.
- GREEN: 657 passed over the 39 test files that name degradations, scan_repository, model_calls
  or write_markdown_report (s10_c2_green9.out); 214 passed over ten model, report and skill files
  (s10_c2_green8.out). ruff, mypy, the three gates and compileall pass, and the gates print what
  they printed before (s10_c2c_exits.txt). `git diff --check` exits 0. No whole-suite run: that is
  step 9.
- The review took three rounds on one reviewer. Round one approved a first shape that counted the
  withheld regions, and remarked that a region with several families was counted as withheld while
  its first family had been put to the judge; its other remarks changed the second sentence,
  `__all__` and a docstring. Round two blocked the sum that replaced that count: it added judge
  calls to region-and-family questions under one name. The count is of judge calls now. Round
  three approved this diff, on the condition that this message carry the measured numbers.

By reading, not measured: a pre-push run makes no judge call (push/runner.py and push/policy.py
pass no client and an execution budget), so the two reasons cannot arise there.

Found and not fixed, for the maintainer:
- .agents/skills/openultrasast-scan/SKILL.md:68-70 and docs/where-we-stand.md:349-350 say that
  `learning_endpoint_unavailable` has no line in report.md. It has had one since f555dee
  (2026-10-02).
- The citations of scan.py in docs/detection-techniques.md: of 24, 19 sit one, two or seven lines
  further down after this commit (5 do not move, 9 move by one line, 1 by two, 9 by seven).
2026-11-27 17:06:25 +01:00
Marius Ciepluch 17d46c0f93 feat(contributor-scan): remove scan runs older than 30 days from the default cache (3.1, run retention)
By maintainer decision. Since 6edae3a a native scan leaves a run directory
under ~/.cache/openultrasast/runs/ and nothing removed them. After a scan's
manifest is written, with no OPENULTRASAST_RUNS_DIR set, the runs in that
default location that are older than 30 days are now removed. The age comes
from the UTC timestamp in the run id, never from file times, so a copied or
touched directory is not misjudged, and a run exactly 30 days old is kept.

Never touched: the scan's own run; anything not named exactly like a run
(only direct children of the runs root whose name is a run id); symlinks,
which are neither followed nor removed; and any location chosen with
OPENULTRASAST_RUNS_DIR, even when it resolves to the default.

OPENULTRASAST_RUNS_RETENTION_DAYS sets the number of days and 0 keeps every
run. A failed prune never fails the scan: it is one notice on the command
line, and the MCP scan and benchmark results now carry a notices key. A
retention longer than the calendar and a directory tree too deep to remove
are both turned into that same behaviour.

Known limits, on record: a removal that fails part-way leaves the run half
deleted and it is retried on every later scan; the prune stops at the first
failure; a clock set far ahead removes earlier runs; a filesystem mounted at
or under an expired run is emptied before the removal fails.

Tests: tests/test_run_pruning.py drives the function and the real command
line (34 tests); tests/test_mcp.py pins the notices. The reviewer attacked
the deletion path with about sixty hostile inputs and twenty-three mutations;
all are killed or kept safe.
2026-11-24 17:51:37 +01:00
Marius Ciepluch 6edae3a585 feat(contributor-scan): a scan writes its run to the user cache, and the ledger only when it learns (3.1, part A)
Where a scan writes. A native scan now creates its run under the user cache,
~/.cache/openultrasast/runs/<scan-id>/ by default ($XDG_CACHE_HOME when it is
set and absolute), prints run_dir=<path> once, and no longer writes anything
under the analysed tree. OPENULTRASAST_RUNS_DIR still wins: an absolute value
is used as given, a relative one resolves against the working directory.
Pre-push storage is unchanged.

The calibration ledger, by maintainer decision: .openultrasast/calibration/
stays the store, and a scan writes the false-positive ledger into the tree
only when its content would change. On a read-only tree the scan records
ledger_not_written, with a sentence in the report, and completes; before, a
read-only target with one rejected finding crashed before report.md existed.

benchmarks/repos/measure.py follows the printed run directory. It read the
run from under the scanned copy, which would have recorded every repository
as failed, and it also read a stale run left in a copy.

Tests: tests/test_scan_output_location.py drives the real CLI and compares
the whole tree before and after; tests/test_repo_measure.py pins the
measurement script; an autouse fixture keeps every test's scan runs out of
the developer's cache; fourteen test files follow the run to its new place.
README, docs/examples.md and the scan skill name the ledger as the one write
a scan makes. _run_scan is touched by one line and stays over the complexity
cap.

Task 3.1 stays open for part B, the readable summary.
2026-11-24 15:33:35 +01:00
Marius CiepluchandClaude Fable 5.1 f5a904b7f2 chore(p0): retire regress, the skill router, the module audit tool and vocabulary.sc
Off every active line (PATHFINDER-2026-10-13/03-unified-proposal.md, cuts).
Deleted: src/openultrasast/regress/ and the deep-mode REGRESS branch (deep
now records a regress_retired degradation and equals standard; proof is the
search-with-proof arm's job), the sandbox docker runner and probe that only
regress used, --fail-on worth-fixing, RegressConfig, the two ledger helpers
only regress called; skills.py and index.py with the hunter pool's skill
routing; model/audit.py; cpg/queries/vocabulary.sc with
benchmarks/push/ontology_gap.py. Docs and the scan skill describe the
retirement. Net: 3,895 lines deleted, 86 added. Targeted tests: 180 passed,
28 skipped; 3,331 tests collect.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-10-13 10:50:01 +02:00
Marius CiepluchandClaude Fable 5.1 c978de9ff8 merge(cleanup): second legacy inventory -- vector index, equality test, unread config keys, status notes
Also drops the removed ousast index line from the scan skill.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
2026-10-02 20:02:53 +02:00
Marius CiepluchandClaude Fable 5.1 16d9ef7110 chore(skills): apply the 2026-10-02 review -- current CLI and evidence, merges, removals, steering names
openultrasast-scan: evidence ladder as verification.py defines it, with the levels nothing produces today; --mode prerequisites, --fail-on, recorded degradations, run artifacts, ousast mcp; retired [evidence] threshold language removed. openultrasast-triage: reasons verified against calibration.py; deterministic fusion; adjudications as labels, plane verdicts as features, rule changes through improve or a registered experiment; fix-audit merged as a fix-and-re-scan section. kiro: spec-quick and spec-batch removed; validate-gap and validate-design merged into spec-design (--gap, --review; the review gate stays); steering-custom merged into steering; core steering names overview.md, roadmap.md, safety-net.md; instrument rule in debug and verify-completion; repo gates named in validate-impl. AGENTS.md, README skills paragraph and tests/test_agent_skills.py (.agents/skills, two product skills, drift tests) updated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
2026-10-02 19:48:01 +02:00
Marius CiepluchandClaude Fable 5.1 5010b15ffc chore(skills): .agents/skills -- the plural directory OpenCode searches by default
Verified against opencode.ai/docs/skills: project-local search paths are
.opencode/skills, .claude/skills and .agents/skills, not configurable.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
2026-10-02 19:24:33 +02:00