# LiveKit SIP MaxCallDuration Not Being Enforced After A Restart

By Rokas Remeika. Published 25 November 2026.

The outbound maximum call duration is enforced by the LiveKit SIP service, not by your application logic. If your container deployment uses a floating image tag, any routine host restart or background pull can silently upgrade the SIP process to a build that handles duration fields differently. To prevent this, pin the SIP container image by its SHA256 digest rather than a tag. This ensures the process enforcing your call duration cap, trunk fields, and dispatch semantics never changes without a deliberate deploy.

## Symptoms

- A scheduled call that should have been capped at a few minutes runs for hours and bills for hours.
- SIP behavior changes on your server, even though you have not deployed any new application code.
- A specific trunk field you set during placement stops being honored.
- A system default you relied on moves, breaking your dispatch rules.
- The misleading observation: you suspect a code regression in your voice agent worker, because that is where you configure the call limits, even though no application deploy occurred.

## What is actually happening

The outbound maximum call duration is enforced by the SIP service, not by your application process. Your code passes a duration limit when it makes the placement request. The SIP process is the actual component that holds the timer, tracks the leg, and sends the teardown signal when that timer expires.

If your compose file or orchestration manifest follows a floating tag, you do not control what software is running. Any host restart, container recreation, or routine background pull can move the SIP process to a newer build.

When that happens, the handling of that duration field can differ. A regression or a semantic change in the SIP process means the only thing standing between a wedged line and a multi-hour carrier bill is now code nobody reviewed. Dispatch rule semantics and trunk field names sit in the exact same blast radius. Because the change occurs inside the SIP container image rather than your application repository, the failure produces no git diff or deployment log on your side.

## How to confirm it

1. Inspect the running container digest on your host using `docker inspect <container_name>`. Expect to see a specific `sha256` hash in the `Image` field; if it differs from your intended version hash, a silent update occurred during a restart.
2. Compare the running container's creation timestamp against the spike in your telephony billing. Expect the creation time to precede the billing spike by minutes; a tight correlation confirms the new image build introduced the duration bug.
3. Look at the raw placement request payload sent by your application code on a failed call. Expect to see the `max_duration` field populated correctly; if the field is populated but the call ran past it, the SIP service ignored the limit.
4. Compare the running container digest with the digest recorded in your deployment logs. Expect the digests to differ; a mismatch confirms that an unverified build was pulled during a host restart or recreate.

## How it works

I pin the SIP image by content digest rather than by a floating tag. A tag points to a moving target. A digest points to a cryptographic hash of the image content. When you pin by digest, the container runtime has strict instructions: run these exact bytes, and never pull anything else, even if the host restarts.

In the compose file, I put the reason for the pin directly in a comment next to the digest string: this service enforces the outbound duration cap, so its version must not drift silently. Putting the explanation inline stops future engineers from cleaning up the file by reverting to a floating tag.

Next to that reason, I put the exact shell command that resolves a new digest. When it is time to upgrade the SIP service, updating the infrastructure is a deliberate two-step process. Somebody runs the command, pastes the new digest into the file, and reviews the change. The upgrade happens because a human decided to apply it, not because a host restart triggered a pull on your behalf.

For the duration limit itself, I compute the outbound duration cap as the expected call length plus a margin. You compute the cap as the expected call length plus a margin, then clamp it to a hard ceiling well below the server-side default. That ceiling sits well below the unconfigured server-side default. The SIP process enforces this clamped value at the transport layer, overriding the default behavior to protect your telephony billing.

## What I would check first

1. Check whether the running SIP container digest matches the release digest recorded at deploy time. If the digests match, it rules out image drift and points to missing or non-positive duration parameters sent by your application code. If a digest is present, it rules out version drift as the cause of the immediate failure.
2. Check the creation timestamp of the currently running SIP container against the start time of the runaway calls. If the container was created immediately before the anomalies began, it rules out an application regression and confirms the runtime environment changed. If the container has been running for months, it rules out a host restart and points toward your application logic.
3. Check the application logs to see if the duration field was passed as a finite, positive number. If the field was falsy or omitted, it rules out a SIP service failure and confirms the application failed to arm the transport-level timer. See [A Wedged Call Bills Until the Server's 24-Hour Default When a Falsy Duration Is Dropped](/blog/a-wedged-call-bills-until-the-servers-24-hour-default-when-a-falsy-duration-is-d/) for the fix.
4. Check the trunk provisioning state inside Redis. If the trunk configuration is missing or malformed after a restart, it rules out the duration cap as the primary fault and points to state loss. See [LiveKit SIP Trunk Does Not Exist After A Container Recreate Or Host Reboot](/blog/livekit-sip-trunk-does-not-exist-after-a-container-recreate-or-host-reboot/) for the recovery steps.

## The difference between policy drift and feature drift

The general rule for infrastructure pinning is straightforward. You pin by digest wherever the component enforces a policy rather than merely implementing a feature.

Feature drift is an application problem. If a new version of a media component introduces a bug in media routing, that failure shows up in your testing pipeline. It degrades the user experience, but you catch it quickly because the symptoms are loud and immediate.

Policy drift is a business problem. When a service enforces limits, routing rules, or cost caps, a change in its behavior does not necessarily break the call. The call might sound perfectly fine to the user, while quietly ignoring the maximum duration ceiling. Feature drift shows up in testing; policy drift shows up in the carrier invoice. Because the SIP service sits directly on the boundary that generates telecom charges, it is a strict policy enforcement point. Its version must be cryptographically locked.

## Pinning the media server alongside SIP

The logic that applies to the SIP service also extends to the rest of the realtime topology. When I run this stack, I pin the media server by digest too.

In a production environment, as discussed in [Self-hosted LiveKit is four services, and the three nobody mentions are where outages come from](/blog/self-hosted-livekit-is-four-services-and-the-three-nobody-mentions-are-where-out/), the topology consists of the media server, the SIP service, Redis, and a TLS terminator. They all run on the host network namespace.

While a drifting media version can cause routing failures or connection drops, SIP is the only one where version drift converts directly into lost money. Pinning the media server stabilizes your network paths. Pinning the SIP server protects your bank account.

## Instrumentation for runaway calls

Observability around call duration requires a specific approach. If you have a duration surface at all, read its tail rather than its mean.

The mean call length hides failures. If you process hundreds of normal three-minute calls, a single call that wedges and runs for six hours will barely move the average. The runaway is always in the tail. If you have a duration surface at all, read its tail rather than its mean.

In addition to tracking the tail length, capture the actual container digest each service resolves to at deploy time. Do not infer the version from the tag. Record the resolved `sha256` string in your deployment logs. When a billing anomaly occurs, comparing the running hash to the deployed hash provides an instant, definitive answer about whether the infrastructure moved underneath you.

## Common questions

**Why did my SIP max call duration stop working without a deploy?**

Your container runtime pulled a newer image version behind a floating tag during a host restart. The new SIP process build handles the duration field differently, ignoring the cap you set.

**Does the voice agent application enforce the call duration limit?**

No, the application code only passes a duration value during placement. The SIP service is the process that actually tracks the timer and tears down the leg when it expires.

**Should I pin all self-hosted infrastructure by digest?**

Pin by digest wherever the component enforces a policy rather than merely implementing a feature. Feature drift shows up in your testing pipeline, but policy drift shows up directly on your carrier invoice.

Canonical URL: https://www.dreamchasers.lt/blog/livekit-sip-maxcallduration-not-being-enforced-after-a-restart
