You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "Astro-Han (via GitHub)" <gi...@apache.org> on 2026/08/29 17:33:44 UTC

[PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Astro-Han opened a new pull request, #4206:
URL: https://github.com/apache/maka/pull/4206

   ## Summary
   
   Long Desktop transcripts kept the full accumulated history in the Renderer snapshot, then added a second row-level virtual layout authority to decide which Turns existed in the DOM. Every batch also sorted and `structuredClone`d the whole snapshot. This made retained heap follow history size and coupled prompt navigation, history anchoring, focus, selection, find, and accessibility to spacer/height compensation state.
   
   This PR makes the Runtime Host replica the only owner of the bounded active transcript range (10 Turns and 512 KiB), keeps `DesktopTranscriptRangeStore` as an immutable reference-stable projection of that range, and renders every active Turn with Chromium `content-visibility: auto`. The replaced row virtualizer, height index, spacers, geometry compensation, full-snapshot sort, and full-snapshot clone paths are deleted in the same diff; there is no compatibility path.
   
   It also removes the remaining warm-scroll LoAF root cause: three onboarding layout selectors used descendant `:has()`. Prompt-rail changes to `data-active`/`aria-current` therefore invalidated the entire chat subtree. `AppShell`, which already owns `showOnboardingHero`, now projects that state directly onto the existing layout element.
   
   ## Architecture responsibilities
   
   - Runtime Host: sole Session / Turn / Transcript / Lifecycle authority; owns byte- and Turn-bounded active range and protects the reader's sequence anchor during history paging.
   - `DesktopTranscriptRangeStore`: one immutable Renderer projection; incrementally maintains ordered identities, freezes changed messages once, and invalidates a single bounded snapshot only when a batch commits. It is disposable derived state, not a second transcript source.
   - React: stable Turn identity and declarative rendering of the Host range only.
   - `useChatScroll`: unchanged sole scroll authority; supplies the visible Turn anchor when requesting older history.
   - Astryx streaming text/parser: unchanged sole streaming display scheduler.
   - Chromium: skips offscreen layout/paint through `content-visibility`; no JavaScript row virtualizer remains.
   - CDP harness: read-only measurement only; it does not participate in product state.
   
   ## Root cause evidence
   
   The first candidate improved aggregate CPU and memory but still produced four warm-scroll runs with a >50 ms LoAF. A CDP trace with style invalidation tracking attributed a 56 ms frame to 48.744 ms of `Document::UpdateStyleAndLayout`, including 46.251 ms of style recalculation across 1,234 elements (69,482 rule fast rejects and 24,815 matches). The invalidation chain began at prompt-rail `data-active` / `aria-current`, propagated through “Affected by :has()”, and marked `.maka-chat-layout` descendants dirty.
   
   Replacing only those three broad relational selectors with the existing owner's direct `data-maka-onboarding` projection reduced the diagnostic sample from 4/7 warm LoAF failures to 0/8 before the formal run. No new observer or scheduler was added.
   
   ## Reproducible CDP A/B
   
   Predeclared primary metrics: CDP `TaskDuration` and `RecalcStyleDuration`. Release gates: >=20% median improvement, >=6/7 paired wins, improvement above A noise, 120 Hz scroll P95 <=12.5 ms, no warm >50 ms LoAF, and no >10% regression in heap/DOM/listeners/session switching or interaction correctness.
   
   - A: locked starting `main` SHA `00a15abdc5e1494e7c7c9d04629ec77644dcf301`
   - B: candidate SHA `daa77a5993f7905286d29bc41f027c93423729ad`
   - Order: `A1-B1, B2-A2, A3-B3, B4-A4, A5-B5, B6-A6, A7-B7`
   - Environment: Apple M5 Pro / 64 GiB, macOS 26.6.2 (25G83), Electron/Chromium 43.4.1, 1000x700 window
   - Controlled inputs: production `build:with-deps` at each SHA, same dependency installation, 120-Turn fixture, same read-only Playwright/CDP script, one worker, 600 px / 240-rAF warm gesture
   
   Raw paired primary results (milliseconds; lower is better):
   
   | Pair | A Task | B Task | Task gain | A Recalc | B Recalc | Recalc gain | A/B frame P95 | B >50 ms LoAF |
   |---:|---:|---:|---:|---:|---:|---:|---:|---:|
   | 1 | 717.5 | 254.1 | 64.6% | 308.8 | 24.6 | 92.0% | 9.3 / 8.7 | 0 |
   | 2 | 545.2 | 280.0 | 48.7% | 231.7 | 26.6 | 88.5% | 9.0 / 9.3 | 0 |
   | 3 | 844.1 | 298.2 | 64.7% | 390.8 | 28.9 | 92.6% | 9.3 / 8.4 | 0 |
   | 4 | 588.2 | 215.0 | 63.5% | 257.2 | 20.2 | 92.1% | 9.3 / 8.9 | 0 |
   | 5 | 746.7 | 202.8 | 72.8% | 343.3 | 18.8 | 94.5% | 8.9 / 9.2 | 0 |
   | 6 | 479.1 | 206.0 | 57.0% | 228.2 | 18.0 | 92.1% | 9.2 / 9.2 | 0 |
   | 7 | 742.7 | 195.7 | 73.6% | 347.6 | 17.6 | 94.9% | 9.1 / 9.3 | 0 |
   
   Aggregate primary distribution:
   
   | Metric | A median / P95 / P99 | B median / P95 / P99 | Median gain | A/B IQR | A/B CV | Paired wins |
   |---|---|---|---:|---|---|---:|
   | Task | 717.5 / 814.8 / 838.2 | 215.0 / 292.8 / 297.1 | 70.0% | 177.9 / 62.7 | 19.6% / 17.5% | 7/7 |
   | RecalcStyle | 308.8 / 377.9 / 388.2 | 20.2 / 28.2 / 28.8 | 93.5% | 101.0 / 7.2 | 21.0% / 20.6% | 7/7 |
   
   The weakest paired gains (48.7% Task and 88.5% RecalcStyle) exceed A's IQR/median noise (24.8% and 32.7%) and CV (19.6% and 21.0%).
   
   Secondary medians:
   
   | Metric | A | B | Change |
   |---|---:|---:|---:|
   | Frame P95 | 9.2 ms | 9.2 ms | 0.0% |
   | Frame P99 | 25.0 ms | 9.3 ms | -62.8% |
   | Frames >12.5 ms | 4 | 0 | -100% |
   | Warm LoAF >50 ms | 0 median; one run had 2 | 0 in all 7 runs | improved |
   | Renderer heap | 25,526,628 B | 25,638,164 B | +0.44% |
   | Nodes | 2,807 | 2,896 | +3.17% |
   | DOM elements | 2,322 | 2,402 | +3.45% |
   | JS listeners | 1,683 | 1,746 | +3.74% |
   | Session switch | 342.3 ms | 284.7 ms | -16.8% |
   
   The 640-Turn repeated-paging stress ran two complete sweeps (24 samples). Mounted Turns stayed at 10; Nodes stayed bounded at roughly 3,006-3,023 (one 2,924 sample); after warm-up the second-sweep heap plateau stayed around 28.28-28.34 MB through the final page instead of tracking accumulated history.
   
   ## Entropy ledger
   
   | Scoped concept | Before | After | Delta / owner |
   |---|---:|---:|---|
   | Transcript semantic authorities | 1 | 1 | Runtime Host remains the only authority |
   | Persistent transcript state added | 0 | 0 | none |
   | Runtime transcript state owners | 3 | 2 | removed Renderer row virtualizer; Host range + disposable Renderer projection remain |
   | Message/layout representations | 3 | 2 | removed virtual-window/height/spacer representation; Host protocol + immutable Renderer snapshot remain |
   | Observer instances in transcript scroll composition | 7 | 5 | removed virtualizer `ResizeObserver` and `MutationObserver`; existing `useChatScroll` and prompt-rail owners remain |
   | rAF scheduler owners | 3 | 2 | removed virtualizer scheduler; existing `useChatScroll` and prompt-rail schedulers remain |
   
   Added concepts and why they cannot be deleted:
   
   - Host Turn cap: supplies the required node/heap bound at the existing authority.
   - Two ordered identity arrays plus one invalidated snapshot reference: preserve immutable message identity without per-batch full sort/clone; all are bounded by and discarded with the Host range.
   - `data-maka-onboarding`: direct projection of an existing `AppShell` boolean, required to express the three layout rules without subtree-wide `:has` invalidation; it stores no independent state.
   - Read-only CDP test: makes the release claim reproducible and remains outside product state.
   
   Deleted in the same diff: row virtualizer hook, height index, virtual layout model, before/after spacers, height LRU, geometry revision and compensation state, virtualizer observers/rAF, full-snapshot sorting, full-snapshot `structuredClone`, and the three broad onboarding `:has` selectors. Diff against A: 26 files, +874 / -1,427 (net -553 lines).
   
   ## Verification
   
   - `npm run build:with-deps` (A and B production builds)
   - Desktop typecheck: pass
   - UI typecheck: pass
   - Biome on all changed/new files: pass
   - Desktop focused unit tests (range store, streaming handoff, transcript identity): 45/45 pass
   - UI focused unit tests (prompt anchor rail, transcript scroll authority): 18/18 pass
   - `transcript-scroll.spec.ts` + `prompt-rail.spec.ts`: 18/18 pass
     - covers streaming tail follow, scroll-away, nested scroller, return latest, both history-anchor paths, stable Turn DOM identity, prompt navigation, focus/selection, browser find/accessibility, and session switch
   - `onboarding-viewport.spec.ts`: 2/2 pass
   - prompt-jump landing repeat: 10/10 pass
   - 640-Turn repeated-paging stress: pass; bounded mounted Turns, Nodes, and warm heap plateau
   - 7-pair interleaved production CDP A/B: pass all release gates above
   - `git diff --check`: pass
   
   ## Risks
   
   - History paging now evicts whole Turns around a protected visible sequence instead of retaining every previously visited message. Tests cover normal/top-edge history loading, prompt navigation outside the active range, return-to-latest, and session reconstruction.
   - `content-visibility` intentionally leaves active-range Turn DOM nodes available for selection, focus, find, and accessibility while Chromium skips offscreen rendering. E2E covers those composition boundaries.
   - The branch is based on the predeclared A SHA. A read-only merge-tree check against current `origin/main` is clean; final integration still needs ordinary current-head CI/review.
   
   ## AI use
   
   Select exactly one:
   
   - [ ] No generative tool made a substantive contribution
   - [x] Generative tooling made a substantive contribution
   
   Tool(s) and scope: Codex diagnosed the CDP trace and style-invalidation root cause, implemented the Host-bounded projection and Renderer simplification, authored tests and the read-only benchmark harness, and prepared the measurements. Material commits include `Generated-by: Codex` trailers.
   
   ## Checklist
   
   - [x] Tests cover the change and fail without it
   - [x] Lint, format, typecheck and the affected suites pass locally
   
   Does this PR entail a change in behavior?
   
   - [x] Yes — described under Summary above
   - [ ] No
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #4206:
URL: https://github.com/apache/maka/pull/4206#discussion_r3888236995


##########
apps/desktop/src/main/desktop-transcript-replica.ts:
##########
@@ -135,7 +140,11 @@ export class DesktopTranscriptReplica {
         replica.#installDurable(durable.messages);
         replica.#hasOlder = durable.nextCursor !== null;
       });
