Skip to content

Coverage ledger: record examined, ruled-out and untested risk classes - #207

Merged
BaaRai merged 2 commits into
mainfrom
feat/coverage-ledger
Nov 12, 2026
Merged

BaaRai merged 2 commits into
mainfrom
feat/coverage-ledger

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

What

A coverage ledger. It records what workers examined, ruled out or left open for each surface and risk class, so that a missing finding never reads as "clean target".

  • New worker tool record_coverage(surface, risk_area, outcome, evidence, reason). Outcomes: reported, no_issue_found, ruled_out, not_applicable, needs_follow_up.
  • New tables coverage_ledger (one current row per task, surface and risk_area) and coverage_ledger_history (every write). New additive column tasks.end_reason.
  • Gaps, unexamined classes and completeness are shown in the planner context, in GET /api/tasks/{id}/coverage, in the coverage card and in the Markdown report (GET /api/report).

Why

The model comes from Strix strix/report/coverage.py (skill_coverage_gaps). The invariant is that absence is not clean. A risk class with no ledger entry is unexamined, never clean. A no_issue_found is never derived from the absence of a finding. It must be written by a worker, with evidence.

Design

  • Two layers. agent_reported holds the ledger entries. machine_observed holds what execution produced: the existing asset coverage (TaskCoverageWithSources with declaredScopeFilter, unchanged) and findings_by_class from findings. The ledger adds the risk-class dimension and the negative results. It does not recompute tested assets.

  • Gaps (db.BuildCoverageLedger, a pure function) come from three sources:

    • (a) an entry with needs_follow_up;
    • (b) a goal vulnclass with no entry at all, reported as unrecorded_risk_class and also listed in unexamined;
    • (c) an entry missing its required field: missing_evidence for no_issue_found, missing_reason for ruled_out and not_applicable.

    Mandatory classes come only from the goals' vulnclass. There is no asset x class matrix. An intent that records nothing creates no gap (recon has no class obligation).

  • Warn, do not block. The tool accepts an entry with missing evidence or reason, records it, and answers "counted as a gap". prove_goal and the done status are unchanged.

  • Switch. Everything follows tasks.coverage_enabled. When it is false, record_coverage is in coverageOnlyTools, so it is dropped from the tool list (the worker now calls DropCoverageTools too). The handler also refuses to write, the planner block is empty, and the API keeps its existing {enabled:false} short-circuit. There is no new environment variable.

  • Seeding. record_coverage is part of WorkerTools(), so BuiltinToolSeeds() and SeedTool (ON CONFLICT DO NOTHING) insert the new key on existing databases at startup. It is bound to worker by default. No existing tool's schema or description is changed, so no migration is needed.

  • Planner. At each round the planner gets one line with entry counters by outcome, the gap count and the top 3 gaps. On the task-timeout final round and on the budget wrap-up round (Hierarchical budgets: min(child, parent) with forced wrap-up (off by default) #206), it gets the remaining gaps instead (at most 25, then a count line). The gap lines are agent-reported text, so they sit inside the round's data envelope (env.wrap("coverage_ledger", ...), F3 nonce framing); the code-owned header and counters stay outside the frame.

  • Small adjacent edits:

    • record_coverage is allowed during the worker budget wrap-up (BudgetWrapupBlocks), like the other write-back tools.
    • It is listed in intercept.noTargetTools: it only writes to the DB, so its surface URL is not a network target.

Choices

These are the points where the brief was ambiguous. Each time I took the conservative option.

  1. Table shape. There are two tables. coverage_ledger has UNIQUE (task_id, surface, risk_area) and is upserted. coverage_ledger_history is append-only, and both writes happen in one transaction. Every text field is normalised to one line in db.RecordCoverage (see Review fixes); risk_area is also lower-cased and matched against the lower-cased goal vulnclass. Both tables have an FK to tasks with ON DELETE CASCADE. They are not added to the task archive/restore path.

  2. Completeness source. CoverageCompletenessFor(status, paused, budget, pastDeadline) decides:

    • budget: tasks.end_reason = 'budget'. The budget settle in engine_timeout.go writes it in the same guarded UPDATE as the terminal status; it is per run (cleared when a revive moves the task back to running).
    • timeout: status = timeout, or done with completed_at >= deadline_at (goals met on the final timeout round still count as a timeout).
    • aborted: failed.
    • paused: the paused flag or status.
    • in_progress: any other status that is not done.
    • complete: done only.

    A budget end reason wins over everything else for that run, even when the final round met the goals. A caveat string is always set, including on complete.

  3. A finding does not close a class. Only a ledger entry satisfies a mandatory class. Findings are reported separately as findings_by_class (machine_observed). A worker that reports a finding is expected to record a reported entry as well.

  4. Planner line when there are no entries. The per-round line is absent until at least one entry exists, as the test list asks. It stays absent even if goals carry a vulnclass. Unrecorded classes still appear in the API, the card, the report and the wrap-up gap list. If you would rather show unexamined classes from round 1, it is a one-line change in renderCoverageLedger.

  5. Wrap-up text. The gap list is added to the planner's wrap-up round (task timeout and budget). The worker wrap-up prompts are unchanged.

  6. API shape. The ledger fields entries, gaps, unexamined, findings_by_class and completeness are flattened into the existing coverage document. db.Coverage embeds *db.CoverageLedger, so the existing fields are unchanged.

  7. Export. "Export" is the Markdown report (GET /api/report), which gets a "Coverage gaps" section with completeness and the gap list (at most 200 entries, then a count line). The findings CSV/JSON export is unchanged.

  8. Ledger scope. The ledger is per task. It does not read inherited source tasks.

Completeness caveat

A run that ended by timeout, the budget wrap-up, pause, abort, or that is still running is reported as complete: false, with a state and a caveat. The caveat says that the absence of a finding does not mean the target is clean and that unexamined classes and open gaps were not covered. The caveat is never omitted. The report always prints it, and the card shows it when the run is incomplete.

Review fixes

Blocker 1: planner injection through ledger text.

  • db.RecordCoverage itself (not only the tool handler) normalises surface, risk_area, evidence and reason to one line: every control character (C0 including \r \n \t, DEL, C1) and U+2028/U+2029 become a space, whitespace runs collapse, ends are trimmed. Then length limits apply: surface 200, risk_area 64, evidence 500, reason 500 (characters). Over a limit the write is refused with e.g. surface too long (max 200); nothing is truncated.
  • agent/planner.go keeps one env := newDataEnvelope() per message, passes it to plannerSituational and to coverageLedgerBlock. Only the gap lines are framed (field=coverage_ledger); the envelope neutraliser rewrites any ARTEX_DATA marker inside them. The header (counters, "prove_goal stays allowed") and the "and N more" line are code-owned and stay outside. The budget line is unchanged (numbers only).
  • Caps: the wrap-up lists at most 25 gaps, then - and N more (see the coverage API/report); the Markdown report lists at most 200, then a count line.

Blocker 2: stale budget completeness after a revive.

  • New column tasks.end_reason TEXT NOT NULL DEFAULT '' (ALTER TABLE ... ADD COLUMN IF NOT EXISTS, like the other additive task columns).
  • SetTerminalStatusGuarded / Manager.SetTaskStatusGuarded take an end reason and store it in the same guarded UPDATE as the terminal status; settleTask passes budget on a budget settle, the normal done path passes empty. A losing writer stores nothing.
  • Cleared when the task leaves the terminal state: in ApplyTaskAdmission (same UPDATE as the terminal -> running revive), in SetStatus to a non-terminal status, and in resetSettledRun (also reached from resetTimeoutRevival), which clears it only if the task is not terminal again.
  • CoverageLedger reads tasks.end_reason. The activity-metadata marker is removed (the "Task run budget exhausted" activity text stays, as on main); there is a single source.

Non-blocking.

  • At most 2000 current ledger rows per task: a new (surface, risk_area) beyond the cap is refused with a clear error; updating an existing key is always allowed. Writers of one task are serialised (SELECT ... FOR UPDATE on the task row) so the cap holds under concurrency. The history stays append-only and is not capped.
  • The planner's per-round block runs one COUNT(*) first and returns early when the task has no entries, instead of the full 4-query load. The wrap-up round still loads the full ledger (unrecorded classes matter there).
  • taskCoverage: on a 500 the real error is logged ([coverage] ...) and the client gets a generic message, as other handlers do.

Limitations

  • evidence is unverified free text. A no_issue_found with fact 999 closes a class even if fact 999 does not exist for the task. This follows Strix's agent_reported model; a later hardening can check that a cited fact/intent/traffic id exists for the task.
  • outcome=reported closes a class without checking that a matching finding exists.
  • Archive/restore does not carry coverage_ledger or coverage_ledger_history. A restored task reads every class as unexamined, which is the conservative direction.
  • The history table is append-only and uncapped (only current rows are capped at 2000 per task).

Tests run locally

The system Go toolchain in Kali (go1.26.10). The PG tests ran against a throwaway postgres:16 container bound to 127.0.0.1, removed afterwards.

  • gofmt -l on the changed files: the only output is agent/tools.go, db/tasks.go, server/manager.go and server/server.go. All four are already unformatted on main at lines this PR does not touch (checked by running gofmt -l on the main versions) and are left as they are.
  • go build ./...: OK.
  • go vet ./...: OK.
  • go test -count=1 ./... with PG: all 16 packages pass.
  • go test -race -count=1 ./agent ./db ./server ./report: on a fresh database all four pass with no data race. When db reuses the database of a previous full run, 4 db tests fail on leftover rows (duplicate llm profile names, a leftover company), as before. One race run of server also reported data races in other tests; the same package on main (afa6f4f) also races intermittently (TestTriggeredConversationInheritsGate, TestTrafficIngestRequiresAuth), so this is pre-existing flakiness, not this PR.
  • Tests:
    • db: TestBuildCoverageLedgerGaps, TestCoverageCompletenessFor, TestCoverageJSONCarriesLedger, TestRecordCoverageUpsertHistory (PG: upsert plus history, ledger load, budget end reason), TestNormalizeCoverageEntry (one-line folding of control characters, exact limits and error text), TestCoverageCompletenessBudgetThenReviveDone (PG: budget settle, losing writer, revive, later planner/worker activity carrying the old marker, normal done => complete), TestRecordCoverageRowCap (PG: new key past 2000 refused, existing key updated).
    • agent: TestRecordCoverageDisabledPassthrough, TestRenderCoverageLedger, TestRenderCoverageLedgerInjection (a surface with \n\n, [[ARTEX_DATA / [[END_ARTEX_DATA and a fake [Operator] line stays on one line inside the one ledger frame: no extra marker, no extra section), TestRenderCoverageLedgerWrapupCap (100 gaps => 25 lines then and 75 more), TestRecordCoverageSeededOnExistingDB (PG), TestRecordCoverageToolWritesEntry (PG).
    • server: TestReviveClearsBudgetEndReason (PG: budget settle stores the reason, same-status admission keeps it, terminal -> running admission clears it, resetSettledRun clears a running task's reason and resetTimeoutRevival leaves a terminal one).
    • report: TestMarkdownCoverageGaps, TestMarkdownCoverageGapsCap (230 gaps => 200 listed plus and 30 more).

Not verified

  • The web UI change (overview-tab.tsx, api.ts) is type-checked by the CI web job but was not visually rendered.
  • No end-to-end run with a real LLM. I have not checked that workers actually call record_coverage, or how the planner reacts to the line.
  • The taskCoverage and getReport handlers are not exercised end-to-end in tests. The JSON shape and the Markdown rendering are tested directly.

Workers record per (surface, risk_area) outcomes with the new record_coverage
tool (reported, no_issue_found, ruled_out, not_applicable, needs_follow_up).
Gaps are needs_follow_up entries, entries missing their required evidence or
reason, and goal vulnclass values with no entry (unrecorded_risk_class), so an
absent finding never reads as a clean target. Completeness marks timeout,
budget wrap-up, pause, abort and running tasks as incomplete with a caveat.

Surfaced in the planner context (one line per round, full gap list on the
timeout/budget wrap-up round), GET /api/tasks/{id}/coverage, the coverage card
and the Markdown report. Follows coverage_enabled; no new env var.
…es, per-run end_reason)

Normalise and length-check ledger fields in db.RecordCoverage, frame the planner gap lines in the data envelope, cap the wrap-up (25) and report (200) gap lists, cap current rows at 2000 per task. Replace the activity budget marker with tasks.end_reason, written with the guarded terminal status and cleared on revive. Generic 500 message in taskCoverage; early return on an empty ledger in the planner block.
@BaaRai
BaaRai merged commit 558b685 into main Nov 12, 2026
3 checks passed
wxcvm referenced this pull request in wxcvm/ARTEX Nov 14, 2026
* feat(coverage): persist task check results and expose coverage gaps

Adapt upstream #207 with task archive, report and overview integration; preserve existing coverage switch.

* fix(coverage): surface structured planning gaps and localize overview
liuxiaobo0920 added a commit to liuxiaobo0920/ARTEX_2 that referenced this pull request Nov 17, 2026
…port

The task report and the findings export asserted every finding with no
qualification: nothing said how far exploitation actually reached (PoE level),
whether the claim was machine-verified (verification status and note), whether
counterevidence was recorded, or whether any traffic was bound. The web UI
badges all of it (VERIFICATION_META, the detail page), so the report — the
artifact a client actually reads — was the last surface still asserting bare
claims.

Render it from one place:

- report/quality.go (new): two constructors and two pure renderers, no I/O, no
  DB handle, so the block is unit-tested without a database.
- Both surfaces call the same helpers, which is the point: the task report and
  the per-finding export cannot drift apart the way duplicated formatting does.
- Missing is explicit: a finding node with no standalone row prints
  "not assessed (no finding record)" instead of an invented zero — the honest
  gap the existing coverage work (BaaRai#207) also insists on.
- Labels match the shipped UI wording (Verification, Confidence rationale,
  Counterevidence) and states are humanised ("Not assessed", "False positive"),
  with an unrecognised value printed verbatim so a new state cannot silently
  vanish from a report.
- Bound-traffic count appears once per document: as a Proof bullet in the task
  report (it has no traffic section), and in the export only when nothing is
  bound — otherwise the traffic section already states it.
- The detailed report is capped at 8 KiB in the task report only, rune-safe, with
  the cap derived into the truncation message; the export is the canonical
  per-finding document and is never silently shortened.
- The export keeps its document structure: the single-finding document gets
  "## Detailed Report" (a section like its siblings), the multi-finding summary
  gets a bold label.

Read paths only: no change to the write side of poe_level or verification_status,
no schema change (all five columns already exist), no API/DTO change (the widened
FindingMeta stays internal to the report path, and the findings list keeps
selecting only what it renders). One extra task-scoped query on GET /api/report,
because findings bodies stay off the list path.

docs/vulnerability-traffic-evidence.md §Export describes the new Markdown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant