fix: address review bot findings on hover prewarm, Shiki cache, activity fan-out

- Sidebar hover prewarm: match Element instead of HTMLElement so resting on
  a row's SVG icons (status pill, PR badge) still resolves to the row's
  prewarm key instead of cancelling the hover.
- Shiki negative cache: bound it (100 entries) since fence labels are
  arbitrary text; evict failed loads from the promise cache so transient
  failures stay retryable; stop adding render-time codeToHtml throws to the
  negative cache so one pathological block can't disable highlighting for a
  supported language.
- Activity projection: skip the thread-row upsert entirely for non-summary
  activity kinds (not just the history rebuild) and skip the corresponding
  shell re-broadcast in ws.ts — high-volume command/output/progress streams
  no longer churn updatedAt or fan out per-event shell upserts.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-07-11 17:28:19 -07:00
1 parent 05e623fee9
commit 6b2f3f8ae8
4 files changed
+44 -14

No files matched your search

@@ -179,8 +179,9 @@ function derivePendingUserInputCountFromActivities(
// Activity kinds that can change the shell summary's pending-approval or
// pending-user-input counters. All other activity kinds (command output,
// file edits, streaming progress, ...) leave the summary untouched, so they
// must not trigger the history-wide summary rebuild.
const SHELL_SUMMARY_ACTIVITY_KINDS: ReadonlySet<string> = new Set([
// must not trigger the history-wide summary rebuild — and the shell stream
// (ws.ts toShellStreamEvent) skips re-broadcasting the thread row for them.
export const SHELL_SUMMARY_ACTIVITY_KINDS: ReadonlySet<string> = new Set([
"approval.requested",
"approval.resolved",
"provider.approval.respond.failed",
@@ -758,6 +759,14 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
}
case "thread.activity-appended": {
// Non-summary activities (command output, file edits, progress, ...)
// change no shell-visible field: the sidebar timestamp prefers
// latestUserMessageAt and status pills derive from session/approval
// state. Skip the row churn entirely so high-volume activity streams
// don't bump updatedAt (and fan out shell upserts) per event.
if (!SHELL_SUMMARY_ACTIVITY_KINDS.has(event.payload.activity.kind)) {
return;
}
const existingRow = yield* projectionThreadRepository.getById({
threadId: event.payload.threadId,
});
@@ -768,9 +777,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
...existingRow.value,
updatedAt: event.occurredAt,
});
if (SHELL_SUMMARY_ACTIVITY_KINDS.has(event.payload.activity.kind)) {
yield* refreshThreadShellSummary(event.payload.threadId);
}
yield* refreshThreadShellSummary(event.payload.threadId);
return;
}
+10
View File
@@ -68,6 +68,7 @@ import * as ServerConfig from "./config.ts";
import * as Keybindings from "./keybindings.ts";
import * as ExternalLauncher from "./process/externalLauncher.ts";
import { normalizeDispatchCommand } from "./orchestration/Normalizer.ts";
import { SHELL_SUMMARY_ACTIVITY_KINDS } from "./orchestration/Layers/ProjectionPipeline.ts";
import * as OrchestrationEngine from "./orchestration/Services/OrchestrationEngine.ts";
import * as ProjectionSnapshotQuery from "./orchestration/Services/ProjectionSnapshotQuery.ts";
import {
@@ -677,6 +678,15 @@ const makeWsRpcLayer = (
) {
return Effect.succeed(Option.none());
}
// Same for high-volume activity kinds (command output, file edits,
// progress): the projection skips the thread row for them, so a
// shell broadcast would be a no-op re-send of unchanged data.
if (
event.type === "thread.activity-appended" &&
!SHELL_SUMMARY_ACTIVITY_KINDS.has(event.payload.activity.kind)
) {
return Effect.succeed(Option.none());
}
return projectionSnapshotQuery
.getThreadShellById(ThreadId.make(event.aggregateId))
.pipe(
+19 -8
View File
@@ -142,7 +142,10 @@ const highlightedCodeCache = new LRUCache<string>(
const highlighterPromiseCache = new Map<string, Promise<DiffsHighlighter>>();
// Languages Shiki has no grammar for (e.g. `sh` fences). Without this negative
// cache every render of such a block retries the grammar load and throws again.
// Fence labels are arbitrary text, so cap both caches: past the cap, unknown
// languages just retry (the pre-cache behavior) instead of growing memory.
const fallbackHighlightLanguages = new Set<string>();
const MAX_FALLBACK_HIGHLIGHT_LANGUAGES = 100;
function findTaskListMarkerOffset(markdown: string, listItemStart: number): number | null {
const firstLineEnd = markdown.indexOf("\n", listItemStart);
@@ -276,6 +279,9 @@ function estimateHighlightedSize(html: string, code: string): number {
}
function getHighlighterPromise(language: string): Promise<DiffsHighlighter> {
if (fallbackHighlightLanguages.has(language)) {
return getHighlighterPromise("text");
}
const cached = highlighterPromiseCache.get(language);
if (cached) return cached;
@@ -284,15 +290,19 @@ function getHighlighterPromise(language: string): Promise<DiffsHighlighter> {
langs: [language as SupportedLanguages],
preferredHighlighter: "shiki-js",
}).catch((err) => {
// Failed loads never stay in the promise cache: unsupported languages are
// remembered in the (bounded) negative cache instead, and transient
// failures for real languages stay retryable.
highlighterPromiseCache.delete(language);
if (language === "text") {
// "text" itself failed — Shiki cannot initialize at all, surface the error
highlighterPromiseCache.delete(language);
throw err;
}
// Language not supported by Shiki — remember that and fall back to "text",
// keeping the resolved promise cached so the grammar load isn't retried on
// every render of a block with that language.
fallbackHighlightLanguages.add(language);
// Language not supported by Shiki — remember that and fall back to "text"
// so blocks with that language stop retrying the grammar load per render.
if (fallbackHighlightLanguages.size < MAX_FALLBACK_HIGHLIGHT_LANGUAGES) {
fallbackHighlightLanguages.add(language);
}
return getHighlighterPromise("text");
});
highlighterPromiseCache.set(language, promise);
@@ -694,13 +704,14 @@ function UncachedShikiCodeBlock({
try {
return highlighter.codeToHtml(code, { lang: effectiveLanguage, theme: themeName });
} catch (error) {
// Log highlighting failures for debugging while falling back to plain text
// Log highlighting failures for debugging while falling back to plain
// text. Render-time throws can be content-specific, so they don't join
// the negative cache — one pathological block must not disable
// highlighting for the whole language. Retries are bounded by the memo.
console.warn(
`Code highlighting failed for language "${language}", falling back to plain text.`,
error instanceof Error ? error.message : error,
);
// Remember the failure so subsequent renders skip the throwing path.
fallbackHighlightLanguages.add(language);
return highlighter.codeToHtml(code, { lang: "text", theme: themeName });
}
}, [code, highlighter, language, themeName]);
+3 -1
View File
@@ -260,7 +260,9 @@ function SidebarHoverThreadPrewarmer() {
onPrewarmTargetChange: setPrewarmThreadKey,
});
const onPointerOver = (event: globalThis.PointerEvent) => {
const target = event.target instanceof HTMLElement ? event.target : null;
// Element, not HTMLElement: row icons are SVG and must still resolve to
// their row's key instead of cancelling the hover.
const target = event.target instanceof Element ? event.target : null;
controller.hover(
target?.closest("[data-thread-prewarm-key]")?.getAttribute("data-thread-prewarm-key") ??
null,