Repository navigation
Conversation
A broadcast persisted without a ttl stored expires_at = now + 72 hours, so a later change to retention couldn't extend it. Store null instead, as the opt-in RFC specified, and bound replay's since at 72 hours ago, so those messages still replay for the same window as before. The bound also applies to Broadcast from Database rows, which already store null. They replayed until the janitor dropped their partition, up to about 100 hours, and now replay for 72 hours. RFC decision 5, REAL-1290. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CRAP Score Report |
The test inserted a row from 73 hours ago, but the fixture only creates partitions from yesterday on. It passed locally because older partitions were left over, and would fail on a fresh database. Create the older partitions in the test. Also write the since bound as Enum.max with NaiveDateTime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the broadcast persistence and replay-window changes.
No open issues 🎉
What changed in this PR
This PR prepares broadcast persistence for configurable retention by storing no expiry when ttl is omitted, while preserving the current 72-hour replay window.
Changes:
- Parse persistence without a TTL as
ttl: niland storeexpires_at: nil; explicit TTL behavior remains unchanged. - Bound replay queries to the last 72 hours, including for rows with no expiry.
- Add and update tests for replay boundaries and no-TTL persistence across broadcast entry points.
| File | Description |
|---|---|
test/realtime/tenants/single_broadcast_test.exs |
Verifies single broadcasts persist with no expiry when TTL is unset. |
test/realtime/messages_test.exs |
Tests nil TTL handling, expiry calculation, and replay bounds. |
test/realtime_web/controllers/broadcast_single_controller_test.exs |
Updates HTTP persistence expectations to no expiry. |
test/realtime_web/channels/realtime_channel/broadcast_handler_test.exs |
Verifies WebSocket persistence stores no expiry without a TTL. |
test/e2e/src/suites/broadcast-persistence.ts |
Updates nullable TTL types and end-to-end assertions. |
lib/realtime/messages.ex |
Implements nil expiry defaults and the 72-hour replay bound. |
Review effort: Balanced
leandrocp
left a comment
There was a problem hiding this comment.
That's a good point to make the max ttl dynamic and bound to max retention. Just one comment to make the intention a bit more clear.
| `ttl: nil` means they gave no ttl, so the message is kept for the retention. | ||
| """ | ||
| @type persist :: %{ttl: pos_integer()} | nil | ||
| @type persist :: %{ttl: pos_integer() | nil} | nil |
There was a problem hiding this comment.
Can we have a more clear type here? Something like :infinity or :max_retention? No preference, just trying to avoid the nil confusion.
| @type persist :: %{ttl: pos_integer() | nil} | nil | |
| @type persist :: %{ttl: pos_integer() | :infinity} | nil |
persist: nil is already not very clear and adding ttl: nil would make persist even more confusing 😄
What
A broadcast persisted without a
ttlnow storesexpires_at = nullinstead ofnow + 72 hours. Replay never reads further back than 72 hours, so a message with noexpires_atstill replays for 72 hours, the same window as today.An explicit
ttlworks as before.Why
This is decision 5 of the configurable retention RFC (REAL-1290). The opt-in RFC specified null for this case, but the code stored a fixed timestamp. With a fixed timestamp, a later change to retention can't extend messages that are already stored.
The change doesn't need the retention setting itself, and it isn't urgent. It can land before the retention setting or with it. Stored rows live 72 to about 100 hours, so rows with the old fixed deadline age out within a few days, and no backfill is needed.
Behavior change
Broadcast from Database rows already store
expires_at = null. Today they replay until the janitor drops their partition, up to about 100 hours. With the new bound onsince, they replay for 72 hours. This matches the docs, which say messages are kept for 3 days.No backfill. Rows stored with a timestamp keep it and expire on their own.
Nothing changes for clients. A persist without a
ttlstill replays for 72 hours, and the janitor still drops the row with its partition. No error codes or API docs change.How it was tested
Messages.parse_persist/1returnsttl: nilfortrue,%{}, and%{"ttl" => nil}.Messages.expires_at/1returns nil for nil.sincestill applies.replay_query/4atnowjust inside and just past 72 hours.ttlstoreexpires_at: nil.ttl_secondsto be null for a persist without attl. It passes in CI.Review first
replay_query/4inlib/realtime/messages.ex. The bound is computed in Elixir, not SQL, so the query shape doesn't change: it still has a plaininserted_atrange and usesmessages_replay_index. The existing "use the replay index" test checks the plan for that shape.Risk and rollback
Rows written after this change have
expires_at = null. If the change is reverted, those rows still replay for 72 hours only through thesincebound, which the revert also removes. They would then replay until their partition drops, up to about 100 hours. That's today's behavior for Broadcast from Database rows, so a revert is safe.Part of REAL-1290.
🤖 Generated with Claude Code