mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-26 01:41:04 +08:00
agent: advisory duplicate check on report_finding via a decision model
Duplicates are the cheapest way to lose reviewer trust, and the only guard today is
a prompt instruction: the worker is told to check list_findings before registering.
It does not hold — in one run against a deliberately vulnerable app three defect
classes were registered twice each (two SQLi, two IDOR, two admin-endpoint
findings), and one of the pairs differed only in wording.
A decision model answers exactly this kind of closed-list question (same defect as
one of these N findings, or not?) with probabilities and no generated text, so the
judgement costs one small request instead of a main-model turn over a six-figure
context. Measured on our own findings before writing any of this (15 candidates,
hand labels): the correct partner 8/8 on a 27B decider and 7/8 on the flash one,
against 7/15 for the constant "always distinct", at 0.66 s and ~1.7k input tokens
per call with zero output tokens. Repeated calls were stable (30/30 identical).
Changes
- agent/triage.go: TriageClient interface, a /v1/systemone HTTP client, and the pure
pieces (state builder, criteria builder, answer parser, threshold) so the logic is
testable without a server.
- report_finding: consults the client before registering. On a duplicate above the
confidence threshold the finding is not registered again; the caller is told which
finding_id it matched and to extend it with update_finding_report.
- Wiring: agent.SetTriageClient on the worker/planner ToolSets, a triage_profile_id
setting (any llm_profiles row whose base_url serves the decision contract; 0 = off),
exposed through the settings API.
Fail-open, by construction
Triage changes an outcome only when it is confident; every other path behaves exactly
as today: no client, no existing findings, empty summary, transport error, non-200,
malformed body, an id the question never offered, or confidence below the threshold
all fall through to normal registration. A wrong suppression loses evidence, a wrong
registration only costs a row — hence the threshold, and hence "advisory".
Verification
- go test ./agent/ passes, including new tests: request shape (model/state/criteria
carry every candidate), distinct answer, unknown id reads as distinct, probability
fallback when confidence is absent, error on 500, no HTTP call without input, state
cap, threshold boundaries.
- red/green on two independent breakages: forcing the threshold false and accepting
an unoffered id both fail the suite; restored, it passes.
- go test ./server/ shows one failure,
TestManagerSOCKS5UDPOptInAndAssetBlockRuleDropsDatagram (bind 127.0.0.2 —
environment), reproduced on clean main in a separate worktree.
- gofmt -l agent/ server/ clean.
Notes
- The profile must serve /v1/systemone. A chat-only decider endpoint (one that refuses
/v1/chat/completions) needs a thin adapter; a decision endpoint works directly.
- Off by default: with no triage_profile_id the platform behaves as before.
The cap on offered findings is a SELECTION, not "the newest N": with a wide graph
the true partner falls out of a newest-first list, so candidates are ranked by
relevance (same class, overlapping endpoint, another task on a shared asset) with
recency only breaking ties. Per-entry summary capping replaces the whole-state
truncation, which used to cut mid-line and leave criteria ids whose state line had
been dropped.
Threshold is a knob, not a constant (live acceptance): on a run with the wider
cross-task pool the model named the right partner in 8 of 9 questions, but its
confidence moved with the question's width — 0.73-0.79 on a small pool, 0.30-0.53
with twenty candidates. Six duplicates were suppressed, and exactly the two that
slipped were the 0.30 and 0.47 ones, both with the correct partner named. A fixed
0.5 cannot fit both ends, so the threshold is a setting (triage_min_confidence,
default 0.5); the low end is affordable because the suppression result tells the
agent to re-register explicitly when the finding is in fact distinct.
Cross-task pool (found by re-measuring the live miss): task_relations only links
spawned tasks, so two tasks created independently against the same target never see
each other's findings and a defect registered in both is invisible to the dedup
question. FindingsSharingAssets joins on the candidate's own asset ids (jsonb
containment, GIN-served) and adds those findings to the question, marked with their
task. On three real cross-task duplicates the wider question names the right partner
in all three (confidence 0.58-0.73, above the threshold), where the own-task pool
could only answer "none".
Regression note (found on a live run, not in CI): FindingID is filled from the findings table, so building the candidate list straight from the nodes dropped every entry and triage never fired ("nodes=6, no usable existing findings"). Covered by TestTriageCandidates_SkipsNodesWithoutFindingRow; findings inherited from a directly related task are kept and marked in the question.
---
Found while running the platform against a live target.
limits: triageDupMinConfidence 0.5 - калибровка 538 пар одной цели (stage3_calibrate.py, 2026-11-22): recall 1.00 при FP 0.47 на 75 жёстких негативах; на истинных дублях в живом прогоне 0.30-0.79
limits: triageMaxExisting 10 - ширина вопроса на реальном дубле (stage3_width.py, 2026-11-22): уверенность 0.81-0.91 до 11 кандидатов, 0.64 на 19, 0.56 на 29; латентность 0.44->1.29 с
limits: triageMaxSummaryChars 400 - p90 длины сводки 334, максимум 564 по 53 находкам графа (2026-11-22)
limits: triageMaxStateChars 6000 - арифметика при потолке 10 записей: 10*(400+60)+480 ~= 5.1 КБ, запас 1.17x
limits: triageHTTPTimeout 20s - наблюдаемая латентность decider 0.26-1.29 с, 3.83-3.96 с на 27B; запас ~5x к худшему
limits: findings pool query limit 50 - самый широкий пул по ассету 31 находка (53 в графе, 2026-11-22), запас 1.6x
limits: ответ decider 1 MiB - наблюдаемый ответ 0.3-2 КБ, запас ~500x
This commit is contained in:
@@ -334,6 +334,15 @@ const (
|
||||
// Target noise profile (off|quiet|balanced|aggressive). When stored it wins over
|
||||
// ARTEX_NOISE_PROFILE, which stays the fallback; applied at startup and on PUT.
|
||||
settingNoiseProfile = "noise_profile"
|
||||
// settingTriageProfile names an llm_profiles row that serves the decision-model
|
||||
// (/v1/systemone) contract: the triage client for closed-list judgements such as
|
||||
// the duplicate check in report_finding. Empty or 0 = triage off (main model
|
||||
// decides, exactly as before). See server/triage.go.
|
||||
settingTriageProfile = "triage_profile_id"
|
||||
// settingTriageMinConfidence is the suppression threshold for a duplicate answer
|
||||
// (0..1, empty = 0.5). Confidence on true duplicates moves with the question's
|
||||
// width, so this is a knob rather than a constant.
|
||||
settingTriageMinConfidence = "triage_min_confidence"
|
||||
// defaultWebSearchBackend is used when web search is on but no backend was picked.
|
||||
defaultWebSearchBackend = "ddgs"
|
||||
// deepSeekWebSearchBackend borrows the active LLM profile instead of its own
|
||||
|
||||
@@ -3897,6 +3897,8 @@ func (s *Server) settingsPayload() map[string]any {
|
||||
return map[string]any{
|
||||
"traffic_capture": s.m.TrafficEnabled(),
|
||||
"agent_traffic_binding": s.m.pg.GetBool(settingAgentTrafficBinding, false),
|
||||
"triage_profile_id": s.triageProfileID(),
|
||||
"triage_min_confidence": s.triageMinConfidence(),
|
||||
"llm_record": s.m.LLMRecordEnabled(),
|
||||
"web_search_enabled": on,
|
||||
"web_search_backend": backend,
|
||||
@@ -3998,6 +4000,14 @@ func (s *Server) putSettings(w http.ResponseWriter, r *http.Request) {
|
||||
// operation-constraint injection scope switches (default both on); take effect immediately (planner/worker read them every round), no agent rebuild needed.
|
||||
ConstraintsInjectPlanner *bool `json:"constraints_inject_planner"`
|
||||
ConstraintsInjectWorker *bool `json:"constraints_inject_worker"`
|
||||
// Triage profile: an llm_profiles row serving the decision-model (/v1/systemone)
|
||||
// contract, used for closed-list judgements (report_finding dedup). 0/null-safe:
|
||||
// omit = keep, 0 = off. Read per agent run, so it applies to runs started afterwards.
|
||||
TriageProfileID *int64 `json:"triage_profile_id"`
|
||||
// Suppression threshold for a duplicate answer (0..1). Lower catches more real
|
||||
// duplicates and risks suppressing a distinct one; the caller is told to
|
||||
// re-register in that case, which is what makes the low end affordable.
|
||||
TriageMinConfidence *float64 `json:"triage_min_confidence"`
|
||||
// Experimental: noa context compaction switch (default off); read per run, applies to runs started afterwards, no agent rebuild needed.
|
||||
NoaCompaction *bool `json:"noa_compaction"`
|
||||
// Vulnerability IM push global settings. The delivery engine re-reads all three every round, so changes
|
||||
@@ -4044,6 +4054,19 @@ func (s *Server) putSettings(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if req.TriageMinConfidence != nil {
|
||||
if err := s.m.pg.SetSetting(settingTriageMinConfidence, strconv.FormatFloat(*req.TriageMinConfidence, 'f', 3, 64)); err != nil {
|
||||
writeErr(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
s.applyTriageThreshold()
|
||||
}
|
||||
if req.TriageProfileID != nil {
|
||||
if err := s.m.pg.SetSetting(settingTriageProfile, strconv.FormatInt(*req.TriageProfileID, 10)); err != nil {
|
||||
writeErr(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if req.NoaCompaction != nil {
|
||||
// The resolver is read per run; toggling takes effect immediately for runs started afterwards, no applyLLM rebuild needed.
|
||||
if err := s.m.SetNoaCompaction(*req.NoaCompaction); err != nil {
|
||||
|
||||
@@ -801,6 +801,8 @@ func (s *Server) agentsForTask(t *Task) *taskAgentBundle {
|
||||
window := workerRuntime.CompactionWindow()
|
||||
wk := agent.NewWorker(workerRuntime, "task-router", s.m.dir, tx, window, s.agentMaxTurns("worker"))
|
||||
wk.SetFindingRecorder(s.evidenceStore())
|
||||
wk.SetTriageClient(s.triageClient()) // advisory dedup on report_finding (nil = off)
|
||||
s.applyTriageThreshold() // stored suppression threshold (cheap, idempotent)
|
||||
wk.SetCompactionWindowResolver(workerRuntime.CompactionWindow)
|
||||
wk.SetNonStreaming(workerRuntime.nonStreaming) // per the task's currently active profile streaming switch (read every turn)
|
||||
wk.SetMaxTokens(workerRuntime.maxTokens) // as above, the output cap also follows the currently active profile
|
||||
@@ -812,6 +814,7 @@ func (s *Server) agentsForTask(t *Task) *taskAgentBundle {
|
||||
wk.SetConstraintInject(s.constraintInjectWorker) // operation-constraint injection into the worker (configurable, on by default)
|
||||
pl := agent.NewPlanner(plannerRuntime, "task-router", s.m.dir, tx, plannerRuntime.CompactionWindow(), s.agentMaxTurns("planner"))
|
||||
pl.SetFindingRecorder(s.evidenceStore())
|
||||
pl.SetTriageClient(s.triageClient()) // the planner registers findings too (wrap-up paths)
|
||||
pl.SetCompactionWindowResolver(plannerRuntime.CompactionWindow)
|
||||
pl.SetNonStreaming(plannerRuntime.nonStreaming)
|
||||
pl.SetMaxTokens(plannerRuntime.maxTokens)
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Autumn-27/artex/agent"
|
||||
)
|
||||
|
||||
// triageClient builds the advisory triage client from the configured profile, or
|
||||
// nil when triage is off. The profile's base_url must serve the decision-model
|
||||
// contract at <base_url>/systemone; the model is the profile's model. Built per
|
||||
// agent run (cheap: one settings read + one profile read), so toggling the setting
|
||||
// takes effect on the next run without an agent rebuild.
|
||||
//
|
||||
// Fail-open by design: an unreadable setting, a missing profile or a profile with
|
||||
// no base_url/model returns nil, and report_finding behaves exactly as before.
|
||||
func (s *Server) triageClient() agent.TriageClient {
|
||||
id := s.triageProfileID()
|
||||
log.Printf("[triage] triageClient: profile_id=%d", id)
|
||||
if id <= 0 {
|
||||
return nil
|
||||
}
|
||||
p, err := s.m.pg.ProfileByID(id)
|
||||
if err != nil || p == nil {
|
||||
return nil
|
||||
}
|
||||
if strings.TrimSpace(p.BaseURL) == "" || strings.TrimSpace(p.Model) == "" {
|
||||
return nil
|
||||
}
|
||||
return &agent.SystemOneClient{BaseURL: p.BaseURL, APIKey: p.APIKey, Model: p.Model}
|
||||
}
|
||||
|
||||
// applyTriageThreshold pushes the stored threshold into the agent package. Called on
|
||||
// boot and on a settings change; an unreadable or out-of-range value keeps the default.
|
||||
func (s *Server) applyTriageThreshold() {
|
||||
if s.m.pg == nil {
|
||||
return
|
||||
}
|
||||
raw, ok, err := s.m.pg.GetSetting(settingTriageMinConfidence)
|
||||
if err != nil || !ok {
|
||||
return
|
||||
}
|
||||
if v, err := strconv.ParseFloat(strings.TrimSpace(raw), 64); err == nil && v > 0 && v <= 1 {
|
||||
agent.SetTriageMinConfidence(v)
|
||||
}
|
||||
}
|
||||
|
||||
// triageMinConfidence reports the stored threshold for the settings API (0 = default).
|
||||
func (s *Server) triageMinConfidence() float64 {
|
||||
if s.m.pg == nil {
|
||||
return 0
|
||||
}
|
||||
raw, ok, err := s.m.pg.GetSetting(settingTriageMinConfidence)
|
||||
if err != nil || !ok {
|
||||
return 0
|
||||
}
|
||||
v, err := strconv.ParseFloat(strings.TrimSpace(raw), 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// triageProfileID returns the configured triage profile id, 0 when off or unreadable.
|
||||
func (s *Server) triageProfileID() int64 {
|
||||
if s.m.pg == nil {
|
||||
return 0
|
||||
}
|
||||
raw, ok, err := s.m.pg.GetSetting(settingTriageProfile)
|
||||
if err != nil || !ok {
|
||||
return 0
|
||||
}
|
||||
id, err := strconv.ParseInt(strings.TrimSpace(raw), 10, 64)
|
||||
if err != nil || id < 0 {
|
||||
return 0
|
||||
}
|
||||
return id
|
||||
}
|
||||
Reference in New Issue
Block a user