Technical document

Infrastructure Design to Truly Leverage AI Coding Agents: Development Efficiency Born from Memory Protection and Multi-level Liveness Monitoring

The key to scaling AI coding agents in practice lies in the infrastructure. This article explains a design that integrates memory protection, watchdog daemons, and dynamic routing to achieve high levels of quality, development speed, and cost efficiency.
AI Development32 minPublication Date October 31, 2026Update date November 23, 2026
Thumbnail for Infrastructure Design to Truly Leverage AI Coding Agents: Development Efficiency Born from Memory Protection and Multi-level Liveness Monitoring

Summary

Key points of this document

  • Introduction: The Inevitable View of AI Coding Tools as "Middleware"
  • 1. Three Major Infrastructure Challenges in Autonomous AI Development
  • 2. Infrastructure Stabilization Mechanism: Autonomous Monitoring Watchdog Daemon

Introduction: The Inevitable View of AI Coding Tools as "Middleware"

In recent years, with the evolution of autonomous AI coding agents (such as Antigravity), development processes that autonomously perform batch editing of multiple files, automatic generation of test code, and even build verification to deployment have become a reality.

However, when engineers begin to seriously operate AI agents in practical settings, many encounter a common obstacle. This is an operational problem where the autonomous development process halts due to resource exhaustion or process hang-ups on the machine running the agent, even before considering prompt or model performance.

Loading diagram...

From a software architecture perspective, an AI coding agent is not an independent, self-contained entity operating directly on the OS, but rather "middleware" built upon an underlying infrastructure.

No matter how intelligent an agent may be, continuous and autonomous development cannot be achieved if the underlying OS layer and infrastructure mechanisms (process management, memory protection, network routing, secret management) are not robustly designed.

This article explains the specific implementation and design philosophy of the infrastructure built on our company's dedicated on-premise integrated development server to maximize the potential of AI agents and achieve a high level of "high quality, high speed, and low cost" simultaneously.


1. Three Major Infrastructure Challenges in Autonomous AI Development

When continuously entrusting autonomous AI agents with practical tasks (such as complex refactoring, E2E test execution, multi-layered builds, etc.), the following critical issues become apparent at the OS and infrastructure layers.

(1) Child Process Stacks and Main Thread Deadlocks

AI agents issue a wide variety of commands (child processes) via the shell, such as builds, tests, and file searches.

If a child process blocks indefinitely (stacks) due to commands waiting for interactive input, unset external network timeouts, or contention for specific locks, the entire agent's control loop falls into a deadlock waiting for a response, completely halting autonomous development until an engineer manually intervenes.

(2) Memory Bloat from Idle Compilers and Development Servers

Java-resident build tools (like Bazel), development servers launched by agents for operational checks (Vite, Next.js, Astro, Wrangler, etc.), and even headless Chromium for E2E test verification, remain in memory after task completion.

When these accumulate, they lead to GBs of memory leaks, putting pressure on the entire OS memory, triggering the OOM Killer, and in the worst case, crashing the agent's core process along with it.

(3) Remaining Zombie Processes Due to Abnormal Process Termination

