Commit 6405bb2
fix(macos): hold the sleep assertion for any non-seeding torrent
The gate was `status == "Downloading"`, which is narrower than the intent. The
engine derives that status from the piece currently being fetched
(`Peer.status()` is `nil | :seed | :connecting_to_peers | index`), so an
**incomplete** torrent reports `"Idle"` or `"Connecting"` whenever no piece is
assigned to it. Behind CGNAT, where a torrent runs on one to three peers, that is
a state it passes through constantly while hunting for somewhere to ask — and
letting the Mac sleep there strands it exactly when re-dialling is the only thing
that can rescue it, because sleep drops every peer connection it might have been
about to establish.
`!= "Seeding"` is the same test the Dock menu already applies when it files
torrents under its "Downloading:" heading, so the assertion and the menu now agree
on what counts as active. There is no paused or stopped status to worry about
letting through: `Peer.status()` has no such value, and a stopped torrent is not
in the list at all.
Found by reading `powerd`'s own log after deploying the original commit —
`log show --predicate 'eventMessage CONTAINS "ElixirTorrentWebUI"'` shows every
acquire and release with an age, which is a better instrument for this than
`pmset -g assertions` because it shows the transitions rather than the current
state. It recorded a release-and-reacquire on a torrent that never stopped being
incomplete. Forty consecutive two-second samples afterwards all read
`"Downloading"`, so this specific flap is not reproduced on demand — but the code
path is plainly there, and the conservative gate has no upside on AC power.
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent db453dd commit 6405bb2
1 file changed
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
27 | 37 | | |
28 | 38 | | |
29 | 39 | | |
30 | 40 | | |
31 | | - | |
32 | | - | |
33 | 41 | | |
34 | | - | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
| |||
0 commit comments