Back to the blog

· Eric Koslow

How VStream is built

How a feature goes from an idea to the live site

Intro

In my last article, Re:VStream, I mentioned that I used agentic (aka AI-driven) tools to aid me with the development of VStream. This generated a good amount of healthy concern over VStream's use of AI development. People are so used to buggy and insecure AI slop apps nowadays that folks rightfully worried that VStream could soon be added to that list. Some folks also politely asked to better understand how VStream could be developed by a single person, securely, while keeping up with all of the work required to maintain a live service.

So in this article I wanted to break down my process and tooling to give you a better understanding of how VStream is being developed this time around as well as the protections put in place to keep all user data secure, even with the use of AI.

Glossary of terms

For the non-technical folks that may be reading this article, here's a quick glossary of terms I'm going to use in the rest of the article.

WordPlain meaning
Pull request (PR)A proposed change to the code, with an online discussion page
Merging codePutting the change into the main copy of the code
AI agentAn AI that can take actions (read code, run commands, write files), not just chat
ModelThe AI itself (Claude, GPT); each company's models have their own blind spots
TestsSmall programs that check the code does what it should
Continuous integration (CI)Servers that run every check on every change before it can be merged

Avoiding slop

As any developer who has used agentic coding in the last year will tell you, while the AI models have gotten a lot better, they're still not perfect by any means. They still make bad architecture decisions, don't follow the style guides you lay out, over complicate things, and can even introduce security holes. What I used to do to avoid these downsides was to be highly involved with every single PR. That meant watching exactly what the AI agents were doing at all times and carefully reading every line of code produced.

The challenge with this approach is it's much easier for the AIs to write code than it is to review it. And every time I found an issue I would need to kick the code back to the AIs to redo it. This is exhausting as a programmer. It's like being a full-time manager of a very excitable junior developer. I remember needing to spend eight-hour days just going back and forth with the AIs and feeling like I wasn't getting anything done.

