unarr/internal/agent
Deivid Soto 1052529ca2 feat(agent): hybrid SSE downlink with long-poll fallback
Replace the bare long-poll wake listener with a hybrid server→agent
downlink that consumes the new GET /api/internal/agent/events SSE stream
first and falls back to the long-poll wake when SSE is unavailable or
silently buffered. Resurrects the SSE client retired with WebRTC
(signal_client.go) as events_client.go — a bounded-scanner reader
(256 KiB line / 1 MiB event) that surfaces heartbeat comments as ping
events so the consumer can detect liveness.

runDownlink dispatches on the new [daemon] downlink config:
  - auto (default): SSE-first; after maxSSEFailures dead/buffered attempts
    fall back to long-poll for 5 min, then re-probe SSE.
  - sse:  SSE only, no fallback (known-good networks / testing).
  - poll: the pre-0.14 long-poll wake only.

A stream is "healthy" only if it delivers a frame within livenessTimeout
(40s vs the server's 15s heartbeat). Crucially the liveness-timeout branch
returns UNHEALTHY even if an earlier frame arrived: a proxy that flushes
the connect preamble (one ping) then stalls must not pin the agent to SSE
forever — that's the partial-buffering case the fallback exists for.

event: command applies typed controls via the same OnControl callback
/agent/sync uses (idempotent); event: sync triggers an immediate sync;
ping is liveness-only. OpenEventStream rides MirrorPool failover for the
initial connect; mid-stream drops close the channel and the loop reopens.

Bump 0.14.0.
2026-06-01 17:31:42 +02:00
..
active_tasks.go feat(agent): auto-resume interrupted downloads after a daemon restart 2026-05-31 22:44:05 +02:00
active_tasks_test.go feat(agent): auto-resume interrupted downloads after a daemon restart 2026-05-31 22:44:05 +02:00
client.go feat(stream): refresh expired debrid links mid-stream (hueco #2/2c) 2026-05-31 17:02:59 +02:00
client_test.go feat(agent): add mirror failover, agent client refactor, status 401 detection 2026-05-15 16:26:43 +02:00
daemon.go feat(agent): hybrid SSE downlink with long-poll fallback 2026-06-01 17:31:42 +02:00
disk.go feat(cli): add login command and refactor shared helpers 2026-04-01 12:20:51 +02:00
disk_test.go test(coverage): raise engine+agent coverage above 50% 2026-05-12 11:21:59 +02:00
disk_unix.go feat: initial commit — unarr CLI 2026-03-28 11:29:42 +01:00
disk_windows.go feat: initial commit — unarr CLI 2026-03-28 11:29:42 +01:00
downlink_test.go feat(agent): hybrid SSE downlink with long-poll fallback 2026-06-01 17:31:42 +02:00
events_client.go feat(agent): hybrid SSE downlink with long-poll fallback 2026-06-01 17:31:42 +02:00
events_client_test.go feat(agent): hybrid SSE downlink with long-poll fallback 2026-06-01 17:31:42 +02:00
mirror_client.go feat(mirror): update fallback URLs to use IPFS and remove GitHub Pages 2026-05-21 16:00:44 +02:00
mirror_pool.go feat(agent): add mirror failover, agent client refactor, status 401 detection 2026-05-15 16:26:43 +02:00
mirror_transport.go feat(agent): give the public API client mirror failover 2026-06-01 15:53:00 +02:00
mirror_transport_test.go feat(agent): give the public API client mirror failover 2026-06-01 15:53:00 +02:00
process_unix.go feat: add clean command to remove temp files, logs, and cached data 2026-03-29 11:04:51 +02:00
process_unix_test.go test(coverage): raise engine+agent coverage above 50% 2026-05-12 11:21:59 +02:00
process_windows.go fix(build): unused variable in Windows process check 2026-03-30 13:11:55 +02:00
state.go refactor(sentry): decouple agent import via string-match, rename predicate 2026-05-27 17:03:26 +02:00
state_test.go fix(sentry): skip "daemon not running" stop/reload errors 2026-05-27 16:50:16 +02:00
sync.go feat(agent): hybrid SSE downlink with long-poll fallback 2026-06-01 17:31:42 +02:00
sync_test.go test: add comprehensive test suite for engine, agent and cmd packages 2026-04-08 23:36:00 +02:00
taskstate.go feat(sync): replace WS+DO transport with unified HTTP sync 2026-04-08 18:50:59 +02:00
taskstate_test.go test(coverage): raise engine+agent coverage above 50% 2026-05-12 11:21:59 +02:00
types.go feat(stream): burn bitmap (PGS/DVB) subtitles into the video via overlay 2026-06-01 09:51:27 +02:00