Skip to content

feat(agent): persist native session state in workspace snapshots#3333

Open
tatoalo wants to merge 1 commit into
mainfrom
posthog-code/mirror-session-transcript
Open

feat(agent): persist native session state in workspace snapshots#3333
tatoalo wants to merge 1 commit into
mainfrom
posthog-code/mirror-session-transcript

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

Directory resume snapshots preserve /tmp/workspace, while Claude Code and Codex keep their native session state under home-directory config paths. Snapshot resumes therefore lose that native state and fall back to rebuilding history from persisted run logs. That loses in-session compaction, starts resumes with unnecessarily full context, and prevents Codex from using native thread/resume.

Follow-up to #3331.

Changes

  • Add optional POSTHOG_AGENT_STATE_DIR configuration to the agent server.
  • Before session initialization, create durable state directories under that root and symlink the native session-bearing directories:
    • Claude Code: projects, session-env, plans, and todos.
    • Codex: sessions and shell_snapshots.
  • Keep credentials, runtime configuration, installed skills, caches, and other ephemeral state outside the persisted root so resumed sandboxes receive current configuration.
  • Leave existing behavior unchanged unless the sandbox launcher configures the state root. Directory-snapshot launchers can point it at /tmp/workspace/.posthog/agent-state so the existing workspace snapshot captures both agents' native resume state.

@trunk-io

trunk-io Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging to main 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

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 3045c06.

@tatoalo tatoalo force-pushed the posthog-code/mirror-session-transcript branch from 2e5a26b to 6362c07 Compare July 10, 2026 14:15
@tatoalo tatoalo changed the title feat(agent): mirror session transcript into the workspace for snapshot resumes feat(agent): persist native session state in workspace snapshots Jul 10, 2026
@tatoalo tatoalo self-assigned this Jul 10, 2026
@tatoalo tatoalo marked this pull request as ready for review July 10, 2026 14:17
@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(agent): persist native session stat..." | Re-trigger Greptile

Comment thread packages/agent/src/persistent-agent-state.ts Outdated
Comment thread packages/agent/src/persistent-agent-state.ts Outdated
@tatoalo tatoalo force-pushed the posthog-code/mirror-session-transcript branch from 6362c07 to 3045c06 Compare July 10, 2026 14:34
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 10, 2026
@tatoalo tatoalo requested a review from a team July 10, 2026 14:39

@github-actions github-actions 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.

Well-tested feature addition that safely migrates and symlinks native agent session directories into a durable workspace root. Both bot-flagged concerns (data loss on first opt-in, partial symlink state from parallel execution) are addressed in the current diff, and the migration logic is defensive against data loss. No API contract changes, no security issues.

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

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants