ARTEX/db
Николай Гусев 24cd7da9af 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
2026-11-23 16:59:40 +03:00
..
migrations feat: add bearer-authenticated Bedrock gateway profiles 2026-11-22 18:27:43 +08:00
activity_outbox.go Stop admitting work before the drain and replay each outbox row once. 2026-11-17 15:41:56 -05:00
activity_outbox_test.go test: clean remaining residual rows across db, agent, and server test suites 2026-11-20 22:54:57 +01:00
activity_page_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
asset_dsl.go fix(company-switcher): address review on #425 2026-11-22 09:44:37 +00:00
asset_dsl_limit_test.go fix(db): bound asset DSL length and parenthesis depth 2026-11-19 14:25:04 +01:00
asset_dsl_or_scope_test.go fix(company-switcher): address review on #425 2026-11-22 09:44:37 +00:00
asset_intercept.go ci: run gofmt in the go job, and format the 11 files it flags 2026-11-15 13:38:35 +01:00
asset_intercept_match.go fix(intercept): match block rules on the declared targets before any lookup 2026-11-11 15:47:58 +01:00
asset_intercept_match_test.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
assets.go fix(db): drop userinfo from an asset URL that cannot be parsed 2026-11-21 19:52:37 +00:00
assets_test.go fix(db): drop userinfo from an asset URL that cannot be parsed 2026-11-21 19:52:37 +00:00
bedrock_gateway_test.go fix: bind Bedrock headers to gateway and redact errors 2026-11-22 22:31:06 +08:00
browser_mcp.go fix(mcp): rewrite npx -y and playwright-mcp rows missing --browser 2026-11-18 22:42:38 +01:00
browser_mcp_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
chat_mentions.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
cleanup_helpers_test.go test(db): close the pool after the row cleanups, report cleanup errors 2026-11-14 00:38:00 +01:00
commands.go db: versioned migrations runner with schema_migrations 2026-11-14 12:52:34 +01:00
companies.go db: report hidden asset count in malformed-ip warning suffix 2026-11-10 15:49:41 +01:00
companies_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
company_lock_test.go feat(assets): add editable company and task scopes 2026-08-24 19:29:14 +08:00
company_scope.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
company_scope_consistency_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
company_scope_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
config.go fix: bind Bedrock headers to gateway and redact errors 2026-11-22 22:31:06 +08:00
config_max_tokens_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
config_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
constants.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
constraints.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
conversation.go feat(intercept): target-gate schema, opt-in flag and approval requests (S3b 1.2-1.4) 2026-11-10 23:05:47 +01:00
conversation_pin_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
coverage_graph_large_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
coverage_ledger.go Coverage ledger: review fixes (one-line capped fields, framed gap lines, per-run end_reason) 2026-11-12 20:48:34 +01:00
coverage_ledger_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
customtool_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
dashboard_usage_indexes_test.go perf(db): add partial covering indexes for dashboard/usage queries (migration 0010) 2026-11-20 21:48:31 +01:00
db.go fix(config): encode the Compose database password instead of pasting it into the URL 2026-11-21 17:25:20 +00:00
db_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
digest.go feat(digest): 探索图冷节点压缩(cold-digest) 2026-09-09 11:52:15 -04:00
evidence_rewrite_flag_test.go feat(llmrec): opt-in LLM context size telemetry and aggregation (P3.5 phase A) 2026-11-20 18:15:23 +01:00
evidence_secrets_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
exploration.go db: pick the newest activity across all evidence lines 2026-11-21 10:20:45 +00:00
exploration_sources.go chore: sync upstream v0.3.6 changes 2026-08-28 14:03:07 +08:00
exploration_sources_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
exploration_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
exploration_tokens_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
export_test.go fix(intercept): judge decisions were stored as unknown (prefix case mismatch) 2026-11-09 12:22:46 +01:00
finding_assets.go fix(company-switcher): address review on #425 2026-11-22 09:44:37 +00:00
finding_assets_test.go fix(company-switcher): address review on #425 2026-11-22 09:44:37 +00:00
finding_dedup_pool.go agent: advisory duplicate check on report_finding via a decision model 2026-11-23 16:59:40 +03:00
finding_quality_test.go test: clean up residual findings, retest conversations, parent assets, and test rows 2026-11-20 22:18:53 +01:00
finding_reasoning_test.go test: clean up residual findings, retest conversations, parent assets, and test rows 2026-11-20 22:18:53 +01:00
finding_retests.go fix(db): run lesson extraction inside the status and retest transaction (#269) 2026-11-21 16:22:27 +01:00
finding_retests_test.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
finding_retests_verification_test.go feat: a completed retest updates the verification state 2026-11-09 21:47:40 +01:00
finding_traffic.go security(agent): wire the capture check into prove_goal and fail closed without it 2026-11-21 08:10:52 +01:00
finding_traffic_archive.go secrets: encrypt the evidence snapshot heads at rest 2026-11-13 22:56:52 +01:00
finding_traffic_archive_test.go test: clean up residual findings, retest conversations, parent assets, and test rows 2026-11-20 22:18:53 +01:00
finding_verification.go feat: verified findings backend (S1) 2026-11-09 20:21:27 +01:00
findings.go fix(company-switcher): address review on #425 2026-11-22 09:44:37 +00:00
findings_test.go test: clean up residual findings, retest conversations, parent assets, and test rows 2026-11-20 22:18:53 +01:00
goal_reopen_test.go fix(db): mirror SetNodeState (blocked_reason, content_version) when reopening goals (#269) 2026-11-21 17:54:21 +01:00
intent_admission.go feat(tasks): add runtime controls and inherited context 2026-08-24 19:29:00 +08:00
intent_claim_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
intent_control_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
intent_delete_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
intercept.go feat: show and filter the decided_by actor in the approval records 2026-11-09 22:35:09 +01:00
intercept_argv_test.go Intercept: argv prefix rules (match_type=argv) 2026-11-13 10:14:39 +01:00
intercept_decided_by_test.go feat: show and filter the decided_by actor in the approval records 2026-11-09 22:35:09 +01:00
intercept_detail.go Intercept judge: closed-question mode, fail-closed to ask 2026-11-12 22:35:11 +01:00
intercept_detail_test.go feat: record which actor decided an intercept approval 2026-11-09 22:17:56 +01:00
intercept_execution.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
intercept_execution_test.go 精简动作审查输入并支持审批来源定位 (#125) 2026-09-15 23:51:37 +08:00
intercept_filter_test.go fix(intercept): judge decisions were stored as unknown (prefix case mismatch) 2026-11-09 12:22:46 +01:00
intercept_persistence_seed.go security(agent): confine the file tools and close the executor review 2026-11-20 05:35:54 +01:00
intercept_persistence_seed_test.go security(agent): confine the file tools and close the executor review 2026-11-20 05:35:54 +01:00
intercept_seed_test.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
intercept_source_test.go fix(intercept): judge decisions were stored as unknown (prefix case mismatch) 2026-11-09 12:22:46 +01:00
jsonb_clean_test.go fix(db): side_question checkpoint 入库前剥除 jsonb 不支持的 NUL 转义 2026-09-12 03:00:28 -04:00
lessons.go fix(db): run lesson extraction inside the status and retest transaction (#269) 2026-11-21 16:22:27 +01:00
lessons_test.go test(agent,db): document and lock risk_accepted goal-proof semantics (#269) 2026-11-21 16:29:53 +01:00
llm_context.go feat(llmrec): opt-in LLM context size telemetry and aggregation (P3.5 phase A) 2026-11-20 18:15:23 +01:00
llm_context_test.go feat(llmrec): opt-in LLM context size telemetry and aggregation (P3.5 phase A) 2026-11-20 18:15:23 +01:00
llm_records_migrate_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
llm_usage.go perf(db): add partial covering indexes for dashboard/usage queries (migration 0010) 2026-11-20 21:48:31 +01:00
llm_usage_cost_test.go test: clean up residual findings, retest conversations, parent assets, and test rows 2026-11-20 22:18:53 +01:00
llm_usage_ts_index_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
llmhealth.go feat(llm): add profile failover and pool health 2026-08-24 19:28:18 +08:00
llmretry.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
llmretry_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
logs.go
migrate.go db: refuse a pending migration older than the newest applied one 2026-11-14 13:10:57 +01:00
migrate_test.go test: reset later migrations in legacy fixture 2026-11-22 18:38:09 +08:00
nkey.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
notification.go fix(db): mirror SetNodeState (blocked_reason, content_version) when reopening goals (#269) 2026-11-21 17:54:21 +01:00
notification_delivery.go Encrypt stored secrets at rest in PostgreSQL 2026-11-13 14:42:56 +01:00
notification_test.go test: clean up residual findings, retest conversations, parent assets, and test rows 2026-11-20 22:18:53 +01:00
schema.sql feat: add bearer-authenticated Bedrock gateway profiles 2026-11-22 18:27:43 +08:00
secrets.go feat: add bearer-authenticated Bedrock gateway profiles 2026-11-22 18:27:43 +08:00
secrets_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
settings.go Bind sessions to a password version so revocation cannot tie inside one second. 2026-11-17 22:54:16 +01:00
settings_insert_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
side_questions.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
side_questions_test.go fix(btw): 修复长对话上下文预算与旁路输入布局 2026-09-11 00:41:01 +08:00
skill_gaps.go feat(server): capability-gap report from skill misses 2026-10-19 00:33:08 +02:00
skill_usage.go 归档 2026-08-28 12:56:29 +08:00
skill_usage_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
skill_visibility_test.go fix(db): record an explicit skill-visibility off instead of deleting the row 2026-11-16 23:48:40 +08:00
target_pins.go feat(intercept): target extraction, resolver, exemptions and the gate in the hook (S3b 1.5-1.7) 2026-11-11 00:34:55 +01:00
target_pins_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_archive_aggregate_stats.go 归档 2026-08-28 12:56:29 +08:00
task_archives.go fix(server): fail the archive job instead of crashing on a worker panic 2026-11-20 21:13:55 +01:00
task_archives_restore.go feat(findings): add report_state separate from triage 2026-11-18 00:07:50 +01:00
task_archives_restore_url_test.go db: normalise archived asset URLs on restore 2026-11-14 12:17:33 +01:00
task_archives_test.go Merge pull request #430 from BaaRai/chore/p36-hygiene 2026-11-20 23:20:51 +01:00
task_assets.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
task_assets_context.go docs(coverage): say "declared domain or IP root" for auto-scope roots (F8) 2026-11-12 09:38:52 +01:00
task_assets_test.go test: clean up residual findings, retest conversations, parent assets, and test rows 2026-11-20 22:18:53 +01:00
task_categories.go feat(tasks): 任务列表支持批量修改分类 2026-08-24 09:16:44 -04:00
task_categories_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_context.go fix(db): skip RSI lesson extract on multi-company tasks 2026-11-17 18:08:49 +00:00
task_context_lock_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_context_unit_test.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
task_credentials.go Encrypt stored secrets at rest in PostgreSQL 2026-11-13 14:42:56 +01:00
task_delete_concurrency_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_intercept.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00
task_list_performance_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_llm_spend_test.go test: clean remaining residual rows across db, agent, and server test suites 2026-11-20 22:54:57 +01:00
task_metadata_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_outcome.go feat(server): per-task outcome card for RSI baselines 2026-10-19 00:28:27 +02:00
task_queue_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_rotation_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_scope.go security(db): mark an agent scope addition as expanded when classification fails 2026-11-21 08:10:52 +01:00
task_scope_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
task_source_limit_test.go feat(tasks): add runtime controls and inherited context 2026-08-24 19:29:00 +08:00
task_templates.go feat: 任务模板支持预设分类与任务级拦截/允许规则 2026-09-19 09:27:03 -04:00
task_templates_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
tasks.go feat: expose concurrent multi-LLM worker rotation 2026-11-16 15:31:47 -06:00
tasks_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
testmain_test.go Encrypt stored secrets at rest in PostgreSQL 2026-11-13 14:42:56 +01:00
testpg.go fix(db): declare Skip on the test skipper interface 2026-11-19 14:38:23 -03:00
tool_usage.go 归档 2026-08-28 12:56:29 +08:00
tool_usage_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
tools.go secrets: encrypt the exec spec of custom tools at rest 2026-11-13 21:52:27 +01:00
tools_secrets_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
traffic_rewrite.go feat(db): store capture-proxy rewrite rules, sealed at rest 2026-11-17 00:12:09 +01:00
traffic_rewrite_test.go Refactor PostgreSQL test skipping logic 2026-11-19 14:23:29 -03:00
traffic_tamper_hooks.go feat(db): add traffic_tamper_hooks migration 0011, sealed CRUD, versions, and rollback 2026-11-21 00:48:27 +01:00
traffic_tamper_hooks_test.go test: stabilize the UDP control-close test and the sealed hook test 2026-11-21 01:00:52 +01:00
triggers.go Translate all Chinese text to English 2026-10-08 23:14:34 +02:00