Commit 701cc12
feat: key-package maintenance as TaskRunner recurring tasks (#3814)
Stacked on #3806 (generic recurrence); the KpRotation/KpDeletion proto
variants land in #3805. Replaces the 5s-poll `KeyPackageCleaner` worker
with two recurring TaskRunner tasks.
## What
- **`KpRotation`** — recurring singleton: rotates + uploads a fresh key
package when the identity's rotation deadline
(`next_key_package_rotation_ns`) is due, then reschedules to the live
column (never a hardcoded +30d). On rotation it self-heals the deletion
singleton and pulls it in to the earliest pending `delete_at_ns`.
- **`KpDeletion`** — recurring singleton: sweeps expired local
key-package material, reschedules to the next pending deadline.
- **Welcome nudge** — after `queue_key_package_rotation` lowers the
column (~5s debounce, a security property), a durable `PullInDeadline`
pulls the rotation task in to match. Closes a real race: without it, a
seed that dispatched before the column write parks ~30d out and the
debounce is silently lost (reproduced; regression-tested).
- **Builder** seeds both singletons + reconciles deadlines to the live
DB columns on every startup (idempotent; also repairs rows stranded by a
crash between a column write and its pull-in).
- **Gutted** the old 5s-poll worker: loop/factory/rotate path deleted;
the struct + local-deletion helpers remain as the `KpDeletion` arm's
implementation.
## Behavior notes
- KP maintenance no longer has its own toggle — it is a critical MLS
function, deliberately coupled to the TaskRunner (no standalone
fallback). `WorkerKind::KeyPackageCleaner` remains in core and all three
bindings' enums for FFI compatibility, but enabling/disabling it is now
a no-op. Disabling the TaskRunner itself — per-kind via worker config or
globally via `disable_workers` — disables KP maintenance with it.
- Pre-registration (fresh client, no identity row): readers return
`None`/false, the rotation seed parks ~30d and converges silently once
registration writes the column. No transient errors.
- Zero migrations; zero reaper changes — recurring rows are
never-expiring seeds (`expires_at_ns = i64::MAX`, `max_attempts =
i32::MAX`), so the existing reaper predicate can't fire on them.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- Macroscope's pull request summary starts here -->
<!-- Macroscope will only edit the content between these invisible
markers, and the markers themselves will not be visible in the GitHub
rendered markdown. -->
<!-- If you delete either of the start / end markers from your PR's
description, Macroscope will append its summary at the bottom of the
description. -->
> [!NOTE]
> ### Replace key-package cleaner worker with TaskRunner recurring tasks
for rotation and deletion
> - Removes the legacy `KeyPackagesCleanerWorker` and replaces it with
durable `KpRotation` and `KpDeletion` task rows managed by the
`TaskRunner` in
[key_package_maintenance.rs](https://github.com/xmtp/libxmtp/pull/3814/files#diff-1d4be0f0b8283620c52870358d20c933cc8086d19b8c804906ce1fc6d99af0eb).
> - `KpRotation` tasks reschedule to the DB-backed
`next_key_package_rotation_ns` deadline; `KpDeletion` tasks reschedule
to the earliest pending `delete_at_ns` across marked key packages.
> - `seed_and_reconcile_kp_tasks` is called at startup (after
`TaskWorker` registration) to seed both recurring tasks and pull in
deadlines from live DB state.
> - `queue_key_rotation` is now synchronous and atomically updates the
rotation column and enqueues a `PullInDeadline` nudge; `nudge_deletion`
does the same for deletion.
> - `is_identity_needs_rotation` now returns `false` pre-registration
and treats a `NULL` rotation column on an existing row as due
immediately, fixing a bug where migrated DBs with `NULL` deadlines were
skipped.
> - Behavioral Change: key-package maintenance no longer runs as a
standalone polling worker; it is now driven entirely by the `TaskRunner`
dispatch loop.
>
> <!-- Macroscope's changelog starts here -->
> #### Changes since #3814 opened
>
> - Modified key rotation queueing to insert-or-ignore rotation seed
tasks before enqueuing pull-in tasks [3cb7a61]
> - Added tests verifying rotation seed self-healing behavior during key
rotation nudges [3cb7a61]
> - Changed `KpDeletion` task rescheduling to use rotation interval
constant instead of fixed 30-day value [3cb7a61]
> - Updated mock implementation to match new trait signature [3cb7a61]
> <!-- Macroscope's changelog ends here -->
>
> <!-- Macroscope's review summary starts here -->
>
> <sup><a href="https://app.macroscope.com">Macroscope</a> summarized
74a0d28.</sup>
> <!-- Macroscope's review summary ends here -->
>
> <!-- macroscope-ui-refresh -->
<!-- Macroscope's pull request summary ends here -->
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent f46d623 commit 701cc12
14 files changed
Lines changed: 852 additions & 299 deletions
File tree
- crates
- xmtp_db/src
- encrypted_store
- xmtp_mls/src
- groups
- tests
- utils/test
- worker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
50 | 61 | | |
51 | 62 | | |
52 | 63 | | |
53 | 64 | | |
54 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
55 | 70 | | |
56 | 71 | | |
57 | 72 | | |
| |||
62 | 77 | | |
63 | 78 | | |
64 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
65 | 88 | | |
66 | 89 | | |
67 | 90 | | |
| |||
72 | 95 | | |
73 | 96 | | |
74 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
75 | 102 | | |
76 | 103 | | |
77 | 104 | | |
78 | 105 | | |
79 | 106 | | |
80 | 107 | | |
| 108 | + | |
| 109 | + | |
81 | 110 | | |
82 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
83 | 116 | | |
84 | 117 | | |
85 | 118 | | |
| |||
89 | 122 | | |
90 | 123 | | |
91 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
92 | 188 | | |
93 | 189 | | |
94 | 190 | | |
| |||
113 | 209 | | |
114 | 210 | | |
115 | 211 | | |
116 | | - | |
| 212 | + | |
117 | 213 | | |
118 | 214 | | |
119 | 215 | | |
| 216 | + | |
120 | 217 | | |
121 | 218 | | |
122 | 219 | | |
123 | | - | |
124 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
125 | 225 | | |
126 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
127 | 239 | | |
128 | 240 | | |
129 | 241 | | |
| |||
132 | 244 | | |
133 | 245 | | |
134 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
135 | 327 | | |
136 | 328 | | |
137 | 329 | | |
| |||
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
| |||
163 | 171 | | |
164 | 172 | | |
165 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
166 | 186 | | |
167 | 187 | | |
168 | 188 | | |
| |||
194 | 214 | | |
195 | 215 | | |
196 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
197 | 225 | | |
198 | 226 | | |
199 | 227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
134 | 138 | | |
135 | 139 | | |
136 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
| 504 | + | |
504 | 505 | | |
505 | 506 | | |
506 | 507 | | |
507 | 508 | | |
| 509 | + | |
| 510 | + | |
508 | 511 | | |
509 | 512 | | |
510 | 513 | | |
| |||
545 | 548 | | |
546 | 549 | | |
547 | 550 | | |
| 551 | + | |
| 552 | + | |
548 | 553 | | |
549 | 554 | | |
550 | 555 | | |
| |||
0 commit comments