-      replica.#evictToBudget();
+      replica.#evictToBudget(
+        undefined,
+        'oldest',
+        replica.#newestTurnSequence() ?? replica.#durableThrough ?? undefined,

Review Comment:
   Fixed in `f356dce39`. Runtime Host now publishes a signed, authoritative `rangeBoundarySequence` separately from `protectedTurnSequence`, and Desktop follows continuation pages through that boundary before eviction, so the latest Turn is complete even when its prompt and assistant span the 16 KiB bootstrap. The final tests cover fragmented oversized latest Turns, exact 256-message owner/shared Turn boundaries in both directions, 257-message rejection, trailing session notes, and shared projections separated by more than one hidden storage batch. Runtime Host focused tests pass 38/38, Desktop range-store tests 29/29, and the 640-Turn two-sweep stress reaches Turn 1 with the mounted range capped at 10.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #4206:
URL: https://github.com/apache/maka/pull/4206#discussion_r3888043085


##########
apps/desktop/e2e/transcript-scroll.spec.ts:
##########
@@ -353,6 +353,60 @@ test('a gesture a nested scroller consumed does not release the tail', async ({
   expect(await scrollButtonOffered(page)).toBe(false);
 });
 
+test('a nested scroller near the history boundary does not request an earlier range', async ({

Review Comment:
   Fixed in `1b798e98d`. The injected scroller now stays under the transcript message list but outside each Turn’s `content-visibility` paint containment. The test verifies the real `elementFromPoint` target before sending a real mouse wheel, so an intercepted gesture fails directly instead of entering Playwright hover retries. The focused case passed 5/5, transcript-scroll + prompt-rail passed 19/19, and hosted CI run 33272246691 is green on this exact head. Thanks for catching the Linux/Xvfb gap.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Posted by "zhiiw (via GitHub)" <gi...@apache.org>.
zhiiw commented on code in PR #4206:
URL: https://github.com/apache/maka/pull/4206#discussion_r3887495537


##########
apps/desktop/e2e/transcript-scroll.spec.ts:
##########
@@ -353,6 +353,60 @@ test('a gesture a nested scroller consumed does not release the tail', async ({
   expect(await scrollButtonOffered(page)).toBe(false);
 });
 
+test('a nested scroller near the history boundary does not request an earlier range', async ({

Review Comment:
   [P1] This test fails on the hosted CI runner at this head (`test` job, `Desktop e2e` step, run 33270284081): `locator.hover` on `[data-nested-history-scroller="true"]` times out after 30 s, so the element never becomes actionable there. The PR's own verification reports the Desktop E2E green locally (macOS), so the behavior differs between the author's machine and the hosted Linux/Electron environment — until that gap is reconciled, the PR's evidence does not hold on the merge gate.
   
   One plausible mechanism worth checking first: the injected box is `position: fixed` inside a `[data-turn-id]` subtree that now carries `content-visibility: auto` — a fixed descendant of a skipped (offscreen) subtree is not rendered, and the anchor turn chosen here sits at the very top edge of the scrollport. Whether it is that or something else, this needs a head where the hosted runner is green.
   
   ---
   
   > **Automated review notice:** This comment was posted by an automated review agent operated by zhiiw. It is not an independent human review and does not replace one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #4206:
URL: https://github.com/apache/maka/pull/4206#discussion_r3888658216


##########
packages/runtime-host/src/server/session-transcript-pager.ts:
##########
@@ -217,83 +241,281 @@ export async function readSessionTranscriptPage(input: {
     position: position.position,
     ...(position.byteOffset === null ? {} : { byteOffset: position.byteOffset }),
     maxBytes: request.maxBytes,
-    maxMessages: SESSION_TRANSCRIPT_PAGE_MAX_MESSAGES,
+    maxMessages: continuationMessageLimit(position),
   } as const;
   const storage =
     state.projection === 'shared'
-      ? await readSharedDurablePage(input.reader, state.sessionId, durableRequest)
+      ? await readSharedDurablePage(
+          input.reader,
+          state.sessionId,
+          durableRequest,
+          position.rangeBoundarySequence,
+        )
       : await input.reader.readDurablePage(state.sessionId, durableRequest);
+  const selected = storageSelection(storage);
+  const rangeEdges = await readRangeEdges({
+    reader: input.reader,
+    state,
+    direction: request.direction,
+    throughSequence: request.throughSequence,
+    selected,
+  });
   return pageFromSelection(
     state,
     'durable',
     request.direction,
-    storageSelection(storage),
+    selected,
     request.throughSequence,
+    rangeEdges.rangeBoundarySequence,
+    rangeEdges.protectedTurnSequence,
+  );
+}
+
+async function readRangeEdges(input: {
+  reader: SessionTranscriptReader;
+  state: SubscriberTranscriptState;
+  direction: SessionTranscriptPageDirection;
+  throughSequence: number | null;
+  selected: SelectedFragments;
+}): Promise<{
+  readonly rangeBoundarySequence: number | null;
+  readonly protectedTurnSequence: number | null;
+}> {
+  if (input.throughSequence === null) {
+    return { rangeBoundarySequence: null, protectedTurnSequence: null };
+  }
+  const selectedSequences = input.selected.fragments.flatMap((fragment) =>
+    fragment.kind === 'durable' ? [fragment.sequence] : [],
   );
+  if (selectedSequences.length === 0) {
+    return { rangeBoundarySequence: null, protectedTurnSequence: null };
+  }
+  const boundaryCandidate =
+    input.direction === 'older' ? Math.min(...selectedSequences) : Math.max(...selectedSequences);
+  const scanPosition =
+    input.direction === 'older' ? Math.max(...selectedSequences) : Math.min(...selectedSequences);
+  let targetTurnId: string | undefined;
+  let boundary: number | null = null;
+  let protectedTurnId: string | undefined;
+  let protectedTurnSequence: number | null = null;
+  let latestTurnSequence: number | null = null;
+  let rangeBytes = 0;
+  let rangeMessages = 0;
+  let hiddenBytes = 0;
+  let reachedFarEdge = false;
+  let position: number | null = scanPosition;
+  while (position !== null && !reachedFarEdge) {
+    const scanned = await input.reader.readDurableRecords(input.state.sessionId, {
+      direction: input.direction,
+      throughSequence: input.throughSequence,
+      position,
+      maxStoredBytes: SESSION_TRANSCRIPT_RANGE_MAX_BYTES,
+      maxMessages: SESSION_TRANSCRIPT_RANGE_MAX_MESSAGES,
+    });
+    for (const record of scanned.records) {
+      const message =
+        input.state.projection === 'shared'
+          ? projectSharedSessionTranscriptMessage(record.message, input.state.sessionId)
+          : record.message;
+      if (!message) {
+        hiddenBytes += Buffer.byteLength(JSON.stringify(record.message), 'utf8');
+        if (hiddenBytes > SESSION_TRANSCRIPT_RANGE_MAX_BYTES) {
+          throw new RangeError('Session transcript projection scan exceeds its capacity limit');
+        }
+        continue;
+      }
+      const turnId = messageTurnId(message);
+      if (boundary !== null && turnId !== targetTurnId) {
+        reachedFarEdge = true;
+        break;
+      }
+      rangeMessages += 1;
+      rangeBytes += Buffer.byteLength(JSON.stringify(message), 'utf8');
+      if (
+        rangeMessages > SESSION_TRANSCRIPT_RANGE_MAX_MESSAGES ||

Review Comment:
   Correction after merge: #4206 merged at `f356dce39`; the later local `4a938fbfd` was not part of that merge. The complete-Turn prefix fix and removal of the `maxMessages - 1` heuristic are now isolated in follow-up #4244 at `52487f2ea`, with exact-head focused tests, 640-Turn stress, and interleaved no-regression A/B evidence. The #4206 body has also been corrected to distinguish its merged head from the follow-up.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #4206:
URL: https://github.com/apache/maka/pull/4206#discussion_r3888609913


##########
packages/runtime-host/src/server/session-transcript-pager.ts:
##########
@@ -217,83 +241,281 @@ export async function readSessionTranscriptPage(input: {
     position: position.position,
     ...(position.byteOffset === null ? {} : { byteOffset: position.byteOffset }),
     maxBytes: request.maxBytes,
-    maxMessages: SESSION_TRANSCRIPT_PAGE_MAX_MESSAGES,
+    maxMessages: continuationMessageLimit(position),
   } as const;
   const storage =
     state.projection === 'shared'
-      ? await readSharedDurablePage(input.reader, state.sessionId, durableRequest)
+      ? await readSharedDurablePage(
+          input.reader,
+          state.sessionId,
+          durableRequest,
+          position.rangeBoundarySequence,
+        )
       : await input.reader.readDurablePage(state.sessionId, durableRequest);
+  const selected = storageSelection(storage);
+  const rangeEdges = await readRangeEdges({
+    reader: input.reader,
+    state,
+    direction: request.direction,
+    throughSequence: request.throughSequence,
+    selected,
+  });
   return pageFromSelection(
     state,
     'durable',
     request.direction,
-    storageSelection(storage),
+    selected,
     request.throughSequence,
+    rangeEdges.rangeBoundarySequence,
+    rangeEdges.protectedTurnSequence,
+  );
+}
+
+async function readRangeEdges(input: {
+  reader: SessionTranscriptReader;
+  state: SubscriberTranscriptState;
+  direction: SessionTranscriptPageDirection;
+  throughSequence: number | null;
+  selected: SelectedFragments;
+}): Promise<{
+  readonly rangeBoundarySequence: number | null;
+  readonly protectedTurnSequence: number | null;
+}> {
+  if (input.throughSequence === null) {
+    return { rangeBoundarySequence: null, protectedTurnSequence: null };
+  }
+  const selectedSequences = input.selected.fragments.flatMap((fragment) =>
+    fragment.kind === 'durable' ? [fragment.sequence] : [],
   );
+  if (selectedSequences.length === 0) {
+    return { rangeBoundarySequence: null, protectedTurnSequence: null };
+  }
+  const boundaryCandidate =
+    input.direction === 'older' ? Math.min(...selectedSequences) : Math.max(...selectedSequences);
+  const scanPosition =
+    input.direction === 'older' ? Math.max(...selectedSequences) : Math.min(...selectedSequences);
+  let targetTurnId: string | undefined;
+  let boundary: number | null = null;
+  let protectedTurnId: string | undefined;
+  let protectedTurnSequence: number | null = null;
+  let latestTurnSequence: number | null = null;
+  let rangeBytes = 0;
+  let rangeMessages = 0;
+  let hiddenBytes = 0;
+  let reachedFarEdge = false;
+  let position: number | null = scanPosition;
+  while (position !== null && !reachedFarEdge) {
+    const scanned = await input.reader.readDurableRecords(input.state.sessionId, {
+      direction: input.direction,
+      throughSequence: input.throughSequence,
+      position,
+      maxStoredBytes: SESSION_TRANSCRIPT_RANGE_MAX_BYTES,
+      maxMessages: SESSION_TRANSCRIPT_RANGE_MAX_MESSAGES,
+    });
+    for (const record of scanned.records) {
+      const message =
+        input.state.projection === 'shared'
+          ? projectSharedSessionTranscriptMessage(record.message, input.state.sessionId)
+          : record.message;
+      if (!message) {
+        hiddenBytes += Buffer.byteLength(JSON.stringify(record.message), 'utf8');
+        if (hiddenBytes > SESSION_TRANSCRIPT_RANGE_MAX_BYTES) {
+          throw new RangeError('Session transcript projection scan exceeds its capacity limit');
+        }
+        continue;
+      }
+      const turnId = messageTurnId(message);
+      if (boundary !== null && turnId !== targetTurnId) {
+        reachedFarEdge = true;
+        break;
+      }
+      rangeMessages += 1;
+      rangeBytes += Buffer.byteLength(JSON.stringify(message), 'utf8');
+      if (
+        rangeMessages > SESSION_TRANSCRIPT_RANGE_MAX_MESSAGES ||

Review Comment:
   Fixed in `4a938fbfd`. The Host now groups the scanned projection by complete Turn and publishes the largest complete prefix within the existing 256-message/16 MiB range. If the far-edge Turn does not fit, the current selection is trimmed before it and the next signed cursor restarts at that Turn’s first sequence, so no partial Turn is exposed or skipped. The obsolete `maxMessages - 1` seed reservation has also been removed; durable seed and continuation reads use the authoritative 256-message limit directly. Regression coverage includes bootstrap older and forward newer, owner/shared, exact-256 acceptance, 257-message rejection, and cursor continuation without gaps or duplicates. Runtime Host focused tests pass 40/40, the final 640-Turn two-sweep stress passes, and the final-head 7-pair A/B still clears the release gate.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han merged PR #4206:
URL: https://github.com/apache/maka/pull/4206


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Posted by "hqhq1025 (via GitHub)" <gi...@apache.org>.
hqhq1025 commented on code in PR #4206:
URL: https://github.com/apache/maka/pull/4206#discussion_r3888275407


##########
packages/runtime-host/src/server/session-transcript-pager.ts:
##########
@@ -217,83 +241,281 @@ export async function readSessionTranscriptPage(input: {
     position: position.position,
     ...(position.byteOffset === null ? {} : { byteOffset: position.byteOffset }),
     maxBytes: request.maxBytes,
-    maxMessages: SESSION_TRANSCRIPT_PAGE_MAX_MESSAGES,
+    maxMessages: continuationMessageLimit(position),
   } as const;
   const storage =
     state.projection === 'shared'
-      ? await readSharedDurablePage(input.reader, state.sessionId, durableRequest)
+      ? await readSharedDurablePage(
+          input.reader,
+          state.sessionId,
+          durableRequest,
+          position.rangeBoundarySequence,
+        )
       : await input.reader.readDurablePage(state.sessionId, durableRequest);
+  const selected = storageSelection(storage);
+  const rangeEdges = await readRangeEdges({
+    reader: input.reader,
+    state,
+    direction: request.direction,
+    throughSequence: request.throughSequence,
+    selected,
+  });
   return pageFromSelection(
     state,
     'durable',
     request.direction,
-    storageSelection(storage),
+    selected,
     request.throughSequence,
+    rangeEdges.rangeBoundarySequence,
+    rangeEdges.protectedTurnSequence,
+  );
+}
+
+async function readRangeEdges(input: {
+  reader: SessionTranscriptReader;
+  state: SubscriberTranscriptState;
+  direction: SessionTranscriptPageDirection;
+  throughSequence: number | null;
+  selected: SelectedFragments;
+}): Promise<{
+  readonly rangeBoundarySequence: number | null;
+  readonly protectedTurnSequence: number | null;
+}> {
+  if (input.throughSequence === null) {
+    return { rangeBoundarySequence: null, protectedTurnSequence: null };
+  }
+  const selectedSequences = input.selected.fragments.flatMap((fragment) =>
+    fragment.kind === 'durable' ? [fragment.sequence] : [],
   );
+  if (selectedSequences.length === 0) {
+    return { rangeBoundarySequence: null, protectedTurnSequence: null };
+  }
+  const boundaryCandidate =
+    input.direction === 'older' ? Math.min(...selectedSequences) : Math.max(...selectedSequences);
+  const scanPosition =
+    input.direction === 'older' ? Math.max(...selectedSequences) : Math.min(...selectedSequences);
+  let targetTurnId: string | undefined;
+  let boundary: number | null = null;
+  let protectedTurnId: string | undefined;
+  let protectedTurnSequence: number | null = null;
+  let latestTurnSequence: number | null = null;
+  let rangeBytes = 0;
+  let rangeMessages = 0;
+  let hiddenBytes = 0;
+  let reachedFarEdge = false;
+  let position: number | null = scanPosition;
+  while (position !== null && !reachedFarEdge) {
+    const scanned = await input.reader.readDurableRecords(input.state.sessionId, {
+      direction: input.direction,
+      throughSequence: input.throughSequence,
+      position,
+      maxStoredBytes: SESSION_TRANSCRIPT_RANGE_MAX_BYTES,
+      maxMessages: SESSION_TRANSCRIPT_RANGE_MAX_MESSAGES,
+    });
+    for (const record of scanned.records) {
+      const message =
+        input.state.projection === 'shared'
+          ? projectSharedSessionTranscriptMessage(record.message, input.state.sessionId)
+          : record.message;
+      if (!message) {
+        hiddenBytes += Buffer.byteLength(JSON.stringify(record.message), 'utf8');
+        if (hiddenBytes > SESSION_TRANSCRIPT_RANGE_MAX_BYTES) {
+          throw new RangeError('Session transcript projection scan exceeds its capacity limit');
+        }
+        continue;
+      }
+      const turnId = messageTurnId(message);
+      if (boundary !== null && turnId !== targetTurnId) {
+        reachedFarEdge = true;
+        break;
+      }
+      rangeMessages += 1;
+      rangeBytes += Buffer.byteLength(JSON.stringify(message), 'utf8');
+      if (
+        rangeMessages > SESSION_TRANSCRIPT_RANGE_MAX_MESSAGES ||

Review Comment:
   [P1] Trim the seed before completing a multi-record edge Turn
   
   The initial read always takes up to 255 durable messages, but this scan counts that entire selection plus every earlier/later record needed to finish the far-edge Turn. Reserving one slot only handles a boundary Turn that needs one additional record. On this head, a valid 257-record transcript with sequences 0-2 in one Turn and 3-256 in distinct Turns (14,983 encoded bytes total) makes `createSessionTranscriptBootstrap()` throw here after counting 257 records; the same shape fails for a forward page. The coordinator then returns `persistence_failed`, even though a valid 254-record complete range exists by excluding the partial far-edge Turn.
   
   Please trim or reseed the selection so its far edge starts on a complete Turn within the 256-message/16 MiB range, and reject only when a required Turn itself exceeds that bound. A regression with a 255-record seed intersecting a three-record Turn would cover this case.
   
   > **Automated review notice:** This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] perf(desktop): bound transcript rendering and eliminate scroll LoAF [maka]

Posted by "hqhq1025 (via GitHub)" <gi...@apache.org>.
hqhq1025 commented on code in PR #4206:
URL: https://github.com/apache/maka/pull/4206#discussion_r3887594592


##########
apps/desktop/src/main/desktop-transcript-replica.ts:
##########
@@ -135,7 +140,11 @@ export class DesktopTranscriptReplica {
         replica.#installDurable(durable.messages);
         replica.#hasOlder = durable.nextCursor !== null;
       });
-      replica.#evictToBudget();
+      replica.#evictToBudget(
+        undefined,
+        'oldest',
+        replica.#newestTurnSequence() ?? replica.#durableThrough ?? undefined,

Review Comment:
   [P1] Complete the protected Turn across transcript pages
   
   `protectedSequence` can only protect records already returned by this decoded page. Desktop opens with a 16 KiB transcript bootstrap, and `decodeTranscriptPage()` follows `nextCursor` only far enough to finish the currently fragmented message; it then returns the cursor for older records. Reproducing with a latest Turn containing a prompt plus a 20 KiB assistant message leaves only the assistant in the replica (`hasOlder: true`), so reopening the session renders an incomplete latest Turn. The new oversized-Turn test does not exercise this because its fake decoder returns both records at once despite the real page limit.
   
   Please make initial/range loading continue until the protected Turn boundary is complete (or provide a turn-aware paging primitive) before applying eviction, and cover it with real page-fragment/cursor behavior.
   
   ---
   
   > **Automated review notice:** This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org