11 November 2026

Debugging a production crashloop from my phone

How a health-check alert became an investigation into async Python, memory, Kubernetes scaling, and a GitOps configuration that existed in Git but not in the cluster.

The alert arrived on my phone.

This is the full investigation. I wrote separately about the async Python defect we found along the way.

BetterStack was reporting timeouts against Immigranta’s production liveness endpoint:

GET /api/health/live
Timeout: no headers received

The endpoint was deliberately shallow. It did not query Postgres, Redis, an embedding provider, or an LLM. It returned a small JSON response to answer one question: is the API process alive?

That made the symptom look simple. It was not.

Most of the initial investigation happened from that phone through Claude Code on the web. I inspected the application, queried the BetterStack log archive with ClickHouse SQL, and posted findings into the pull request. I moved to a laptop only when the investigation needed direct access to the Kubernetes cluster.

The laptop did not merely confirm the leading theory. It overturned it.

The first plausible answer

Immigranta’s API used a single Uvicorn worker. During the code review, I found two synchronous SDKs being called inside asynchronous request paths:

  • The embedding client made a blocking HTTPS call during every RAG query.
  • The Stripe client made blocking network calls during checkout and billing operations.

In an asynchronous Python server, a blocking call on the event-loop thread can stop that worker from serving every other request. That includes a simple liveness request.

The theory fit several observations:

  • Production received traffic while staging received very little.
  • The failing endpoint did not use Postgres, so a shared database did not explain why only production timed out.
  • A slow embedding or Stripe request could temporarily prevent the single worker from responding.

I moved those calls into worker threads with asyncio.to_thread.

query_embedding = await asyncio.to_thread(
    self.embedder.embed_text,
    rewritten.rewritten_query,
)
checkout_session = await asyncio.to_thread(
    gateway.create_checkout_session,
    params=params,
    idempotency_key=checkout_idem_key,
)

That was a correct fix. It was also not the incident fix.

The logs rejected the traffic theory

The first few alerts made the failure look intermittent. The archived logs told a different story.

I queried one startup marker from every application boot. The table name below is redacted; it must be replaced to run the query:

SELECT
  dt,
  JSONExtract(raw, 'message', 'message', 'Nullable(String)') AS event,
  JSONExtract(raw, 'context', 'system', 'pid', 'Nullable(Int64)') AS pid
FROM <redacted_log_table>
WHERE
  _row_type = 1
  AND dt BETWEEN '2026-06-10 15:00:00' AND '2026-06-11 13:00:00'
  AND JSONExtract(raw, 'message', 'message', 'Nullable(String)')
      LIKE '%Sentry/GlitchTip initialised%'
ORDER BY dt ASC

The query returned 192 boot markers between June 10 at 15:22 UTC and June 11 at 12:42 UTC. There were usually four to six boots in each half-hour window. A new process appeared approximately every six minutes for more than 21 hours, then the pattern ended around 12:42 UTC.

I initially called these “restarts.” That wording turned out to matter. The logs proved repeated boots, but logs alone could not tell me whether Kubernetes was restarting a container inside one pod or replacing the pod itself.

More importantly, the application was almost completely idle.

There were no chat requests, no billing requests, and no RAG pipeline activity overnight. Every process completed startup, logged a cleanup run, sat silent, and disappeared. The archive contained no application errors or graceful shutdown messages.

A traffic-induced event-loop block does not run on a six-minute metronome at 3 a.m. when there is no traffic.

The first theory was no longer credible as the cause of the repeated boots.

The second plausible answer

The new pattern looked environmental:

clean boot -> idle for about six minutes -> silence -> clean boot

With no traceback and no shutdown log, I suspected a hard kill. The most obvious candidate was an out-of-memory kill against the pod’s 500 MiB memory limit.

That theory also sounded reasonable. The service initialized LLM clients, embedding infrastructure, database pools, and other production dependencies. A process can start successfully, grow over several minutes, cross its limit, and be killed without producing an application traceback.

But it was still a theory formed from outside the cluster.

The cluster changed the vocabulary

From the laptop, I checked the running pod’s memory use and status directly in Kubernetes.

Memory usage was approximately 276 MiB against a 500 MiB limit. There were no OOMKilled or Evicted states in the pod status or events.

Then one field in kubectl describe pod changed the direction of the investigation:

Restart Count: 0

The containers were not restarting. Each cycle had created a new pod with a new name.

That distinction is easy to lose when application logs are the only evidence. A new process appears as a “restart” in the log archive either way. Kubernetes has a more precise account:

  • The same pod name with an increasing restart count means the container is restarting.
  • A new pod name with restart count zero means the workload is being replaced or rescaled.

The events explained what was actually happening. KEDA scaled the deployment from one replica to zero after its idle cooldown. Almost immediately, ArgoCD self-heal restored the Helm-declared replica count of one.

The system repeated this sequence:

flowchart TD
    A["Deployment has 1 pod"] --> B["No traffic during KEDA cooldown"]
    B --> C["KEDA/HPA writes replicas = 0"]
    C --> D["Kubernetes deletes the pod"]
    D --> E["ArgoCD compares live state with Helm replicaCount = 1"]
    E --> F["ArgoCD self-heal writes replicas = 1"]
    F --> G["Kubernetes creates a new pod"]
    G --> A

The six-minute metronome was not a crashloop. It was a reconciliation loop between two controllers with different instructions.

The configuration was correct in Git

The repository already contained the intended protection:

ignoreDifferences:
  - group: apps
    kind: Deployment
    jsonPointers:
      - /spec/replicas

This tells ArgoCD not to self-heal the deployment’s replica count because an autoscaler owns that field.

The same change that enabled KEDA scale-to-zero on June 5, 2026 also added this rule. Yet the live ArgoCD Application did not contain it.

The reason was a gap in the GitOps boundary. ArgoCD continuously reconciled the Helm chart referenced by the Application, so the KEDA configuration reached production. At the time, however, nothing continuously reconciled the Application resource itself. It had originally been applied manually.

Git therefore contained both halves of a correct change:

  • Enable KEDA with minReplicas: 0.
  • Tell ArgoCD to ignore /spec/replicas.

Only the first half had reached the cluster.

The GitOps system was faithfully reconciling from a stale set of instructions.

The fix

I reapplied the production Application manifest to the ArgoCD control cluster.

This made the live ArgoCD configuration match Git and removed replica drift from the differences ArgoCD should self-heal.

We then made a separate product and reliability decision to keep one warm production replica:

replicas:
  min: 1
  max: 3

The timestamps matter. The live Application received ignoreDifferences at 11:54 UTC. Production moved to minReplicas: 1 at 12:41 UTC, and the last archived boot marker appeared around 12:42 UTC as that deployment took effect.

The evidence therefore supports two separate conclusions:

  • The controller conflict was caused by a stale live Application that did not ignore autoscaler changes to /spec/replicas.
  • The final end of scale-to-zero activity coincided with moving production to a warm minimum of one replica.

I do not want to turn those into one magic command after the fact. Reapplying the Application corrected the GitOps configuration. Raising the minimum removed scale-to-zero and its cold starts from a monitored, user-facing production API.

The production checks after the change showed:

  • One healthy pod.
  • Zero container restarts.
  • Approximately 276 MiB used against a 500 MiB limit.
  • A KEDA HPA with one to three replicas.
  • The ArgoCD Application contains ignoreDifferences.

What I learned

Logs report symptoms at their own layer

The application archive showed 192 boots. It could not tell me that Kubernetes was creating 192 different pods. The cluster’s object identity and events were the missing evidence.

A good fix can be unrelated to the incident

Moving blocking SDK calls off the event loop was still necessary. Rejecting it as the root cause did not make the code change wrong. Incident work requires separating “this is a real defect” from “this defect produced today’s failure.”

A fixed cadence points to a scheduled mechanism

Random application failures rarely occur at nearly identical intervals for 21 hours. Our pod births repeated roughly every six minutes, even overnight with no traffic. That interval closely matched KEDA’s idle cooldown plus the time needed for ArgoCD to reconcile and start another pod.

The cadence narrowed the search. Instead of asking only, “What code could crash this process?”, I should also have asked, “What component is configured to act every few minutes?” In Kubernetes, that means checking autoscaler cooldowns, health-probe intervals, controller reconciliation, scheduled jobs, and lease renewals. The repeating interval was not background detail. It was a fingerprint of the mechanism causing the loop.

Git is not the live system

Seeing the right YAML in a repository proves intent, not deployment. For every important configuration object, ask what reconciles that object and where the reconciliation chain begins.

Use a control group

A sibling service in the same cluster used minReplicas: 1 and remained stable. Development had KEDA disabled. Those comparisons narrowed a broad “production-only” mystery to the configuration that differed.

Monitoring samples reality

BetterStack recorded 20 incidents across the two days, but the log archive contained 192 boot markers. A three-minute uptime probe can establish that users experienced downtime; it cannot reconstruct every transition in a faster control loop.

The post-mortem changed the GitOps topology

Reapplying one Application fixed the stale live configuration, but it did not remove the process that created the drift. The incident could recur whenever a future pull request changed an ArgoCD Application manifest and nobody manually applied it.

The durable post-mortem action was to create a parent ArgoCD application named root-prod. It watches the directory containing the production service applications and reconciles those Application resources into the ArgoCD control cluster.

flowchart LR
    G["Git: argocd/application/prod"] --> R["root-prod Application"]
    R --> I["immigranta-backend-prod Application"]
    R --> M["mcplambda-backend-prod Application"]
    R --> O["Other production Applications"]
    I --> H["Helm chart + production values"]
    H --> K["Production Kubernetes resources"]

Before root-prod, Git managed the service resources below each Application, but not the Application objects themselves. After root-prod, the reconciliation chain begins one level higher. A future change to ignoreDifferences, the destination cluster, sync policy, or value-file path is now deployed by ArgoCD instead of depending on human memory.

That was the real post-mortem output: not only correcting the broken state, but making that class of drift harder to create again.

From alert to prevention

The phone was useful because it let me start immediately. I could inspect code, query archived logs, and disprove the traffic theory before reaching a laptop. The cluster was decisive because it exposed pod identity, restart counts, events, and controller ownership.

The complete investigation crossed those layers:

flowchart LR
    A["Alert<br/>Phone notification<br/>Source review"]
    B["Logs<br/>No traffic<br/>Six-minute cadence"]
    C["Cluster<br/>Restart Count = 0<br/>Controller conflict"]
    D["Prevention<br/>Apply ignoreDifferences<br/>minReplicas = 1<br/>root-prod app-of-apps"]
    A --> B --> C --> D

The incident started with a plausible answer in the application code. It ended with a change to how production configuration is reconciled.

That is the standard I want from a post-mortem: explain what happened, preserve the evidence that overturned the wrong answers, and change the system so the same operational gap does not depend on someone remembering a command next time.

If you see a similar pattern

Start with the rhythm of the failure. A new application boot every few minutes, including quiet hours, points toward a timer or controller. Compare boot times with requests and with Kubernetes events before blaming a busy endpoint.

Then check what Kubernetes actually replaced. If pod names keep changing while each pod’s restart count stays at zero, Kubernetes is creating new pods. A container crash inside one pod would increase that pod’s restart count. Check memory use and termination reasons before concluding that an out-of-memory kill occurred.

If the number of replicas keeps moving between zero and one, find every system allowed to change that number. An autoscaler and a deployment controller can each be working as configured while repeatedly undoing each other’s changes.

Finally, compare the live controller configuration with Git. A correct file in the repository only helps if something applies updates to that file’s resource. Trace the chain all the way from the parent application to the workload it manages.

In our case, KEDA scaled the idle service to zero and ArgoCD restored the replica count to one. Applying the missing ArgoCD rule resolved that conflict. Keeping one warm replica addressed the product’s need for a responsive API. We also made the parent ArgoCD application manage its child applications, so future changes to their settings are applied automatically.

Comments