It turns out the solution to AI problems is often more AI. There are many AI review tools out there like CodeRabbit or Greptile that will have independent AIs review a pull request and point out issues with it. The idea is that you use independent AIs that weren't part of the building process at all. That way they haven't seen the code before and can more easily detect issues without being biased by how it was built. But to keep things lean, back in early October I decided to build my own AI review loop instead. Instead of me needing to go back and forth with the AIs, I would instead have my own review tool enforce coding styles, simplicity, security, etc. and let the builder AIs know when they messed up. Each problem a reviewer reports is called a "finding". The builder AI would then address the findings and submit new code for a second round of review (a "round" is one pass of review followed by the builder's fixes). This would repeat until there were no more issues discovered. Only at that point am I alerted that the PR is ready for final human review. This cuts back the amount of back and forth I need to do and ensures my time isn't wasted reviewing slop. This is the main way I'm now able to keep up with the sheer volume of PRs that are required to build something like VStream.

How a feature is made

  me                    the builder (an AI agent)             the reviewers (other AI agents)
  ──                    ─────────────────────────             ───────────────────────────────
  problem + rules  ──▶  researches, writes a plan
  read the plan    ◀──
  "build it"       ──▶  writes code and tests,
  answer questions ◀──  asks when a call is mine
                        opens a draft pull request  ──▶  planner splits it into lanes
                                                         each lane reviews one concern
                                                         verifier tries to disprove each finding
                        reads the comments          ◀──  what survives is posted
                        fixes or argues back        ──▶  next round checks every answer
                                  (repeat until nothing is open)
  read the guide   ◀───────────────────────────────────  review guide is written on the PR
  decide, merge

1. Laying out the problem and aligning on a solution

Every feature starts with a simple problem statement. What is the exact problem users are having that we need to solve? This can either be a bug that users are facing or a lack of capabilities we need to address. After laying out the problem I ask the AI to explore the code and propose how it would solve the problem. Here's an example prompt I used recently:

I want us to preserve scroll position when scrolling through the feed of posts. For example, I open up my feed and start to scroll through it. Maybe it needs to load a couple extra pages of posts as I'm scrolling. Eventually I come across a post I find interesting and click into it to view its replies. [...] If I press back again I should be at the same scroll position on my main feed as when I went into that original post. This requires us to remember not only the scroll positions but also to preserve the lazily loaded data as well.

How would you suggest we implement this?

After a bit of research the agent comes back with a proposal:

[...]

What I'd build

  1. Stop FlashList correcting while its screen is unfocused. PagedList passes { disabled: true } for maintainVisibleContentPosition when the screen is not focused. I have not tried this yet, so it is the first thing to prove.

  2. Fix the double push, so the row's press ignores a press that landed on a link inside it.

  3. Add a web-only scroll keeper at the stack, not per page. A wrapper in the product stack's screenLayout records each scroller's offset while its screen is focused and re-applies it when focus returns.

  4. Add a regression test that runs the round trip and asserts the same post sits at the same offset. [...]

Normally the produced plan makes sense and I'm able to approve and have it start building in the background. But sometimes a plan is produced that either lacks some context that only I have, or it proposes a technical solution that I know is sub-optimal for some reason. In those cases, I correct the agent and have it re-propose a plan using the new context and/or corrections. This continues until the plan makes sense and I approve it.

2. The build

From there, the AI agent follows the approved plan and writes the code. To ensure it writes code that follows VStream's standards and works, it uses a series of "skills" that I've written for the agent as well as automatic checks that must pass.

A "skill" is just a written document that tells the agent how to do a certain thing. This includes coding standards, how to best use certain libraries, how to write secure code, how to write good tests, etc. These documents were all written by me and periodically updated as the VStream environment changes.

The agent is also told how to run these "static checks" on its own work, using two main commands. Unlike AIs (which are basically random probability machines), these commands are deterministic. Meaning the same inputs create the same outputs. There is no way for the AI to lie and say it formatted the code correctly, when it didn't, because the static formatter checker will find that lie and point it out to the AI. These same checks also run on VStream's continuous integration servers to ensure they pass before any change written by an AI can be merged.

"check:static": "pnpm run format:check && pnpm run lint && pnpm run lint:rules && pnpm run typecheck
                 && pnpm run check:boundaries && pnpm run check:dead && pnpm run check:i18n
                 && pnpm run check:lexicons",
"check": "pnpm run check:static && pnpm run test",

Essentially: ensure the code is formatted correctly, the code follows VStream's and industry best standards, mathematically the code should work (typechecking), each part of the code only imports what it is allowed to, there is no unused (dead) code, check that every sentence is translated, and finally run a whole test suite against a real database. At the time of writing VStream has 966 test files and 9,369 tests that are run against every change.

Finally, the AI is told that when it's finished writing its own code and has statically verified it all works, it should open a pull request to be reviewed by the AI reviewers.

3. An AI review planner plans out the review

Not all code changes are the same and require the same type of review. Some changes are simple, purely cosmetic and only require a UI review comparing the old and new UIs. Other changes may not affect how things look, but instead change how we persist login credentials. Those changes are extremely dangerous and require a deep review on how they affect security.

Because of those differences, the first step of VStream's AI review pipeline is a review planner AI. These are its instructions:

You plan the AI review of one pull request. You do not review it yourself. Read enough of the diff
to decide who should look at what, then answer in the schema.
[…]
A lane is one reviewer with one focus over a set of files. Plan every lane the change needs and none
it does not: one reviewer reads carefully only so much, so keep each lane under about 1,500 changed
lines and split a larger area into several.

The planner splits the review into "lanes". Each lane is one AI reviewer with a single focus, like security or performance, looking at a set of files. The kinds of lane it can plan:

FocusLooks for
correctnesslogic errors, broken flows, unhandled states, races, wrong error mapping
datamigrations, constraints, indexes, transactions, locking vs optimistic concurrency
securityauthn/authz gaps, injection, secrets, CSRF/CORS, trusting client input, SSRF
performanceN+1 queries, unbounded reads, missing indexes, hot-path allocations, web bundle size
conventionsthis repository's rules in AGENTS.md and docs/conventions that no linter enforces
uiscreens that changed: drives the client on the web, and natively where it differs

Three more are always added on the first round: history (does this undo something an earlier change did on purpose), completeness (can a person finish what this starts) and simplicity (would much less code do).

Here is a real plan, from round 1 of pull request #4236 (a paid membership's join and cancel page). It planned 13 lanes: four checking correctness, one each for data, security, performance, conventions and UI, a second opinion on the money code, and the three that are always added. Many lanes cover the same files, just from different perspectives.

4. The review lanes each run

Once the code review is planned, each code reviewer runs in its own walled-off copy of the code. Each reviewer is given a unique (unless doubled up on purpose) prompt and area to focus on. Here's the security lane's whole prompt:

**Security.** Who can call each changed endpoint, and what stops them acting on someone else's data?
Auth is middleware here, not a handler call; a handler that trusts an id from the request rather
than the session is a finding. Look for injection, SSRF, open redirects, secrets in logs or
responses, CSRF/Origin gaps on mutations, rate limits missing on anything that sends mail or costs
money, and webhook handlers that do not verify their signature.

And every review lane's prompt is prepended with:

You are an adversarial code reviewer on one lane of a multi-reviewer review. Your job is to find
real defects before a human spends time on this pull request. Other lanes cover other concerns; stay
on yours.
[…]
Report a finding only when you can name a concrete input, state or sequence that produces wrong
behaviour, data loss, a security hole, a crash, a measurable performance problem, or a violation of
a written rule in this repository.
[…]
Ten real findings beat thirty guesses; zero findings is a valid answer.

5. A verifier verifies the findings

In tech there is the concept of "signal versus noise". "Signal" is data that is useful and you can take action based off of it. "Noise" is data that is low value and often distracting. The idea is to have as much signal as possible and as little noise as possible. Because VStream uses so many review lanes there can often be dozens of findings after a review. But not every finding is "high signal" and a lot of them may just be "noise". That's because AI often wants to do its job pathologically. The reviewer AI was told to find issues so it found issues. But now we need another AI whose job is to do the opposite, refute findings as much as possible. The verifier's prompt starts like this:

You validate a code review finding before it is posted on a pull request. Reviewers over-report;
your job is to **refute** it. Assume it is wrong until the code proves otherwise. Only findings you
confirm reach the author, [...]

The verifier is asked to score each finding based on the following rubric. Only findings that get a score of 80 or above will be posted as a real issue on the PR. The bar is set at 80 to keep the signal-to-noise ratio very high while making sure the most important issues still get fixed:

- 0: Not confident at all. This is a false positive that doesn't stand up to light scrutiny, or
  is a pre-existing issue.
- 25: Somewhat confident. This might be a real issue, but may also be a false positive. […]
- 50: Moderately confident. You were able to verify this is a real issue, but it might be a
  nitpick or not happen very often in practice. […]
- 75: Highly confident. You double checked the issue, and verified that it is very likely it is a
  real issue that will be hit in practice. […]
- 100: Absolutely certain. You double checked the issue, and confirmed that it is definitely a
  real issue, that will happen frequently in practice. The evidence directly confirms this.

It's also told what findings should get a 0 automatically:

- A problem that was there before this pull request, unless the pull request introduced it, made it
  reachable, or made it worse.
- Anything the formatter, linter, typechecker or compiler catches […]. CI runs them all.
- General quality, such as test coverage, documentation or an unspecific security worry, unless
  `AGENTS.md` or a file in `docs/conventions/` requires it for this case. Then quote the rule.
- A pedantic nitpick a senior engineer would not raise, or something that only looks like a bug
  until you read the code around it.

Here were the real findings for the first round of reviews for that same pull request #4236:

8 findings to address before human review.

35 raised by 13 lanes, 27 dropped by validation (incorrect, duplicate, or not worth a fix cycle).

Here were some of the dropped findings:

  • Add an index matching the purchases keyset, scored 8: "Per-account Encore periods are tiny, since there is one per month, and the account_id index already narrows the scan. A new index would add write cost for no measurable gain."

  • A failed first Encore read temporarily hides the card, scored 50: "The claim that retries run out and the card stays blank until reload is contradicted by the recurring five-second retry. […]"

  • No test proves the signed-out round trip back to /encore?join=1, scored 0: "General test coverage findings are excluded unless a written rule specifically requires coverage for this case. […]"

6. Verified findings are posted on the pull request

Here are some real example findings from previous pull requests:

A link that follows a channel for you (pull request #4322, security, found by both models across five lanes). In plain English: anyone could have posted a link that made every signed-in person who clicked it publicly follow a channel.

🟠 Major · Any ?follow=<handle> link makes a signed-in reader follow that channel without pressing Follow

The arrival effect follows when two things hold: the route's follow parameter equals the button's handle, and the viewer is signed in. Nothing checks that this reader pressed Follow while signed out, so the URL alone authorises the write. Anyone can write that URL.

Opening /c/@mochi_vt?follow=mochi_vt while already signed in calls relationships.followChannel on mount and shows "You're following Mochi". That follow is a public action: it lands in the account's AT repository and notifies the target. […]

Fix: tie the intent to the press. […]

A password reset that left a way back in (pull request #4762, security). In plain English: someone who knew your old password could hold on to an unused sign-in code and trade it for a fresh login after you reset.

🟠 Major · An OAuth code authorized before the new password can still be exchanged for a token after it

[…] Nothing ties the code to the password, so exchanging it after this route returns writes a brand-new token row with full access. This breaks the guarantee in the route's comment and the PR body: "A new password ends every other way into the account."

A creator told to withdraw their money, then refused (pull request #4697, completeness, blocker, found by both models in three lanes). In plain English: a creator deleting their account is told to withdraw their earnings within 30 days, and the same change had locked the Withdraw button.

🔴 Blocker · The new write gate refuses every payout action, so a creator whose deletion is pending can't withdraw

[…] Failure: a creator with a cleared balance asks for deletion and opens Payouts, which the redirect allows. They see their balance and preview, then press Withdraw. payouts.requestPayout answers account_restricted: This account is being deleted; keep it to make changes. […] After 30 days the purge runs and the balance can no longer be paid out. The person can reach this journey but can't finish it, and AGENTS.md forbids shipping that ("Ship whole or ship dark").

7. The original builder AI addresses the comments

The original builder AI is alerted that new issues have been posted on its PR. It wakes up and is told to address the issues. That said, the builder is not required to obey the new findings:

For each finding, decide whether it is right. You are not obliged to comply: a reviewer can be
wrong.

- **Fix it** when it is right. Make the smallest change that removes the defect, and add or adjust
  the one test that proves it [...]. When the finding carries a **reproduction test**, start from
  it: it failed against this head for the reason given.
- **Rebut it** when it is wrong or not worth changing: do not change code, and write the reply that
  explains why, with the evidence (the caller, constraint or test that makes it impossible).
- **File it** when it is right and what it asks for is open work outside this pull request [...].
  Do not file a defect this pull request introduces; fix that.
- **Hand it to a person** when it is right but only a person can do it [...].

Here's the real fix from pull request #4322:

🔧 Fixed in feat(client): Follow the channel a reader asked to before signing in. The signed-out press is now recorded on the device: session storage on the web, memory on a device (follow-intent.ts). On arrival the button spends it with takeFollowIntent(handle). The follow parameter is only a hint and is removed on arrival, so a crafted link, a reload or another tab never follows on its own.

And here's an example of a builder arguing back against a found issue. The reviewer wanted a notification held back from fans who had muted the channel on Bluesky:

💬 Not changed. The bell at All is the reader's own VStream choice for this channel, and the push carries only the channel's name, never the post, the same as a go-live or new-upload push, which do not consult Bluesky mutes either. A per-follower AppView read before each push would turn a fan-out page of 200 into 200 AppView calls as each follower. […]

The reviewer, next round:

↩️ withdrawn · I agree. The All bell is the reader's own VStream choice, and the push and mail name only the channel, never the post. Go-live and upload notices don't consult Bluesky mutes either, and an AppView read per follower would cost 200 calls per page. […]

Rebuttals are rare: of the 1,541 findings posted so far, only 17 were withdrawn after a builder pushed back.

8. Repeat until nothing is open

After the original builder addresses all of the posted issues, another round from the AI review process is kicked off. The next round checks each response against the new code.

- `fixed`: the code at the new head no longer has the defect. Read the current code; do not trust
  the reply alone.
- `withdrawn`: the author replied with an argument that the finding is wrong or not worth fixing,
  and the argument is correct [...]. A defect this pull request introduces is never settled by
  filing it.
- `disputed`: the author argued against it and you are not convinced, or replied that only a person
  can act on it [...]. A human will decide [...].
- `open`: nothing addressed it, or the attempted fix does not work.

Oftentimes it takes multiple back and forths before there are no more findings left. For example, this is a finding from round 1. In plain English: if you had already reported something as nudity and then reported it again as child abuse, the second report did nothing, and you were told it worked.

🟠 Major · Escalate existing reports when resubmitted as child safety

If a member first reports a target as nudity and later reports it as child_safety, the unique reporter/target constraint makes the insert do nothing. The early return at line 339 preserves the original policy and bypasses urgent mail, while the dialog still reports success. The report therefore receives neither the new queue priority nor the immediate staff alert; a dismissed report also remains dismissed. […]

Round 2 then found that the fix for that had its own problem. In plain English: if your first report had already been passed on to Bluesky, Bluesky was never told it was now a child-safety report, but you were still told it was sent.

🟠 Major · Raising a forwarded Bluesky report to child_safety never sends the CSAM reason to Bluesky, yet the reporter is told "sent"

[…] Failure: a member reports a Bluesky post as nudity with alsoToBluesky: true, and forwardOnce sends it and sets forwarded_at. The member then reports the same post as child_safety with alsoToBluesky: true.

  1. The insert conflicts and raiseToChildSafety sets the policy to child_safety. Staff get the urgent mail.

  2. claimForwarding finds forwarded_at set and returns nothing. forwardOnce then answers "sent".

  3. Bluesky never receives reasonChildSafetyCSAM, and the reporter is told it was sent.

Of the 408 reviewed pull requests, 76 finished in one round, 160 in two, 90 in three, 39 in four and 28 took five or more. If something takes more than 4 rounds, the PR is automatically paused and flagged for me. That way the AI can't get into some sort of doom loop. I decide what happens next, which sometimes means sending it back for more rounds (the record is 11).

Here's how the loop has done so far:

StatCount
Pull requests merged since the review loop started440
Findings posted on a pull request1,541
Posted findings by severity64 blocker, 465 major, 1,012 minor
Posted findings filed under security44
Rounds a pull request takesmedian 2, most ever 11

9. A review guide is written for me

Now that (hopefully) the PR is in a very good place, it's time for me to review it by hand. That said, it may be hours or days since I approved the original plan. To save me time reviewing, I ask the AI to write one last deliverable on the PR, a review guide. This is a part of that prompt:

You write the review guide for a pull request that has passed AI review and is about to go to a human. When they finish your guide they should understand its core logic, data flows and tradeoffs well enough that they are well set up to review the code efficiently and effectively.

What it must record for each decision:

- `decisions`: what the pull request chose (`decision`), the alternatives it rejected
  (`alternatives`), why it chose this over each of them (`reason`), and what the choice costs
  (`cost`), including any the reader must own (a product call, a behaviour change people will
  notice). [...] When the pull request records no reason, say so in `reason` and give the strongest
  one the code suggests, marked as inferred.

A real guide, for the sign-up fix (pull request #4766). Its opening paragraph:

Before this change, a stranger could stop someone signing up with their own email address. Ten wrong sign-up codes typed in an hour, from any registration, made the server refuse every code for that address, the owner's correct one included (#3853). Now a wrong code counts only against the registration it was typed into. Guessing is still capped per address, because an address is mailed at most three codes an hour (five tries each). […] The one thing to judge: a stranger can still use up an address's three mailed codes, and keep doing so after a staff clear. The PR accepts this on purpose: the worst a stranger can now do is make the owner wait an hour or contact support, never get a correct code refused.

And here's a part from its list of decisions:

  • Keep a per-address cap on codes mailed (3/hour, any visitor), even though a stranger can use it up.

    • Rejected: No per-address cap, relying on per-IP limits only.

    • Why: Without a per-address cap, VStream would mail any inbox as often as an attacker with enough IPs likes. With it, the worst a stranger can do to the owner is a wait or a support ticket, never a correct code refused.

    • Cost: A stranger can still keep an owner from getting a code by asking for 3 an hour. […] Owners also lose two resends per hour (5 → 3). Product needs to accept both.

The guide also contains visual diagrams like this one to make the change easier to follow:

How staff look up and clear the codes sent to an address
staff.signUpAddress(email) requireStaffActor (fresh 2FA) signUpAddress addressSendTimes (last hour, oldest first) codesSent, limit, refusedUntil staff.clearSignUpAddress(email, reason) requireWritableStaffActor, accountMutationLimit, auditReason clearSignUpAddress DELETE email_code_sends for email + audit.record in one transaction state after clear (0 of 3) Staff (console) StaffConsole op AccountsModeration PostgreSQL

10. I review, decide and merge

After I read the review guide, I'm able to open up the code and look through it by hand. Because of the guide I already know how the code works from a high level and I know where to focus and where things can go wrong. To be quite honest, at this stage I mostly find nitpicks due to the scrutiny of the previous rounds of review. These are things I probably would have implemented a bit differently myself, but the solution is good enough. When that happens rather than update the PR itself, I update skills and AI review prompts so future implementations will do it the way that I would have done it. In this way the pipeline gets better and stronger over time.

Finally, after familiarizing myself with the code and double-checking it's all good, I click the merge button and the feature or fix is completed.

Keeping your data private

The agents never see real user data. They work on their own copy of the code, against a local database filled with made-up test accounts, and every paid service (payments, video, email) is swapped for a fake one. They can't deploy, can't reach production, and can't merge. Every change still goes through me before it reaches you.

AI Software Factory

What I just described is what is now known as an "AI Software Factory". Basically it's an automated process where a "signal" goes in like an approved plan, a product spec, a production error, or a user reported bug and a process is kicked off to scope, build, and verify often without the need for the human in the loop until the very end.

For those that asked, this is how I'm able to build out a product as complicated as VStream as a single developer. This flow has enabled me to do things like:

  • Kick off 5 plans right before going to bed and waking up to 5 ready to go PRs in the morning

  • When I'm taking the train home and have a quick feature idea, I can kick off a workflow and often have a PR waiting for me by the time I'm home

  • Get a bug report from a user and feed it directly into the factory and know a well-scoped and proper fix will be produced in an hour in the background while I do research on a completely different part of the app

There is a lot of concern that because VStream was built using AI, then it must be a security-riddled mess. But I've personally found that with this kind of system, a ton of attack vectors I would have never thought of are caught and fixed before any bad code is ever released. I think the current version of VStream is much more secure than the version people were using 2 years ago.

Hopefully this was useful or informative for those that were seeking this information. Again, I want to stress that if the fact VStream uses these AI techniques and systems at all makes you uncomfortable, you're totally in the right to not use VStream. But for others, I hope this article gave you more confidence in VStream rather than less.