Skip to content

AI-3597: a scheduled call's turn refused for money fails the run - #2277

Merged
kanat merged 16 commits into
mainfrom
kanat/ai-3597-voice-money-refusal
Nov 24, 2026
Merged

kanat merged 16 commits into
mainfrom
kanat/ai-3597-voice-money-refusal

Conversation

@kanat

@kanat kanat commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

A phone task whose call was answered, and whose turn the model then refused for money, said nothing to the user: the agent sat silent on the call until the user hung up or scheduledCallLimit passed, and the run settled delivered to phone (found in the review of #2191, R1.8). Kanat's money rule for scheduled deliveries (AI-2055, AI-3183) says such a delivery ends failed, final, under the refusal's money code, and a transient money check (spend_check_unavailable) is retried. #2191 did that for the conversation, text and thread channels; this PR applies the same rule to voice (orchestrator ruling on AI-3597, applying Kanat's AI-2055 decision to the placed-call path).

Root cause: carryOutAnswered (acceleration/internal/api/scheduled_delivery.go:1272 on dff7498) drained the call session's events and never read them. The agent.Error that a money-refused model call ends a turn with (agent.Agent.fail, internal/agent/agent.go:4816) reached it and was dropped.

How it works

DeliverScheduledTask -> deliverChain -> deliverByPhone
└─ TakeCall (the run rings once)
   ├─ taken already -> fail final under the reason the call ended
   │                  (a retry after a refused turn: the money code)
   └─ placeCall
      ├─ phone.Call refused for money -> unpaid: money code,
      │                                  final unless transient
      └─ carryOutOnCall
         ├─ session cannot open for money -> unpaid: money
         │  code on the run, final (callEnded)              (new)
         └─ holdCall -> carryOutAnswered
            FollowUp the task, then read each call event:
            ├─ refused for money before the agent answered
            │   -> turnRefusal -> unpaid -> agent hangs up  (new)
            │   final (callEnded), whether the money was refused
            │   or could not be checked: the call is rung once
            ├─ agent.Responded -> answered
            ├─ refused for money after that -> a later turn,
            │   call held, delivered                        (new)
            └─ call ends or reaches its limit -> delivered

It reuses turnRefusal, unpaid and deliveryReason; no new helper. callEnded makes every failure after the call was placed final: a placed call is rung once.

Path table

Path First attempt Retry Test
Call refused for money before it is placed failed, money code, final (unchanged) none TestAPhoneTaskOfAnOrganizationWithNoCreditIsNotRetried (existing)
Answered, turn refused for money failed, money code, final; agent hangs up none TestACallWhoseTurnIsRefusedForMoneyFailsUnderTheMoney
Answered, turn refused: money cannot be checked failed, spend_check_unavailable, final; agent hangs up; the call stays taken none: rung once TestACallWhoseTurnIsRefusedWhileMoneyCannotBeCheckedFailsFinalAfterOneRing, TestACallWhoseTurnIsRefusedIsRungOnceWhateverTheAttemptsBetweenFailedUnder
Placed, session cannot open: money cannot be checked failed, spend_check_unavailable, final; the call stays taken none: rung once TestACallWhoseSessionCannotOpenWhileMoneyCannotBeCheckedFailsFinal, TestACallWhoseSessionCannotOpenIsRungOnceWhateverTheFirstChannelFailedUnder
Placed, session cannot open for money failed, money code, final; the run keeps the code none TestACallWhoseSessionCannotOpenForMoneyFailsUnderTheMoney
Answered, turn fails not for money delivered by phone when the user hangs up (unchanged) none TestACallWhoseTurnFailsNotForMoneyIsDelivered
Answered, turn answered delivered by phone (unchanged) none TestACallWhoseTurnIsAnsweredIsDelivered
Answered, a later turn refused for money delivered by phone (unchanged) none TestACallWhoseLaterTurnIsRefusedForMoneyIsDelivered

A transient money refusal on a placed call is final too (orchestrator decision on AI-3597, round 2): a phone call is the most intrusive channel, a bounded second ring would need a per-run record the scheduler does not have, and two review rounds found paths where the user was rung more than twice. So the call is rung once, whatever refuses it, and every failure not about money keeps the call taken as before (deliverByPhone, AI-2021).

User-facing note

A phone task whose answered call's turn is refused for money no longer keeps the user on a silent call and settles delivered: the agent hangs up and the run fails under the refusal's code, such as insufficient_credits, not tried again. Under spend_check_unavailable it fails under that code, final, as well: a placed call is rung once. A placed call whose session cannot open for money fails under the refusal's code too. A refusal after the agent answered on the call is a later turn's, and the task stays delivered. The scheduled-tasks skill's error table says the same.

Validation

  • New tests in TelnyxUnpaidSuite (scheduled_unpaid_test.go): a placed call on a ringing test edge, with the organization's real money state (spent credit; the Redis that holds are shared through taken down).
  • On the base (scheduled_delivery.go from dff7498), the two refusal tests fail ("the call was never let go") and the three controls pass; on the head all five pass.
  • Mutations: one batched script (mut/run.sh, mut/run2.sh for three mutants that did not build or apply on the first pass), run against TestTelnyxUnpaidSuite -testify.m TestACall:
Mutant in carryOutAnswered Killed by
base scheduled_delivery.go both refusal tests
refusal ignores answered TestACallWhoseLaterTurnIsRefusedForMoneyIsDelivered
refusal returns nil both refusal tests
refusal answered as failed (undeliveredFinally(ReasonFailed, …)) both refusal tests
answered set on any event but agent.Responded both refusal tests
greeting counts as answered equivalent, clause dropped in round 1: on a call the greeting is agent.Said, never agent.Responded

Round 0 (orchestrator decisions D1.1, D1.2)

  • D1.1: a transient money refusal on a placed call gives the call back (callEnded -> ReleaseCall); the retry's turn runs under the rerun's id (replyCommand), and that rerun refused again is final. Mutants killed: never give back, always give back, no rerun id, rerun not final.
  • D1.2: a call session that cannot open for money records the money code on the run (carryOutOnCall -> unpaid). Mutant killed: the money branch removed. A follow-up refused at once for money (followUpWithin) is not changed: no money check runs synchronously in Session.FollowUp, so no such refusal reaches it.

Rounds 1 and 2

  • Round 1 (R1.2, R1.3): the refusal keeps its own failure, so refusedTurn holds and the walk over the channels ends at the call (asserted in TestACallWhoseTurnIsRefusedForMoneyFailsUnderTheMoney); the greeting clause is dropped (equivalent: on a call the greeting is agent.Said, never agent.Responded).
  • Round 2 (R2.1): the one-time give-back of a call refused while the money could not be checked (D1.1, R1.1) derived "given back already" from the last attempt's reason, so the user could be rung on three or four attempts (channels [text, call] with the text failing first; an attempt between failing before it rang). The give-back and the _call_r1 rerun are removed: a call's turn refused for money, transient or final, ends the run final under its money code after one ring (callEnded). Tests TestACallWhoseTurnIsRefusedIsRungOnceWhateverTheAttemptsBetweenFailedUnder and TestACallWhoseSessionCannotOpenIsRungOnceWhateverTheFirstChannelFailedUnder are the reviewer's two rows; the give-back restored makes all four call tests of this PR fail.

Merge order

Independent of #2272 (AI-3595) now: the call has no retry, so no earlier reason reaches it. Merge main in before merging.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE

kanat and others added 3 commits November 23, 2026 18:57
The root CHANGELOG is written once per release (.claude/skills/pr/SKILL.md); the note is in the PR body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
@github-actions github-actions Bot added the docs label Nov 23, 2026
kanat and others added 5 commits November 23, 2026 20:20
…its retry

A placed call whose answered turn is refused because the organization's money
could not be checked is given back to its run (ReleaseCall), so the retry
places the call again and runs the turn again under the rerun's id
(replyCommand). The rerun refused as well fails the run, final, so the user is
rung twice at most. A final refusal for money keeps the call taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
… code

carryOutOnCall's failed Create saved delivery_failed on the run (callEnded)
even when the session was refused for money; it now fails under the
refusal's own code (unpaid), final unless the money could not be checked, and
a worker that takes the run over reads that code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 62c4521f4 merged onto main at e1be8e3b1, in a scratch worktree. CI: this is a draft, so go and integration are skipped and CodeQL Analyze (go) is pending. CI runs at gh pr ready. On the merged tree, TestTelnyxUnpaidSuite, TestScheduledTasksSuite and the internal/api unit tests pass, and vet and gofmt are clean. Base control: with main's scheduled_delivery.go, the 3 not-money and answered tests pass (their ends are unchanged) and the 4 refusal tests fail.

[Question] R1.5 This PR should merge after #2272. On main today, a worker that takes the run over during the retry wait finds run.Error NULL after ReleaseCall. Then replyCommand returns _call, because that turn failed and the reason is not money. The FollowUp is a Duplicate (session.go:1123), so the agent says nothing on the second call and the run ends delivered when the user hangs up. R1.1's fix also reads Earlier. #2272 at 502b8f420 fills that gap: its SetAttemptReason writes error only while session_id='', and ReleaseCall guarantees that. So the two PRs fit together, provided #2272 lands first. The orchestrator decides the order.

Checked and sound:

  • A final money refusal still rings once (both final tests keep the SessionID).
  • A transient refusal of an answered turn ends the walk on the first attempt.
  • After a transient Create refusal, the walk goes on to the next channel, as base does for any Create failure.
  • Testing only that _call_r1 exists, together with answeredOn, is enough (the no-rerun-id mutant is killed).
  • On D1.2, the fixer's dispute about the followUpWithin half holds: FollowUp runs no money check synchronously (session.go:1106-1133, agent.go:993-1009, native.go:77-96).

Verdict: request changes, for R1.1 (a user can be rung up to 4 times when the money check is down).

if !errors.As(err, &failure) {
return err
}
if !failure.Final {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Blocker] R1.1 Nothing limits how often a placed call is given back. Every transient money refusal releases the call, so a user can be rung on all 4 attempts (1 + DeliveryRetries). Two cases:

  • The call's session cannot open while money cannot be checked (carryOutOnCall, :1194). Each attempt dials the user with phone.Call and then Create is refused. The probe repeats that refused Create attempt by attempt and gets rings=4.
  • The turn is refused on attempt 1, and the session is refused on attempt 2. Attempt 2 comes back non-final and is given back, so a third TakeCall succeeds.

Both break "a user is rung at most twice", which this PR's body and the skill row both claim. On the base, a Create failure was final: one ring.

Fix: give the call back once. If moneyCode(delivery.Earlier) holds, make the failure final and record the reason:

if !failure.Final && moneyCode(delivery.Earlier) {
	failure.Final = true
}

With that in place, the rerun branch in carryOutAnswered can go. I checked this sketch: all 7 TestACall* tests pass, and both probes end at 2 rings.

Test row for TelnyxUnpaidSuite. Call callOn, then uncheckable, then dial. Expect a failure that is not final, with SessionID empty. Then set Earlier=spend_check_unavailable, call takeCall, then dial again. Expect a final failure, with the SessionID of the second call kept. This row fails on head (rings=4) and passes with the sketch. It also kills mutant RM1 (R1.3).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d6eab92: TestACallWhoseSessionCannotOpenWhileMoneyCannotBeCheckedIsGivenBackOnce (fails with the moneyCode(delivery.Earlier) clause reverted, and with RM1). Head 7b9031c.

}
if refusal := turnRefusal(event); refusal != nil && !answered {
if rerun {
return undeliveredFinally(deliveryReason(refusal), refusal)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Should fix] R1.2 This line wraps the refusal in a new scheduling.Failure. Failure has no Unwrap (scheduler.go:102-108), so refusedTurn returns false for this error. A probe confirms it: refusedTurn is true for the first attempt's refusal and false for this one. As a result, deliverChain (:313) does not stop at the call. For a task with channels [phone, sms], the next channel runs a new turn after the user was rung twice. If that channel fails non-final, final = final && ... turns the run non-final. That contradicts "that rerun refused as well fails the run, final".

Fix: keep the refusal's own Failure and set Final, or take R1.1's fix and delete this branch.

Test row: add s.True(refusedTurn(outcome.err), "the walk ends at the call") to TestACallWhoseTurnIsRefusedAgainOnItsRetryFailsTheRun. I checked it: it fails on head and passes with the R1.1 sketch.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0cfa2a1: s.True(refusedTurn(outcome.err)) in TestACallWhoseTurnIsRefusedAgainOnItsRetryFailsTheRun (fails with the rerun branch restored). Head 7b9031c.

}
return refusal
}
if reply, ok := event.(agent.Responded); ok && reply.Purpose != agent.PurposeGreeting {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Should fix] R1.3 Three mutants survive:

  • RM1: in carryOutOnCall, replace unpaid(err) with undeliveredFinally(deliveryReason(err), err). Nothing tests the give-back of a transient Create refusal. The R1.1 test row kills it.
  • RM6: in carryOutAnswered, the first-attempt return refusal keeps Reason and Final but drops turnRefused. Then no test checks that the walk ends at the answered call. Row: add s.True(refusedTurn(outcome.err)) to TestACallWhoseTurnIsRefusedForMoneyFailsUnderTheMoney. I checked it: it passes on head and fails under RM6.
  • M4/RM2: the Purpose != agent.PurposeGreeting clause on this line. This mutant is equivalent, because on a call the greeting never arrives as agent.Responded. It comes as agent.Said (agent.go:1366). Responded carries PurposeGreeting only when options.Text is set (agent.go:1340), composedFor never returns it (agent.go:2881), and callSpec sets Text=false (:1166). Fix: drop the clause. If check-in and update lines must not count as the answer, use reply.Purpose == "" and add a test for it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e38cf65: s.True(refusedTurn(outcome.err)) in TestACallWhoseTurnIsRefusedForMoneyFailsUnderTheMoney (fails under RM6); greeting clause dropped (equivalent). RM1 killed by the R1.1 test. Head 7b9031c.

