Commit d97d6b1
committed
feat(streaming): add sliding TTL to Redis stream keys
Mirror scaleapi/scale-agentex#215 (server-side adapter): pipeline XADD
with EXPIRE so each task:* stream key gets a sliding TTL. Orphaned
streams (no writes for the TTL window) self-delete in Redis without
needing an explicit cleanup_stream call from the caller.
This is the right shape of fix for the SDK's leak: an explicit DEL on
terminal task transitions (an earlier draft of this PR) introduced a
race where the server's task_updated event published to the same
topic could be deleted before a connected frontend SSE consumer read
it. EXPIRE sidesteps that — TTL only fires after inactivity, so an
actively-streaming agent or actively-reading consumer keeps the key
alive, and the key only ages out once everyone is done with it.
Defaults match the server: REDIS_STREAM_TTL_SECONDS=3600 (1h),
overridable via env var. Setting it to 0 short-circuits to plain XADD
(no TTL refresh), matching the server's escape hatch.
Implementation notes:
- transaction=False on the pipeline: connection-level batching, no
MULTI/EXEC overhead for what's already a fast op.
- raise_on_error=False: an EXPIRE failure after a successful XADD
must not surface to the caller. The message has been published;
retrying would duplicate it. We log and move on. Next successful
XADD will reset the TTL anyway.1 parent 46ed066 commit d97d6b1
1 file changed
Lines changed: 49 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
| |||
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
38 | 52 | | |
39 | 53 | | |
40 | 54 | | |
| |||
55 | 69 | | |
56 | 70 | | |
57 | 71 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
64 | 106 | | |
65 | 107 | | |
66 | 108 | | |
| |||
0 commit comments