Commit ca31a07
fix(run): honour AbortSignal at start and after polling
Closes #370.
`replicate.run()` accepted `options.signal` but only checked it as a poll
exit condition. Two paths still silently completed:
1. A signal that was already aborted before `run()` was called fell through
to `predictions.create()` and waited on the prediction as usual.
2. A signal that aborted during polling broke the poll loop, but the
caller's awaited promise resolved with the empty output of the canceled
prediction (or `undefined`) instead of throwing — the cancellation was
invisible to the consumer.
`run()` now:
- Calls `signal.throwIfAborted()` before any HTTP work happens, matching
the `fetch`/standard-AbortController contract.
- Forwards `signal` to `predictions.create()` so the initial create fetch
is itself abortable.
- After the poll loop exits with an aborted signal, best-effort cancels
the prediction (swallowing any cancel-side error so the abort remains
the higher-priority signal) and then calls `signal.throwIfAborted()` so
the awaited promise rejects with `AbortError`.
The existing "Aborts the operation when abort signal is invoked" test is
updated to assert the new throwing contract; two new regression cases
cover the pre-aborted-signal short-circuit and the no-network guarantee.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2fd6f39 commit ca31a07
2 files changed
Lines changed: 61 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
148 | 153 | | |
149 | 154 | | |
150 | 155 | | |
| |||
153 | 158 | | |
154 | 159 | | |
155 | 160 | | |
| 161 | + | |
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
159 | 165 | | |
160 | 166 | | |
161 | 167 | | |
| 168 | + | |
162 | 169 | | |
163 | 170 | | |
164 | 171 | | |
| |||
191 | 198 | | |
192 | 199 | | |
193 | 200 | | |
194 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
195 | 211 | | |
196 | 212 | | |
197 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1598 | 1598 | | |
1599 | 1599 | | |
1600 | 1600 | | |
1601 | | - | |
1602 | | - | |
1603 | | - | |
1604 | | - | |
1605 | | - | |
1606 | | - | |
1607 | | - | |
1608 | | - | |
1609 | | - | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
1610 | 1615 | | |
1611 | 1616 | | |
1612 | 1617 | | |
1613 | 1618 | | |
1614 | | - | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
1615 | 1623 | | |
1616 | 1624 | | |
1617 | 1625 | | |
| |||
1625 | 1633 | | |
1626 | 1634 | | |
1627 | 1635 | | |
1628 | | - | |
1629 | | - | |
1630 | | - | |
1631 | | - | |
1632 | | - | |
1633 | | - | |
1634 | 1636 | | |
1635 | 1637 | | |
1636 | 1638 | | |
1637 | 1639 | | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
1638 | 1666 | | |
1639 | 1667 | | |
1640 | 1668 | | |
| |||
0 commit comments