4 Commits
Author SHA1 Message Date
Marius Ciepluch e2163a4fea feat(scan): an unwritable tree keeps a scan's learnings under the runs directory (item 5b)
The decision of the maintainer on the ninth session's menu, answer 9 (.kiro/handover.md,
untracked, 1340-1343 as it stood on 2026-11-27; the option as offered, 1451-1452):

> 9. The ledger in the image. Answer: "Decide the key now": a digest of the tree's files
> (the `fingerprint` of the `provenance` stage is no digest), one ledger per digest under
> the runs directory; a design note is shown to the maintainer before any code.

The design note (/tmp/opencode/s10_c10_design_note.md, 299 lines) was reviewed in five
rounds before it was shown, and shown to the maintainer whole on 2026-11-27 with its three
questions. The maintainer's answers came on 2026-11-28, through the question tool, each the
recommended option as offered: "Stand as written (Recommended)" on the note's rule of reading
and writing (its section 3.3), "With the runs, by last use (Recommended)" on how long a ledger
stays (section 3.5), and "Build it now (Recommended)". The dated note on task 3.1 of
.kiro/specs/contributor-scan/tasks.md (lines 459-502) carries the rule as approved.

The fault: the image mounts the target read-only, so the ledger a scan writes into the tree
(<target>/.openultrasast/calibration/false_positive_learnings.json) cannot be written there,
the scan records ledger_not_written, and the next scan in the image starts without the
learnings of the one before.

What changed
- src/openultrasast/tree_digest.py: tree_digest(target, runs_directory) (line 48), a sha256
  over one entry per file in path order (the length of the path, a colon, the path, a tab,
  the sha256 of the bytes), after a version line. Left out: links, the directories a scan
  ignores (IGNORED_DIRS, so that the tree's ledger does not change its own key) and the runs
  directory, whichever way it is reached (by device and inode). A file that cannot be read
  and a directory that cannot be listed are named "unreadable"; a directory that can be
  listed but not searched raises, as the scan's own reading of the tree does.
- src/openultrasast/digest_ledger.py: the ledger of a digest, calibration/<digest>.json under
  the runs directory, in the JSON of the tree's ledger. read_digest_ledger (line 47) reads it
  and marks it as used; settle_digest_ledger (line 65) applies the rule.
  The tree took the write: the ledger is removed. The tree refused: the ledger is written
  with its own entries and this scan's new ones, never one whose finding id the tree's
  ledger has, only when that differs from its content, and removed when that would leave it
  empty. No write: a ledger whose every entry the tree's ledger also has is removed. One that
  could not be read (a file that is not a ledger, whatever its top level or its depth) is
  taken for empty and goes, unless the tree refused and this scan wrote it. It is written
  through a temporary file of the writer's own and a rename (line 112).
- src/openultrasast/cli.py: the stage tree_digest, before any stage reads the tree
  (cli.py:603-605); _read_ledgers (cli.py:1085-1099), the tree's ledger and then the
  digest's, the tree's entry winning by finding id; _persist_calibration_feedback
  (cli.py:1101-1136), which writes the tree's ledger when its content would differ from what
  it held, also when only the digest's entries are new to it; the manifest's ledger block
  (cli.py:731-735); a notice when the digest's ledger could not be written or removed
  (cli.py:755).
- src/openultrasast/run.py: prune_expired_ledgers (run.py:112), called by prune_scan_runs
  (run.py:71-99). Under calibration/ of the same two locations as the runs, a ledger, or the
  temporary file it was written through, last used OPENULTRASAST_RUNS_RETENTION_DAYS days
  ago is removed; 0 keeps all. Files called something else, links and directories stay. A
  removal that fails is said once and costs the scan nothing.
- src/openultrasast/reports.py: write_manifest takes ledger (reports.py:212, 254-255). The
  ledger_not_written sentence names the digest's ledger when it holds the learnings
  (reports.py:461-467, chosen at 479-483).
- README.md, docs/examples.md, docs/architecture.md and
  .agents/skills/openultrasast-scan/SKILL.md say where the learnings of a read-only tree go,
  and what removes them.

Two departures from recorded decisions, both put to the maintainer in the note and accepted
with it:
- The tree's ledger is written when a scan learns nothing new, because the digest's entries
  are new to it. The decision of 2026-11-24 says it "is written only when a scan learns
  something" (spec.json:68).
- A ledger of a digest is removed when it expires, and its time is changed when a scan reads
  it. The decision of 2026-11-24 says "the scan's own run and anything not named like a run
  are never touched" (spec.json:73), and dates a run by its id, where a ledger is dated by
  its use.

Measured
- The built function gives the note's prototype's digest for the four-file subject
  (915506a8...) and for libpng's copy (1dcd664f...): s10_c10_port.out.
- In the image, on the final code. A probe image of openultrasast:dev (3f959b31f2f2) with
  the tree's package copied over it, built at 09:06:36Z and holding the tree's 297 .py files
  (s10_c10_image_probe/03_probe_sources.out, s10_c10_sources_still_equal4.out). Standard
  mode, no key, network none. The four C files of contrib/examples of libpng and their
  README, copied fresh and mounted read-only at /target; a scratch runs directory mounted at
  /reports with the wrapper's OPENULTRASAST_RUNS_DIR=/reports (s10_c10_image_probe.sh,
  stamps 09:06:36Z to 09:09:14Z, 2026-11-28).
  - The first scan learns four entries and keeps them in /reports/calibration/<digest>.json:
    calibrations_applied=0, project_score 26, the manifest's ledger {digest_ledger: written,
    learnings_read: {digest: 0, tree: 0}} (10_, 11_). The report names the file.
  - The second scan of the same bytes reads them: calibrations_applied=2 on two files,
    project_score 59, penalty_total 32.0, learnings_read 4 from the digest's ledger,
    digest_ledger "left as it was" (20_, 21_). The file's time is that of the second scan's
    read, 09:07:19Z (22_).
  - The digest the scan took in the image equals the one taken on the host for the same
    files (s10_c10_image_digest_host4.out). The target is unchanged
    (s10_c10_image_target_same4.out).
  - Three earlier runs of this probe and of the native run below, each on the code as it
    stood before a later correction of the same rule (the value for a ledger that could not
    be read; a ledger whose top level is not an object; one nested too deep), gave the same
    numbers. Their stamps: 08:12:50Z to 08:17:31Z, 08:23:38Z to 08:27:42Z and 08:50:15Z to
    08:54:17Z. They are kept as s10_c10_image_probe_run1, _run2, s10_c10_native_run1,
    _run2 and _run3; of the third image run s10_c10_image_probe_run3.out and the host,
    target and sources checks numbered 3 remain, since s10_c10_image_probe_run3 is empty.
    Its files were read by the reviewer in round two.
