perf(agent): skip session JSONL sanitize when file is unchanged - #76791
Merged
Conversation
Every reconnect re-runs sanitizeSessionJsonl, which reads and JSON-parses every line of the native Claude transcript. For long sessions that file reaches tens of MB, adding seconds to each resume. Remember the file stat of the last clean pass and skip the read when it matches. The SDK only appends, which changes size and mtime, so any real change forces a re-parse; staleness only ever causes extra work, not a skipped heal. Generated-By: PostHog Code Task-Id: 5d24ea17-aec0-4334-884e-c2639867e260
Same swap as the conversation caches in #3976: lru-cache v11 is already a workspace dependency, so the hand-rolled capped Map goes away. Generated-By: PostHog Code Task-Id: 5d24ea17-aec0-4334-884e-c2639867e260
The healed path recorded the stat of the renamed file, taken after the rename, so bytes appended by a concurrent writer in that window would have been certified clean and skipped by every later pass. Record the tmp file's stat instead: rename preserves it, and any post-rename append already mismatches it, forcing a re-parse. Generated-By: PostHog Code Task-Id: 47cdc119-1c24-42ec-ac36-74c43cdd7f4e
Not run in CI (test globs only match *.test.*). Numbers land in the PR description; rerun with pnpm vitest bench in packages/agent. Generated-By: PostHog Code Task-Id: 47cdc119-1c24-42ec-ac36-74c43cdd7f4e
Regenerated for the new packages/agent dependency; same resolution the source PR locked (11.2.5). Generated-By: PostHog Code Task-Id: 96e133e1-f570-432f-b8ff-bce4202f5b7f
|
😎 Merged successfully - details. |
This was referenced Aug 3, 2026
Contributor
|
Reviews (1): Last reviewed commit: "chore(agent): add lru-cache to the agent..." | Re-trigger Greptile |
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 |
…lean-jsonl-sanitize
Contributor
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
HostHog preview —
|
dmarticus
approved these changes
Aug 20, 2026
Contributor
Author
|
/trunk merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports PostHog/code#3977 onto
products/desktop/after the desktop import (the code repo'smainis frozen). Original commits and authorship are preserved viagit am.Problem
Part 2 of the task re-open latency work (see #76788). Every agent reconnect runs
sanitizeSessionJsonlover the native Claude transcript (~/.claude/projects/.../<sessionId>.jsonl): a full read plus aJSON.parseper line. These files grow to tens of MB on long sessions, so every re-open of a cold task pays seconds of parse work before the session can resume, even when the file was already verified clean moments earlier.Changes
lru-cache, already a workspace dependency), and return early when the current stat matches.Compared to the source PR, the only monorepo-specific change is the lockfile: instead of carrying the source
pnpm-lock.yamlhunk blindly, theproducts/desktop/pnpm-lock.yamlimporter entry was regenerated for the newpackages/agentdependency (same resolution,lru-cache@11.2.5).How did you test this code?
products/desktop/:pnpm install --frozen-lockfile,pnpm typecheck(24/24 packages), and the full@posthog/agentvitest suite (100 files, 1771 tests passing).Automatic notifications
Docs update
Not applicable (desktop app internals),
skip-inkeep-docslabel applied.🤖 Agent context
Autonomy: Human-driven (agent-assisted)
This PR is a port of PostHog/code#3977, 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), source lockfile hunk excluded and re-derived against the monorepo lockfile instead. Part 2 of 3 ported PRs on task re-open latency.Created with PostHog Code