Comment thread .claude/skills/scheduled-tasks/SKILL.md Outdated
| `account_suspended`, `insufficient_credits`, `system_limit_reached`, `spend_limit_reached`, `user_limit_reached` | A step the organization may not pay for was refused for money (suspended, no credit left, or a spent limit): an SMS, WhatsApp or iMessage text or a thread task's reply (`dlc.ErrUnpaid`, or its reservation), the task's session opening or being carried on, a turn the model refuses, on a text channel (an `agent.Error` in `captureReply`, which ends the walk over the channels, `refusedTurn`), in the conversation (`followUpInConversation` waits for the turn to end and reads it from the session's events; a turn that ends any other way is still `delivered`) or on a thread task (`deliverOnThread` reads it from the session's events), or its call. The run records the refusal's own code (`deliveryReason`, `scheduled_delivery.go:334`), never `channel_unreachable` or `delivery_failed`, and the router warns, naming the task | no (`unpaid`, `scheduled_delivery.go:355`) |
| `spend_check_unavailable` | The router could not check what the organization has spent, so it refused the step for now (`policy.Transient`). A turn it refused runs once more on the retry, under `st_<run>_r1`: the scheduler hands the next attempt the reason this one failed under (`deliverWithRetries`), a hand-off to the router holding the session carries it (`scheduledHandOff.Earlier`), and `replyCommand` reruns a failed reply after a money code. A conversation rerun refused as well fails the attempt under the same code (`followUpInConversation`), so the run fails once its retries are spent. A reply that failed for any other reason is read back as it was | yes (`unpaid` leaves it retryable) |
| `account_suspended`, `insufficient_credits`, `system_limit_reached`, `spend_limit_reached`, `user_limit_reached` | A step the organization may not pay for was refused for money (suspended, no credit left, or a spent limit): an SMS, WhatsApp or iMessage text or a thread task's reply (`dlc.ErrUnpaid`, or its reservation), the task's session opening or being carried on, a turn the model refuses, on a text channel (an `agent.Error` in `captureReply`, which ends the walk over the channels, `refusedTurn`), in the conversation (`followUpInConversation` waits for the turn to end and reads it from the session's events; a turn that ends any other way is still `delivered`) or on a thread task (`deliverOnThread` reads it from the session's events), or its call, placed or not: a placed call whose session cannot open fails under the refusal's code (`carryOutOnCall`); on an answered call, a turn refused before the agent answered anything hangs up (`carryOutAnswered`), and a refusal after that is a later turn's, still `delivered`. The run records the refusal's own code (`deliveryReason`, `scheduled_delivery.go:334`), never `channel_unreachable` or `delivery_failed`, and the router warns, naming the task | no (`unpaid`, `scheduled_delivery.go:355`) |
| `spend_check_unavailable` | The router could not check what the organization has spent, so it refused the step for now (`policy.Transient`). A turn it refused runs once more on the retry, under `st_<run>_r1`: the scheduler hands the next attempt the reason this one failed under (`deliverWithRetries`), a hand-off to the router holding the session carries it (`scheduledHandOff.Earlier`), and `replyCommand` reruns a failed reply after a money code. A conversation rerun refused as well fails the attempt under the same code (`followUpInConversation`), so the run fails once its retries are spent. A reply that failed for any other reason is read back as it was. A call refused this way, its session or its answered turn, is given back to the run (`callEnded`, `ReleaseCall`), so the retry rings the user again and runs the call's turn again under `st_<run>_call_r1` (`carryOutAnswered`); that rerun refused as well fails the run under the same code, final, so the user is rung twice at most | yes (`unpaid` leaves it retryable) |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Should fix] R1.4 The text here ends with "so the user is rung twice at most". That is not true on head (see R1.1). Other docs still describe the old "rings once" rule:

  • scheduled_delivery.go:1082 (deliverByPhone): "An occurrence rings once ... neither a retry nor a worker taking the run over rings the user again".
  • internal/scheduling/AGENTS.md:145: "A call rings once ... (S5)". Line 152 of the same file: "the give-back of a call not placed".
  • internal/store/scheduled_task_run.go:186 (ReleaseCall): "took and could not place".

