Skip to content

perf(sessions): extend transcript eviction grace from 20s to 3min - #76792

Open
arnohillen wants to merge 3 commits into
masterfrom
posthog-code/extend-evict-grace
Open

perf(sessions): extend transcript eviction grace from 20s to 3min#76792
arnohillen wants to merge 3 commits into
masterfrom
posthog-code/extend-evict-grace

Conversation

@arnohillen

Copy link
Copy Markdown
Contributor

Ports PostHog/code#3978 onto products/desktop/ after the desktop import (the code repo's main is frozen). Original commits and authorship are preserved via git am.

Problem

Part 3 of the task re-open latency work (see #76788, #76791). A settled task's parsed transcript is evicted 20 seconds after its view unmounts. Anyone flipping between a few tasks slower than that pays a full disk read plus a three-pass re-parse of the log on every return, which is seconds of main-thread work for large transcripts.

Changes

  • SESSION_EVENT_EVICT_GRACE_MS goes from 20s to 3 minutes. Eligibility is unchanged: only disconnected, settled sessions with no pending prompt are evicted, and the eviction/rehydration machinery is untouched.
  • Exported the constant and the residency test now imports it instead of duplicating the value.
  • Bounds the session budget on logs-only hydration too (the reconcile path missed the budget cap when a task had logs but no session events).

The memory tradeoff is bounded: only transcripts viewed in the last 3 minutes stay warm, and everything else about the residency system (rehydrate on return, retry after failed reads) behaves exactly as before.

How did you test this code?

  • Existing residency suite covers the behavior around the constant (evict after grace, cancel on return, rehydrate from disk, retry on failed read); it now imports the constant so it can't drift.
  • New test for the logs-only reconcile budget bound.
  • Verified in the monorepo from products/desktop/: pnpm install --frozen-lockfile, pnpm typecheck (24/24 packages), and the full @posthog/core vitest suite (247 files, 2970 tests passing).

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

Not applicable (desktop app internals), skip-inkeep-docs label applied.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

This PR is a port of PostHog/code#3978, recreated here by PostHog Code following the /porting-code-prs skill: patch series applied with git am --directory=products/desktop/ (original authorship and commit messages preserved; no lockfile changes in this one). Part 3 of 3 ported PRs on task re-open latency.


Created with PostHog Code

Twenty seconds after navigating away from a settled task, its parsed
transcript is freed and the next visit pays a full log read and re-parse.
That turns ordinary task flipping into repeated multi-second reloads.
Three minutes keeps recently viewed transcripts warm while still freeing
memory for genuinely backgrounded sessions.

Generated-By: PostHog Code
Task-Id: 5d24ea17-aec0-4334-884e-c2639867e260
Reconciling a task with a log_url but no workspace path hydrated the
full transcript into the store without arming the idle-session eviction
that connectToTask and the cloud reconcile branch run, so logs-only
residency was bounded by time alone. With the grace now at 3 minutes
that gap would let a triage pass over many logs-only tasks stack
unbounded transcripts; evict on this path like the others.

Generated-By: PostHog Code
Task-Id: 47cdc119-1c24-42ec-ac36-74c43cdd7f4e
Quantifies the store-side parse a task flip re-pays after eviction,
which is the cost the longer grace avoids. Not run in CI (test globs
only match *.test.*); rerun with pnpm vitest bench in packages/core.

Generated-By: PostHog Code
Task-Id: 47cdc119-1c24-42ec-ac36-74c43cdd7f4e
@arnohillen arnohillen added the skip-inkeep-docs Use this label to skip an Inkeep docs PR in posthog.com label Aug 3, 2026
@arnohillen arnohillen self-assigned this Aug 3, 2026
@trunk-io

trunk-io Bot commented Aug 3, 2026

Copy link
Copy Markdown

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "bench(sessions): add a reproducible rehy..." | Re-trigger Greptile

@trunk-io

trunk-io Bot commented Aug 3, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

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

Labels

skip-inkeep-docs Use this label to skip an Inkeep docs PR in posthog.com

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant