fix(desktop): bound start marks for traces that never record

Blind-review round 3 (Sonnet) finding: beginChannelSwitchTrace marked
unconditionally but only record() cleared, so every abandoned/dropped
trace (forum visits, route exits, hidden-window and frame-starved
drops) leaked a permanent buzz:channel-switch:start entry. Clearing
the previous start mark at begin bounds the buffer to one entry no
matter how the prior trace ended.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Max Lampert <maxwell@squareup.com>
This commit is contained in:
Max Lampert
2026-08-24 20:46:52 -07:00
parent 446174bc1d
commit f6d3388ecf
2 changed files with 27 additions and 0 deletions

View File

@@ -248,6 +248,27 @@ test("an undisturbed settle records exactly one measure", async () => {
});
});
test("abandoned switches never accumulate start marks", async () => {
await withSettleHarness(async ({ abandon, begin }) => {
const { CHANNEL_SWITCH_START_MARK } = await import(
"./channelSwitchPerf.ts"
);
performance.clearMarks?.(CHANNEL_SWITCH_START_MARK);
// Traces that die without recording (forum visits, route exits, drops)
// never reach record()'s buffer clearing — begin() must bound the
// buffer itself or weeks-long sessions accumulate a mark per abandon.
for (const channelId of ["aaaa", "bbbb", "cccc", "dddd"]) {
begin(channelId);
abandon(channelId);
}
assert.equal(
performance.getEntriesByName(CHANNEL_SWITCH_START_MARK).length,
1,
);
performance.clearMarks?.(CHANNEL_SWITCH_START_MARK);
});
});
test("a settle in a hidden window drops the trace instead of recording", async () => {
await withSettleHarness(
async ({ begin, settle, flush, measures }) => {

View File

@@ -201,6 +201,12 @@ export function beginChannelSwitchTrace(channelId: string): void {
windowFetch: null,
membersFetch: null,
};
// Clear the previous start mark here, not only in record(): traces that
// die without recording (forum visits, route exits, drops) never reach
// record()'s buffer clearing, and weeks-long sessions would accumulate a
// stray mark per abandon. Clearing at begin bounds the buffer to one
// start mark no matter how the previous trace ended.
performance.clearMarks(CHANNEL_SWITCH_START_MARK);
performance.mark(CHANNEL_SWITCH_START_MARK, { detail: { channelId } });
}