Skip to content

perf(session): reuse cached history during hydration - #4681

Merged
reachjalil merged 1 commit into
devfrom
fix/thread-switch-latency
Sep 9, 2026
Merged

reachjalil merged 1 commit into
devfrom
fix/thread-switch-latency

Conversation

@reachjalil

Copy link
Copy Markdown
Member

Summary

Avoid rebuilding unchanged thread history when cached snapshots are reapplied. Rendering previously cached its own UI projection, while hydration reconstructed every message separately. Snapshot-envelope updates also discarded rendering's projection cache, repeating conversion and reconciliation work.

This is a performance follow-up to #4676, not a rollback of the hydration freshness fixes.

Changes

  • Share weak-keyed snapshot-array and source-message projections between rendering and hydration, including unchanged history when only the tail refreshes.
  • Copy affected message parts before applying early streaming deltas so the shared projection remains immutable.
  • Extend existing regression tests for cached revisits, changed-tail freshness, and frozen projections while retaining tool-result, todo, and cross-thread delta protection.

Cache lifetimes, revert behavior, and freshness rules remain unchanged.

Focused measurement

After warm-up, 20 reapplications of a 140-message cached history performed 5,600 source-text projection reads before the change and zero after. The fixture also checks that changed tail content arrives and historical message references remain stable.

This is a deterministic operation count, not a measured frame-time or thread-switch latency improvement.

Verification

Verdict: Incomplete — focused checks passed; runtime journey proof is not yet available.

Checked commit: f1be459ffd161c1774c725b31ae006b88f7659a4, based on 9b5a5913cf22f20f2200f8c536c6abd81ef5667c.

Check Result
pnpm --filter @openwork/app exec bun test --isolate ./tests/session-render-state.test.ts ./tests/session-sync-permissions.test.ts Exit 0; 61 passed, 0 failed, 5,883 assertions
pnpm --filter @openwork/app typecheck Exit 0
git diff --check origin/dev...HEAD Exit 0

The focused regression reproduced redundant history conversion before repair. No full app journey, live frame-time profile, or end-to-end evidence publication was run in this pass. Unit results do not establish runtime proof or that every reported hesitation is resolved.

Remaining runtime verification

Run the existing thread-switch continuity journey on this exact head:

OPENWORK_EVAL_REF=f1be459ffd161c1774c725b31ae006b88f7659a4 pnpm evals:e2e new-split-session

Verify warm and cold history, held refetches, split-session isolation, and ongoing streaming. Measure long-thread switching separately before making an app-level latency claim.

@vercel

vercel Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 9, 2026 5:35pm UTC
3 Skipped Deployments
Project Deployment Actions Updated
openwork-den Skipped Skipped Sep 9, 2026 5:35pm UTC
openwork-diagnostics Skipped Skipped Sep 9, 2026 5:35pm UTC
openwork-landing Skipped Skipped v0 Sep 9, 2026 5:35pm UTC

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (f1be459ffd161c1774c725b31ae006b88f7659a4). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Passed · 1/1 tests · 2/2 assertions · 0 images

Commit f1be459ffd161c1774c725b31ae006b88f7659a4 · selected evidence

Open review report

@reachjalil
reachjalil merged commit 21e275f into dev Sep 9, 2026
27 checks passed

This branch was successfully deployed

1 active and 3 inactive deployments
Preview – openwork-app — f1be459f Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-landing — f1be459f Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-den — f1be459f Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-diagnostics — f1be459f Deployed Sep 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant