feat(findings): grouped duplicate suggestions, ranked candidates, relaxed merged acceptance (Codex rewrite)

Authored entirely by Codex CLI (codex exec, reasoning effort high), one session
resumed across capacity fallbacks:
- gpt-6.1-sol (schema + initial db work, stopped at capacity)
- gpt-6-astra (db/server/agent/frontend, stopped at capacity)
- gpt-6-sol (remaining items, tests, fixes; stopped at capacity after final checks)

Schemes 1+2+3: prompt/acceptance (2..20, evidenced differences justify
independent, merged no longer blocked by unified report), group suggestions with
member table, superset reuse/subset superseded, veto-aware reject/exclusion,
anchor re-anchoring trigger, sweep after merge/reject/remove, frontend group card
with stale-response guard, candidate scoring with tier/hit_reasons/strong_total.
This commit is contained in:
RuoJi6 committed 2026-10-24 21:55:45 +08:00
1 parent b0d6ad5d76
commit 09e90b4170
12 files changed
+740 -115

No files matched your search

+48
View File
@@ -1488,6 +1488,54 @@ CREATE TABLE IF NOT EXISTS finding_case_suggestions (
UNIQUE(left_id,right_id),
CHECK(left_id < right_id)
);
-- A suggestion is a group. left_id/right_id remain compatibility anchors for
-- old clients and are kept at the two smallest surviving member ids.
ALTER TABLE finding_case_suggestions DROP CONSTRAINT IF EXISTS finding_case_suggestions_left_id_right_id_key;
CREATE TABLE IF NOT EXISTS finding_case_suggestion_members (
suggestion_id BIGINT NOT NULL REFERENCES finding_case_suggestions(id) ON DELETE CASCADE,
finding_id BIGINT NOT NULL REFERENCES findings(id) ON DELETE CASCADE,
PRIMARY KEY (suggestion_id, finding_id)
);
CREATE INDEX IF NOT EXISTS idx_finding_case_suggestion_members_finding
ON finding_case_suggestion_members(finding_id);
INSERT INTO finding_case_suggestion_members(suggestion_id, finding_id)
SELECT id, left_id FROM finding_case_suggestions ON CONFLICT DO NOTHING;
INSERT INTO finding_case_suggestion_members(suggestion_id, finding_id)
SELECT id, right_id FROM finding_case_suggestions ON CONFLICT DO NOTHING;
-- Anchors have cascading foreign keys. Re-anchor a group before an anchor
-- finding is deleted so a 3+ member suggestion survives the cascade.
CREATE OR REPLACE FUNCTION finding_case_suggestion_reanchor() RETURNS trigger
LANGUAGE plpgsql AS $$
DECLARE
sid BIGINT;
new_left BIGINT;
new_right BIGINT;
BEGIN
FOR sid IN
SELECT id FROM finding_case_suggestions
WHERE left_id = OLD.id OR right_id = OLD.id
LOOP
SELECT min(m.finding_id) INTO new_left
FROM finding_case_suggestion_members m
JOIN findings f ON f.id = m.finding_id
WHERE m.suggestion_id = sid AND m.finding_id <> OLD.id;
SELECT min(m.finding_id) INTO new_right
FROM finding_case_suggestion_members m
JOIN findings f ON f.id = m.finding_id
WHERE m.suggestion_id = sid AND m.finding_id <> OLD.id
AND m.finding_id > new_left;
IF new_left IS NOT NULL AND new_right IS NOT NULL THEN
UPDATE finding_case_suggestions
SET left_id = new_left, right_id = new_right
WHERE id = sid;
END IF;
END LOOP;
RETURN OLD;
END $$;
DROP TRIGGER IF EXISTS finding_case_suggestion_reanchor ON findings;
CREATE TRIGGER finding_case_suggestion_reanchor
BEFORE DELETE ON findings FOR EACH ROW
EXECUTE FUNCTION finding_case_suggestion_reanchor();
-- Rejected/detached pairs are a durable human veto, also checked on group unions.
CREATE TABLE IF NOT EXISTS finding_case_blocks (
left_id BIGINT NOT NULL REFERENCES findings(id) ON DELETE CASCADE,