Rails World 2026: Agent-Proof Your Rails App: Your Codebase Is the Prompt (Kinsey Durham Grace) Video: https://www.youtube.com/watch?v=QMkZ2J24XGI Talk page: https://www.rubyevents.org/talks/agent-proof-your-rails-app-your-codebase-is-the-prompt Unedited machine transcript, generated with Whisper. It contains recognition errors (names, technical terms). Check the video before quoting. ---- - Awesome, hi everyone. Thank you so much for coming. I'm Kinsey. I used to work at GitHub on their co-pilot coding agent platform team, but now I am starting my own thing. I'm super excited about it, and I've been diving into AI research because of this, so bear with me today. some papers and things like that. And at the end, I will have a QR codes that you can scan if you're interested and want to read more about it. But yes, as I mentioned, I was at GitHub before watching agents try to work in people's code bases all the time. And it was definitely the most humbling job I've ever had because when the agent fails, it's usually not failing because of actual programming. It's failing because of other things. It can write Ruby, good Ruby. This is not an agent capability thing. struggle with is beyond that. So today we're gonna talk about what it actually takes to trust our coding agents regardless of which one you're using. Then we'll dive into tangible changes that we can make in our code and our architecture to get these agents to perform better. And then all of my claims as I mentioned today are rooted in research that I will link at the end. So let's talk about how we can build more trust when we are writing code with a coding agent. Maybe we can even get to a point where we're not even having to review the code that it's writing. So I want to start by asking, raise your hand if you actually trust what your coding agent writes today. I see a couple hands. And then how many of you can merge code that it writes without reviewing it? Oh, that's impressive. A couple. That's awesome. So the 2026 State of Code Developer Survey found that 84% of developers are using AI to write code, but only 29% trust it, and that seems similar to the number of raised in the room today. This is down 11% year over year, so we are really far from actually trusting our agents. We're all aware that review is a new bottleneck. I've had a ton of conversations with people just talking about how much of a slog that is. Just our review cues are insane. All your time is spent reviewing code that Claude writes. And a study this year looked at over 33,000 agent authored PRs across 2,800 repos. at the same time as other agents. And between two agents working concurrently, the conflict rate is over 41%, and this is from actual source code, not just dependencies, and that's textual conflicts only. It doesn't count the PRs that merge cleanly and implement the same helper twice and you don't even realize it. Generation is really, really cheap, and verification is not. And you're not going to fix this problem by reviewing harder. We'll be more careful in review is the plan I hear the most, a scalable plan. So there's three ways that the agent can break your trust, right? It guesses it's certain, but it's wrong, and it says it found it. I was actually reading, digging into the tool calls of a coding agent, and I realized that it wasn't even opening the file of the code that it pretended to know everything about, literally. It didn't even open the file, and then that was mind-blowing to me. So what steps can you actually take to make your coding more trustworthy and this is something I was not doing at first or I was doing it, I was doing it manually. I was not setting up my agents so that they could verify locally after they wrote code to make a change. I would work in a loop and then test locally myself and realize that the code it wrote didn't even work locally even though CI was green, my test passed, etc. So I stopped asking myself does this diff look right and I started asking what did the agent prove before it could tell me it was done, just like you might with a junior developer that you're mentoring or working with QA. A bug fix means that fails before and passes after, not one written after to match whatever the fix did. So that's the most common way an agent produces a green suite. Also, UI changes, make sure that it can actually go and run it locally and verify that. A performance change, two traces to make sure that it worked, got faster, and the build pass is just not enough of a verification at this point. We need more than that. I was spending so much time verifying locally myself the code that the agent had written, but we need to enable our agents to verify themselves. And honestly, Rails is great for this. Most teams adopting agents build a verification harness from nothing, but bin Rails tests is built in and already runs for us. System tests mean that agent can drive real flow instead of describing what it think would happen. So fixtures and factories mean a migration get verified against something real world-like. I do recommend adding one verification skill per risky or important feature. So do your tests prove behavior or do they prove the code didn't raise? The agent will try and satisfy the second one over and over and not the first unless you explicitly tell it to because agents are lazy and want to do something as quick as possible. Test locally sounds obvious until you watch an agent try and do it. Setupbench is a benchmark that measures whether an agent can get a repo running from scratch. It basically just dropped agents into bare Linux sandboxes and asked them to stand up a dev environment. And the best model only managed to do that 62% of the time. And the failure modes are really interesting because they're all fixable by someone like us. So if you can run, it can run your code and still cannot run your tests, which means it cannot produce evidence, right? It invents constraints, it changes ports, writes config values, it totally makes them up. 45% of the runs, changes didn't survive the shell. It installed with dash dash user, set in a variable, of course, and then it's gone in the next section. So this was interesting to me. So here's an example of how you can build a verification skill. It's just a file, just a markdown file with four sections, boot, drive, evidence, three specific observable things, not does this look good? You know, does publication live, true, does the post render at its public URL, and the search index has a row in it. Also, clean up. The evidence list is a contract. The agent cannot say done without producing those three. That's the whole mechanism. And it lives in a repo, so these can be reviewed just like code. It's important to bucket things like this because often I do see teams kind of go overboard with verification and try to verify everything equally, but this can get really slow and expensive. does cost tokens and time. So you really need to spend it with the budget in mind. Pstack is a plugin that you can use to help with verification as well. I link it at the end. It's a great plugin. And I'll also talk a little bit more about this in a bit, something that you can use to get the ball rolling on this. One last thought here that has really helped me with coding agents is we treat coding agents like an examiner treats a student. At least I was doing this. I don't know about you all. But we look at the final answer and we grade it. it, right? A mentor watches the work. On the left, you have examining. You read the diff at the end. You correct the output in a review comment once. The lesson ends with that pull request. The next session, it makes the same exact mistake because it doesn't remember. On the right, you have mentoring, though. You watch the tool call while it works, not the diff afterwards. That is the actual job now, and it's the part people skip because it isn't in the pull request. method, not the output, and then you write the correction down. And it lands somewhere that isn't a person, either a skill, a lint rule, a feature map, a CI check, because a real mentee would remember, but an agent doesn't. The lesson doesn't land in your repo. You did not teach it anything. You just had a nice conversation with something that will never retain what it learned. Big waste of your time. So how does trust actually get built? First, you're going to want to watch it work. every token, every tool call, you're not reviewing, you're supervising. And your throughput is going to be worse than if you were just doing it yourself. But actually dig into those, because like I mentioned, when it was telling me about this code, it wasn't even opening the file. Stage two, you read every line of the dip. I think a lot of people are doing this now, and this is really hard to scale past one agent. Then you stop reading style and structure, because CI starts to enforce these, and you really start to look at intent. Stage four is where the big jump comes in. You read the evidence first from all of the verification setup. What did it prove? And then you can just spot check the code. Stage five, it merges on green and you review what landed in the morning. Nobody decides to trust an agent. You climb and build trust incrementally, step by step. And every step must be achieved with evidence. So it's important to note that traditional tests are prompting the agent to write tests does not buy you a lot. And I was definitely doing this. There's a paper on self-debugging with self-generated tests, and when the model writes the test after writing the code, the test just inherited the same misunderstanding. It is not checking the work. It's just agreeing with itself twice. Their finding was post-execution self-debugging struggles on basic problems precisely because of that bias. What works better is in execution. The agent observes intermediate steps while the thing runs, which is really the difference between my test pass and did I watch it happen? So test first or test from a trace. Never test afterward from memory. This is a really good checklist to go through to ensure that you can keep moving up the curve to a point where you can trust them to auto-merge your PRs. You can also turn this into a dashboard, but you want to look at clean merge rates, the seven-day revert rate. Did you, you know, put it in production and have to revert it seven days later? Evidence catch rate, how often the required failed before any human looked at it and review latency if your median time from open to merge starts rising you climbed way too fast and you want to take step back down the curve now we're going to move on to talking about how code and architecture we can write code and architecture differently so we have better results using coding agents too the rails foundation ran and created a benchmark this august called agent on rails it's super interesting definitely read it, I link it at the end. It took 21 Atomic Rails tasks against WriteBook, a real application, eight models and over 500 runs. It had deterministic grading, no LLM judge. Opus 5 solved 92% of the tasks. The three other models cleared 84. So they basically, the result of this was they state that Atomic Rails work is mostly a solved problem for frontier models. So it's obvious that this is not a model capability problem. If an agent writes bad code in your app, the question isn't which model did you pick. Even the worst performing frontier model scored 73%. The agent harness is also not the problem. A research team at Queen's University took 35 releases of the same coding agent, pinned the model, and let only the harness change. So whatever moved, the scaffolding moved, it held the model constant and varied only the scaffolding. Because the resolve rate was flat at 30.5% mean, which doesn't really mean anything, but token consumption nearly doubled. An earlier version peaked at 39%, beating the sophisticated later harnesses. So the only thing that changed was the code somebody wrote around the model, and the harness changed nothing. Back to the Rails Foundation benchmark, the task that separated everyone was to delete a user's account properly. eight of 24 runs compared to the models clearing 90% an hour earlier. Four things make it hard, and not one is about reasoning. It touches every model that reference to user. The right answer lives in your dependent destroy and dependent nullify options across different files. And nothing tells you what properly means. Destroy, anonymize, keep invoices seven years for finances. That definition isn't in your code base. It's in a person's head, maybe a Slack thread, or maybe nowhere. And notice you can't verify it either. This stat was really interesting to me. The benchmark tracked whether each run used the real Rails API or hand rolled its own. Recall range from 8% to 35%. That's the best any model did at reaching for what Rails already gives you. Then they split success by what the model actually did. These agents aren't remembering Rails. They're rediscovering your app from a bash prompt, one grip at a time, every single run. 92% of the runs used the right API. 64% of the runs found the API and shipped something else anyway. So knowing the convention and ignoring it is worse than never knowing it, in my opinion. And that really changed how I thought about this. The dangerous agent isn't the ignorant one. It's the one that saw your convention, understood it, and decided the wrong path looks shorter. So I'm going to take that one. And that's not a model problem. That's an environment problem. Agents are lazy and look for the easiest and shortest path to solve a problem. So, hand-rolled code mostly works, which is exactly why it's dangerous. You didn't get a worse implementation, you got a permanent obligation with no upstream, no patches, etc. And it costs you twice, because hasMany is already in the model's weights and your custom helper is in nobodies. So every hand-rolled implementation makes your codebase worse as a context window. framework from scratch for agents, you'd land close to Rails. But Rails is also really good at hiding things. Concerns, injecting behavior, never written in a class, single table inheritance, deciding the real type at runtime, et cetera. Same language, same framework, difference is whether behavior is declared or magic. Rails lets you do both. Your agent can only read one. So a multi SWE benchmark looked into what the best performing languages same agents, eight languages. Python was at 42%. So Ruby is not even on this chart. It isn't in the benchmark at all. So if you're choosing a stack purely for agent throughput, the honest answer is not Rails, it's Python. The authors attribute the spread mostly to training data representation, not to language merit. So Python is really overrepresented on the internet, and that's the finding. Notice really what this means. It means nobody outside our community was going to measure this. which is exactly why the Rails Foundation did and built their own eval suite. So thank you to the Rails Foundation for investing in this. Yeah, super helpful. Another study I want to talk about is the repo mirage. It takes real repos and applies perturbations that change nothing about a behavior. A perturbation is a controlled change to where code lives and not what it does. So any drop in performance has exactly one possible cause. They didn't make the code harder to read. They made the facts harder to reach. And across eight frontier models, issue resolution went from 66% to 49%. A quarter of the agent's capability was gone without touching what the code does. And these are the three that I was interested in. Dependency path and direction, basically replacing direct imports with multi-hop proxy chains. And that's concerns, including concerns, delegate change, auto load magic, et cetera. Local value externalization too, and that's splitting configs across YAML and initializers and the database. Files access went from 4.77 to 13.24, nearly three times as much reading for the same job. Remember the attention budget, and this is what spending it looks like. It isn't that the agent gives up, it simply wanders. Naming is a big one, no surprise here. researchers took working code and stripped out every meaningful identifier. Same structure, same behavior, just nothing like a human would name it. On real-world code, GPT-5's ability to explain what a class does fell from 87 to 58. Frontier model comprehension on real-world code, oh, it dropped 29 points just from renaming things to worse and unclear names. If a person has to run your app to know what happens, so does the agent. The difference is a person can play with the code in the console, verify behavior, or even ask the person who wrote it, right? You can ping your co-worker next to you or on Slack. And let's say the agent gets 59 minutes, one branch, an ephemeral container, zero institutional memory every time. What stays implicit can never be proven, not by the agent and not by you. So let's talk about metaprogramming briefly. We're going to go back to the Rails Foundation benchmark for a second. they just give the agent exactly one tool, a shell, because that's very similar to what a coding agent has right now, unless you add more to it, which means the agent is finding things in your code by searching for strings. So here's a perfectly reasonable piece of Ruby, six lines. It generates a timestamp reader for every state in the machine. I've written something like this in production before, honestly. And here's your agent looking for published at, and surprise, it can't find it. The method is only real at runtime. The agent does not like to come back and tell you that it couldn't find it. So it's going to hallucinate a definition that seems right, build on top of it, or write its own copy right where it's working, or edit something that looks similar. All three of those will produce a diff that looks okay in review. That's the whole problem. You're not going to fully trust that you or someone else will catch this, especially when we are already so burnt out from the excessive amount of reviewing at this point. an engineer at SpaceX AI, she actually wrote the P-Stack plugin. She runs a standing team of coding agents in production that auto-merge without her even looking at the PR. But this is what it took for her to get there. Her and her team shipped over 600 refactoring PRs to build the architecture that their agents are working inside. Smarter problems alone cannot close this gap. Everyone wants, you know, the 24 plus 100, but 600 plus PRs is really the price and a lot of to get there? The distinction changed how I worked. I started thinking in terms of constraints versus prompts. On the left, we have an instruction. Always use the service layer for billing. You put it in an agent's MD file and you think you're good to go. Putting it in my agent's MD file was my answer to a lot of things. But look what it is in the system. It's just a handful of tokens competing with 200,000 others. It started to degrade as context filled up, and runs did not always obey everything that was in my file because it just couldn't. And you find out what was ignored in review in a diff that touched 40 files, and then on the right, the same rules as a CI check that fails the build on a direct billing right. It also doesn't cost any tokens, and it's enforced deterministically, and that is a crucial part. The agent runs your test, hits the failure, corrects itself, and the bad PR is never filed. don't tell the agent what to do, they change what it can see as possible. And their why proof is possible at all. You can't verify against the suggestion. Agents really need guardrails and bumpers. Constraints beat instruction, and architecture is the biggest constraint of all. It decides how many files a change touches, and that number turns out to predict almost everything. I also want to touch a little bit on modular versus monolith, too, because you might be curious. a benchmark for this. It was called Moduleth Bench, and it tested four domains, implemented twice, one modular, monolith, and one microservice. It used the same tasks, generation, bug fixing, etc. The monolith averaged 97.7, microservices 70.7, and it got there with about 40% fewer tool calls. So it seems that agents, they do work better in monoliths. Rails organizes your code by what kind of thing it is. and nobody has ever filed a ticket asking you to change all the models, right? A layer is a category, a feature is a unit of change. One feature can live in six directories when it's organized by layer, none of which are named after the feature. Organized by feature, you have one directory, and grep can find all of it. That's a vertical slice. And Jeremy Miller says it better than I can. You're not making it prettier, you're shrinking the blast radius of find everything out about invoices. three ways that you can draw a boundary in a Rails app. You can use namespace modules. Shopify's pack work is also great for declaring dependencies and privacy. Violations will fail on the build and not in runtime, so I would make it a CI gate if I were you. Also, engines, the boundary lives in the loader. Isolate namespace, you get your own routes, helpers, table prefixes, et cetera, and violations show up at the run and not in review. Focus on convention, then a CI gate, and the wrong thing simply doesn't boot. Every model should also own its own tables. Nobody else touches them. On the left, onboarding reaches into billing schema. Billing can now never change that table. On the right, onboarding asks one call site, one owner, and billing can rewrite its internals whenever and nothing else notices, including your agent. The key is cross-module foreign keys. They hardwire the coupling into the schema itself. And here's the agent part. If reaching is normal, in your app, the agent learns that reaching is allowed, and it's going to do the same thing at scale in every single PR. So what can an agent actually do with architecture? Somebody also measured this properly. Same model, same code, three levels of help. Tell it exactly what the flaw is and ask it to confirm. It did great. Point it at a starting class and ask it to find the related ones. Still good. Just say, find the coupling problems, and it drops off. And then the one that was super interesting, to me. Same open-ended question, but now there's code in the context window that has nothing to do with the problem, and the agent completely fell apart. Barely a quarter of what was scored when you told it the answer. Adding noise costs more than reviewing every hint, so the model is a good design reviewer and a really bad design detective, which tells you exactly what your job is. Your architecture's job is to point. It isn't to be discoverable by a sufficiently clever agent and if you're ever tempted to just point an agent at your architecture and say fix it somebody tried that too group of researchers small bench put 65 real-life hard architectural smells in scikit-learn the best agent resolved at only 47 but resolution percentage isn't the interesting part the most aggressive agent fixed 31 smells and introduced 140 net minus 109 i know i was like wow this is insane the conservative conservative one fixed 19 and introduced three, net plus 16. So it was the same task, but a very different outcome. And the difference was restraint, not capability. Experts checked the flag smells for the aggressive agent and 63% of them were false positives. So the agent was wrong about a majority of them and went and fixed them anyways. This was also super interesting to me. They measured how much code the agent wrote against how much architectural smell shows up. the more it wrote, obviously, the worse the structure got every single time. Then they tried the obvious fix. They used better prompts with more detail, more instruction, and it made no measurable difference at all. And I feel like I reach for that a lot, like just add more to, you know, the prompt. So the amount it writes predicts the damage. That's the whole argument for constraints. You cannot prompt your way out of this. You can only make the wrong thing harder to do in your applications. more than no boundaries at all. If your app is new or you can't name your domains yet, don't do this. And don't do it because I stood up here and say, architecture matters here, but do it where your agents already keep failing. Let's take a step back for a moment and look at the enforcement ladder that you can begin to implement. At the bottom, a comment or a doc, right? The agent may read it, but it's a toss-up. AgentsMD is better, but it is not reliably in the context window and is still competing with everything else. Only put what's surprising about your app in here. Assume the model already knows Rails. Next is a convention it can pattern match against. 40 controllers do a thing one way and one doesn't and the agent learns your convention from the 40 files. That's free. A generator is the first step where you really stop asking. You're not telling it where the service objects go. You're making the command that puts them there cheaper than writing the file by hand. It'll take the cheap path because agents always do. Then a lint rule. Wrong code is visibly wrong, locally, immediately. A failing CI check. It cannot merge past this one or make it into production. And at the top, a type or interface boundary. So my challenge for you today is to pick the three rules your agents break the most. Think about the ones you keep leaving the same review comments about on pull requests. Move each up exactly one step. Not to the top, just one step. And a lot of an afternoon and the return is really permanent going back to the pstack plugin i mentioned earlier it has two investigation skills that i really like and they exist for the same reason you have slash how and that's the thing you'd otherwise get by running the app and playing with it except it's written down and the agent can do it itself it's also nice for when you're onboarding to a new application slash why is the one that i really like it queries get history issues docs and team chats in parallel to recover the decision behind the code because intent was never in the repo. It's in the PR thread from 2023 or somebody's memory. And notice what a feature map actually is. It's what happens when you stop re-asking these two questions every session and write the answers down once. Feature maps take time to implement, but they're a huge win when it comes to agent performance for your repo. Here's an example of one. The trap is super helpful because no amount of reading helps this. It lives in one engineer's head and review twice a year when someone gets bitten by it, right? 10 lines can replace 15 tool calls of rediscovery every session. But also one thing to be aware of, if a map can drift, make sure you automate the refresh. Somebody also measured this. They gave models the mismatched comments. GPT-4 went from 43.5, went from 44.7% to 22.1, halved. GPT-4 dropped 10 points. So accurate documentation is roughly free. and sale documentation is going to cost you. I just threw so much information at you all, but I do want to touch a little bit on where we're headed given how fast AI is moving. I really see the future being multi-agent. Everything we talked about today assumed one, and that is simply not going to be our reality. Lauren says this. I love it. Naive parallelization just makes them right fast, swap faster. And yeah, you need to get your one agent working reliably. give it context, require evidence, and then parallelize. Go deep first. And once verification is handled, the bottleneck moves one more time. Multi-agent study put 32 agents on one code base and measured what happened. With no coordination, 78% of completions were redundant, agents solving the same thing unaware of each other, which is crazy. Then they added get native leases and shared completion state. So duplicate work from there went to zero. down from 410 to 48 and locks alone weren't enough you need shared state but we're not quite there yet so of course the fix again was not a better model surprise it was infrastructure and a shared legible place to look importance is going to grow exponentially with multi-agents so it's really essential that we get this right now and there's something that this community has believed for over 20 years that the rest of the industry is now only getting around to measuring convention over configuration was never really about productivity. It was about care. A predictable and clear place to put things is a message to whoever shows up next. You won't have to ask. We called it a framework because somebody always comes next. Sometimes it's a new hire in their first week. Sometimes it's whoever is on call at 2 a.m. opening a file that they've never seen. And sometimes it's an agent that has no memory at all, one that will read your repository more carefully than any person ever has and then forget every word of it by the morning. And sometimes it's you, 18 months from now, with absolutely no recollection of why you did it that way. So, make it findable. That's the playbook. You've been writing a context window this whole time. You just never knew who was going to read it, because somebody always comes next. Thank you so much for coming to listen to me. I would love to connect on LinkedIn or Twitter. And these are some of the things that I referenced. screen, use your QR code for a lot of the papers that I referenced. Yeah. And then if you're interested in trying PSAC, but the Rails Foundation agent report was also super interesting. So thank you.