Skip to content

docs(agents): persist durable state to cloud, not localStorage - #3253

Closed
raquelmsmith wants to merge 1 commit into
mainfrom
posthog-code/persist-durable-state-to-cloud-guidance
Closed

docs(agents): persist durable state to cloud, not localStorage#3253
raquelmsmith wants to merge 1 commit into
mainfrom
posthog-code/persist-durable-state-to-cloud-guidance

Conversation

@raquelmsmith

Copy link
Copy Markdown
Member

Problem

PostHog Code has no local database of its own, so agents building persistence default to localStorage or host-local files. That's the wrong home for anything account-scoped: it doesn't survive a reinstall and doesn't follow the user to another machine. This is the same root cause behind the custom-instructions-clearing complaint raised in a Slack thread. The database exists, it's just remote (PostHog cloud, reached through @posthog/api-client), and agents don't reach for it by default.

Changes

Adds a Persisting State section and a Forbidden Patterns entry to AGENTS.md (CLAUDE.md symlinks to it). It's a decision rule, not a blanket ban: localStorage and host-local files stay correct for device-local ephemeral view state (panel sizes, last-open tab, dismissed hints). Anything account-scoped or durable (settings, custom instructions, preferences that should sync) persists to PostHog cloud via @posthog/api-client from a core service.

Refs PostHog/posthog#76201.

How did you test this?

Docs-only change. Nothing to run.

Automatic notifications

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

PostHog Code has no local database, so agents default to localStorage for state that should really live in PostHog cloud. Add a Persisting State section and a Forbidden Patterns entry directing account-scoped/durable state to @posthog/api-client from a core service.

Generated-By: PostHog Code
Task-Id: 9fe2069a-5b32-408f-98e9-f66969b41a30
@raquelmsmith raquelmsmith self-assigned this Jul 8, 2026
@trunk-io

trunk-io Bot commented Jul 8, 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

@raquelmsmith
raquelmsmith marked this pull request as ready for review July 15, 2026 14:47
@raquelmsmith raquelmsmith added the Stamphog This will request an autostamp by stamphog on small changes label Jul 15, 2026
@raquelmsmith
raquelmsmith requested a review from a team July 15, 2026 14:48

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

Purely additive docs clarifying where durable state should be persisted. No code, no logic, no risk.

@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Security Review

The guidance does not distinguish user, project, and organization ownership. Since the current API client mainly uses project/team-scoped persistence, personal settings could be exposed to or overwritten by other team members.

Reviews (1): Last reviewed commit: "docs(agents): persist durable state to c..." | Re-trigger Greptile

Comment thread AGENTS.md

## Persisting State

PostHog Code has no local database. Durable, account-scoped state (settings, custom instructions, saved preferences) persists to PostHog cloud through `@posthog/api-client`, called from a `core` service. It is not `localStorage` and not host-local files. Cloud persistence is what makes state survive a reinstall and sync to the user's other machines.

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.

P1 security Account Scope Maps to Team State

The existing @posthog/api-client persistence methods are primarily scoped to the current project/team, but custom instructions and personal preferences are user-owned. An implementer following this rule can place one user's settings in a team resource, allowing another team member to read or overwrite them. The guidance should require an explicit user, project, or organization ownership scope and an ownership-validating endpoint.

Rule Used: When implementing new features, ensure that owners... (source)

Learned From
PostHog/posthog#31236

Comment thread AGENTS.md

| State | Home |
| --- | --- |
| Account/durable (settings, custom instructions, preferences that should sync) | PostHog cloud via `@posthog/api-client`, from a `core` service |

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.

P2 Prescribed Storage API Is Missing

@posthog/api-client has no general user-scoped persistence method for the listed custom instructions or saved preferences. When an implementer follows this table, the documented destination cannot store that state without first adding a dedicated cloud endpoint and client method, which encourages reuse of an unrelated team-scoped API or leaves the feature without a valid persistence path.

@tatoalo tatoalo 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.

PostHog Code has no local database

We do though, we are rocking sqlite

@raquelmsmith

Copy link
Copy Markdown
Member Author

PostHog Code has no local database

We do though, we are rocking sqlite

@tatoalo what is the purpose of that db?

@tatoalo

tatoalo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@raquelmsmith basically it's the local source of truth of which repos/tasks exist and their git+PR+archive state, your auth tokens & org/project prefs, the Channels tab/window layout, and background-run/session-import bookkeeping so everything needed to restore your local session

@raquelmsmith

Copy link
Copy Markdown
Member Author

Hmm. I don't love that we have two databases. Why is this not in the main PostHog database?

@tatoalo

tatoalo commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@raquelmsmith yeah so mainly due to the fact that we are working on a desktop application, so it's orders of magnitude faster to have local data instead of relying on network hops to reach our DBs + some stuff we really just need locally and don't really need synced back to us. (this unlocks also offline capabilities or slow-network scenarios for some stuff)

@github-actions

Copy link
Copy Markdown

This PR has had no activity for 7 days and has been marked stale. We are moving to the monorepo and tightening PR staleness in preparation, so it will be closed in 7 days if no further activity occurs.

@github-actions github-actions Bot added the stale No recent changes to PR label Jul 28, 2026
@charlesvien

Copy link
Copy Markdown
Member

Closing stale PRs ahead of Friday's monorepo migration. If this is a mistake, rebase and reopen for review.

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

Labels

stale No recent changes to PR Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants