# Yunke PDF offline workflow acceptance

Part of the [AI Voice Agent](/docs/modules_handbook/shared/voice-agent/readMe.md).
This records software checks, not permission to enable a provider or live pilot.

## What it does

Connects the PDF's three funnel scenarios to the existing rule/scanner/job paths and
checks shared last-moment stop conditions. The new scenario tests use provider doubles
for Retell and App-mode Yunke; they do not create an App task or test a handset. Native
task/receipt/result/copy contracts have their separate fake-tested suites.

## How it works

| PDF scenario/check | Offline evidence | Real acceptance still required |
| --- | --- | --- |
| Registration with AI-call consent | Public `/register` → queued AI job → one call row; replay does not place twice, for both providers | Approved script/consent and a newly authorized owner-number call |
| One day before the session | BEFORE_EVENT, offset 1440; two scanner ticks claim one send, correct session/campaign | Scheduler/queue timing and device execution |
| Thirty minutes after start, not joined | AFTER_EVENT, offset 30, no_show_only and a live webinar; one claimed send | Real attendance webhook timing, outcome and follow-up samples |
| Late join/confirmed attendance | Zoom join or registration `STATUS_ATTENDED` suppresses the no-show call | Real event/attendance reconciliation |
| Changed session/registration | Removed/muted registration, cancelled or genuinely past session suppresses an unsubmitted call | Operator stop drill; accepted remote tasks need separate stop proof |
| Contact policy | DNC is checked at execution, before either provider | Approved production policy/configuration |
| Redial/final missed | Existing redial suite verifies confirmed misses only, one final missed message, source/arm/window/cap controls; new checks stop for removed/muted/attended registration | Verified Yunke non-answer/busy/voicemail formats and remote retry/expiry semantics |
| Unknown App creation | Existing split test now also mutes the registration before recovery; original uncertain attempt is retained without resending | Controlled queue/stop acceptance, not guessed cancellation |
| A/B report | Existing split/report regressions preserve assignment, lead denominators and unknown outcomes/cost/transcripts | Real pilot observations, bills and human comparison |

### Corrections exposed by acceptance

Initial negative checks reproduced missing execution-time guards in both providers:
queued/deferred AI jobs could still place after a registration was muted/removed or a
session cancelled/over; registration attendance alone did not spare a no-show call.
Queued redials also missed muted/removed registration. The shared job/service now
rechecks these facts, using the existing `SKIP_CONDITION`/attended outcomes. Person/session
stops do not manufacture a final missed-call follow-up.

Session expiry uses `Event::live_status`, the existing source of truth. A Zoom webinar
that is still live may overrun its scheduled end and remains callable; genuinely past
non-after-ended rules stop. Explicit AFTER_ENDED rules retain their post-session behavior.

Recovery of an already accepted/uncertain App task stays before these new unsubmitted-send
guards. It does not reclassify the remote task as cancelled, submit a replacement or switch
providers. Muting/blocking platform work is not proof that the phone's existing queue stopped.

Current combined evidence: **79 tests / 810 assertions** across six workflow, funnel,
redial, split and report files. Pint/diff checks pass; one existing PHPUnit XML deprecation
remains. All providers, queues, notifications and email are faked. The registration/scanner
checks are local application execution, with no vendor HTTP, dial, media download or send.

### Completed final offline acceptance

The report timestamp/cost checks are now complete: **6 tests / 39 assertions** pass.
An earlier start is unknown rather than an absolute positive wait; a zero wait stays zero.
Pending App rows without call IDs retain unknown cost. Mean cost per non-refused local
attempt is available only with complete cost coverage; observed IDs are labeled honestly.

The thank-you phone-correction path is also corrected: it reuses only the WhatsApp bonus
entry point and freezes the original event in server session context. It queues no new
AI/email/SMS/voice welcome or call-me offer, with either original AI checkbox value and
either provider. Existing pending initial calls still resolve the current phone normally;
correcting a number is not a new request to call. The existing verified-phone/account and
auto-sign-in protections remain in force. **48 tests / 376 assertions** pass across five
workflow, thank-you and adversarial identity files; four new cases first reproduced the
unwanted AI enqueue. No real message, call or provider request was sent.

The consolidated source `17513ad1b` run passes **483 PHP tests / 5854 assertions** plus
**15 frontend tests**. PHP outbound network was denied except local MySQL; frontend
outbound network was denied entirely. One existing PHPUnit XML deprecation remains.
Unchanged T9 component compilation/import evidence is retained rather than repeated.

The original-PDF page 5 confirmed-won check is complete: automatic funnel calls stop for
this lead's `FunnelJourney::STATUS_WON` in the same funnel. Queued redials stop quietly
even if their policy was removed, using frozen funnel context or the original send as a
legacy fallback. Three negative checks reproduced missing suppression before the fix.
Other funnels' wins and an explicit paid-path rule on an active journey stay independent;
an intermediate payment is not automatically a won deal. Already accepted/uncertain
vendor work is still not reclassified as cancelled. Historical conversions not recorded
in this funnel need owner cohort review; lack of a recorded win is not proof of no sale.

Final updated consolidated evidence is **491 PHP tests / 5880 assertions**, with the
same outbound restriction; the **15 unchanged frontend tests** remain passing evidence.
One existing PHPUnit XML deprecation remains. The
[external approval/live-test/deployment/stop pack](/docs/modules_handbook/shared/voice-agent/yunke-live-acceptance.md)
is prepared. No live gate is open. The App/Web candidate differs from the PDF's official
import/webhook route; owner/vendor acceptance of that route remains external.

## Reference usage

```sh
php vendor/bin/phpunit tests/Feature/Event/AiCallPdfWorkflowTest.php tests/Feature/Event/FunnelAiCallAutomationTest.php tests/Feature/Event/FunnelAutomationReminderTest.php tests/Feature/VoiceAgent/AiCallRedialTest.php tests/Feature/VoiceAgent/AiCallSplitTest.php tests/Feature/VoiceAgent/AiCallPilotReportTest.php
```

Keep the test/runtime boundary: memory-only test gates are not a live release. The prior
single owner call permission was consumed; another task/call/download needs separate
approval. Supported completed-call fake contracts do not validate unknown Yunke intent
or non-answer enums, lawful contact records, hardware stability, deployment or a pilot.

## Related files

- `tests/Feature/Event/AiCallPdfWorkflowTest.php` — both-provider PDF scenarios and stale-work stops.
- `app/Jobs/Automation/SendFunnelAiCall.php` — original-task recovery and execution-time guards.
- `src/VoiceAgent/Services/AiCallRedial.php` — registration/attendance/session checks before retry.
- `tests/Feature/VoiceAgent/AiCallRedialTest.php`, `AiCallSplitTest.php`, `AiCallPilotReportTest.php` — shared pilot regressions.
- [Funnel automation](/docs/modules_handbook/manage/events/funnel-automation/readMe.md).
- [Pilot routing](/docs/modules_handbook/shared/voice-agent/pilot-routing.md).
- [Recording copies](/docs/modules_handbook/shared/voice-agent/yunke-recordings.md).
- [Progress and remaining acceptance](/docs/modules_handbook/shared/voice-agent/yunke-pdf-progress.md).
- [External acceptance and release pack](/docs/modules_handbook/shared/voice-agent/yunke-live-acceptance.md).
