feat(ami): M7 CP3 — AMI Originate waits for answer before running the app#159
Merged
Merged
Conversation
… app `handle_originate` ran the dialplan app/exten IMMEDIATELY after `driver.call()` put the INVITE on the wire, without waiting for the far end to answer. For a PJSIP origination that meant the app executed (and the leg often tore down) before the carrier's 200 OK — emitting activity before answer and orphaning a delayed 200. Now, for a PJSIP Originate, after the INVITE is sent the handler waits (up to the Originate Timeout) for the store channel to reach `Up` — which the 2xx path sets on answer — before running the app. On rejection/hangup/timeout it abandons the leg (CANCEL a still-pending INVITE via `cancel_or_bye_outbound_leg`) WITHOUT running the app and reports OriginateResponse: Failure. Flagship receiver-side proof: tests/cp3-originate-wait — the offline carrier DELAYS its 200 and tags every captured datagram phase=pre / phase=post. GREEN: the pre-answer window carries ONLY the INVITE (no ACK/BYE/CANCEL, no RTP); the answer is ACKed and the app's BYE arrive phase=post (timeline: INVITE@0.77s, 200@2.77s, ACK@2.77s, BYE@3.77s). Captured RED: disabling the wait -> the app runs immediately, the delayed 200 is orphaned (no post-answer ACK, no BYE) -> POST-ANSWER assertion FAIL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
M7 CP3 (flagship) — AMI Originate waits for answer before running the app
handle_originateran the dialplan app/exten immediately afterdriver.call()put the INVITE on the wire — before the far end answered. For a PJSIP origination
the app executed (and the leg usually tore down) before the carrier's 200 OK,
orphaning a delayed answer.
Fix
For a PJSIP Originate, after the INVITE is sent the handler waits (up to the
Originate
Timeout) for the store channel to reachUp— set by the 2xx answerpath — before running the app. On rejection/hangup/timeout it abandons the leg
(CANCEL a still-pending INVITE via
cancel_or_bye_outbound_leg) withoutrunning the app and reports
OriginateResponse: Failure.Flagship receiver-side proof (isolated offline-carrier harness)
tests/cp3-originate-wait/run.sh— the carrier DELAYS its 200 and tags everycaptured datagram
phase=pre(before it sent the 200) orphase=post:Nothing but the INVITE reaches the carrier in the 2-second pre-answer window; the
ACK and the app-driven BYE arrive only after the 200.
Captured RED
Disable the wait (app runs immediately):
The delayed 200 is orphaned (never ACKed) because the app ran and abandoned the
leg before answer → POST-ANSWER assertion RED.
cargo test --workspace --exclude pjsip-shim+clippy … -D warningsgreen.Rust 1.97.0. (CP3 is an end-to-end Originate-timing behavior; the harness is its
RED-capable proof.)