Fix: once R1.1 is fixed, change each of them to say that a placed call refused while money could not be checked is given back once.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7b9031c: docs say a placed call refused while money could not be checked is given back once (SKILL.md row, deliverByPhone, callEnded, carryOutAnswered, scheduling/AGENTS.md S5, ReleaseCall).

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delta round 2 of AI-3597 (head 7b9031c, merged onto main 9effc9b): NO-GO, one Should fix.

Prior findings

  • R1.1 fixed. Dropping the Final override fails TestACallWhoseSessionCannotOpenWhileMoneyCannotBeCheckedIsGivenBackOnce and TestACallWhoseTurnIsRefusedAgainOnItsRetryFailsTheRun. My round-1 probe (turn refused, then session open refused) now ends at 2 rings and a third TakeCall is refused.
  • R1.2 fixed. Making the refusal always final fails 3 tests, and the refusedTurn assert is in place.
  • R1.3 fixed. Ignoring answered fails TestACallWhoseLaterTurnIsRefusedForMoneyIsDelivered. Restoring the greeting clause survives, and that is equivalent: on a call the greeting is agent.Said, and Responded carries a purpose only for text agents (agent.go:1340, 1366).
  • R1.4 fixed in the docs, but the sentence "rung twice at most" is still false on one path (R2.1).
  • R1.5 resolved by the merge order. #2272 and #2277 compose: the code merges clean and both suites pass on the composed tree. Only .claude/skills/scheduled-tasks/SKILL.md conflicts (the two money rows), so whichever merges second resolves it.

