Rahman Nugar, a developer exploring the intersection of AI agents and distributed systems, has published a detailed walkthrough on building a parallel incident investigation system. The project leverages Upstash Box for isolated execution environments and Upstash QStash for asynchronous job dispatching. This approach solves a critical pain point in modern microservices: the inability to safely run multiple AI-driven investigations concurrently without resource contention or security risks.
The Core Architecture: Isolation is Key
The system is built around a small commerce application simulating an order lifecycle, instrumented with OpenTelemetry, Prometheus, Loki, and Tempo. When Grafana detects an anomaly, such as increased latency or repeated failures, it triggers an alert. The Incident Service receives this webhook and creates a transactional outbox entry. Instead of running the AI agent directly on the application server, the system publishes a job to QStash, which delivers it to a signed receiver. This receiver then provisions a dedicated Upstash Box for each investigation attempt, ensuring that every agent operates in its own isolated cloud container with a distinct filesystem and network stack.
Leveraging Upstash Box for Agent Execution
Upstash Box provides programmable cloud containers that act as the execution environment for the AI agents. The implementation uses the @upstash/box SDK to create boxes with specific configurations, including a Node.js runtime, a 'small' resource size, and a custom network policy. The network policy is particularly strict, allowing outbound connections only to upstash.com, the evidence origin, and api.openai.com if an agent is configured. This separation of concerns is vital: the Box provides the terminal and filesystem access, the Codex harness manages the agent loop, and the OpenAI model handles reasoning. The agent is restricted to read-only evidence, preventing it from remediating services or installing packages during the investigation phase.
Dispatching Jobs with QStash
The dispatch mechanism relies on Upstash QStash to handle asynchronous delivery with retries and request signing. The Incident Service uses a versioned InvestigationJob interface to structure the payload, which includes the incident ID, investigation ID, and a traceparent for observability. A separate publisher process claims pending outbox entries and uses QStashβs /v2/batch endpoint to publish multiple jobs in a single HTTP request. This batch processing capability allows the system to handle bursts of alerts efficiently. The signed receiver on the worker side verifies the message integrity before acknowledging it, ensuring that only authorized investigation jobs trigger the expensive process of provisioning new cloud containers.
Evidence Preparation and Security
Before an agent starts, the system prepares a scoped set of evidence. An allowlist defines which source files and runbooks are relevant to specific services, such as payment-timeouts.md for the payment service. The worker reads these files from the local repository, calculates a SHA-256 hash for each, and copies them into the Box workspace. The Box verifies these hashes upon startup; a mismatch triggers a Runbook identity mismatch error, preventing the agent from running on potentially corrupted or incorrect code. This ensures that the agentβs analysis is grounded in the exact version of the codebase that was running during the incident. The system also enforces strict size limits: individual documents cannot exceed 32 KB, and the total catalog is capped at 64 KB.
Key Takeaways
- Isolation Prevents Interference: Running AI agents in separate Upstash Box containers prevents resource contention and security issues when investigating multiple incidents simultaneously.
- Strict Network Policies: Configuring custom network policies in Box limits outbound access to only necessary domains, enhancing security for agent-driven tasks.
- Transactional Outbox Pattern: Using a transactional outbox with QStash ensures reliable, asynchronous dispatch of investigation jobs without blocking the main application flow.
- Evidence Integrity: SHA-256 hashing of source files and runbooks ensures agents investigate the correct codebase version, with automated failure if mismatches occur.
The Bottom Line
This implementation is a blueprint for moving AI agents out of the main application loop. By treating agent execution as a separate, isolated infrastructure concern rather than an inline code path, developers can build more robust, scalable, and secure incident response systems.