
Summary
Key points of this document
- First, we narrow down the targets for removing human-in-the-loop.
- Constraints are defined such that the system stops when AI fails.
- Actions are for triggers, Cloud Build for execution control.
Overview
In discussions about entrusting development and maintenance to AI, attention tends to focus on AI's inference capabilities and prompt design. However, for operations that exclude humans from the execution loop, what's more important than AI being smart is to only handle deterministically detectable targets, narrow the scope of changes, enforce stops with CI, and leave audit trails and cost-stop conditions.
First, we narrow down the targets for removing human-in-the-loop.
The expression "excluding humans from the execution loop" can be easily misunderstood. What is excluded here is the procedure where a human presses a button at each step of detection, diagnosis, fix proposal creation, PR creation, and CI judgment. It does not mean unconditionally handing over requirement changes, design decisions, security boundary changes, or handling of production data to AI.
The targets are recurring maintenance tasks in large-scale web applications and monorepos with multiple services. We limit this to issues where detection conditions can be written in code, such as missing multilingual resources, null values, remaining Japanese text, placeholder inconsistencies, unused translation keys, production debug statements, dependency direction violations, missing OpenAPI summaries or responses, and docs drift.
This narrowing down means AI is no longer a free-exploring entity from the start. A deterministic scanner generates findings, an orchestrator classifies them, passes limited context to the AI API only when necessary, a patch guard inspects the diffs, and CI determines pass/fail. AI output is useful, but it is not placed at the center of the execution loop.
Constraints are defined such that the system stops when AI fails.
In automated maintenance design, stop conditions upon failure are more important than the flow upon success. AI API outputs can vary even with the same input. The codebase changes daily. The base branch is also updated. External CI and Cloud Build operate asynchronously. Given these premises, we first define boundaries that prevent dangerous diffs from spreading even without human intervention during the process.
Patches are limited to a maximum of 8 files, 500 changed lines, and 180KB. Authentication, OAuth, Cookie, CORS, migration, secret, infra, lockfile, generated file, unprovided context, deletion, and renaming are excluded from automatic correction. Once this scope is exceeded, it is recorded as a failure in the ledger rather than asking AI for additional corrections.
Execution frequency is also limited. A maximum of 2 daily tasks, 4 weekly tasks, and 8 monthly tasks. Attempts on the same PR are limited to 3 times within 7 days. Failures where the change fingerprint does not change will not be re-billed. Ambiguous automation limits only lead to increased costs and diffs upon failure.
- The targets handled are limited to findings reproducible by a deterministic scanner.
- Before calling the AI API, confirm all of the following: number of targets, maximum patch size, excluded areas, and budget reservation.
- Patches that touch dangerous areas are discarded, even if the proposed fix seems correct.
- Do not repeat retries with unchanged input for the same failure fingerprint.
Actions are for triggers, Cloud Build for execution control.
In the overall architecture, we keep GitHub Actions thin. Actions are only responsible for daily, weekly, and monthly schedule triggers and asynchronous submission to Cloud Build. If Actions handle diagnosis, AI calls, patch application, and PR creation, logs, permissions, retries, and billing control become scattered.
Execution control is centralized in an orchestrator within Cloud Build. The orchestrator sequentially controls the deterministic scanner, GitHub Issue ledger, AI API, patch guard, branch creation, PR creation, and status posting. This allows handling asynchronous job IDs, finding fingerprints, budget reservations, actual AI costs, patch inspection results, created PRs, and failure reasons within a single context.
This division of responsibility also affects how CI is perceived. A green GitHub Actions job does not mean the final result of Cloud Build. If a PR becomes mergeable just because Actions asynchronously submitted to Cloud Build and completed successfully, the PR might be merged before crucial fix verification is finished.
- GitHub Actions: schedule, workflow_dispatch, Cloud Build asynchronous submission, log archive.
- Cloud Build orchestrator: scanner, Issue ledger, AI API, patch guard, PR creation, final status posting.
- GitHub Issues: Not an approval UI, but an audit ledger to track budget, fingerprints, attempts, PRs, and failures.
- Branch protection: Use Cloud Build's final result as the required status, not Actions.
Make the data flow from detection to correction unidirectional.
The basic flow is scan, ledger, reserve, diagnose, patch, guard, PR, CI, status. First, a deterministic scanner creates findings and calculates a fingerprint for each finding. Next, a ledger entry is created in GitHub Issues, and a conservative maximum amount is reserved before calling the AI.
The context passed to the AI API is narrowed down to the type of finding, relevant files, surrounding code, and permitted correction policies. We assign large-scale, routine classification and translation tasks to Gemini, and code corrections with limited context to OpenAI API. Here, we do not fix specific model names, but rather center the design on dividing roles according to the nature of the processing.
Once AI returns a patch, it does not immediately proceed to a PR. A patch guard inspects the number of changed files, changed lines, size, forbidden areas, deletions or renames, generated files, lockfile changes, and access to unprovided context. Only diffs that pass are applied to the branch and created as a PR.
- Findings have fingerprints, allowing the same issue to be tracked in the same ledger entry.
- Budget reservation is done before AI calls, and the difference from actual cost is returned upon completion.
- Do not mix classification/translation and code correction in the same AI call.
- Diffs that cannot pass the patch guard are treated as failure results, not as correction candidates.
Daily tasks diagnose only failed tasks and perform chained corrections.
In asynchronous CI, there are multiple sources of failure. GitHub Actions has Cloud Build submission logs, Cloud Build has the final build ID and detailed logs, and PRs retain Checks and commit statuses. The orchestrator correlates these and re-diagnoses only the findings corresponding to failed builds or checks.
In chained corrections, instead of recreating the entire PR, only additional patches necessary for failed tasks are created. Attempts on the same PR are limited to 3 times within 7 days, and if failures with the same fingerprint continue, processing stops without re-billing. This avoids a situation where AI is called unlimitedly when CI is red.
Weekly and monthly tasks change the granularity of targets.
In the weekly loop, we perform a codebase-wide static audit. This targets multilingual leaks, null values, remaining Japanese text, placeholder inconsistencies, stale keys, unused translation keys, production debug statements, and dependency direction violations. We look more broadly than daily tasks, but keep detection conditions deterministic.
Deleting unused translation keys solely by simple string search is dangerous. Exclude dynamic prefixes, continuously observe the same fingerprint for 14 days, then delete both Japanese and English simultaneously. Deleting only one part of a translation key can cause other inconsistencies, so deletions are handled in pairs.
In the monthly loop, we audit conditions closer to production. We retrieve the actual OpenAPI from active Cloud Run instances and check for missing summaries, tags, and responses. We also look at frontend shell, proxy, deployment registration, and docs drift. Monthly tasks are run less frequently and are geared towards discovering discrepancies with the actual environment.
Weekly: Audit multilingual, placeholder, stale key, unused key, debug statements, and dependency direction violations.
- Unused translation key: Exclude dynamic prefixes, observe the same fingerprint for 14 days, then delete both Japanese and English simultaneously.
- Monthly: Audit active Cloud Run OpenAPI, frontend shell, proxy, deployment registration, and docs drift.
- Separate the number of targets and maximum corrections for daily, weekly, and monthly tasks.
- The budget is controlled by pre-reservation, not by actual cost aggregation.
If AI API cost control relies solely on actual cost aggregation, you only find out it was expensive after a failure. In this design, a 7-day rolling budget is set to $100, and a conservative maximum amount is reserved before calling the AI. Tasks that cannot be reserved will not be executed.
The reserved amount is calculated from the number of target findings, maximum tokens, expected responses, and retry limits. After execution, the actual token cost is returned to the ledger, and the difference from the reservation is released. Fewer targets mean lower API costs, so narrowing down targets with the scanner directly leads to cost reduction.
The GitHub Issues ledger records budget reservations, actual token costs, finding fingerprints, number of attempts, created PRs, and failure reasons. Issues are not for human approval. They serve as an audit trail to explain later what basis automation used for spending and where it stopped.
The 7-day rolling budget is fixed at $100.
- Reserve the maximum amount before calling the AI API; if reservation fails, do not execute.
- Reserve the maximum amount before calling the AI API; if reservation fails, do not execute.
- Limit to 2 daily, 4 weekly, and 8 monthly.
- Design to reduce both the reserved amount and actual cost if the number of target findings decreases.
Branch protection trusts only the final result.
The most dangerous thing in asynchronous CI is confusing initiation with completion. Even if Actions triggers Cloud Build and turns green, it doesn't mean Cloud Build's verification succeeded. For main branch protection, the required status will be Cloud Build's final result, not Actions' successful initiation.
Upon Cloud Build completion, use the GitHub App's installation token to post to the PR head SHA.cloud-build/ci post status. The required check must be attached to the PR head SHA. If status is posted only to the test-merge SHA, it may not be recognized as a GitHub required check.
CI verifies the PR's test-merge SHA. This is to ensure builds and tests pass with the base branch and PR head combined. However, the status is posted to the head SHA. If the base branch is updated, re-verification is required by strict branch protection.
- Verification target: PR's test-merge SHA.
- Status post target: PR head SHA.
- Required status:
cloud-build/ci. When base is updated: enforce re-verification with strict branch protection. - Safety boundaries mechanically take precedence over AI's persuasiveness.
Even if AI returns a plausible reason for a fix, we will not adopt diffs that fail the patch guard. Authentication, OAuth, Cookie, CORS, migration, secret, infra, lockfile, generated file, unprovided context, deletion, and rename are excluded from automatic correction. These are rejected by diff inspection, not by prompt requests.
This boundary reduces the number of items that can be fixed. However, in operations where humans are not in the execution loop, the ability to stop is more important than the ability to fix. Automation is used not to force difficult changes, but to ensure simple, reproducible maintenance is not missed.
Findings that are excluded will remain in the ledger. The information to be kept includes why it was excluded, which forbidden area it touched, and what aspects a human should look at next. The fact that it could not be automated is also an important operational output.
Verification does not end with unit tests alone.
Implementation verification includes 15 unit tests around the orchestrator and scanner, as well as checking syntax, YAML, real-environment OpenAPI, GitHub App authentication, model references, and both success and failure status lifecycles. Especially for status lifecycle, it's meaningless unless we confirm that the required status remains red not only on success but also on failure.
In a monorepo, lockfile handling also affects the entire CI. During verification, we confirmed frozen lockfiles for 262 workspaces, all Docker builds, and unit tests. If an outdated lockfile remains, the entire CI will halt even for changes that seem unrelated to the target service.
OpenAPI auditing is not sufficient with just the existence of generated files. In the monthly loop, we retrieve actual OpenAPI from running Cloud Run instances and check for summary, tags, responses, and docs drift. By looking at the deployed entities, we can detect discrepancies between expectations in the repository and the production path.
Unit tests: 15 items, focusing on orchestrator, scanner, budget, and status lifecycle.
- Syntax/YAML: Verify workflow, Cloud Build settings, and generated configuration fragments.
- Real environment: Check Cloud Run's OpenAPI, GitHub App authentication, and model references.
- Monorepo: Pass frozen lockfiles for 262 workspaces, all Docker builds, and unit tests.
- Failure examples serve as material for defining design boundaries.
The first failure is asynchronous Actions turning green prematurely. When Actions triggers Cloud Build and finishes, it appears successful on GitHub. However, if Cloud Build itself is still running, verification is not complete. From this failure, we designed it so that Actions is not a required check.
The second is the SHA for status posting. While it's correct for CI to verify the test-merge SHA, the status that needs to be recognized as a required check must be on the PR head SHA. If posted only to the merge SHA, it might appear incomplete under branch protection despite being verified.
The third is an outdated lockfile. Even with small package changes, if the lockfile isn't updated, the entire CI will halt due to a frozen lockfile. Instead of having AI automatically fix lockfiles, it's safer to exclude lockfiles from automatic correction and explicitly stop when detected.
Do not make initiation success and final success the same check.
- Design with separate SHAs for verification target and required status posting.
- Exclude lockfiles from automatic patching due to their wide impact.
- Do not suppress failures; incorporate them back into implementation as conditions for future stops.
- Operational audits prioritize reproducibility over human approval.
This design, instead of requiring human approval every time, retains rich information that can be traced later. Finding fingerprint, scanner version, input context, budget reservation, actual token cost, AI API role, patch guard results, PR, CI results, and failure reasons are all kept in the same ledger.
It's not dangerous because there's no approval. What's dangerous is being unable to reproduce later what basis a change was made on, why that cost was incurred, or where it stopped. Using GitHub Issues as an audit ledger leaves a history in a place regular developers see daily.
On the other hand, it's also important not to use Issue comments as an approval UI. Introducing an approval wait makes the execution loop dependent on human reaction speed again. Automation targets should be defined narrowly enough to proceed without approval, and targets that cannot be narrowed should be placed outside automatic correction from the start.
Changes for which this method is unsuitable are also clear.
This method is suitable for maintenance tasks that can be deterministically detected. It is effective in areas where detection conditions and acceptance conditions can be written, such as multilingual resources, OpenAPI metadata, debug statements, dependency directions, and docs drift.
Conversely, it is not suitable for interpreting requirements, judging screen experience, changing security boundaries, redesigning authentication or permissions, DB migration, infrastructure changes, secret management, or production data operations. These are not impossible to automate, but rather areas where safety is difficult to guarantee with only narrow patches and deterministic verification.
Furthermore, in environments where CI is too slow or tests are almost nonexistent, stopping conditions become weak even before AI is considered. To remove human-in-the-loop, prior to AI performance, you need CI that can detect failures, branch protection that enforces required statuses, and a budget ledger to halt costs.
It's not AI performance, but how it's stopped, that determines the quality of automated maintenance.
AI development and maintenance that excludes humans from the execution loop becomes harder to establish as AI is given broader discretion. To establish it, deterministic detection, narrow change boundaries, AI API role separation, patch guards, enforced CI, branch protection, audit ledgers, and budget stop conditions must be created first.
AI speeds up classification, translation, and code correction in limited contexts. However, what to target, how much to fix, which CI results to trust, and when to stop spending should be decided by system design, not AI.
The central judgment in this design is simple: rather than trusting what AI seems to get right, trust a structure that stops small when AI makes a mistake. What's needed to remove human-in-the-loop is not an AI that judges on behalf of humans, but an execution foundation that doesn't proceed in a dangerous direction even without human intervention.
FLARES LLC


