Detect an in-dialog re-INVITE by checking that the INVITE contains the same Call-ID and From tag as the established dialog; respond immediately with 100 Trying to prevent retransmission timeouts while you process the new SDP offer.
Inspect the new SDP: a hold is signaled by a=sendonly or a=inactive in the offer (or an IP address of 0.0.0.0 in the connection line for older implementations); respond with 200 OK and a=recvonly or a=inactive in the answer accordingly and pause media sending.
For a codec change, compare the offered codec list against the established codecs; if the intersection is non-empty, select the new preferred codec, update your RTP sessions, and include the updated codec in the 200 OK answer.
After sending 200 OK, wait for the ACK to confirm the renegotiation is complete before switching media; do not change the RTP stream until the ACK arrives.
If your endpoint cannot accept the re-INVITE (e.g., unsupported codec, resource unavailable), respond with an appropriate 4xx or 5xx response; the existing media session continues unchanged as per RFC 3261.
For attended transfer, a re-INVITE from the transferring party may arrive with a Replaces header referencing a different dialog; validate the Replaces dialog exists and replace the media session atomically.
Known gotchas
Glare occurs when both ends send a re-INVITE simultaneously; RFC 3261 prescribes that the side with the higher SIP From tag should retract its re-INVITE with a 491 Request Pending — handle 491 responses by retrying after a random back-off.
Some SIP implementations send re-INVITEs without a SDP body (an offerless re-INVITE); in this case the 200 OK must contain the SDP offer and the ACK must contain the SDP answer — reverse of the normal flow.
Failing to send the ACK after receiving a 200 OK for a re-INVITE causes the remote UA to retransmit 200 OK repeatedly and eventually terminate the dialog with a BYE after a timeout.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp