{"slug": "when-a-build-breaks-the-bug-fixes-itself", "title": "When a build breaks, the bug fixes itself", "summary": "A developer at Shipeasy has automated the entire CI failure resolution pipeline: when a build fails, it automatically files a bug ticket, and an AI agent investigates, writes a patch, and opens a pull request. The system uses existing infrastructure like Google Cloud Pub/Sub and a Rails webhook controller, requiring no new infrastructure. The engineer's role is reduced to reviewing the AI-generated PR.", "body_md": "**When a build breaks, the bug fixes itself**\n\nWe stopped babysitting CI failures. Now a red build files its own bug — and an AI agent picks it up and ships the fix.\n\n**PROBLEM — A failed build told no one**\n\nOur CI would fail, and then… nothing would happen. The failure sat quietly in a build console that nobody keeps open. Eventually someone would notice a change hadn't gone out, go digging, and realize the build had been red for hours.\n\nAnd noticing was the easy part. Actually resolving it meant a whole code session: pull up the logs, find the failing step, reproduce it, and have an engineer sit down and personally shepherd the fix from broken to green. Every red build cost real human hours — plus the invisible tax of the delay before anyone even knew there was a problem.\n\nThe true cost of a broken build was never the build. It was a person having to find it, understand it, and hand-fix it.\n\n**SOLUTION — The failure files its own ticket — and an agent takes it from there**\n\nNow nobody watches a console and nobody triages. The moment a build fails, it automatically files a bug in Shipeasy — our ops platform — as a real, prioritized ticket with the failing step, the branch, and a link to the logs already attached.\n\nFrom there it leaves human hands entirely. Shipeasy hands the bug to an AI agent, which investigates the failure, writes the patch, and opens a pull request against it. The loop that used to be \"human notices → human reads logs → human fixes\" is now \"build fails → bug appears → agent fixes.\" The engineer's job shrank to reviewing a PR that already exists.\n\n**DESIGN — How the whole thing hangs together**\n\nThe pipeline is deliberately boring — every hop is either something the cloud already does for free, or a service we already run:\n\n`main`\n\npublishes automaticallyWhat makes this cheap is the shape of it: we added no new infrastructure. The event was already on a bus (Pub/Sub). We already ran a service that could receive it. All we wrote was the glue in the middle.\n\n**IMPLEMENTATION — How it worked out in Rails**\n\nThe build side needed no changes at all — Cloud Build publishes to the cloud-builds topic on its own. So the work was three small pieces: one gcloud command, one route, and one controller.\n\n```\ngcloud pubsub subscriptions create cloud-build-failures \\\n  --topic=cloud-builds \\\n  --push-endpoint=\"https://our-app/webhooks/cloud_build?token=$SECRET\" \\\n  --message-filter='attributes.status = \"FAILURE\"\n    OR attributes.status = \"INTERNAL_ERROR\"\n    OR attributes.status = \"TIMEOUT\"'\nscope \"/webhooks\", module: :webhooks do\n  post \"cloud_build\", to: \"cloud_build#create\"\nend\nclass Webhooks::CloudBuildController < Webhooks::ApplicationController\n  before_action :verify_token\n\n  FAILURE_STATUSES = %w[FAILURE INTERNAL_ERROR TIMEOUT]\n\n  # POST /webhooks/cloud_build\n  def create\n    message = params[:message]\n    return head(:bad_request) if message.blank?\n\n    build  = decode_build_json(message[:data])   # base64 JSON → Hash\n    status = (message.dig(:attributes, :status) || build[\"status\"]).to_s\n    return head(:ok) unless FAILURE_STATUSES.include?(status)\n\n    return head(:ok) unless first_delivery?(build[\"id\"])   # dedupe\n\n    file_bug_for(build, status)\n    head :ok\n  end\n\n  private\n\n  # Compare-and-set on the build id: the first delivery wins, redeliveries no-op.\n  def first_delivery?(build_id)\n    Rails.cache.write(\"cloud_build:filed:#{build_id}\", true,\n                      unless_exist: true, expires_in: 7.days)\n  end\n\n  def verify_token\n    expected = App::Secrets.cloud_build_webhook_secret\n    provided = params[:token] || request.headers[\"X-CloudBuild-Token\"]\n    head :unauthorized unless\n      ActiveSupport::SecurityUtils.secure_compare(provided.to_s, expected.to_s)\n  end\nend\n```\n\nThe one line that files the ticket. The controller hands the build context to a thin Shipeasy client. This is the exact call — it turns a red build into a first-class bug that opens a GitHub issue, pings Slack, and becomes eligible for the auto-fix agent:\n\n``` python\ndef file_bug_for(build, status)\n    subs = build[\"substitutions\"] || {}\n\n    ShipeasyOps::Client.new.file_bug(\n      title:              \"Cloud Build #{status.downcase} on #{subs[\"BRANCH_NAME\"]} — #{subs[\"SHORT_SHA\"]}\",\n      steps_to_reproduce: \"Cloud Build trigger \\\"#{subs[\"TRIGGER_NAME\"]}\\\" reported #{status}.\",\n      actual_result:      \"Logs: #{build[\"logUrl\"]}\\n\\n#{build.dig(\"failureInfo\", \"detail\")}\",\n      expected_result:    \"The build completes and deploys.\",\n      priority:           \"high\",\n      tags:               %w[cloud-build ci],\n    )\n  end\n```\n\nAnd the client itself is just a typed wrapper over one HTTP call — no new gems, no framework. This is all it takes to create a bug on the platform:\n\n``` python\ndef file_bug(title:, steps_to_reproduce:, actual_result:, expected_result:, priority:, tags:)\n    post(\"/api/admin/ops\", {\n      type:             \"bug\",\n      title:            title,\n      stepsToReproduce: steps_to_reproduce,\n      actualResult:     actual_result,\n      expectedResult:   expected_result,\n      priority:         priority,\n      tags:             tags,\n    })\n  end\n\n  def post(path, body)\n    req = Net::HTTP::Post.new(URI(\"#{BASE_URL}#{path}\"))\n    req[\"Authorization\"] = \"Bearer #{@admin_key}\"   # sdk_admin_… key\n    req[\"X-Project-Id\"]  = @project_id\n    req[\"Content-Type\"]  = \"application/json\"\n    req.body = body.compact.to_json\n\n    res = Net::HTTP.start(req.uri.host, req.uri.port, use_ssl: true) { |h| h.request(req) }\n    JSON.parse(res.body)\n  end\n```\n\nThat's the whole integration. The failure travels from Cloud Build to a filed, prioritized bug through two managed hops and about forty lines of Ruby — and the moment it lands, it's the platform's problem, not a person's.\n\n**SHIPEASY — One problem, several ways to solve it**\n\n**THE PAYOFF — The last red build nobody had to fix**\n\nA build died with `FATAL ERROR: Reached heap limit — JavaScript heap out of memory`\n\n. The bundle outgrew its memory ceiling. The agent recognized the OOM pattern and opened a PR with the entire fix:\n\n```\n- NODE_OPTIONS=\"--max-old-space-size=4096\"\n+ NODE_OPTIONS=\"--max-old-space-size=8192\"\n```\n\nA teammate who doesn't write backend merged it. The person who \"fixed\" it never had to know what a heap limit is.\n\nThe failure notices itself, files itself, fixes itself, and asks a human for nothing more than a nod.\n\nBefore standing up new infrastructure to react to an event, check whether the event is already on a bus you can subscribe to — and whether something you already run can catch it.\n\nThe ops side of this runs on Shipeasy — the ticket, the agent, the rollout. Core product is the ops queue that delegates to agents. Free tier, no card required; Team at $49/seat/mo removes limits.\n\n→ [shipeasy.ai](https://shipeasy.ai) · → [docs.shipeasy.ai/sdks/ruby](https://docs.shipeasy.ai/sdks/ruby) · → [github.com/shipeasy-ai/shipeasy](https://github.com/shipeasy-ai/shipeasy)", "url": "https://wpnews.pro/news/when-a-build-breaks-the-bug-fixes-itself", "canonical_source": "https://dev.to/shipeasy/when-a-build-breaks-the-bug-fixes-itself-3nmm", "published_at": "2026-08-16 00:02:19+00:00", "updated_at": "2026-08-16 00:11:12.594344+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "mlops", "artificial-intelligence"], "entities": ["Shipeasy", "Google Cloud Build", "Google Cloud Pub/Sub", "Rails"], "alternates": {"html": "https://wpnews.pro/news/when-a-build-breaks-the-bug-fixes-itself", "markdown": "https://wpnews.pro/news/when-a-build-breaks-the-bug-fixes-itself.md", "text": "https://wpnews.pro/news/when-a-build-breaks-the-bug-fixes-itself.txt", "jsonld": "https://wpnews.pro/news/when-a-build-breaks-the-bug-fixes-itself.jsonld"}}