Skip to content

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

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

perf(sessions): extend transcript eviction grace from 20s to 3min#76792
arnohillen wants to merge 5 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

@scheduled-actions-posthog

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the stale label – otherwise this will be closed in another week. If you want to permanently keep it open, use the waiting label.

@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

React Doctor found 1 issue in 1 file · 1 warning.

1 warning

packages/ui/src/features/sessions/components/SessionView.tsx

Reviewed by React Doctor for commit 49406a2.

@hosthog

hosthog Bot commented Aug 16, 2026

Copy link
Copy Markdown

HostHog preview — posthog-desktop-web

Latest build (49406a2): https://e8fa4c59982a42eb86725067736dcd5b.hosthog.dev

Employee-gated; every push gets a fresh URL whose content never changes. All previews stop serving when the PR closes.

@scheduled-actions-posthog

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the stale label – otherwise this will be closed in another week. If you want to permanently keep it open, use the waiting label.

Keeps the 3 min transcript eviction grace alongside the new resident
background transcript cap from master.

Generated-By: PostHog Desktop
Task-Id: 341e450d-132c-42dd-abf2-52b22f99c3f6
@github-actions

Copy link
Copy Markdown
Contributor

🤖 CI report

Trunk lane — non-backend lane

This PR is assigned to the non-backend lane. It does not run backend Python tests and may merge in parallel with PRs in other lanes.

@arnohillen arnohillen added waiting Prevents stale-bot from marking the PR as stale. stamphog Request AI approval (no full review) labels Sep 4, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved.

Contained perf tuning to a desktop session-eviction timer plus a bounded-budget fix on the logs-only reconcile path, with new/updated tests covering both; no risky territory (no auth, billing, API, CI, deps, or data migration) so no independent assurance is required despite cross-team authorship.

  • 👍 on the PR from greptile-apps[bot].
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 91L, 2F substantive, 125L/4F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1c-medium (125L, 4F, single-area, perf)
stamphog 2.0.0b4 .stamphog/policy.yml @ 49406a2 · reviewed head 49406a2

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 stamphog Request AI approval (no full review) waiting Prevents stale-bot from marking the PR as stale.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant