fix: 修复 file_path 始终为 null 的问题#217
Conversation
根因:
1. agent_tasks.py 中三元表达式缺少括号,运算符优先级导致 location 解析异常
2. LLM 返回的 findings 可能没有 file_path,直接保存导致数据库中大量 null
3. orchestrator 文件扩展名白名单过于严格,漏掉 .yaml/.json 等非传统代码文件
4. merge 逻辑未考虑 garbage path,可能将有效路径覆盖为无效值
修复内容:
- 三元表达式加括号修复优先级 bug
- _save_findings 和 analysis 中新增 file_path 必填校验,空值跳过并记录 warning
- 新增 verdict 字段保存到数据库(confirmed/likely/uncertain/false_positive)
- orchestrator 放宽文件扩展名校验,改用 endsWith('/') 排除目录
- merge 逻辑增强:garbage path 不参与 merge,避免覆盖有效路径
|
@Windelly is attempting to deploy a commit to the tsinghuaiiilove-2257's projects Team on Vercel. A member of the Team first needs to authorize it. |
Review Summary by Qodo(Agentic_describe updated until commit e56dcfd)Fix file_path null issue with validation and enhanced merge logic
WalkthroughsDescription• Fix file_path null issue by adding type-safe extraction and validation - Correct ternary operator precedence with parentheses - Skip findings without valid file_path with warning logs - Add fallback to location/file fields when file_path empty • Enhance finding deduplication and merge logic - Prevent garbage paths from overwriting valid file paths - Support cross-file matching only for garbage paths or prefix matches - Relax orchestrator file extension validation to support config files • Add verdict field to track finding confidence levels - New database column for confirmed/likely/uncertain/false_positive - Expose verdict in API response and use for verification status - Include verdict in statistics calculation • Improve findings filtering consistency across analysis pipeline - Filter invalid findings before statistics calculation - Use filtered findings for severity and verification counts - Add Alembic migration for verdict column Diagramflowchart LR
A["Raw Findings from LLM"] -->|Type-safe extraction| B["Extract file_path"]
B -->|Validate & filter| C["Skip invalid findings"]
C -->|Normalize| D["Normalized Findings"]
D -->|Dedup logic| E["Merge with existing"]
E -->|Prevent garbage overwrite| F["Valid Findings"]
F -->|Save to DB| G["AgentFinding with verdict"]
G -->|Expose in API| H["AgentFindingResponse"]
File Changes1. backend/alembic/versions/009_add_verdict_to_agent_findings.py
|
Code Review by Qodo
1.
|
| code_snippet=code_snippet[:10000] if code_snippet else None, | ||
| suggestion=suggestion[:5000] if suggestion else None, | ||
| is_verified=is_verified, | ||
| verdict=verdict, # 🔥 新增:保存 verdict 到数据库 | ||
| ai_confidence=confidence, # 🔥 FIX: Use ai_confidence, not confidence |
There was a problem hiding this comment.
1. Verdict migration missing 🐞 Bug ≡ Correctness
AgentFinding 新增了 verdict 字段且保存时会写入该列,但 Alembic 迁移里 agent_findings 表定义不包含 verdict,运行时插入会失败并触发回滚,导致任务可能“完成”但 findings 实际未入库。
Agent Prompt
### Issue description
`AgentFinding.verdict` 已写入 ORM 并在保存 findings 时赋值,但数据库迁移未添加该列,导致写库失败并回滚。
### Issue Context
- 现有 `agent_findings` 表由 Alembic revision `006_add_agent_tables` 创建,未包含 `verdict`。
- `_save_findings` 构建 `AgentFinding(..., verdict=verdict)` 会在 DB schema 未升级时触发插入失败。
### Fix Focus Areas
- backend/alembic/versions/006_add_agent_tables.py[146-232]
- backend/app/models/agent_task.py[355-363]
- backend/app/api/v1/endpoints/agent_tasks.py[1345-1396]
### Suggested fix
1. 新增一个 Alembic revision:
- `op.add_column('agent_findings', sa.Column('verdict', sa.String(length=30), nullable=True))`
- `op.create_index('ix_agent_findings_verdict', 'agent_findings', ['verdict'])`(如需要)
2. downgrade 中对称 `drop_index/drop_column`。
3.(可选)若写库失败不应“静默成功”,考虑在 `_save_findings` commit 失败时向上抛错或将 `saved_count` 置 0,避免任务统计误导。
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
1. Add Alembic migration for verdict column in agent_findings table 2. Analysis agent: fallback to location/file fields when file_path is empty 3. API response: expose verdict field in AgentFindingResponse
|
@CodiumAI-Agent review |
|
Closing and reopening to trigger Qodo re-review after addressing feedback. |
|
Persistent review updated to latest commit 5b9d3e0 |
…ype safety, verdict index
|
Round 2 fixes pushed. Reopening for Qodo re-review. |
|
Persistent review updated to latest commit f3d0b74 |
|
Round 3 fixes pushed. Reopening for Qodo. |
|
Persistent review updated to latest commit 9c77394 |
|
Fixed NameError. Reopening for Qodo. |
|
Persistent review updated to latest commit e56dcfd |
根因分析
本 PR 修复了 Agent 审计任务中 findings 的 字段始终为 null 的问题,该问题导致前端无法定位漏洞文件位置。
Bug 1:三元表达式运算符优先级错误
中从 字段提取文件路径时,三元表达式缺少括号:
Bug 2:无 file_path 的 findings 直接入库
LLM 有时返回不含 的 findings,这些无效数据直接写入数据库。
Bug 3:orchestrator 文件扩展名白名单过严
只允许 ,漏掉 等配置文件。
Bug 4:merge 逻辑未考虑 garbage path
当 new_file 为无效值(如
?)时,仍可能覆盖 existing 的有效路径。修复内容
验证