Suites on head merged onto main: TestTelnyxUnpaidSuite ok, TestScheduledTasksSuite ok.

Mutations: 8 run, 2 survived. The Earlier != "" mutant (R2.1) survives. The other survivor is outside this delta (followUpWithin made non-final, a base line).

Question 2 (money on another channel): not a Should fix. The first transient refusal on the call is final only after an earlier attempt already failed under money, so the run was retried once already. That matches Kanat's rule and is no worse than base.

}
// The attempt before this one failed under a money code: its call was given back
// already, so this one is kept, and the user is rung twice at most.
if !failure.Final && moneyCode(delivery.Earlier) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R2.1 [Should fix] "Given back once" is keyed on moneyCode(delivery.Earlier), the reason of the last attempt only. The call can ring more than twice when that reason is not a money code. Two ways:

  1. Channels are [text, call] and the text channel fails first for a non-money reason. deliverChain records the first channel's reason (line 315), so every attempt's Earlier is that reason while the call keeps being refused for money. A probe over all 4 attempts gives rings=4, every one given back.
  2. An attempt between the two fails before it rings (user on a call, number lookup error, daily tier limit). The next attempt's Earlier is that reason. A probe gives rings=3.

On base a call failure was always final, so this is new. No test covers it: the Earlier != "" mutant survives.

