Skip to content

feat: add durable skills-based code review agent - #270

Open
Ray997543 wants to merge 1 commit into
trpc-group:mainfrom
Ray997543:codex/durable-code-review-agent
Open

feat: add durable skills-based code review agent#270
Ray997543 wants to merge 1 commit into
trpc-group:mainfrom
Ray997543:codex/durable-code-review-agent

Conversation

@Ray997543

Copy link
Copy Markdown

No description provided.

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Ray997543
Ray997543 force-pushed the codex/durable-code-review-agent branch from 2bd2546 to 7fabe37 Compare July 30, 2026 17:08
@Ray997543
Ray997543 force-pushed the codex/durable-code-review-agent branch from 7fabe37 to 0bdfab8 Compare July 30, 2026 17:40
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@86b5f7d). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             main        #270   +/-   ##
==========================================
  Coverage        ?   87.85545%           
==========================================
  Files           ?         482           
  Lines           ?       45189           
  Branches        ?           0           
==========================================
  Hits            ?       39701           
  Misses          ?        5488           
  Partials        ?           0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@helloopenworld

Copy link
Copy Markdown
Contributor

AI Code Review

我已经完成了对 diff 的逐行审查,并核实了关键问题。以下是我的审查结论。

发现的问题

🚨 Critical

未发现 Critical 级别问题。安全关键路径(HMAC 验签使用 hmac.compare_digest、Git/Docker 全部使用参数数组无 shell=True、token 仅通过环境变量传递且校验 \n/\r 防头注入、clone URL 校验 HTTPS+主机白名单+拒绝内嵌凭证、workspace 清理有路径校验)实现正确。

⚠️ Warning

  • examples/code_review_agent/github_integration/app.py:42-46:Webhook 体大小限制可被绕过

    • body = await request.body() 再检查 len(body) > max_payload_bytes。当请求使用 chunked transfer 且不带 Content-Length 时,首个基于 header 的检查被跳过,Starlette 会把整个请求体缓冲进内存后才触发第二个检查,攻击者可借此发送超大 payload 造成 OOM。建议在读取前用 request.stream() 配合 max_payload_bytes 边读边截断,或显式拒绝缺失 Content-Length 的请求。
  • examples/code_review_agent/code_review/database.py:334:SQLite 引擎未配置 busy timeout,并发写入会抛 database is locked

    • create_engine(database_url, future=True) 未设置 connect_args={"timeout": ...}。Worker 运行时 service.process_heartbeat 通过 asyncio.to_thread 共用同一 ReviewStore 并发写库(心跳每 lease/3 秒、处理过程中多次 update_github_delivery),默认 SQLite 部署下极易触发 database is locked。建议为 SQLite URL 注入 connect_args={"timeout": 30} 并视情况启用 WAL。
  • examples/code_review_agent/code_review/database.py:594-612complete_github_job 未校验租约未过期,成功处理可能被误判为“租约丢失”而重试

    • renew_github_job_lease(带 lease_expires_at > now)不同,complete_github_job 只校验 status=="leased"lease_owner。若处理期间租约到期被 _recover_expired_jobs 回收(置为 queued、清空 lease_owner),当前 worker 的 complete 会得到 rowcount==0,触发 RuntimeError("lease was lost"),使一次实际已成功完成并持久化的评审进入失败/重试路径,可能把成功 Check Run 标记为 failure 并重复发布评论。建议在 complete 条件中加入 lease_expires_at > now,或在完成前以“已成功”语义幂等收尾。
  • tests/code_review/test_github_integration.py:缺少“处理完成时租约恰好过期并被回收”的并发测试

    • 现有 test_durable_job_lease_recovery_and_replay 只验证过期租约被重新 claim,未覆盖上一条 Warning 描述的“完成与回收竞态”路径,高风险的并发状态流转无回归保护。建议补一条用例:人为把 lease_expires_at 提前到处理结束前,断言 complete_github_job 行为与 delivery 最终状态符合预期。

💡 Suggestion

  • examples/code_review_agent/code_review/context_builder.py:98-99:上下文裁剪直接改写持久化对象
    • build_review_context 直接对 review_run.changed_files 中的 ChangedFilechanged_file.patch = patch(截断)和 is_truncated = True 赋值,导致入库与 review.json 中保存的是截断后 patch 而非原始 diff,审计/回放时丢失原始变更。当前行号映射走 hunks 不受影响,故不阻塞;建议对副本裁剪、保留原始 patch 入库以保留完整审计证据。

总结

整体安全与并发设计扎实(验签、命令注入防护、沙箱加固、租约/幂等队列均到位),不存在必须修复的 Critical 问题。四处 Warning 集中在 Webhook 防 DoS、SQLite 并发稳定性、租约完成竞态及对应测试缺口,建议在接入真实 GitHub 流量前修复。

测试建议

  • 补充“处理完成时租约已过期并被另一 worker 回收”的并发用例,覆盖 complete_github_job 竞态与 delivery 最终状态。
  • 补充一条对 SQLite 默认部署下并发写库(心跳 + 处理同时进行)的稳定性测试,验证 database is locked 不会中断评审。

@Ray997543

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Rook1ex added a commit to trpc-group/cla-database that referenced this pull request Jul 30, 2026
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.

2 participants