Repository navigation
Commit 518a9e7
authored
* fix(cache): SWR background revalidation runs under a derived context — no shared handle-store swap, no shared-arg stamping (#684 plan 010)
Production waitUntil is Promise.resolve().then(fn), so the stale-hit
background revalidation's prologue runs one microtask after scheduling —
INSIDE the foreground's render window. The prologue swapped the SHARED
requestCtx._handleStore (restore only in finally, i.e. after the whole
revalidation's I/O) and stamped INSIDE_CACHE_EXEC onto shared tainted args.
Consequences, all reproduced with production-faithful scheduling:
(a) foreground handle pushes during the window landed in the background's
isolated store — lost from the live document; (b) those misrouted pushes
were PERSISTED into the revalidated cache entry (cross-contamination);
(c) a concurrent foreground ctx.set()/ctx.headers.*() threw
INSIDE_CACHE_EXEC. The existing suite pinned the hazardous behavior behind
queue-style waitUntil mocks that run the background after the foreground
finished — exactly the ordering production does not have.
Fix: the background body runs under a DERIVED context
(Object.create(requestCtx) with an own _handleStore — the shell-capture
isolation pattern). Background pushes land in the isolated store and are
captured/persisted as before; the foreground's store is never touched; no
restore step exists because nothing shared is mutated. The background no
longer stamps shared args: in-fn misuse is caught by the miss path's stamps
on the function's FIRST execution (an entry only becomes
stale-revalidatable because a stamped miss ran clean) — that invariant is
now recorded at the miss-path stamp itself.
Tests: the two pinning tests re-pointed to the safe contract; a new
production-faithful race test gates the background open mid-window and
asserts no swap, no stamp, foreground push reaches the live store, and the
revalidated entry carries only background pushes. The mocked
runWithRequestContext now threads its ctx (a passthrough would hide the
isolation under test). Red-before-green: 2 failed on the old code, 20/20
with the fix.
* ci: trigger full run post-ready
1 parent b7588cb commit 518a9e7
2 files changed
Lines changed: 152 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
32 | 42 | | |
33 | 43 | | |
34 | 44 | | |
| |||
256 | 266 | | |
257 | 267 | | |
258 | 268 | | |
259 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
260 | 275 | | |
261 | 276 | | |
262 | 277 | | |
| |||
307 | 322 | | |
308 | 323 | | |
309 | 324 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
314 | 328 | | |
315 | | - | |
316 | | - | |
317 | 329 | | |
318 | 330 | | |
319 | 331 | | |
320 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
321 | 422 | | |
322 | 423 | | |
323 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | 415 | | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
435 | 435 | | |
436 | 436 | | |
437 | 437 | | |
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
465 | 452 | | |
466 | 453 | | |
467 | 454 | | |
468 | 455 | | |
469 | 456 | | |
470 | 457 | | |
471 | 458 | | |
472 | | - | |
473 | | - | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
474 | 463 | | |
475 | 464 | | |
476 | 465 | | |
| |||
507 | 496 | | |
508 | 497 | | |
509 | 498 | | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | 499 | | |
| 500 | + | |
| 501 | + | |
519 | 502 | | |
520 | 503 | | |
521 | 504 | | |
| |||
601 | 584 | | |
602 | 585 | | |
603 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
604 | 594 | | |
605 | 595 | | |
606 | 596 | | |
| |||
0 commit comments