Conversation
XERK-444 fixed the in-flight /api/agents snapshot clobbering a newer SSE patch for per-host agent records via sseClock/mergeSnapshot, but left the two other SSE-patched top-level keys in scope-out. They had the identical race: - cache.migrations (sessions.html) reverts a move's phase backward - cache.orgColors (index/usage/sessions.html) reverts an org colour pin Stamp the migrations/orgColors SSE handlers into the same patchedAt map (under '@'-prefixed keys that can't collide with a host key), and in mergeSnapshot keep the live value when it was patched after the fetch's captured 'since', else take the snapshot's. Single values, so a whole-value keep-if-newer suffices. Tests mirror the XERK-444 in-flight cases in sessions/dashboard/usage suites.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes XERK-545: an in-flight
/api/agentssnapshot clobbering a newer SSE patch to two top-levelcachekeys — the same race XERK-444 fixed for per-hostcache.agents, on the two other SSE-patched keys it deliberately left out of scope.cache.migrations(sessions.html) — amigrationsSSE event advancing a move's phase (e.g.exporting→importing) was reverted when the held (older) snapshot resolved, flickering the phase backward.cache.orgColors(index.html, usage.html, sessions.html) — anorgColorspin (red→blue) reverted to red when the stale snapshot landed.Both are low-severity, transient, self-healing (the window is the load-time poll racing an early SSE event, since SSE-healthy pages don't re-poll). Pre-existing — the pre-XERK-444 wholesale replace clobbered these too.
How
Extends the existing XERK-444
sseClock/patchedAt/mergeSnapshotmachinery to these keys:migrations/orgColorsSSE handlers nowstampPatch("@migrations")/stampPatch("@orgColors")— the@-prefix can't collide with an agent record'skey(a hostname).mergeSnapshot(body, since), after rebuildingbody.agents, keeps the livecache.migrations/cache.orgColorswhen it was patched after the fetch's capturedsince, otherwise takes the snapshot's. Single values, so a whole-value "keep if newer" — not the keyed-list merge the agents case needs.migrationsis protected only on sessions.html (the only page that consumes it);orgColorson all three.Tests
Added XERK-545 cases mirroring the XERK-444 in-flight tests:
turma/tests/sessions.test.js— migrations keep-live + the "unraced snapshot still replaces" negative; orgColors keep-live (both via the realsse.emithandlers).turma/tests/dashboard-tiles.test.js— orgColors keep-live + negative (realconnectSSEhandler).turma/tests/usage.test.js— orgColors keep-live via a genuinely in-flightrefresh()(fetch pending while the SSE handler fires).node --test turma/tests/*.test.js(the CI invocation) → 1700 pass, 1 skipped (pre-existing), 0 fail.QA
Handed to the
qaagent (first pass) — VERDICT: PASS, no defects. It ran the full suite green, then reverted only the three.htmlsource files (keeping the committed tests) and confirmed all four new cases FAIL against pre-fix code — proving they exercise the shippedmergeSnapshot/connectSSEvia the page-script harness, not a reimplementation. It independently enumerated everyes.addEventListeneron the three pages and confirmed the fix is complete (no other top-level-cache-mutating handler left unprotected). Not run: an end-to-end browser drive of the flicker — the defect is pure client-side cache-state ordering the node harness already asserts on with a real in-flight fetch.Parity / scope
/api/agentssnapshot atomically and never interleaves a partial SSE patch into a live cache, so this race is structurally absent (per CLAUDE.md's XERK-444 note). Not aPARITY.mdgap.orgColorsrace but was deliberately excluded from both XERK-444 and XERK-545 (it has nomergeSnapshotat all — a wholesalecache = await r.json()), so a fix there is a different shape and a scope decision. Filed as XERK-546 with repro + file:line rather than growing this PR onto an out-of-scope page.