kunibert
All repositories: gitoria
5.0 KB
# Konrad: design and lessons (for the gitoria reviewer)Konrad: ASI's PR reviewer on GitHub since 2026-10-21. About 1300 lines of Bun/TypeScript, one service. The model is codex (gpt-6.1-sol, reasoning effort max) in a read-only sandbox, run as a separate unix user.## Flow per wake-up1. Event → job queue (sqlite). One job per PR at a time; a newer event updates the queued job, never doubles it.2. Always review the PR's *current* head, never the sha from the (possibly late) event.3. Skip when nothing is new (same head, no new replies, not forced).4. Set the status to pending → git fetch the PR head and base into a bare cache (forced refspecs: force-pushes happen) → check out the head.5. Diff **locally**: merge-base(base, head)..head. Never use the forge's diff API (GitHub caps it at 300 files).6. Spec: tickets named in the PR title + issues referenced, **with comments oldest-first; later comments overrule the description**. Missing or partial comments: mark the spec INCOMPLETE, so no "missing requirement" findings.7. Run the model. Output is JSON against a schema: summary, axes, verdict, findings[{axis, path, line, severity, title, body}], replies[{thread, body, resolve}].8. Findings on lines that are in the diff → inline comments. All others go into the review body under "Not on changed lines".9. Post the review, set the status (failure on request_changes), persist the session.## Three separate axes (never let one mask another)- **correctness**: bugs, security, data loss, edge cases, wrong tests.- **spec**: missing or partial requirements, scope creep, wrongly implemented requirements. Every spec finding quotes the spec line.- **standards**: the repo's documented rules (AGENTS.md/CLAUDE.md incl. @includes, CONTRIBUTING, …), cited by file + words. Skip what linters already enforce. Code smells are allowed only as nits titled "possible <smell>".## Memory (the most valuable part)- One model session per PR, *resumed* on every wake-up. The prompt holds only the delta:- new commits (diff last..head, **limited to the PR's files**, so merges from base drop out; the full PR diff sits next to it as the scope);- new human replies and resolve flips on the bot's own threads;- refreshed spec;- `@bot <text>` notes from the conversation.- Rules: a resolved thread, or one with an accepted reason, is settled and never raised again. If the bot disagrees, it replies in the thread instead of opening a new finding. Fixed → reply + resolve. `findings` = only new points. The verdict covers the whole PR as it stands.- Settled keys are persisted: the forge may refuse to resolve, and they must survive anyway.- Generation counter: a reset during a running review makes that run's writes no-ops.- Seen-watermarks per thread: highest comment id, not counts (deleted comments break counts).- A lost session falls back to a fresh one with a one-line ledger of earlier threads.- `@bot reset` = fresh, unbiased session, which also drops pending notes.## TriggersPush / PR opened / ready-for-review; the re-request icon (forced); a human reply in a bot thread; `@bot reset`; `@bot <text>`.## Lessons (each one cost a bug)- Never post "could not review" comments on PRs. Alert the operator instead (Konrad → hub alert). Surface the model's own error events: stderr only shows progress.- Force-pushes: forced fetch refspecs. Shallow caches: deepen before declaring history rewritten.- Merging base into the branch is not scope creep: filter the delta to the PR's paths (name-status -z, both rename sides).- Review headers must count still-open threads ("0 new, 1 still open"). Otherwise "0 findings" next to request_changes looks broken.- Findings outside the diff need a way to be answered (`@bot <text>`), or they block forever.- Long prompts go to a file the model reads (the argv limit is about 128 KB).- A second, independent comparison (vs CodeRabbit, 91 PRs, 2026-11-01):- Konrad: 74% valid, 2 min median. CodeRabbit: 59% valid, 8 min. Overlap only 10–18%.- Gaps: Konrad must **run the repo gates** (lint, typecheck, unused-code check, tests: 131 reviews said "deps missing"). It also misses cross-repo deploy order and contracts, caching/backfill/timeouts (a checklist helps), and its spec axis is too eager ("move to a separate PR" = most false alarms).- Ready-to-commit code suggestions are missing.## What I'd do differently from day oneRun the gates in a prepared workspace (deps installed). Diff locally from the start. Add a category checklist to the prompt. Keep a per-repo "accepted decisions" memory. Use an operator alert channel instead of PR comments for failures.## Lanes (planned for Konrad, not yet used by it)On ASI's review box there are 10 lanes: one full workspace per lane with every repo checked out and dependencies installable, each with a read-only app credential. Idea, not built: the reviewer leases a lane per PR, installs deps, and runs the repo gates (lint, typecheck, knip/unused, unit tests) against throwaway DBs. Gate results go into the prompt as facts, so the model does not guess. This is the top gap the CodeRabbit comparison found.