fix: a batch the user themselves cancelled is not called a lapse

Picking "Alap" revokes the consent, and a batch still in flight is then answered by the server with
the same 409 a real expiry gets. The 409 arm only checked that the consent session had not changed,
not that this tab was still streaming — so the user's own log gained a "diagnostics level lapsed"
line for a level they had just turned off themselves, plus a pointless `me` refetch. The same guard
also stops a lapse this tab has already announced being announced a second time.

Measured in Chrome by holding the POST at the network layer, switching to Alap and only then
answering 409: the line appears without the guard and not with it.

Three tests that named the session counter never reached it — they settled the refusal while the
stream was already stopped, where `unsubscribe` does the work, so the counter could be deleted from
both arms with the suite green. The refusal now settles after the re-raise, which is the ordering it
exists for. Same for the queue trim on the 429 path: the old test unshifted a batch into an empty
queue, so the trim was a no-op and only the subscribe path was ever measured.
This commit is contained in:
2026-09-17 23:45:29 +02:00
parent 07e3ea3737
commit 986bc8d01e
2 changed files with 92 additions and 2 deletions
+11 -2
View File
@@ -128,8 +128,17 @@ async function flush(): Promise<void> {
queue.unshift(...batch);
keepNewest();
}
} else if (err instanceof HttpError && err.status === 409 && takenIn === session) {
lapse(); // the server has it off: withdrawn in another tab, or lapsed by its clock
} else if (
err instanceof HttpError &&
err.status === 409 &&
takenIn === session &&
unsubscribe
) {
// The server has it off: withdrawn in another tab, or lapsed by its clock. `unsubscribe`
// means THIS tab does not already know — without it, the 409 answering a batch that was in
// flight when the user picked Alap writes "lapsed" into their own log for a level they
// revoked, and a lapse this tab has already announced gets announced a second time.
lapse();
}
} finally {
inFlight = false;