Fix: make "already given back" a fact about the run, not the last attempt (a per-run flag or counter set by ReleaseCall and read by callEnded; that needs a migration, so the orchestrator decides). The cheaper option is to make Earlier keep a money code over an earlier channel's reason and stay across a pre-ring failure.

Test rows (both fail on head):

  • callOn plus uncheckable, 4 attempts with Earlier="unreachable": at most 2 takeCall succeed and the second call's failure is final.
  • Ring, turn refused, an attempt with Earlier="on_a_call" that does not ring, ring refused again, a fourth attempt: still at most 2 rings.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in aca2a3f (code + tests 82e36aa): per the orchestrator decision the give-back is gone. A placed call is rung once: callEnded makes every failure after the call was placed final, so a turn refused while money cannot be checked ends the run under spend_check_unavailable after one ring, refusedTurn true, and the call stays taken on the run. The ReleaseCall path and the _call_r1 rerun are removed. Your two rows are TestACallWhoseTurnIsRefusedIsRungOnceWhateverTheAttemptsBetweenFailedUnder (case b, earlier reason on_a_call) and TestACallWhoseSessionCannotOpenIsRungOnceWhateverTheFirstChannelFailedUnder (case a, earlier reason unreachable); both fail with the previous callEnded restored, together with the two other call tests that assert one ring. Docs (SKILL.md row, AGENTS.md S5, ReleaseCall comment, PR body) now say a placed call is rung once.

