Skip to content

fix(desktop): retain the largest cacheable transcript tail - #96921

Open
helix4u wants to merge 1 commit into
NousResearch:mainfrom
helix4u:fix/desktop-transcript-cache-first-paint
Open

helix4u wants to merge 1 commit into
NousResearch:mainfrom
helix4u:fix/desktop-transcript-cache-first-paint

Conversation

@helix4u

@helix4u helix4u commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

The Desktop transcript cache currently serializes the newest 40 messages, then falls back directly to the newest 8 when that exceeds the 256 KiB cap. If those 8 are still too large, it drops the cache entry even when a smaller complete suffix would fit. That turns a cacheable recent transcript into a cold resume on the next launch.

This replaces the fixed fallback with a bounded binary search for the largest complete message suffix that fits. It preserves the existing 40-message and 256 KiB limits, never truncates a message, and needs at most six serialization attempts.

The durable transcript-tail cache is existing core Desktop behavior introduced by merged PR #89510. This PR fixes that core cache's serializer independently of #96721. PR #96721 is related because it keeps an already-cached transcript visible while the live session resumes; this PR ensures the existing cache does not unnecessarily discard a complete suffix that #96721 could paint.

This is intentionally separate from the transcript-provenance work in #96130. It changes only which bounded payload is retained after the caller has already established the cache identity.

Desktop performance series

This change is one independently reviewable layer of the same Desktop startup and first-interaction performance pass.

The three Python backend PRs share startup files but solve separate stages. Recommended landing order is #96749, then #96750, then #96751, rebasing the next PR only after the preceding one lands. #97032 is an independently reviewable Electron ordering change. The remaining renderer and Bot Mode PRs can also land independently; their effects compose without making cached state authoritative.
This PR owns transcript-cache retention correctness: the existing bounded cache keeps the largest complete suffix that fits instead of dropping a cacheable tail.

Related Issue

No linked issue.

Related work:

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Security fix
  • Documentation update
  • Tests (adding or improving test coverage)
  • Refactor (no behavior change)
  • New skill (bundled or hub)

Changes Made

  • Replace the fixed 8-message retry in apps/desktop/src/store/transcript-tail-cache.ts with a bounded search for the largest complete suffix under the existing cap.
  • Add a regression case where three heavy messages exceed the cap but the newest two fit and must remain cacheable.

How to Test

  1. Run npm run test:ui -- src/store/transcript-tail-cache.test.ts --maxWorkers=4 --reporter=verbose from apps/desktop.
  2. Run npm run typecheck from apps/desktop.
  3. Run npx eslint src/store/transcript-tail-cache.ts src/store/transcript-tail-cache.test.ts from apps/desktop.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass (not applicable to this renderer-only TypeScript change; focused Vitest and Desktop typecheck passed)
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Windows 11

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) - N/A; behavior and bounds are documented beside the serializer
  • I've updated cli-config.yaml.example if I added/changed config keys - N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows - N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide - pure renderer/localStorage logic, no platform-specific path
  • I've updated tool descriptions/schemas if I changed tool behavior - N/A

Screenshots / Logs

Focused result: 15 tests passed, including the new short-heavy transcript regression. Desktop typecheck and affected-file ESLint also passed.

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

fix(desktop): retain the largest cacheable transcript tail

  1. apps/desktop/src/store/transcript-tail-cache.test.ts:54 — The old fixed-8-message retry (take last 8, if oversized drop all) discarded an otherwise cacheable tail when fewer than eight heavy messages fit (e.g. 3×100KB where the newest 2 fit under the cap, but the 8-slice was 300KB and got dropped entirely). The fix iteratively shrinks or keeps the largest suffix under the byte cap (saveTranscriptTail loop), so the newest 2 survive.

  2. The new test keeps the largest complete suffix when fewer than eight heavy messages fit constructs 3×100KB heavies, saves, and asserts loaded.length==2 with IDs short-heavy-1, short-heavy-2 — directly proves the previous zero-result bug and the new suffix-maximizing behavior.

No blocker. The cache cap and eviction remain per-session, no cross-profile leak.

(Comment drafted and posted by Hermes Agent, an AI assistant acting on behalf of @Enough1122.)

@helix4u

helix4u commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator Author
image

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants