> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thoras.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# In-Place Resize Behavior

> How Thoras handles in-place pod resizing, what happens when a resize cannot complete, and the safety controls that protect your workloads.

When vertical scaling is configured with `update_mode: in_place` or
`update_mode: in_place_or_recreate`, Thoras patches running pods directly
through the Kubernetes resize API instead of recreating them. This page explains
what happens when that resize cannot complete and how Thoras responds depending
on your update policy.

For configuration details, see
[Update Policy](https://docs.thoras.ai/guides/vertical-pod-rightsizing.md#update-policy) and the
[AIScaleTarget reference](https://docs.thoras.ai/reference/ast-definition.md#update_policy).

## When a Resize Cannot Complete

After Thoras patches a pod's resource requests, the kubelet attempts to actuate
the change by adjusting the container's cgroup. Two situations can prevent this:

* **Insufficient node capacity.** An upsize requires more CPU or memory than the
  node can allocate. Kubernetes reports a `PodResizePending` condition on the
  pod. Its reason is `Deferred` when the resize could fit once other pods free
  capacity, and the kubelet retries it as capacity frees up. Its reason is
  `Infeasible` when the resize can never fit on the node, for example a request
  above the node's allocatable capacity.
* **Memory limit below live usage.** A memory limit decrease that would drop
  below the container's current working set is accepted by the API server (the
  patch succeeds), but the kubelet cannot safely shrink the cgroup. Kubernetes
  reports a `PodResizeInProgress` condition with reason `Error`, and the kubelet
  retries on every sync cycle.

In both cases, the pod keeps running, and any change the kubelet has not applied
stays at its previous value. `status.containerStatuses[*].resources` shows the
resources each container is running with, and
`status.initContainerStatuses[*].resources` does the same for sidecar
containers. No data is lost and no containers are restarted by the stall itself.

From chart 5.6.0 (platform 4.124.0), Thoras treats all three reasons as a
stalled resize. Earlier versions do not detect `PodResizePending`, so they never
treat a resize held back by node capacity as stalled.

## Behavior by Update Mode

How Thoras responds to a stalled resize depends on `update_mode`:

### `in_place`

Thoras never evicts or recreates the pod. If the kubelet cannot complete the
resize, the pod stays running with its current resources. The stall resolves on
its own when conditions change (for example, other pods are descheduled and free
up node capacity, or a new forecast lowers the recommendation).

This mode is appropriate for workloads where continuity is more important than
converging to the recommendation quickly.

### `in_place_or_recreate`

Thoras attempts in-place resize first. If a pod's resize of a resource listed in
[`recreate_resources`](https://docs.thoras.ai/reference/ast-definition#recreate_resources) stalls for
more than two minutes, Thoras evicts that specific pod so it can be recreated
with the correct resources by its controller (Deployment, StatefulSet, etc.).
Only the stalled pods are evicted; pods that resized successfully are left
alone.

`recreate_resources` lists only `memory` by default. If a CPU resize stalls and
`cpu` is not listed, the pod keeps running with its previous resource
allocation, as it does in `in_place` mode. Charts before 5.6.0 instead evict a
stalled pod whenever `memory` is listed, whichever resource stalled.

This is the recommended mode for most workloads because it combines the
low-disruption benefits of in-place resize with a reliable fallback.

## Safety Controls

Thoras applies several layers of protection when evicting pods as part of the
recreate fallback.

### PodDisruptionBudgets

Evictions use the
[Kubernetes Eviction API](https://kubernetes.io/docs/concepts/scheduling-eviction/api-eviction/),
which enforces your PodDisruptionBudgets. If a PDB would be violated, the API
server rejects the eviction and Thoras defers the remaining pods to a later run.
This is different from a rollout restart, which replaces the entire ReplicaSet
and is not gated by PDBs at the individual pod level.

### Disruption batching

Evictions are paced using the
[`disruption`](https://docs.thoras.ai/reference/ast-definition#disruption) settings on the
AIScaleTarget. Thoras applies changes in batches (default: up to 20% of replicas
at a time, with at least 60 seconds between batches) and counts pods that are
already terminating or not-Ready against the budget. This prevents stacking
disruption when a prior batch has not finished rolling.

### Circuit breaker

If pods keep coming back stale after eviction for the same recommendation (for
example, because the admission webhook is not applying the new values), Thoras
stops evicting. The circuit breaker opens after repeated no-progress cycles and
backs off exponentially before probing again. This prevents runaway eviction
loops.

## Observability

The following signals cover the disruption lifecycle discussed on this page:

| Signal | Type | What it tells you |
| - | - | - |
| [`thoras_disruption_circuit_breaker_open`](https://docs.thoras.ai/guides/metrics#disruption-circuit-breaker) | Prometheus gauge | Breaker is tripped: evictions stopped for this AST |
| [`thoras_ast_disruption_completions_total`](https://docs.thoras.ai/guides/metrics#ast-disruption-completions) | Prometheus counter | A disruption cycle finished (all stale pods converged) |
| `DisruptionInProgress` condition | AST status | A batch is actively rolling (`BatchStarted`, `BatchEvicted`, or `Complete`) |
| `DisruptionCircuitBreaker` condition | AST status | Breaker state (`Open`, `Closed`, `HalfOpenProbe`) |

Prometheus metrics are detailed on the [Monitoring Thoras](https://docs.thoras.ai/guides/metrics.md)
page. AST status conditions are visible via
`kubectl get ast <name> -n <namespace> -o jsonpath='{.status.conditions}'`.

## Operational Guidance

### Concurrent upsizes on the same node

When multiple pods on the same node receive an upsize at the same time, the node
may not have enough capacity for all of them. Thoras handles each pod
independently: pods that resize successfully stay in place, and pods that stall
follow the fallback path for the configured `update_mode`.

To reduce the likelihood of node-capacity stalls:

* **Reserve headroom on nodes.** If you use a node autoscaler like Karpenter,
  consider configuring a small amount of reserved capacity so upsizes have room
  to land without waiting for a new node.
* **Use `disruption` settings to pace changes.** Smaller batch sizes and longer
  intervals give the node autoscaler time to respond between batches.
* **Rely on forecasting.** Thoras predicts resource needs ahead of time, so
  upsizes are typically applied before a spike rather than during one, reducing
  contention.

### Choosing between `in_place` and `in_place_or_recreate`

| Consideration | `in_place` | `in_place_or_recreate` |
| - | - | - |
| Pod continuity | Guaranteed. Pods are never evicted by Thoras. | Pods may be evicted if resize stalls. |
| Convergence speed | Slower. Stalls resolve only when external conditions change. | Faster. Stalled pods are recreated with correct resources. |
| Best for | Stateful workloads, long-running jobs, workloads sensitive to restarts. | General-purpose services where converging to the recommendation matters more than avoiding a single pod restart. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.