spec(dspy-driver): design for stage one, on the seam the hunt code already has

Two producers (the prover's trace, Joern's taint and dominance results), two driver
inputs, arms as masks of the existing paired ablation, three samples with a vote, one
page per example, and the cache keys in the memory store. Generated, not approved.
The answers to the second menu of 2026-11-30 are recorded in the roadmap.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Marius Ciepluch
2026-11-30 10:03:52 +01:00
co-authored by Claude Fable 5.2
parent b38dcdbc60
commit 1aad435265
6 changed files with 289 additions and 4 deletions
+2 -2
View File
@@ -41,14 +41,14 @@ open_fronts = 0 # filled by the gate script once it exists
[spec.dspy-driver]
status = "active" # opened 2026-11-30
line = "dspy-driver"
phase = "requirements-generated"
phase = "design-generated"
owner = ["src/openultrasast/hunt"]
closes = "n/a (active)"
[spec.hunter-learning-loop]
status = "done" # 2026-11-30: built; open tasks moved to dspy-driver
line = "hunter-learning-loop"
phase = "requirements-generated"
phase = "design-generated"
owner = ["src/openultrasast/learn", "src/openultrasast/tool_hunter.py", "src/openultrasast/hunter_tools.py"]
closes = "n/a (active)"
+273
View File
@@ -0,0 +1,273 @@
# Design Document: the DSPy driver, stage one
## Overview
This design covers stage one only, as Requirement 7.4 demands: the example book, the wiring of abstract
interpretation into the driver, the cache, the delivery check E0 and the baseline E1. It adds no stage
that has no result before it.
The finding that shapes it: `src/openultrasast/hunt/` already has the seam this stage needs. A driver input
is produced by a versioned **producer** (`hunt/producers.py`), every producer records provenance
(`ok`, `reason`, `version`, `bytes_read`), and an experiment arm is a **mask** that drops producers or
inputs (`hunt/ablation.py`, `ousast-hunt run --mask`). So the wiring is two new producers and two new
inputs, and E1 is a paired ablation over three masks. Nothing here is a new framework.
Every statement about existing code below was read on 2026-11-30, not run, except where "run" is said.
### Goals
- The driver receives the prover's trace and Joern's results for a change, or a stated cause why not.
- A maintainer can open one page per example and see input, answers, hit or miss, and the miss cause.
- E0 and E1 run from two commands, write their records, and can be read against fixed marks.
- A second run of E0 starts no engine; a second run of E1 makes no model call.
### Non-Goals
- No change to the driver's signature, module, instruction or tools. E1 measures the driver as built.
- No compilation, no case memory, no curator, no new engine query or fact.
- No change to the hook, the scan path, the proof arm or the benchmark machinery.
- No new shared contract. The core model contract (`hunt/model_contract.py`) is not adopted in this stage.
## Boundary Commitments
### This Spec Owns
- Two producers, `trace` and `joern`, and their two driver inputs.
- The example book: its manifest, its repositories map, its freeze digest.
- The sampling wrapper (three answers per question, found on two of three).
- The page renderer and the two commands that run E0 and E1.
- The cache keys for Joern results and model answers in the memory store.
### Out of Boundary
- `hunt/prover.py`, `semantic/`, `cpg/`, `model/taint.py`, `model/dominance.py`: called, never changed. A
missing fact or an unresolved call is recorded as a cause and reported to `engine-change-scoped-analysis`.
- `hunt/program.py` beyond the input table; `hunt/ablation.py`, `hunt/runner.py`, `hunt/accept.py`,
`hunt/propose.py`: used as built.
- Every admission and evaluation population.
### Allowed Dependencies
- `openultrasast.hunt` (producers, table, runner, ablation, metric, program), `openultrasast.hunt.prover`.
- `openultrasast.cpg.backend.JoernBackend`, `openultrasast.model.specs`, `model.taint`, `model.dominance`.
- `openultrasast.memory` and `openultrasast.budget` (after roadmap step C1 moves them out of `plane/`).
- DSPy 3.4.x as pinned. No new third-party package.
### Revalidation Triggers
- A change of a producer's output shape or version: every stored annotation of that producer is void.
- A change of the engine image, the Joern version or a query file: every cached Joern result is void.
- A change of the example book after its freeze: a new digest, a new series (Requirement 1.7).
- A change of the driver's program, model or sampling settings between arms: the run is refused.
## Architecture
### Existing Architecture Analysis
| Existing part | What stage one does with it |
| --- | --- |
| `producers.PRODUCERS`: `diff`, `source`, `semantic`, `taxonomy`; each a `Producer(name, version, columns, compute)` | adds `trace` and `joern` in the same form |
| `table.FEATURE_NAMES`, `PROVENANCE_NAMES` | adds the two producers' columns; provenance columns come for free |
| `program.INPUTS` (name, feature column, description) | adds `trace` and `engine_flows`; order after `obligations` |
| `prover.prove_change(root, change, ctx)` returns `ProverResult(findings, coverage, degradations, traces)` | called once per change by the `trace` producer |
| `model/specs`: taint spec for `path` in Python, JavaScript and TypeScript; dominance spec for `access_control` in all three (run on 2026-11-30) | the `joern` producer asks both, per changed function |
| `ablation.Manifest`, `register`, `run`, `analyse`: paired arms, masks, registered before the run | E1 is one manifest with three masks |
| `runner.run`: resumable, one record per change, spend ledger, `InstrumentFailure` | unchanged; the sampling wrapper sits around the program |
| `metric.search_outcome`: a finding within ten lines of the label | the hit rule of Requirement 6.3 |
| `memory.MemoryStore.put_blob / get_blob` by content | the cache |
### Boundary Map
```mermaid
flowchart LR
book["Example book: manifest + repos map + digest"] --> rows["compute_rows per change"]
rows --> p1["producers that exist: diff, source, semantic, taxonomy"]
rows --> p2["trace producer -> prove_change"]
rows --> p3["joern producer -> JoernBackend, taint and dominance queries"]
p3 <--> cache["memory store: joern results by key"]
p1 --> table["feature table with provenance"]
p2 --> table
p3 --> table
table --> e0["E0: delivery report, no model"]
table --> arms["three masks"]
arms --> prog["HuntProgram, asked 3 times"]
prog <--> cache2["memory store: answers by request digest"]
prog --> pages["one page per example"]
pages --> e1["E1: counts, paired differences, the mark"]
```
### Technology Stack
| Layer | Choice | Note |
| --- | --- | --- |
| Driver | DSPy 3.4.1, `HuntProgram` as built, DeepSeek through `dspy.LM` | unchanged in this stage |
| Trace | `hunt/prover.py` over tree-sitter | no engine start |
| Engine | Joern inside the shipped image, through `JoernBackend` | the image is rebuilt from HEAD before the first recorded run |
| Store | `openultrasast.memory`, file backend by default, S3 on RustFS when `OUSAST_MEMORY` says so | no bucket setup in this stage |
## File Structure Plan
### Directory Structure
```
src/openultrasast/hunt/
annotations.py the two producers: trace and joern; the closed cause lists; the cache keys
sampling.py ask a program k times, vote, keep every answer
pages.py render one page per example from run records; set the miss cause
book.py load, check and freeze the example book; refuse reserved repositories
benchmarks/driver/
book/ book.toml (the thirty changes), repos.json is local and git-ignored
e0.py the delivery check
e1.py registers the three-arm manifest and runs it
tests/
test_hunt_annotations.py, test_hunt_sampling.py, test_hunt_pages.py, test_hunt_book.py
```
### Modified Files
- `src/openultrasast/hunt/table.py`: `FEATURE_NAMES` gains `"trace": ("trace",)` and
`"joern": ("flows", "dominance")`.
- `src/openultrasast/hunt/producers.py`: `PRODUCERS` gains the two producers.
- `src/openultrasast/hunt/program.py`: `INPUTS` gains two rows; nothing else.
- `src/openultrasast/hunt/cli.py`: two subcommands, `page` and `rerun` (Requirement 3.5, 3.6).
## System Flows
**E0.** Load the frozen book. For each change, check out its head, run `compute_rows` with all producers.
Write the annotation of each producer with its provenance. Report per family and language how many
vulnerable examples have a nonempty annotation whose trace or flow touches the labelled function, and the
causes for the rest. No program is built and no key is set.
**E1.** Register one manifest: the book's digest, the three masks, model and version, three samples, the
ceiling, the mark of Requirement 6.4. Run the arms over the same changes. For each example and arm, ask
three times, keep the three answers, vote. Render the pages. Compare each annotated arm with the arm
without annotation, per family. State whether the mark is met.
The three masks, over the same program:
| Arm | Mask (dropped) | Families reported |
| --- | --- | --- |
| A none | `trace`, `joern` | both |
| B prover | `joern` | access control |
| C joern | `trace` | path traversal, and access control through the dominance answer |
## Requirements Traceability
| Requirement | Met by | Checked by |
| --- | --- | --- |
| 1.1 to 1.4 | `book.py`, `benchmarks/driver/book/book.toml` | `test_hunt_book`; the list the maintainer approves |
| 1.5 | `book.py` refuses a repository named by a reserved population; it reuses the guard the tree has for reserved repositories | a test with a reserved identity |
| 1.6, 1.7 | the freeze digest in every record | a test that an edited book gives a new digest and refuses a mixed series |
| 2.1 | `annotations.trace` | a fixture change with a known trace; bytes nonzero |
| 2.2 | `annotations.joern` | one Python and one TypeScript repository in the shipped image |
| 2.3, 2.5 | the closed cause lists; failed is not empty | a test per cause; an engine that exits nonzero gives `failed` |
| 2.4, 5.6 | provenance columns plus engine exit status, start-up and query seconds | the E0 record |
| 2.6 | E0 and E1 refuse a Joern result that does not carry the image digest | a test |
| 2.7, 4.2, 4.3 | arms read the same stored table; the manifest names one difference | a test that a second difference is refused |
| 2.8, 5.7 | cache keys | E0 run twice: second run starts no engine, same bytes |
| 3.1 to 3.4 | `pages.py` | golden pages on fixtures |
| 3.5, 3.6 | `ousast-hunt page`, `ousast-hunt rerun` | a test with the scripted model |
| 4.1, 4.8 | `ablation.register` and one decision line appended to the record | the registered file exists before the first call |
| 4.4, 4.5 | `ablation.analyse` plus the top-K counts | a fixture analysis |
| 4.6, 6.7 | the runner's budget and the spend meter | a test that the run stops at the ceiling and keeps its records |
| 4.7 | the instrument-failure share per arm | a test at two failures in ten |
| 5.1 to 5.5 | `benchmarks/driver/e0.py` | the E0 record itself |
| 6.1 to 6.6, 6.8 | `benchmarks/driver/e1.py` | the E1 record under `benchmarks/measurements/` |
| 6.3 | `sampling.py` | a test of the vote on scripted answers |
| 7 | this document covers stage one only | review |
| 8.1, 8.2 | `book.py` and `runner.refuse_pilot` | tests |
| 8.4, 8.5 | the spend ledger; the commands unset both keys unless `--paid` is given | a test |
## Components and Interfaces
### Producer `trace`
- **Input:** root, change, path, line, the shared `Context`.
- **Does:** calls `prove_change` once per change (kept on the context), selects the traces whose operation
or hops lie in the changed function, and renders each as ordered text: entry and boundary, parameters
with origin, each hop with the guards before its call, the operation with its line and arguments, the
guards required, those that dominate, and what is missing.
- **No result:** one cause from: no entry recognised; operation not recognised; call unresolved; language
not supported. Taken from the prover's `coverage.unchecked_by_reason` and `degradations`. To verify in
the first task: that these two fields are enough to set the cause per location; if not, the cause is
"to be read" and the gap is reported.
- **Output column:** `feature.trace.trace`, a list of trace texts or the cause statement.
### Producer `joern`
- **Input:** as above.
- **Does:** builds or loads the graph for the change's head revision once per revision, then asks, for
each changed function, the taint query with the `path` spec of the file's language and the dominance
query with the `access_control` spec. Renders flows as ordered steps (source, each step with file and
line, sink, sanitizers on the path) and the dominance answer as operation, guard, and whether the guard
dominates.
- **No result:** one cause from: no source-to-sink path; language not supported; engine did not start;
engine timed out. "No path" is a result of a query that ran; the other three are failures.
- **Instrument proof:** the record holds the image digest, the Joern version, the source bytes the graph
was built from, the exit status, start-up seconds and query seconds. Zero bytes or a nonzero exit marks
the annotation failed.
- **Output columns:** `feature.joern.flows`, `feature.joern.dominance`.
### Cache
- **Joern result key:** sha256 over repository, revision, file path, function content digest, language,
family, query file digest, spec digest, engine image digest. Stored with `put_blob("annotations/joern", ...)`.
- **Graph:** the engine's own graph cache is used as it is; this design adds no second one.
- **Model answer key:** the request digest the runner already computes (`runner.input_digest`) plus the
sample index and the model version. Stored with `put_blob("responses", ...)`. DSPy's own disk cache stays
on; the store makes the answers reusable from another machine.
- **Void by key:** any changed part of a key is a miss. There is no other pruning in this stage.
### Sampling
- `ask(program, inputs, k=3) -> list[Prediction]`, each call with its own sample index so the cache keeps
three answers and the model is not asked for one answer three times.
- `vote(predictions, tolerance=10)`: a location counts when at least two of three answers name it within
the tolerance; the agreement share is kept for every named location.
- To verify in its task: that DeepSeek through `dspy.LM` returns different samples at the fixed
temperature; if three calls return one cached answer, the design uses DSPy's rollout id for the sample
index.
### Pages
- One Markdown file per example and arm under the run directory: the label, each annotation with its byte
count and provenance, the three answers, the vote, hit or miss.
- Miss cause, set from records where they decide it: no annotation (provenance says failed or a cause);
wrong family (a named location matches, the family does not); wrong location (the family matches, no
location within tolerance). "Annotation wrong" and "annotation right and not used" need a person: the
page is marked "to be read" (Requirement 3.4).
### Example book
- `book.toml`: per change an id, repository, base and head revisions, kind (vulnerable or ordinary), and
for a vulnerable change the family, the labelled file and lines, the fixing revision and the source of
the label. The format is the manifest `ousast-hunt run` already reads, so no loader is new.
- The freeze writes the digest of the canonical file; every record carries it.
## Error Handling
- A producer never raises into the run: it returns a cause or a failure with its reason, as the existing
producers do.
- An engine failure fails the annotation, never the run; more than one failed example in ten of an arm
makes the experiment "not read" (Requirement 4.7).
- The ceiling stops the run and keeps finished records; the report lists what is undone.
- A repository of a reserved population stops the command before any checkout.
## Testing Strategy
- **Unit, offline, no engine and no key:** the cause lists, the cache keys, the vote, the page renderer,
the book checks. The scripted model that the hunt tests already use stands in for the driver.
- **Engine, in the shipped image:** the `joern` producer on one Python and one TypeScript fixture
application with a known path traversal; skipped by cause where the image is absent.
- **The measurements are the acceptance:** E0 then E1 on the frozen book, each read against its mark.
A green unit suite does not close this stage; the two records do.
## Risks, each with what would show it
| Risk | Shown by | Then |
| --- | --- | --- |
| The prover recognises few entries in the book's frameworks (it did on the admission repositories) | E0: access control not ready | the examples and causes go to engine work; E1 runs for the ready family only |
| Joern finds no path on real applications in the time allowed | E0: path traversal not ready, causes "timed out" or "no path" | as above; the start-up and query times are in the record |
| The annotation is right and the driver ignores it | E1 pages: "annotation right and not used" | the next stage is the signature (E4), not more facts |
| Three samples agree always | E1: agreement is 0 or 1 everywhere | E3 is answered early: sampling adds cost and no signal at these settings |
| Thirty examples are too few to tell arms apart | E1: paired difference of one example | the mark of Requirement 6.4 is not met; no claim is made |
+2 -2
View File
@@ -3,7 +3,7 @@
"created_at": "2026-11-30T00:00:00+01:00",
"updated_at": "2026-11-30T00:00:00+01:00",
"language": "en",
"phase": "requirements-approved",
"phase": "design-generated",
"approvals": {
"requirements": {
"generated": true,
@@ -11,7 +11,7 @@
"note": "maintainer 2026-11-30: 'approved.'; thresholds of Requirements 5 and 6 as proposed; memory amendment recorded in requirements.md"
},
"design": {
"generated": false,
"generated": true,
"approved": false
},
"tasks": {
+12
View File
@@ -209,6 +209,18 @@ What follows from it:
embedder, tools in a loop) and none for pruning or for a memory agent; that part is this project's to
build and to measure.
### Answers to the second menu of 2026-11-30 (maintainer, with the question tool)
- **Memory:** "M1 now, M2/M3 by result". The cache is built in stage one of `dspy-driver`; the case
memory and the curator get criteria only after E1 is read.
- **The plane cut:** "C1 now, rest after E1". The memory store and the spend meter move out of the
plane package now; C2 to C5 wait until the baseline is read.
- **Docker:** "One image": Joern and `ousast`, for the scan and the driver. The task base image, its
workflow and the runner image go with C4.
- **The example book:** "I propose, you approve". Candidates come from the development catalogs and
the vibe-code pairs, checked against every admission population; the maintainer sees the list of
thirty before it is frozen.
### Open for the maintainer
- The spend ceiling of N3.