Repository navigation
Commit a9ec02a
fix(core): [Unhandled Sessions 2] Don't let a queued SessionStart overwrite a newer session (#5920)
* fix(core): Make session cache writes session-id aware
SessionEnd previously deleted session.json unconditionally and
SessionStart always rotated it. A delayed end or start could therefore
drop a newer session snapshot. Both paths now compare session ids and
start times before deleting or rotating, and a new persistCurrentSession
lets callers flush the active session to disk.
Co-authored-by: Cursor <cursoragent@cursor.com>
* ref: follow Session rename in EnvelopeCache
Co-authored-by: Cursor <cursoragent@cursor.com>
* docs: explain why stale session envelopes must not clobber newer state
Co-authored-by: Cursor <cursoragent@cursor.com>
* ref(session): make the two stale-envelope checks read the same way
Both session paths in EnvelopeCache answer the same question - is this
envelope stale relative to what is already on disk - but the end path
inlined eight clauses and phrased it as "preserve", while the start path
hid it behind a helper and negated it. Name both isStaleSessionEnd and
isStaleSessionStart so the shared idea is visible, and move the "why"
onto those helpers.
Also narrows the JavaUtilDate suppression to the comparison itself and
fixes a comment that still claimed the item reader only served starts.
Co-authored-by: Cursor <cursoragent@cursor.com>
* ref(cache): replace the stale-start comparison with an identity check
session.json has only two writers, the SessionStart path and
persistCurrentSession. So if a start envelope finds its own session id
already on disk, persistCurrentSession put it there for the live session,
and that copy is necessarily at least as advanced. There is nothing to
measure: comparing the unhandled flag and error count answered a question
that only ever has one answer.
The start path collapses to "if this envelope is about a different
session than the one on disk, behave as before; otherwise leave it
alone", which also avoids rotating a running session into
previous_session.json.
Co-authored-by: Cursor <cursoragent@cursor.com>
* ref(cache): restore catch (Throwable) in the envelope session reader
Narrowing this pre-existing catch was incidental to the feature and the
only thing in this PR that alters existing behaviour: an Error while
parsing the session item used to be swallowed so the store continued and
the envelope still reached disk, whereas propagating it abandons the
store partway.
It was also inconsistent, converting one of six catch (Throwable) blocks
in this file simply because the edit landed next to it. The new
readSessionFromDisk keeps catch (Exception), so new code still refuses to
swallow fatal errors.
Co-authored-by: Cursor <cursoragent@cursor.com>
* ref(cache): delete the current session file unconditionally again
The SessionEnd guard only paid off in a narrow window: a SessionEnd still
queued while a newer session had already started and recorded an
unhandled error. Dropping it degrades to the behaviour on main, because
the queued SessionStart rewrites the file moments later, just without the
flag. That cost a session.json read and deserialize on every SessionEnd
for every SDK.
The SessionStart guard stays. Its window is far wider, since app start is
when the transport is busiest flushing the previous run's cache, and its
failure mode is worse than a lost flag: movePreviousSession files the
running session as the previous one.
Co-authored-by: Cursor <cursoragent@cursor.com>
* ref(cache): fold the session-id comparison into one predicate
Co-authored-by: Cursor <cursoragent@cursor.com>
* ref(cache): track the out-of-band session id instead of re-reading it from disk
Co-authored-by: Cursor <cursoragent@cursor.com>
* ref(cache): rename isLateDuplicateStart to isAlreadyPersisted
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(sessions): don't let the persisted session guard swallow a SessionStart
The guard skipped the SessionStart write whenever the id matched the last
persisted one, even when session.json no longer held that session:
- a queued SessionEnd for the prior session deletes the file the live
session was just persisted to, so the skipped write left no session on
disk at all
- a failed persist still recorded the id, so the queued write that would
have repaired the truncated file was skipped too
Clear the id on SessionEnd and only record it when the write succeeded.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(cache): Clear the persisted session id when the write fails
writeSessionToDisk truncates the current session file before serializing, so a
failed persist leaves it corrupt. lastPersistedSessionId kept pointing at it,
and isAlreadyPersisted then skipped the rotation that would have replaced the
file, on the premise that it still held the live session.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 0699a94 commit a9ec02a
3 files changed
Lines changed: 248 additions & 13 deletions
File tree
- sentry
- api
- src
- main/java/io/sentry/cache
- test/java/io/sentry/cache
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4901 | 4901 | | |
4902 | 4902 | | |
4903 | 4903 | | |
| 4904 | + | |
4904 | 4905 | | |
4905 | 4906 | | |
4906 | 4907 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
| |||
118 | 124 | | |
119 | 125 | | |
120 | 126 | | |
121 | | - | |
122 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
123 | 132 | | |
124 | 133 | | |
125 | 134 | | |
| |||
129 | 138 | | |
130 | 139 | | |
131 | 140 | | |
132 | | - | |
133 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
134 | 150 | | |
135 | 151 | | |
136 | 152 | | |
| |||
274 | 290 | | |
275 | 291 | | |
276 | 292 | | |
277 | | - | |
278 | | - | |
| 293 | + | |
279 | 294 | | |
280 | 295 | | |
281 | 296 | | |
| |||
295 | 310 | | |
296 | 311 | | |
297 | 312 | | |
298 | | - | |
| 313 | + | |
299 | 314 | | |
300 | 315 | | |
301 | 316 | | |
| |||
309 | 324 | | |
310 | 325 | | |
311 | 326 | | |
312 | | - | |
313 | | - | |
314 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
315 | 344 | | |
| 345 | + | |
| 346 | + | |
316 | 347 | | |
317 | 348 | | |
318 | 349 | | |
| |||
337 | 368 | | |
338 | 369 | | |
339 | 370 | | |
340 | | - | |
| 371 | + | |
341 | 372 | | |
342 | 373 | | |
343 | 374 | | |
| |||
349 | 380 | | |
350 | 381 | | |
351 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
352 | 396 | | |
353 | 397 | | |
354 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| |||
160 | 164 | | |
161 | 165 | | |
162 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 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 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
163 | 350 | | |
164 | 351 | | |
165 | 352 | | |
| |||
491 | 678 | | |
492 | 679 | | |
493 | 680 | | |
494 | | - | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
495 | 685 | | |
496 | 686 | | |
497 | 687 | | |
498 | 688 | | |
499 | 689 | | |
500 | 690 | | |
501 | | - | |
| 691 | + | |
502 | 692 | | |
503 | 693 | | |
504 | 694 | | |
| |||
0 commit comments