When tasks are canceled or agents crash, sending only standard signals (like SIGTERM) leaves multi-nested descendant processes and background tasks as orphans (zombies) on the OS. These processes continue to hold onto ports and temporary file locks (e.g., Chromium'sSingletonLock), causing subsequent task executions to fail repeatedly.


2. Infrastructure Stabilization Mechanism: Autonomous Monitoring Watchdog Daemon

To fundamentally resolve these issues, we developed and introduced an autonomous watchdog daemon that resides in the infrastructure layer.

Loading diagram...

(1) Recursive Process Tree Traversal and Automatic Rescue of Stuck Tasks

The watchdog daemon activates every 30 seconds and recursively traverses all descendant processes, starting from the PID of the agent's core processes (language_server, etc.).

  • Stuck Determination Algorithm:
    • Uptime (etimes) exceeds a predefined threshold (default 8 minutes).
    • And CPU usage remains stagnant at a low level (2% or less).
    • However, resident base daemons, IDE cores, MCP servers, and internal schedulers are strictly protected by an exclusion list.
  • Safe Rescue Signal:

Gradually sends signals (SIGTERM → SIGINT) to child processes determined to be stuck, safely terminating them. This immediately notifies the parent agent of the termination status from the OS, allowing it to escape deadlock and transition to an autonomous recovery turn.

(2) Automatic Release of Resident Memory in Idle State

  • Collection of Build Tools (e.g., Bazel):

Bazel servers, responsible for high-speed builds of large repositories, automatically terminate after 5 minutes of idle state (CPU 2% or less), immediately returning over 2-4GB of resident heap memory to the OS.

  • Collection of Abandoned Development Servers and Verification Browsers:

The agent cross-references frontend development servers launched for validation and E2E test browsers (Playwright Chromium) with the active access status of the Preview Router, described later. It safely stops abandoned servers holding ports that are not actively being browsed.

  • Automatic cleanup of the /tmp directory:

It collects temporary files older than 30 minutes, with a protection mechanism to skip files if a currently running process has an open file handle to them.


3. Multi-layered Liveness Monitoring and Complete Process Isolation with cgroups

It's meaningless if a single monitoring script itself fails. Therefore, we have established a multi-layered self-healing architecture combining systemd and cgroups.

Loading diagram...

(1) Complete termination by cgroups (KillMode=control-group)

In the systemd unit definition, KillMode=control-group is specified for the AI agent's service.

This ensures that when the agent restarts or stops, all descendant processes generated under it are physically and completely purged by the Linux kernel's cgroup (control group) feature, eradicating any lingering zombie processes.

(2) Mutual Liveness Monitoring between Monitoring Daemons (Self-Healing)

  • antigravity-watchdog.sh is launched by a periodic timer.
  • It double-checks the process status of the AI agent itself, the watchdog daemon (agy-watchdog), and the remote development agent.
  • If a crash or unexpected stop is detected, systemctl --user restart is immediately issued, allowing autonomous recovery within minutes even in an unattended environment.
  • The browser-specific watchdog service (browser-watchdog) detects Chromium containers running for over 30 minutes, performs a graceful stop, and automatically deletes residual lock files (SingletonLock etc.) within the profile to prevent freezing on the next startup.

4. Development Support Platform: Dynamic Routing and Secure Secret Injection

The role of the infrastructure layer is not limited to maintaining stable operation. It also integrates network and authentication layers to allow agents to autonomously perform preview checks and securely communicate with external APIs.

ComponentImplementation TechnologyRole and Impact on Development Process
Preview RouterNode.js + http-proxy / Port 25173Dynamically switches development server ports while keeping external public URLs fixed. Agents can provide previews without needing to be aware of port numbers.
Cloudflare Tunnelcloudflared (systemd resident)Enables secure external access via an encrypted tunnel without directly exposing internal on-premise server ports to the outside.
1Password CLI Integrationop-run.sh / Template Injection.env.*.op Injects only necessary secrets into processes on-demand from templates. Ensures no plaintext sensitive information is ever stored in Git repositories.
Keyring Auto-Unlockunlock-keyring.serviceAutomatically unlocks GNOME Keyring headlessly when the server starts. 1Password CLI and browser authentication operate fully autonomously even without a GUI login.
Docker Compose EnvironmentVarious DBs / Spanner / MailpitContainerizes databases (PostgreSQL+pgvector, MariaDB, etc.) and mock servers per project, ensuring the host OS remains completely clean.
Distributed Remote CacheBuildBuddy (BES / Remote Cache)Caches build artifacts remotely, reducing agent rebuild times from minutes to seconds.

5. Results: The Three Pillars of Quality, Development Speed, and Cost Optimization

Generally, there's a trade-off: "increasing development speed lowers quality" and "pursuing quality skyrockets costs (personnel and infrastructure)." However, by deploying AI agents on a robust infrastructure, a breakthrough emerges that simultaneously elevates all three factors.

Loading diagram...

(1) Leap in Quality

Complete project isolation via Docker Compose and clean process termination via cgroups eliminate flaky issues like "previous task remnants holding ports, leading to false test results." AI agents can consistently complete E2E tests and regression validations in a pristine environment.

(2) Leap in Development Speed

A watchdog daemon detects and automatically rescues stuck tasks, eliminating development stagnation where "a command stopped midway after being left for hours." Furthermore, integration with a distributed remote cache (BuildBuddy) minimizes compilation and build wait times, allowing agent trial-and-error loops to run at maximum speed.

(3) Dramatic Cost Reduction

Running high-spec cloud instances 24/7 incurs enormous operating costs. This configuration utilizes dedicated on-premise Linux workstations (with large memory and dedicated GPUs) while thoroughly implementing idle memory cleaning and automatic resident process collection to optimize hardware lifespan and power efficiency. Human maintenance and troubleshooting efforts are also reduced to near zero.


6. Practical Application Checklist: Infrastructure Requirements to Confirm Before Introducing an AI Agent

If you are considering a full-scale introduction of an autonomous AI coding agent into your company's development environment, we recommend checking whether the following infrastructure requirements are met.

  • Process Monitoring: Is there a mechanism to automatically detect, forcibly terminate, and notify the main thread when a child process executed by the agent is indefinitely blocked?
  • Resource Reclamation: Is a daemon running to automatically stop and release build tools and test browsers so that they do not continue to occupy memory in an idle state after task completion?
  • cgroups Control: Is control applied (KillMode=control-groupe.g., using systemd) that can terminate an entire process group (including descendants) at once?
  • Environmental Independence: Are middleware components (databases, message queues, etc.) for each project separated by containers, designed not to contaminate the host OS?
  • Secure Secret Injection: Are plain-text secrets not hardcoded in the agent's configuration files, but dynamically deployed into memory securely via CLI?
  • Preview Abstraction: Is a reverse proxy or dynamic routing in place that allows external verification via a consistent URL, even if the development server's port number changes?

Summary

An AI coding agent is not merely an extension of a text editor; it is an autonomous system that materializes code while actively consuming OS resources.

The maximum performance of an agent, which is a "middleware," is drawn from the sophistication of the underlying "infrastructure." Memory protection, automatic process recovery, secure secret injection, and complete environmental isolation. Only by designing and building these as an inseparable system can autonomous AI development achieve true stability and overwhelming development speed.

Technical documents

We will continue to increase technical documentation.

We will continue to organize our thoughts on AI, cloud, business app development, requirements definition, and operational design into documents.

Go to technical documentation list