kanat and others added 3 commits November 23, 2026 22:55

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: GO (round 3, head aca2a3f merged onto main 6d447f6)

Prior findings

  • R2.1 fixed: the give-back and the _call_r1 rerun are gone; callEnded sets Final on every failure after the call was placed (scheduled_delivery.go:1257). The transient refusal of an answered turn or of the session open ends the run under spend_check_unavailable, final, after one ring, with refusedTurn true (tests ...FailsFinalAfterOneRing, ...FailsFinal, and the two R2.1 rows for cases a and b). Mutations, one file restored each time: dropping Final = true fails 4 tests; dropping SetCallReason 4; dropping the session-open money branch 3; reading the refusal after an answer 1; never setting answered 1; never reading the turn refusal 3. All killed.
  • R1.1, R1.2, R1.3, R1.4 stay fixed (R1.1 and the give-back path no longer exist; the refusedTurn asserts and the docs hold). R1.5 is moot: nothing is given back, so the merge order against #2272 no longer matters for rings.

Orchestrator notes

  1. A non-money failure after the call was placed: no change from base. Every *scheduling.Failure that reached callEnded on base was already Final (carryOutOnCall and holdCall use undeliveredFinally; carryOutAnswered returns undeliveredFinally(ReasonFailed) or a context error, which is not a Failure and returns early). So failure.Final = true changes only the two new transient money sources. A base retry could not ring again either: TakeCall answers already_called.
  2. Dead code: none. ReleaseCall has one caller left, deliverByPhone on a call that was not placed (scheduled_delivery.go:1140, as on base). retried, uncheckableCall are gone; every helper of the suite is still used. rerunSuffix, replyCommand and refusedAgain still serve the text, conversation and thread paths. No stale "given back once / rung twice" text left in the docs.

New findings: none.

Run: TestTelnyxUnpaidSuite and TestScheduledTasksSuite pass on the head merged onto main (go test -tags integration -p 1), scheduling and store unit tests pass, gofmt and both go vet clean. CI: the code scanners pass; go and integration skip on a draft.

Details: reviewer-3.md in the ledger.

@kanat
kanat marked this pull request as ready for review November 23, 2026 22:28
@kanat
kanat merged commit dc88f2f into main Nov 24, 2026
20 of 21 checks passed
@kanat
kanat deleted the kanat/ai-3597-voice-money-refusal branch November 24, 2026 07:43
kanat added a commit that referenced this pull request Nov 24, 2026
thesyncim pushed a commit that referenced this pull request Nov 24, 2026
## Why

The `api` group of Integration (router) does not compile on main since
dc88f2f ([run
45350145644](https://github.com/GetStream/Agents/actions/runs/45350145644)):

```
internal/api/scheduled_unpaid_test.go:1200:2: cannot assign to scheduledPhoneWindow (neither addressable nor a map index expression)
```

[#2277](#2277) set the
package-level `scheduledPhoneWindow` and `scheduledCallLimit` in
`TelnyxUnpaidSuite.callOn`.
[#2293](#2293), merged before
it, made them constants and moved the values a test changes onto the
router. Each passed CI on its own. Until this lands, every PR whose CI
runs the `api` group fails.

## Changes

- `callOn` sets `s.router.phoneWindow` and `s.router.callLimit` and
restores them in its cleanup, as `scheduled_phone_test.go:136-138` does.
Test-only.

## Validation

- `go vet -tags integration ./internal/api`: compiles.
- `go test -tags integration ./internal/api -run TestTelnyxUnpaidSuite
-count=1`: ok (99.7 s), including the three tests that go through
`callOn`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant