In five days, I had 68 PRs merged in Keboola Connection. The number of files that depend on Zend in the new Symfony code dropped from 1,295 to 706. I say “had them merged” because agents did most of the work. I still had to keep an eye on a few things.
Five days, 68 PRs
In Dark factory in two sentences I wrote about the first roughly 22 hours. At that point, 13 PRs had been merged. The line kept running, though. We started on 11 November and finished on the evening of Monday, 16 November.
| Metric | Before | After |
|---|---|---|
Files in src/ that depend on Zend |
1,295 | 706 |
| Zend controller actions | 70 | 70 |
.phtml templates |
61 | 55 |
Zend_Json used in src/ |
Yes | No |
That's 589 fewer files that depend on Zend, a drop of 45%. Every PR ran a selected E2E suite in CI and went through the CI Status Gate. Either the reviewer bot or a human approved it.
Most of the work was fairly mechanical. Constants and enums got a native owner. Native services and factories replaced Storage_Service_*. Controllers and processors got the Doctrine DevBranch instead of the Zend row. Library classes moved from the legacy library into src with the same FQCN. This is exactly what an agent is great at, and I don't need to stand over it.
So where do I stop agents from going full auto? Login and authorization changes, for example. Even if it looks like a simple type hint swap, I want to take a proper look.
Authorization: hands off without permission
The agent needed explicit permission for every change in Auth, SAML, MFA and SOX. A human always approved changes in Auth and SOX. SAML and partner integrations needed an explicit OK from a human reviewer. E2E tests can't cover everything there, so the reviewer needs to take a close look and test the change manually when needed.
That's where the biggest PR of the sprint landed. Switching to the native StackFeatures and audit log dispatcher in Auth, SAML, MFA and OAuth cut the number of files that depend on Zend by 88. The agent prepared the change and waited for my decision. I made an exception for those two classes and left the review to a human.
On paper, it was a type hint swap. An integration test showed that the alias for StackFeatures still initialized the legacy service. We removed the alias, the E2E tests passed, and CI was green after the rebase. Then the PR went to review.
That time, we had a test that caught it. On another occasion, an agent wrote token refresh code for a colleague. The tests passed even though a short-lived token could be used to get a long-lived one. A user could stay signed in longer than intended. That's why I want someone to look at what an Auth change allows and which of those cases the tests actually cover.
A behaviour change? That's my call
The agent stopped on its own at three changes involving Storage_Service_Version::url(), TableExportOptions and Admin_Service_ManageApps. To go any further, it would have had to change the behaviour or first capture how the legacy version behaves. It set them aside and left the decision to me.
First up was Storage_Job_Exception. Renaming the class would change the error name in Datadog, and we have monitors that depend on that name. So I kept the old name. New code uses a native exception that extends the old one. All 103 original throw statements in the legacy code stay as they are.
With ValidationException, we could safely move it into Symfony and change its FQCN. The user sees a readable error message. We don't check the class name anywhere or rely on it to catch the exception. The API stayed the same and the code is a bit cleaner.
I only allowed controller actions to move if they had real E2E coverage and were outside Auth, SAML, MFA, SOX and OAuth. I allowed Datadog changes for those actions. The API had to stay the same, and any changes to the database schema had to go through me.
When we looked at moving MergeRequest to Doctrine, we hit a snag with the snapshot. After the move, it would call Storage_Service_Version::url(). That would've taken us back to a method we'd just set aside because of the risk of changing its behaviour. We estimated the move at eight points and considered it high risk, so we left it out of the sprint.
Data: a flaky test that wasn't flaky
During the sprint, cli-tests kept failing. It looked like a flaky test. It wasn't. It was a real bug in the local provisioning rollback, which overwrote updatedAt. The fix went out as a separate PR.
Another E2E run failed with Storage in region us-east-1 cannot be assigned to project in region us-east4. It had nothing to do with the PR. The test picked the latest S3 storage owned by keboola, and there was one from a different region on the test stack. Another session had created it manually for other suites, so deleting it wasn't an option. The agent tracked down the cause on its own. Once I gave it the OK to touch the shared stack, it changed only the owner to client. I handed the test fix off to a separate session. The test should only pick storage in the project's region.
Operations: when the whole machine goes down
Then there are things that have nothing to do with code. In the night before 15 November the subagents stopped responding. Full Btrfs metadata, filesystem in read-only. The factory wasn't cleaning up its worktrees, and there were dozens of them by then. Two tasks in progress were left uncommitted.
I deleted the worktrees of merged PRs and a new rule was added: always remove the worktree after merge. The main session then restarted four subagents. Since then they stop at a draft PR, E2E and the ai-review label. Switching to ready and putting it into the merge queue is handled by the main session itself.
BTW, the whole Btrfs thing had a few more interesting twists. But more on that another time.
Two things proved their worth: at most 3 ready PRs at a time and serialized E2E suites.
How I have it set up
- Auth, SAML, MFA, SOX, OAuth: hands off without explicit permission, approval always by a human.
- Behaviour changes, API, DB schema: my call.
- Everything else: E2E and CI Status Gate, the reviewer bot can approve.
- Anything that doesn't fit the rules: the agent parks it and leaves it to me.