mirror of
https://github.com/block/buzz.git
synced 2026-11-26 03:01:38 +00:00
fix(desktop): eliminate mounted-view CPU burn — compositor-safe shimmer, observer append fast path, poll-tick disk reads (#6198)
## Summary Live 0.5.16 review (Royal Court thread) traced the sustained 20–25% WebContent CPU burn in any large mounted channel with a working agent to three defects, in descending impact: 1. **Shimmer animation forces per-frame style + compositing walks.** `.buzz-shimmer` animated `background-position` under `-webkit-background-clip: text`, which WebKit cannot run on the compositor: every frame did a full document style resolve plus a recursive compositing-hierarchy update over the timeline's layer tree. The highlight now lives on an `aria-hidden` overlay child duplicating the label text and animates **opacity only** (compositor-accelerated); a real element is used instead of `::after` generated content so screen readers never see the duplicate text. Visual: the moving sweep becomes a gentle pulse. `prefers-reduced-motion` removes the overlay entirely — static muted label, exactly as before. 2. **Observer journal whole-journal dedup + re-sort per append.** Every one-per-second observer frame rebuilt a dedup Set over up to 3000 retained events and re-sorted the whole journal with a `Date.parse`-per-comparison comparator. In-order batches (the ordinary live path, same condition as the existing incremental transcript fold) now dedup within the batch and concat; out-of-order/replayed arrivals keep the full path. 3. **Redundant disk reads in the 5s agent-list poll.** `build_managed_agent_summary` re-read the global config from disk per call despite receiving it as a parameter, and re-read the teams store per tracked pair — 2N redundant reads per poll tick for N agents. Both are now caller-supplied; one-shot command paths use a `summarize_from_disk` helper. Same stores, same `unwrap_or_default` failure posture, read once. ## Evidence (mechanism attribution, live 0.5.16-block, mounted ~1500-event channel) - True-idle mounted view (working-state UI live): **25.08% mean / 24.15% median** WebContent CPU; post working-state decay: **6.33% / 3.50%**. - Reduce Motion A/B during a live agent turn (isolates the shimmer, working UI still mounted): **19.50% mean → 5.39% mean** (72% collapse). Native 10s samples: `Document::resolveStyle` 379 samples → 1; `updateCompositingLayersAfterStyleChange` 378 → 0; recursive `updateBackingAndHierarchy` 363 → 6. - The shimmer mechanism predates 0.5.16 (CSS unchanged since #3151); current multi-agent workloads exposed and amplified it. The mention regression itself was fixed separately in #6182. ## Testing - `desktop` observer store suites: 55/55 pass, including 5 new tests pinning the fast-path invariants (equal-timestamp seq ordering, duplicate-batch redelivery, intra-batch duplicates, overlapping late arrival takes the slow path, transcript-equals-replay on both paths). - `cargo test --lib managed_agents` (1016 passed) and `--lib commands` (727 passed); `cargo clippy` clean; `pnpm typecheck` + biome clean. - Release gate for the patched build (per Mongo): active-turn mounted CPU must collapse from the ~21–25% baseline with no per-frame style/compositing walk in a native sample — measured on Wes's workspace once a build with this branch is running. Findings and raw samples: `RESEARCH/LIVE_0_5_16_WEBKIT_ATTRIBUTION_2026_08_18.md`, `RESEARCH/RENDERER_STEADY_STATE_LOOP_AUDIT_2026_08_18.md`, `.scratch/live-app-review/` (Carl/Donut/Mongo/Brain, Royal Court thread 01a7fe75). --- *Opened by Brain (agent) via @wesbillman's account on his behalf — coordinated in Buzz channel agent-mention-policy-royal-court, thread 01a7fe75.* --------- Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -303,3 +303,116 @@ describe("live observer journal retention — eviction floor (reconnect replay)"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("live observer journal — in-order append fast path ordering/dedup", () => {
|
||||
// The common live path (every batch strictly after the retained tail) skips
|
||||
// the whole-journal dedup Set and re-sort. These pin the observable
|
||||
// invariants that authorize that skip: identical ordering, dedup, and
|
||||
// transcript against the general path.
|
||||
beforeEach(() => {
|
||||
resetAgentObserverStore();
|
||||
});
|
||||
|
||||
/** An event with an explicit timestamp, for equal-timestamp tie-breaks. */
|
||||
function makeEventAt(seq, timestampMs) {
|
||||
return {
|
||||
...makeEvent(seq),
|
||||
timestamp: new Date(timestampMs).toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
it("test_equal_timestamp_batch_orders_by_seq", () => {
|
||||
// A one-second harness frame batches several events sharing a timestamp;
|
||||
// the tie-break is seq. Deliver them out of seq order in one batch.
|
||||
const t = 1_760_000_100_000;
|
||||
syncAgentObserverEvents(AGENT_PUBKEY, [makeEventAt(1, t - 1000)]);
|
||||
syncAgentObserverEvents(AGENT_PUBKEY, [
|
||||
makeEventAt(4, t),
|
||||
makeEventAt(2, t),
|
||||
makeEventAt(3, t),
|
||||
]);
|
||||
assert.deepEqual(
|
||||
getAgentObserverSnapshot(AGENT_PUBKEY).events.map((event) => event.seq),
|
||||
[1, 2, 3, 4],
|
||||
"equal-timestamp events are retained in seq order",
|
||||
);
|
||||
});
|
||||
|
||||
it("test_duplicate_batch_redelivery_is_ignored", () => {
|
||||
// Relay redelivery of the newest batch: every event duplicates the tail,
|
||||
// so nothing is admitted, nothing is notified.
|
||||
const batch = [makeEvent(1), makeEvent(2), makeEvent(3)];
|
||||
syncAgentObserverEvents(AGENT_PUBKEY, batch);
|
||||
let notifications = 0;
|
||||
const unsubscribe = subscribeAgentObserverStore(() => {
|
||||
notifications += 1;
|
||||
});
|
||||
try {
|
||||
syncAgentObserverEvents(AGENT_PUBKEY, batch);
|
||||
} finally {
|
||||
unsubscribe();
|
||||
}
|
||||
assert.deepEqual(
|
||||
getAgentObserverSnapshot(AGENT_PUBKEY).events.map((event) => event.seq),
|
||||
[1, 2, 3],
|
||||
"a redelivered batch adds nothing",
|
||||
);
|
||||
assert.equal(notifications, 0, "a pure-duplicate batch notifies no one");
|
||||
});
|
||||
|
||||
it("test_batch_with_intra_batch_duplicate_admits_once", () => {
|
||||
// A batch strictly after the tail still dedups within itself.
|
||||
syncAgentObserverEvents(AGENT_PUBKEY, [makeEvent(1)]);
|
||||
syncAgentObserverEvents(AGENT_PUBKEY, [
|
||||
makeEvent(2),
|
||||
makeEvent(3),
|
||||
makeEvent(2),
|
||||
]);
|
||||
assert.deepEqual(
|
||||
getAgentObserverSnapshot(AGENT_PUBKEY).events.map((event) => event.seq),
|
||||
[1, 2, 3],
|
||||
"an intra-batch duplicate is admitted exactly once",
|
||||
);
|
||||
});
|
||||
|
||||
it("test_late_arrival_overlapping_tail_takes_slow_path_and_dedups", () => {
|
||||
// A replayed window straddling the tail: partly duplicate, partly new,
|
||||
// partly older-than-tail. Not all-after, so the general path must dedup
|
||||
// against the whole journal and re-sort.
|
||||
syncAgentObserverEvents(AGENT_PUBKEY, [
|
||||
makeEvent(1),
|
||||
makeEvent(2),
|
||||
makeEvent(4),
|
||||
]);
|
||||
syncAgentObserverEvents(AGENT_PUBKEY, [
|
||||
makeEvent(2),
|
||||
makeEvent(3),
|
||||
makeEvent(4),
|
||||
makeEvent(5),
|
||||
]);
|
||||
const events = getAgentObserverSnapshot(AGENT_PUBKEY).events;
|
||||
assert.deepEqual(
|
||||
events.map((event) => event.seq),
|
||||
[1, 2, 3, 4, 5],
|
||||
"overlapping late arrival dedups against the journal and sorts into place",
|
||||
);
|
||||
assert.deepEqual(
|
||||
getAgentTranscript(AGENT_PUBKEY),
|
||||
buildTranscript(events),
|
||||
"the transcript equals a full replay after a mixed-path sequence",
|
||||
);
|
||||
});
|
||||
|
||||
it("test_fast_path_transcript_equals_full_replay", () => {
|
||||
// Pure in-order streaming (fast path every time) must produce the same
|
||||
// derived transcript as a replay of the retained window.
|
||||
fillSequential(50);
|
||||
const events = getAgentObserverSnapshot(AGENT_PUBKEY).events;
|
||||
assert.equal(events.length, 50);
|
||||
assert.deepEqual(
|
||||
getAgentTranscript(AGENT_PUBKEY),
|
||||
buildTranscript(events),
|
||||
"in-order fast-path appends derive the same transcript as a replay",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user