AI Engineer Code 2025
Infra that fixes itself, thanks to coding agents — Mahmoud Abdelwahab, Railway
Loading slides…
Read the talk
Infra that fixes itself, thanks to coding agents
Railway Autofix connects infrastructure metrics, durable workflows and a remotely controlled coding agent to turn a suspected service problem into a pull request for human review.
From a talk by Mahmoud Abdelwahab
Before you start: Familiarity with HTTP status codes, GitHub pull requests and basic service metrics will help you follow the workflow.
A memory leak is obvious; a slow query may not be
The Railway dashboard opens on several deliberately unhealthy services. In the first, memory usage keeps climbing, suggesting a leak that could eventually crash the process. Its request charts also show many HTTP 500 responses. Mahmoud Abdelwahab reports a 94% request error rate and responses taking multiple seconds for this demo service. These are dashboard readings from the demonstration; the request denominator and measurement window are not specified.
In production, that combination would likely mean pages and urgent investigation. But the next service illustrates a less obvious failure: it queries Postgres, its CPU usage looks ordinary, and its memory chart is somewhat spiky without immediately looking disastrous. There are failed requests and an elevated error rate, but the strongest signal is extremely high response latency. Slow database queries make the experience painful even when resource charts look relatively normal. Abdelwahab illustrates the user impact with a roughly 30-second page load.
The usual response is to configure thresholds for CPU, memory or request errors, receive an alert, and then assemble the explanation yourself from logs, metrics and traces. An alert identifies a symptom; a useful repair needs the surrounding evidence. The proposed change is to let a coding agent monitor that evidence and prepare a fix, so the operator’s next task becomes reviewing and shipping a pull request. Human approval remains part of the workflow.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Monitor a time window, then investigate affected services
The path from a Railway incident to a GitHub pull request begins with scheduled project-health monitoring. Suggested intervals are every 10, 15 or 30 minutes. Each run performs a small sequence:
- Fetch the application architecture: deployed frontends, backends, crons and queues.
- Fetch each service’s CPU and memory utilization.
- Fetch HTTP metrics, including error rates and counts of 400 and 500 responses.
- Compare the measurements with thresholds and return the affected services.
The output is a list of candidates for investigation, not yet a diagnosis.
Why poll instead of starting the workflow from an alert webhook? Abdelwahab prefers analyzing a slice of time because individual threshold crossings can be noisy. An illustrative spike to 80% CPU utilization warrants investigation, but does not by itself establish a fault. A spiky workload may still be operating correctly when viewed alongside the rest of its behavior.
The next workflow gathers more context for suspicious services. High resource utilization with clean logs may simply mean the application is getting more use. A proposed extension would scan repository code to identify upstream providers and then check their status pages. If a payment processor is down, the appropriate recommendation could be to wait for that provider to recover rather than modify application code.
When the evidence does point toward an application defect, combine the signals: many HTTP 500s, high memory utilization and errors identifying a failing endpoint. Add the application architecture and affected-service details, then turn that context into a repair plan. The coding agent can clone the repository, derive a to-do list, implement the changes and open a pull request. This separates broad monitoring, focused investigation and code editing into distinct stages.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resume failed workflows without repeating successful steps
These workflows depend on several external services, so failure recovery is part of the design. Abdelwahab introduces durable execution through Inngest, using a separate processVideoUpload example. A video-upload event starts three operations: call a transcription API, ask an LLM to summarize the transcript, and store both results in a database. Each operation can fail independently.
Durable steps provide automatic retries, with retry behavior and failure handling configurable; the walkthrough mentions exponential backoff as an option. Successful step outputs are persisted and reused. If transcription and summarization succeed but the database write fails, recovery can reuse the first two results and retry the write.
The step boundaries in that example can be expressed in TypeScript as follows. The application supplies its transcription, summarization and storage functions; each external operation runs inside its own durable step.
typescript
import { Inngest } from "inngest";
type VideoOperations = {
transcribe: (videoUrl: string) => Promise<string>;
summarize: (transcript: string) => Promise<string>;
save: (record: {
videoUrl: string;
transcript: string;
summary: string;
}) => Promise<void>;
};
export function createVideoWorkflow(operations: VideoOperations) {
const inngest = new Inngest({ id: "video-processing" });
return inngest.createFunction(
{ id: "process-video-upload" },
{ event: "video/uploaded" },
async ({ event, step }) => {
const videoUrl = String(event.data.videoUrl);
const transcript = await step.run("transcribe", () =>
operations.transcribe(videoUrl),
);
const summary = await step.run("summarize", () =>
operations.summarize(transcript),
);
await step.run("save", () =>
operations.save({ videoUrl, transcript, summary }),
);
return { videoUrl, stored: true };
},
);
}
| Step | State when the write fails | Recovery |
|---|---|---|
| Transcribe | Result persisted | Reuse transcript |
| Summarize | Result persisted | Reuse summary |
| Save | Failed | Retry database operation |
The handler can execute again; successfully persisted steps do not need to repeat their external work. That is why API and database calls belong inside durable steps. Abdelwahab attributes the speed and cost benefits to avoiding repeated work, then applies the same pattern to Railway API calls for architecture, resource metrics and HTTP metrics.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Run the coding agent behind an API
For the coding agent, the demo uses OpenCode, an open-source terminal agent presented as an alternative to Claude Code, with a choice of model providers. The architectural feature that matters here is its client-server separation: running opencode starts a terminal UI and a server. The terminal is one client of that server, so the infrastructure workflow can become another client.
A headless OpenCode server hosted on Railway exposes the agent through an API. Its environment supplies the tools the agent needs, including filesystem access and configured Git. The workflow service can therefore request repository work remotely while the agent performs edits and prepares pull requests in its own server environment.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Package the agent and its tools
The Railway Autofix repository separates the orchestration API and OpenCode into two directories. In the recording, Bun runs a small server wrapper that Abdelwahab calls createOpenCodeServer, listening on port 4096. The current companion Dockerfile instead launches opencode serve directly; the recorded wrapper’s exact historical SDK identifier is not established by the current code.
The container defines the agent’s working environment. It installs curl, jq, Bash, Git and the GitHub CLI, followed by OpenCode. Git is configured, the server port is exposed, and GitHub CLI authentication enables pull-request creation. These tools are what let the remote agent move from a natural-language repair plan to concrete repository operations.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Inspect a monitoring run
With OpenCode running, the orchestration API starts at localhost:3000. Inngest’s debugging UI lists functions, each representing a workflow with inspectable steps. The intended live sequence is scheduled monitoring followed, when an issue is detected, by service-context collection and fix generation:
monitor project health → pull service context → generate fix
The demo starts this chain manually and shows the downstream workflows being invoked. Railway-specific environment variables provide deployment context; Abdelwahab notes that Railway supplies them automatically on the platform.
The first monitoring step retrieves the project architecture. Its output identifies the database, deployed services and their configurations, repository locations, and volumes. This gives the later agent more than an isolated error message: it knows which pieces of the application exist and where their code lives.
Independent metric-fetching steps then run in parallel. Their outputs include readable summaries for the coding agent. In the displayed database summary, Abdelwahab reports average CPU usage of 0.93 vCPU and memory usage of 31.96 GB against a 32 GB maximum. The aggregation window is not specified, but the memory reading supplies a concrete reason to investigate pressure near the displayed ceiling.
HTTP metrics are collected for each of the three deployed services. They include separate error percentages for 400 and 500 responses, latency, and status counts. Formatting these measurements into summaries gives the next workflow a consistent account of how each service is behaving, alongside the resource measurements and architecture.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Turn service context into a repair plan
The pull service context workflow receives the monitoring payload and fetches HTTP logs, build logs and deployment logs for affected services. It also carries an architecture summary describing three services, one database, volumes and an environment labeled production. Although the debug UI displays this text awkwardly on one line, the agent receives it as Markdown. The collected context then passes to generate fix.
Fix generation begins with an AI analysis step. Architecture and performance evidence become a plan containing debugging steps and recommendations. One displayed recommendation is to reproduce the problem locally under the same load, run the application and investigate errors encountered along the way. That is a proposed debugging action in the plan, rather than a demonstrated reproduction result.
The workflow passes the recommendations to the coding agent and creates a session. A session acts like a separate chat context: with multiple repositories, each repository can have its own session. The agent works from that context toward the expected completion condition—an open pull request containing its changes.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
The demonstrated endpoint is a pull request
The final screen shows an open pull request. Its conversation includes a change summary, an analysis summary, identified root causes and descriptions of what was fixed. This is the concrete handoff: the operator can review a proposed repair together with the agent’s explanation, rather than begin with only an alert.
Review and merge remain human decisions. Abdelwahab’s next step is to merge if the changes look good; the recording does not show a merge, redeployment or post-fix health measurement. The demonstrated result is therefore the path from detected infrastructure trouble to a reviewable code change. He closes by inviting questions on X/Twitter and pointing viewers to the companion repository.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Companion source code for the infrastructure-monitoring and coding-agent demo, organized into API and OpenCode services.
Documentation for running a headless OpenCode server and controlling it through an HTTP API.
Further reading
- Inngest durable executionDocumentation
Explains how persisted step results and retries let workflows resume after failures.
Updates since the talk
Current JavaScript and TypeScript interfaces for starting OpenCode or connecting to an existing server.
Current CLI commands for retrieving resource and HTTP metrics with time filters and JSON output.
Full transcript
Loading transcript…