- The shipped image, the control, on the same files: calibrations_applied=0 and
  project_score 26 on both scans, no ledger block and no ledger (30_ to 42_).
- Natively, on a fresh copy of the same five files, the network off (s10_c10_native.sh,
  09:09:14Z to 09:10:38Z): the first scan writes the tree's ledger (calibrations_applied=0,
  project_score 26, digest_ledger none), the second reads it (calibrations_applied=2,
  project_score 59, learnings_read 4 from the tree's ledger), and no ledger of a digest is
  made (s10_c10_native/10_ to 22_).
- The probe left no container (2 before, 2 after: 00_, 91_) and its image is removed (90_,
  92_).

Tests
- tests/test_tree_digest.py (7) and tests/test_digest_ledger.py (11, one over nine contents
  a file may hold); seven tests in tests/test_scan_output_location.py, six through the scan
  (three over two cases) and one on _read_ledgers; six in tests/test_run_pruning.py; one
  sentence in tests/test_reports.py. The scan test of a refused write selects its run by
  name now, since the runs directory holds calibration/ as well.
- RED on an archive of e231b78 with the final test files: the two unit files do not import
  (s10_c10_red14.out); the scan, pruning and report files give 15 failed, 101 passed
  (s10_c10_red13.out; the tree's tree_digest.py and digest_ledger.py were copied into that
  archive, since the test file imports both, and cli.py, run.py and reports.py were HEAD's).
  On the tree before each fix: the test of a ledger that is not a JSON object failed
  (s10_c10_red8.out), and so did the content nested too deep and its scan test
  (s10_c10_red12.out).
- GREEN on the final tree: 134 passed over the five files (s10_c10_green9.out); 873 passed
  over the 60 files of the scan path (s10_c10_wide4_full.out; the list is
  s10_c10_testfiles.txt); the docs and skills tests, with the strict site build, 11 passed
  (s10_c10_docs_tests4.out; no page changed after it).
- Gates on the final tree: ten zeros (s10_c10e_exits.txt), the three gate outputs equal to
  the baseline.

- Review: three rounds against e231b78, by one reviewer subagent, read-only; no
  docker and no wrapper run, the probes read from their files. Round one blocked
  on one finding and measured it end to end on a scratch tree: a ledger of a
  digest whose top level is not a JSON object raised AttributeError in the tree's
  loader and stopped the scan (exit 1), against the note's "a cache must not stop
  a scan". Round two approved with remarks, which the code and the tests took:
  RecursionError joined the tuple (digest_ledger.py:57), with a ninth content in
  the unit test and a scan test of a ledger that is not a ledger, red before the
  fix (s10_c10_red12.out). Round three approved the code, the tests and the dated
  note, and blocked on one sentence of this message, which named
  s10_c10_image_probe_run3 as kept: that directory is empty. On the final tree the
  reviewer measured the scan past a digest's ledger nested 5000 deep (exit 0,
  "unreadable", the file removed) and passed 30000 contents through
  read_digest_ledger, with none let through; it re-ran the five files (134
  passed), the docs and skills files with two scan files outside the sixty (20
  passed), ruff, mypy (297 files) and the comparison of the three gate outputs
  with the baseline, the gates themselves not run; it recomputed the three
  digests, matched the tree's 297 .py files to the fourth probe image's list, and
  read the fourth image and native runs. The third image run's files were read in
  round two, before they were lost. The sentence was reworded as the reviewer
  wrote it.

By reading, not measured
- A pre-push run does not go through _run_scan, and src/openultrasast/push names no ledger:
  nothing changes there.
- ousast benchmark and the MCP server call _run_scan and get the rule as a scan does.
- mark_all of the hunt tooling lists the children of a runs root it is given; it has no
  caller under src.

Found and not fixed, for the maintainer
- The note says the digest stage's seconds are in the manifest. No stage's are: a stage's
  time is in trace/events.jsonl (stage_start and stage_end), and so is this one's. The pages
  and the dated note do not repeat the sentence.
- The report's sentence (reports.py:461-467) says this scan's learnings are kept in the
  ledger of the digest whenever that file holds some of them (cli.py:1131-1133). A new
  learning whose finding id the tree's ledger already holds is left out by the rule; the
  tree's version stands, and the new evidence text is in the run directory alone. The
  sentence is the note's as approved.
- The tree's own ledger stops the scan when its top level is not a JSON object, or when it
  is nested too deep (calibration.py:157-159, read at cli.py:610 outside any stage). That
  is older than this commit; the ledger of a digest does not.
- read_digest_ledger raises when calibration/ cannot be searched, as the tree's ledger does
  when .openultrasast/calibration cannot (digest_ledger.py:53).
- By reading: a tree whose runs directory is the target itself gets another digest at every
  scan, since its run directory is made inside the target before the stage. Such a tree can
  be written, so its own ledger takes the learnings and no ledger of a digest is made.
- docs/architecture.md draws no provenance stage, which cli.py runs between
  entry_point_mapping and rank.
- The wrapper builds its image only when the image is missing: until a rebuild, a scan
  through it runs the shipped code, which has none of this.
- The notice of a removed ledger names the runs directory as the scan sees it (/reports in
  the image), not the host's path.

Not checked
- the whole test suite; Windows; ops/shell/ousast.ps1 (not read for this commit); two scans
  of one tree at once; the wrapper and the compose route (the probe used docker run with the
  wrapper's mount and override); a removal that fails on a real cache; Docker Desktop, where
  a directory mounted twice may not keep one inode.
2026-11-28 10:21:05 +01:00
Marius Ciepluch efa311a112 fix(shell): the wrapper passes the retention days into the image (item 5b)
The maintainer's second decision on answer 7, taken on 2026-11-27 while the scan path
change (312c09b) was reviewed. Put with the question tool, in this question: "Answer 7
... is built, measured and reviewed, with one consequence the decision does not cover.
The wrapper passes only OPENULTRASAST_RUNS_DIR into the image, never
OPENULTRASAST_RUNS_RETENTION_DAYS. ... How should the retention reach the image?" The
option chosen, in full: "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. The scan in the image then
honours the host's setting, 0 included. Measured: compose passes a variable named
without a value only when the host sets it. This commit stays the scan path alone; the
wrapper is the next commit." Not chosen: "Document it", "Hold answer 7".

What changed.
- ops/shell/ousast.sh: the compose run passes -e OPENULTRASAST_RUNS_RETENTION_DAYS,
  without a value, beside the runs directory's override; the comment above it says why.
- ops/shell/ousast.ps1: the same option, edited by reading: no PowerShell is installed
  here.
- tests/test_shell_wrapper.py: test_the_container_path_passes_the_retention_into_the_image.
- tests/test_run_pruning.py: the guard test of 312c09b pinned one text,
  "-e OPENULTRASAST_RUNS_DIR=/reports ousast". With the new option between the two it
  now pins the word OPENULTRASAST_RUNS_DIR=<WRAPPER_RUNS_MOUNT> wherever it stands in
  the wrapper's text.

Measured, through the wrapper function itself. The script is /tmp/opencode/s10_c8_probe.sh
and its files are under /tmp/opencode/s10_c8_probe/, one per measurement; those of the
wrapper runs start with the command and then with the line that ran. bash sources the
working tree's ops/shell/ousast.sh and runs `ousast scan examples --mode quick` with
HOME at a scratch directory, so the runs directory the wrapper mounts at /reports is a
scratch one; the real ~/.cache/openultrasast/runs was not touched
(/tmp/opencode/s10_c8_real_runs.out). The image is openultrasast:dev (3f959b31f2f2) with
the working tree's package copied over it, under a tag that OUSAST_VERSION gives to
compose, so the wrapper finds an image and does not build. Network off. No key is in the
shell's environment; compose reads the checkout's .env by default, and that file names
both keys, which docker-compose.yml:44-45 pass on, so the containers may have had them:
not looked at, and no measurement depends on it (quick mode, network none). Compose
5.5.1. Each scratch runs directory held a run of 40 days ago, a run of 5 days ago and a
directory called notes. The stamps run from 18:54:48Z to 18:54:58Z.
- Retention unset on the host (10_changed_unset.out): "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_changed_unset_after.out).
- Retention 0 on the host (20_changed_zero.out, 21_changed_zero_after.out): no notice;
  the expired run stays, with the run of 5 days ago, the new run and notes.
- Retention 3 on the host (30_changed_three.out): "notice: removed 2 runs older
  than 3 days from /reports"; both old runs are gone (31_changed_three_after.out).
- The control: HEAD's wrapper (312c09b) with retention 0 on the host (40_head_zero.out):
  "notice: removed 1 run older than 30 days from /reports". That is the gap this
  commit closes (41_head_zero_after.out).
- What the container sees of the variable under the wrapper's two options, asked of the
  image's Python (50_variable_unset.out, 51_variable_zero.out, 52_variable_empty.out):
  unset, "set to 0" and empty, as on the host. An empty value reads as not set
  (config.py, _runs_retention_days).
- The wrapper the probe ran is the tree's, and the package it was built from equals the
  tree's (03_probe_sources.out is a bare list of digests).
- The probe image is removed (90_remove_probe.out); no container remains
  (91_containers_after.out), and openultrasast:dev alone is left (92_images_after.out).

Tests. RED: an archive of HEAD (src, ops, tests, pyproject.toml) with the new test, the
package imported from the archive and the wrapper HEAD's (s10_c8_red2.out: 1 failed,
6 passed, at "ValueError: 'OPENULTRASAST_RUNS_RETENTION_DAYS' is not in list").
GREEN on the final tree: 78 passed over tests/test_shell_wrapper.py,
tests/test_run_pruning.py, tests/test_task_images.py, tests/test_docs_site.py and
tests/test_removed_plane_references.py (s10_c8_green4.out; the command is not in the
file). Mutants, the tree with one line changed, run on the two wrapper and pruning
test files (the copies are /tmp/opencode/s10_c8_mutB and s10_c8_mutD):
- WRAPPER_RUNS_MOUNT = "/reports2" fails the guard and the first test of 312c09b
  (s10_c8_mutB2.out: 2 failed, 41 passed);
- the wrapper's word changed to OPENULTRASAST_RUNS_DIR=/reports2 fails the guard and
  the wrapper test of d1f61fb (s10_c8_mutD2.out: 2 failed, 41 passed).
Two earlier GREEN runs failed on the guard as it was (s10_c8_green.out,
s10_c8_green2.out): that is the change to tests/test_run_pruning.py.

Checks on the final tree: ruff format, ruff check, mypy, compileall and the three gates
pass, and the gates print what they printed before the change (s10_c8b_exits.txt);
bash -n on ops/shell/ousast.sh exits 0.

- Review: two rounds by a reviewer subagent, reading and re-running, no docker. Round one
  approved the four files and conditioned the commit on the message: "Network off, no
  key" was unsupported, since compose reads the checkout's .env, which names both keys,
  and the review line was a placeholder. Round two checked the tree after the optional
  remarks were taken (the guard takes the word exactly; the shell command is on two
  lines) and found the code right: GREEN 78 passed again, both mutants 2 failed and 41
  passed, the probe's second run read as stated. One condition remained: the stamps at
  line 39, 18:54:48Z to 18:54:58Z.

By reading, not measured.
- ops/shell/ousast.ps1: no PowerShell is installed here.
- No page says what the wrapper passes into the image, so none needed a change:
  README.md and docs/examples.md say that OPENULTRASAST_RUNS_RETENTION_DAYS sets the
  days and that 0 keeps every run, and through the wrapper that is now true.
- A value the host sets that is not a whole number of days now stops the scan in the
  image with the message a native scan gives (config.py, _runs_retention_days); before
  it did not reach the image.

Not checked: the whole test suite; Windows and ops/shell/ousast.ps1; whether the keys
of the checkout's .env reached the probe's containers.
2026-11-27 19:59:50 +01:00
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 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