CodeSentry Swarm

- Backend & AI Engineer
- November 2026
- In Progress
In numbers
- AI agents, each behind its own queue
- 3
- From a new pull request to a proposed fix, live
- 111s
- Model cost for 22 reviewed pull requests
- 0.13USD
- Spans in one trace, from webhook to verdict
- 15
About the Project
CodeSentry Swarm is a multi-agent pipeline that audits a pull request, tests its own hypothesis in an isolated sandbox, and comments a typed fix. The idea behind it: the probabilistic part lives behind a queue, and the decisions that matter are made by deterministic code.
When a pull request opens, a signed webhook reaches an API on Cloud Run, which stores the task in Firestore and answers right away. Triage, on Gemini, reads the diff and writes a hypothesis, a pytest test and the edits. A Cloud Run Job runs that test in a sandbox with no network: it must fail on the pull request, and the whole suite must pass with the fix. The Judge reads the exit codes and writes the verdict; it can reject a green run but never approve a red one. A failing run goes back to Triage with feedback, up to three times, and then asks a person. Every step is a Pub/Sub message with retries and a dead-letter queue, and every model call is a span in Cloud Trace with its tokens and cost.
I built it in November 2026 as the live demo for my talk From Endpoints to Agent Swarms, first given at Universidad Indoamérica. I wanted to show the backend patterns that make agents safe to run, not another chat window: queues, idempotent stages, sandboxes, budgets and tracing. It is Python and FastAPI, deployed with Terraform and MIT-licensed, and it also runs offline with hand-written scenarios for anyone who wants to try it without a cloud account.
How it works
The path a request takes, step by step.
- Pull requestSigned GitHub webhook
- APICloud Run answers 202 and stores the task in Firestore
- TriageGemini writes a hypothesis, a test and the fix
- SandboxCloud Run Job with no network and no roles
- JudgeGemini reads the exit codes and writes the verdict
- CommentThe fix and a typed report on the pull request
Decisions
The choices that shaped it, and what each one cost.
Put every agent behind a queue
- A slow or failing model call retries with backoff instead of holding the webhook open. After 5 attempts the message lands in a dead-letter queue instead of disappearing.
- Pub/Sub starts a new trace for each message and Eventarc arrives with no context, so the trace ID has to travel by hand.
Let exit codes decide, not the model
- The new test must fail before the fix and the whole suite must pass after it. The Judge can reject a green run, but it can never approve a red one.
- Green is evidence, not proof: a test that only covered its own case let a wrong rounding fix through. That is why a human merges.
Run untrusted code in a job with no identity
- The sandbox has no network and its service account has no roles. It reads the code and writes the result through signed URLs that expire in 15 minutes.
- The first run took 1 min 32 s to start, so a live demo needs a warm-up pull request first.
Derive the task ID from the commit
- The ID comes from the repository, the pull request number and the commit, so a redelivered webhook lands on the same task and each stage is claimed once.
- Every new push is a new task, so pushing again means another review and another comment.
